T
- Type of point, currently can be Node or Vertpublic abstract class Shape<T extends PointsList<T>> extends Object implements IQuimpSerialize, Iterable<T>
This abstract class keeps head point of Shape and control number of points in Shape, allows for inserting points to the Shape. Generally assumes that Shape is closed, so PointsList is looped
Modifier and Type | Field and Description |
---|---|
static int |
BAD_HEAD
List contains node marked as head but without proper flag or null.
|
static int |
BAD_LINKING
List is not closed.
|
static int |
BAD_NUM_POINTS
Number of list elements does match to the number stored in
POINTS . |
protected ExtendedVector2d |
centroid
Centroid point of the Shape.
|
protected T |
head
first node in double linked list, always maintained, initialised in constructor.
|
static int |
LIST_OK
List is correct: has head, looped.
|
static int |
MAX_NODES
Max number of nodes allowed in Shape.
|
protected int |
nextTrackNumber
Next node ID's.
|
static int |
NO_HEAD
No head found among first 10000.
|
protected int |
POINTS
number of points.
|
Constructor and Description |
---|
Shape()
Default constructor, creates empty Shape.
|
Shape(double[] x,
double[] y,
T elInst,
boolean inner)
Create Shape of elements elInst with coordinates x and y.
|
Shape(List<? extends Tuple2d> p,
T elInst,
boolean inner)
Create Shape of elements elInst with coordinates p.
|
Shape(Shape<T> src)
Copy constructor.
|
Shape(Shape<T> src,
T destType)
Conversion and copy constructor.
|
Shape(T h)
Create Shape from one point, created Shape will be looped.
|
Shape(T h,
int n)
Create Shape from existing list of points (can be one point as well).
|
Modifier and Type | Method and Description |
---|---|
void |
addPoint(T n)
Add node before head node assuring that list is a closed loop.
|
void |
afterSerialize()
This method is called after restoring object from JSON but before returning the object.
|
Roi |
asFloatRoi()
Return current Shape as ImageJ float number polygon.
|
Roi |
asIntRoi()
Return current Shape as ImageJ ROI object.
|
List<Point2d> |
asList()
Returns current Shape as list of points (copy).
|
Polygon |
asPolygon()
Return current Shape as Java polygon.
|
void |
beforeSerialize()
This method is called just before JSON is generated.
|
void |
calcCentroid()
Calculate centroid of Shape.
|
T |
checkIsHead()
Check if there is a head node.
|
void |
clearElements()
Clear Elements array that stores list of {Node, Snake} in ArrayList form.
|
int |
countPoints()
Count number of Points in Shape.
|
boolean |
equals(Object obj) |
void |
freezeAll()
Freeze all nodes in Shape.
|
ExtendedVector2d |
getCentroid()
Getter for centroid.
|
Rectangle2D.Double |
getDoubleBounds()
Get bounds of Shape.
|
T |
getHead()
Get head of current Shape.
|
double |
getLength()
Add up lengths between all verts.
|
int |
getNumPoints()
Get number of points in Shape.
|
int |
hashCode() |
T |
insertPoint(T n,
T ne)
Insert point ne after point n.
|
Iterator<T> |
iterator() |
void |
makeAntiClockwise()
Make Shape anti-clockwise.
|
void |
removePoint(T n,
boolean inner)
Remove selected point from list.
|
void |
reverseShape()
Turn Shape back anti clockwise.
|
void |
scale(double stepSize)
Scale current Shape by stepSize.
|
void |
setHead(int nodeIndex)
Assign head to node nodeIndex.
|
void |
setHead(T newHead)
Set head of the shape to given element of the list.
|
void |
setHeadClosestTo(ExtendedVector2d phead)
Set head to element closest to given coordinates.
|
void |
setPositions()
Calculate position of Shape element expressed as distance of element on Shape perimeter from
head.
|
String |
toString()
Print Shape nodes.
|
void |
unfreezeAll()
Unfreeze all nodes in Shape.
|
void |
updateNormals(boolean inner)
Update all node normals.
|
int |
validateShape()
Validate correctness of the Shape.
|
double[] |
xtoArr()
Convert coordinate of Shape to array.
|
double[] |
ytoArr()
Convert coordinate of Shape to array.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
protected int nextTrackNumber
protected T extends PointsList<T> head
protected int POINTS
protected ExtendedVector2d centroid
calcCentroid()
called. after change of the
Shape and also in afterSerialize()
and beforeSerialize()
public static final int MAX_NODES
public static final int LIST_OK
validateShape()
,
Constant Field Valuespublic static final int BAD_HEAD
validateShape()
,
Constant Field Valuespublic static final int NO_HEAD
validateShape()
public static final int BAD_LINKING
validateShape()
public static final int BAD_NUM_POINTS
POINTS
.
This can happen when Shape(PointsList, int)
is used. See validateShape()
.
public Shape()
public Shape(T h, int n)
List of points must be looped.
h
- head point of the listn
- number of points in the listvalidateShape()
public Shape(T h)
h
- head point of the listpublic Shape(Shape<T> src)
src
- source Shape to copy fromRuntimeException
- when T does no have copy constructorpublic Shape(Shape<T> src, T destType)
Converts between different types of PointsList. src is source Shape of type T to
convert to other Shape based on PointsList other type (but in general extended from
PointsList) Typical approach is to convert Snake to Outline (Node
to
Vert
).
Can be used as copy constructor.
src
- input Shape to convert.destType
- object of base node that PointsList is composed fromRuntimeException
- when T does no have copy constructorpublic Shape(List<? extends Tuple2d> p, T elInst, boolean inner)
p
- list of coordinateselInst
- instance of requested element typeinner
- direction of normales. For Outlines set to true, for snakes to
BOA_.qState.segParam.expandSnakepublic Shape(double[] x, double[] y, T elInst, boolean inner)
x
- coordinatesy
- coordinateselInst
- instance of requested element typeinner
- direction of normals. For Outlines set to true, for snakes to
BOA_.qState.segParam.expandSnakepublic String toString()
public ExtendedVector2d getCentroid()
public void calcCentroid()
This method modifies internal field centroid.
public Rectangle2D.Double getDoubleBounds()
public double getLength()
public void setPositions()
First element has position 0, last 1. Element at position 0.5 is in half length of perimeter
public void updateNormals(boolean inner)
inner
- Direction of normals. If false they are set outwards the shape.public T getHead()
public void setHead(T newHead)
Element must be referenced on list.
newHead
- reference of new head.public void setHead(int nodeIndex)
nodeIndex
- Index of node of new headpublic void setHeadClosestTo(ExtendedVector2d phead)
phead
- point to set head closestpublic T checkIsHead()
Traverse along first 10000 elements and check if any of them is head.
public int validateShape()
Check if Shape has head, it is correct and all nodes have previous and next neighbour.
public void addPoint(T n)
If initial list condition is defined in such way:
head = new Node(0); //make a dummy head node NODES = 1; FROZEN = 0;
head.setPrev(head); // link head to itself head.setNext(head);
head.setHead(true);
The addPoint will produce closed bidirectional linked list. From first Node it is
possible to reach last one by calling
PointsList.getNext()
and from the last one, first should be accessible by calling
PointsList.getPrev()
.
For initialisation only.
n
- Node to be added to listpublic T insertPoint(T n, T ne)
n
- reference pointne
- point to be inserted after reference.public void removePoint(T n, boolean inner)
Check if removed point was head and if it was, the new head is randomly selected. Neighbors are linked together. There is no protection here against removing last node at all.
n
- point to removeinner
- direction of normal vectors of ShapeShape(List, PointsList, boolean)
public int getNumPoints()
public void makeAntiClockwise()
public void reverseShape()
public Polygon asPolygon()
public List<Point2d> asList()
public Roi asFloatRoi()
public Roi asIntRoi()
public int countPoints()
Number of Points is stored in local POINTS field as well. This method can verify if that field contains correct value.
public void unfreezeAll()
public void freezeAll()
public void scale(double stepSize)
Direction of scaling depends on direction of normals.
stepSize
- incrementPointsList.updateNormale(boolean)
,
calcCentroid()
,
setPositions()
,
PointsList.setClockwise(boolean)
public double[] xtoArr()
public double[] ytoArr()
public Iterator<T> iterator()
iterator
in interface Iterable<T extends PointsList<T>>
public void beforeSerialize()
IQuimpSerialize
beforeSerialize
in interface IQuimpSerialize
Serializer.save(String)
public void afterSerialize() throws Exception
IQuimpSerialize
afterSerialize
in interface IQuimpSerialize
Exception
- from wrapped object in any problem. This is implementation dependentSerializer.load(String)
public void clearElements()
It should be called after every serialisation.
Copyright © 2002–2019 Department of Computer Science, Warwick University. All rights reserved.