public class Snake extends Shape<Node> implements IQuimpSerialize
Node list may be modified externally but then method such as findNode(), updateNormals(), calcCentroid() should be called to update internal fields of Snake. If number of nodes changes it is recommended to create new object.
Modifier and Type | Field and Description |
---|---|
boolean |
alive
true if snake is alive Changed during segmentation and user interaction.
|
double |
startingNnodes
how many nodes at start of segmentation.
|
BAD_HEAD, BAD_LINKING, BAD_NUM_POINTS, centroid, head, LIST_OK, MAX_NODES, nextTrackNumber, NO_HEAD, POINTS
Constructor and Description |
---|
Snake()
Construct empty Snake object.
|
Snake(double[] x,
double[] y,
int id)
Construct Snake object from X and Y arrays.
|
Snake(List<? extends Tuple2d> list,
int id)
Construct Snake object from list of nodes.
|
Snake(Node h,
int n,
int id)
Create a snake from existing linked list (at least one head node).
|
Snake(PolygonRoi r,
int id)
Initialises snake from PolyginRoi.
|
Snake(Roi r,
int id,
boolean direct)
Create snake from ROI
|
Snake(Snake src)
Copy constructor.
|
Snake(Snake src,
int id)
Copy constructor with new ID.
|
Modifier and Type | Method and Description |
---|---|
void |
afterSerialize()
Call super and then oo Snake related actions
|
void |
beforeSerialize()
Call super and then oo Snake related actions
|
void |
blowup()
Deprecated.
|
void |
correctDistance(boolean shiftNewNode)
Ensure nodes are between maxDist and minDist apart, add remove nodes as required.
|
void |
cutIntersects()
Cut out intersects.
|
void |
cutLoops()
Cut out a loop Insert a new node at cut point.
|
void |
editSnake()
Edits the snake.
|
boolean |
equals(Object obj) |
void |
freezeNode(Node n)
Freeze a specific node.
|
Rectangle |
getBounds()
Gets bounds of snake.
|
int |
getSnakeID()
Get ID of Snake.
|
int |
hashCode() |
void |
implode()
Implode.
|
Node |
insertNode(Node n)
Insert default Node after Node v.
|
boolean |
isFrozen()
Check if all nodes are frozen.
|
void |
printSnake()
Prints the snake.
|
void |
removeNode(Node n)
Remove selected node from list.
|
void |
scaleSnake(double amount,
double stepRes,
boolean correct)
Scale current Snake by amount in increments of stepSize.
|
protected void |
setSnakeID(int snakeID)
Change current snakeID.
|
String |
toString()
Print Shape nodes.
|
void |
unfreezeAll()
Unfreeze all nodes.
|
void |
unfreezeNode(Node n)
Unfreeze a specific node.
|
addPoint, asFloatRoi, asIntRoi, asList, asPolygon, calcCentroid, checkIsHead, clearElements, countPoints, freezeAll, getCentroid, getDoubleBounds, getHead, getLength, getNumPoints, insertPoint, iterator, makeAntiClockwise, removePoint, reverseShape, scale, setHead, setHead, setHeadClosestTo, setPositions, updateNormals, validateShape, xtoArr, ytoArr
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public boolean alive
snake is killed by SnakeHandler.kill()
method usually called after unsuccessful
segmentation.
public double startingNnodes
public Snake(Node h, int n, int id)
List is referenced only not copied Behaviour of this method was changed. Now it does not make copy of Node. In old approach there was dummy node deleted in this constructor.
h
- Node of listn
- Number of nodesid
- Unique snake ID related to object being segmented.public Snake(Snake src, int id)
src
- Snake to be duplicatedid
- New idpublic Snake(Snake src)
src
- to be duplicatedpublic Snake(Roi r, int id, boolean direct) throws BoaException
r
- ROI with object to be segmentedid
- Unique ID of snake related to object being segmented.direct
- directBoaException
- on wrong number of polygon pointspublic Snake(PolygonRoi r, int id) throws BoaException
r
- polygon to initialise Snakeid
- id of SnakeBoaException
- on wrong number of polygon pointsSnake(Roi, int, boolean)
public Snake(List<? extends Tuple2d> list, int id) throws BoaException
list
- list of nodes as Vector2did
- id of SnakeBoaException
- on wrong number of array points (<3).public Snake(double[] x, double[] y, int id) throws BoaException
x
- x coordinates of nodesy
- y coordinates of nodesid
- id of SnakeBoaException
- on wrong number of array points (<3).public Snake()
public int getSnakeID()
protected void setSnakeID(int snakeID)
snakeID
- the snakeID to setpublic void printSnake()
public void unfreezeAll()
unfreezeAll
in class Shape<Node>
public void freezeNode(Node n)
n
- Node to freezepublic void unfreezeNode(Node n)
n
- Node to unfreezepublic boolean isFrozen()
public final void removeNode(Node n) throws BoaException
Perform check if removed node was head and if it was, the new head is randomly selected. Neighbors are linked together
n
- Node to removeBoaException
- on insufficient number of nodespublic void implode() throws BoaException
BoaException
- if oval could not be initialized.@Deprecated public void blowup() throws Exception
Exception
- the exceptionpublic void scaleSnake(double amount, double stepRes, boolean correct) throws BoaException
Updates centroid and normalised position.
amount
- scalestepRes
- incrementcorrect
- if true it corrects the node distanceBoaException
- if node distance correction failedShape.scale(double)
,
Outline.scaleOutline(double, double, double, double)
public void cutLoops()
public void cutIntersects()
cutLoops()
,
Outline.cutSelfIntersects()
public void correctDistance(boolean shiftNewNode) throws BoaException
shiftNewNode
- shiftNewNodeBoaException
- when number of nodes is less than 3 after removalpublic Node insertNode(Node n)
n
- Node to insert new Node afterpublic Rectangle getBounds()
public void editSnake()
public void beforeSerialize()
beforeSerialize
in interface IQuimpSerialize
beforeSerialize
in class Shape<Node>
Shape.beforeSerialize()
public void afterSerialize() throws Exception
afterSerialize
in interface IQuimpSerialize
afterSerialize
in class Shape<Node>
Exception
- from wrapped object in any problem. This is implementation dependentShape.afterSerialize()
Copyright © 2002–2019 Department of Computer Science, Warwick University. All rights reserved.