public class TriMesh
extends java.lang.Object
implements java.io.Serializable
Each tri in the mesh references three nodes. Depending on the context, these three nodes are labelled as 0, 1, and 2, or A, B, and C, in counter-clockwise (CCW) order. Here is a picture:
2(C)
*
/ \
/ \
0(A)*-------* 1(B)
Each tri has up to three neighbors (nabors), corresponding to the three
edges of the tri. Tris on the convex hull of the mesh have one or more
null nabors. Each nabor is labelled by the node opposite its edge. For
example, the tri nabor 0 (or A) is opposite the node 0 (or A).
Nodes are constructed with float coordinates that are stored internally as perturbed doubles. This perturbation minimizes the likelihood that three or more nodes are exactly co-linear, or that four or more nodes lie exactly on the circumcircle of any tri in the mesh. Only the least significant bits of the double coordinates are altered, so that casting the perturbed doubles to floats always yields the float coordinates with which nodes are constructed.
Modifier and Type | Class and Description |
---|---|
static class |
TriMesh.Edge
A directed edge.
|
static interface |
TriMesh.EdgeIterator
Type-safe iterator for edges.
|
static class |
TriMesh.EdgeList
A dynamically growing list of edges.
|
static class |
TriMesh.Node
A node, which may be added or removed from the mesh.
|
static interface |
TriMesh.NodeIterator
A type-safe iterator for nodes.
|
static class |
TriMesh.NodeList
A dynamically growing list of nodes.
|
static interface |
TriMesh.NodeListener
Implemented to monitor the addition and removal of nodes in the mesh.
|
static interface |
TriMesh.NodePropertyMap
Implemented by maps that associate property values with mesh nodes.
|
static class |
TriMesh.NodeStepList
A dynamically growing list of nodes and steps.
|
static class |
TriMesh.PointLocation
The location of a point relative to the mesh.
|
static class |
TriMesh.Tri
One triangle (tri) in the mesh.
|
static interface |
TriMesh.TriIterator
A type-safe iterator for tris.
|
static class |
TriMesh.TriList
A dynamically growing list of tris.
|
static interface |
TriMesh.TriListener
Implemented to monitor the addition and removal of tris in the mesh.
|
Constructor and Description |
---|
TriMesh()
Constructs an empty mesh.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addNode(TriMesh.Node node)
Adds a node to the mesh, if the mesh does not already contain
a node with the same (x,y) coordinates.
|
void |
addNodeListener(TriMesh.NodeListener nl)
Adds the specified node listener.
|
void |
addTriListener(TriMesh.TriListener tl)
Adds the specified tri listener.
|
void |
clearNodeMarks()
Clears all node marks, so that no node is marked.
|
void |
clearTriMarks()
Clears all tri marks, so that no tri is marked.
|
int |
countNodes()
Returns the number of nodes in the mesh.
|
int |
countTris()
Returns the number of tris in the mesh.
|
void |
disableOuterBox()
Disables outer box testing, without altering the outer box.
|
void |
enableOuterBox()
Enables outer box testing.
|
TriMesh.Edge |
findEdge(TriMesh.Node na,
TriMesh.Node nb)
Finds an edge of a tri in the mesh that references the specified nodes.
|
TriMesh.Node |
findNodeNearest(float x,
float y)
Finds the node nearest to the point with specified coordinates.
|
TriMesh.Node |
findNodeNearestSlow(float x,
float y)
Finds the node nearest to the point with specified coordinates.
|
TriMesh.Tri |
findTri(TriMesh.Node node)
Returns a tri that references the specified node.
|
TriMesh.Tri |
findTri(TriMesh.Node na,
TriMesh.Node nb)
Returns a tri that references the specified nodes.
|
TriMesh.Tri |
findTri(TriMesh.Node na,
TriMesh.Node nb,
TriMesh.Node nc)
Returns a tri that references the specified nodes.
|
TriMesh.Edge[] |
getEdgeNabors(TriMesh.Node node)
Gets a new array containing the edge nabors of the specified node.
|
void |
getEdgeNabors(TriMesh.Node node,
TriMesh.EdgeList nabors)
Stores the edge nabors of the specified node in the specified array.
|
TriMesh.EdgeIterator |
getEdgesOnHull()
Gets an iterator for all edges on the hull of the mesh.
|
TriMesh.Node[] |
getNodeNabors(TriMesh.Node node)
Gets an array of node nabors of the specified node.
|
TriMesh.NodeStepList |
getNodeNabors(TriMesh.Node node,
int stepMax)
Finds all node nabors that are within the specified maximum
number of steps of the specified node.
|
void |
getNodeNabors(TriMesh.Node node,
TriMesh.NodeList nabors)
Appends the node nabors of the specified node to the specified list.
|
TriMesh.NodePropertyMap |
getNodePropertyMap(java.lang.String name)
Gets the node property map with the specified name.
|
java.lang.String[] |
getNodePropertyMapNames()
Returns the names of the node property maps.
|
TriMesh.NodeIterator |
getNodes()
Gets an iterator for all nodes in the mesh.
|
TriMesh.Tri[] |
getTriNabors(TriMesh.Edge edge)
Gets an array of tri nabors of the specified edge.
|
void |
getTriNabors(TriMesh.Edge edge,
TriMesh.TriList nabors)
Appends the tri nabors of the specified edge to the specified list.
|
TriMesh.Tri[] |
getTriNabors(TriMesh.Node node)
Gets an array of tri nabors of the specified node.
|
void |
getTriNabors(TriMesh.Node node,
TriMesh.TriList nabors)
Appends the tri nabors of the specified node to the specified list.
|
TriMesh.TriIterator |
getTris()
Gets an iterator for all tris in the mesh.
|
long |
getVersion()
Gets the version number for the mesh.
|
boolean |
hasNodePropertyMap(java.lang.String name)
Determines whether this mesh has a node property map with specified name.
|
protected void |
init()
Initialization for use in constructers and serialization (readObject).
|
boolean |
isInner(TriMesh.Edge edge)
Determines whether the specified edge is an inner edge.
|
boolean |
isInner(TriMesh.Node node)
Determines whether the specified node is an inner node.
|
boolean |
isInner(TriMesh.Tri tri)
Determines whether the specified tri is an inner tri.
|
boolean |
isMarked(TriMesh.Node node)
Determines whether the specified node is marked (red).
|
boolean |
isMarked(TriMesh.Tri tri)
Determines whether the specified tri is marked (red).
|
boolean |
isMarkedBlue(TriMesh.Node node)
Determines whether the specified node is marked blue.
|
boolean |
isMarkedBlue(TriMesh.Tri tri)
Determines whether the specified tri is marked blue.
|
boolean |
isMarkedRed(TriMesh.Node node)
Determines whether the specified node is marked red.
|
boolean |
isMarkedRed(TriMesh.Tri tri)
Determines whether the specified tri is marked red.
|
boolean |
isOuter(TriMesh.Edge edge)
Determines whether the specified edge is an outer edge.
|
boolean |
isOuter(TriMesh.Node node)
Determines whether the specified node is an outer node.
|
boolean |
isOuter(TriMesh.Tri tri)
Determines whether the specified tri is an outer tri.
|
TriMesh.PointLocation |
locatePoint(float x,
float y)
Locates a point with specified coordinates.
|
void |
mark(TriMesh.Node node)
Marks the specified node (red).
|
void |
mark(TriMesh.Tri tri)
Marks the specified tri (red).
|
void |
markBlue(TriMesh.Node node)
Marks the specified node blue.
|
void |
markBlue(TriMesh.Tri tri)
Marks the specified tri blue.
|
void |
markRed(TriMesh.Node node)
Marks the specified node red.
|
void |
markRed(TriMesh.Tri tri)
Marks the specified tri red.
|
boolean |
moveNode(TriMesh.Node node,
float x,
float y)
Moves a node in the mesh to the specified (x,y) coordinates.
|
boolean |
removeNode(TriMesh.Node node)
Removes a node from the mesh, if the node is in the mesh.
|
void |
removeNodeListener(TriMesh.NodeListener nl)
Removes the specified node listener.
|
void |
removeTriListener(TriMesh.TriListener tl)
Removes the specified tri listener.
|
void |
setOuterBox(float xmin,
float ymin,
float xmax,
float ymax)
Sets and enables the outer box for this mesh.
|
void |
validate()
Validates the internal consistency of the mesh.
|
public TriMesh.NodePropertyMap getNodePropertyMap(java.lang.String name)
name
- the property map name.public boolean hasNodePropertyMap(java.lang.String name)
name
- the property map name.public java.lang.String[] getNodePropertyMapNames()
getNodePropertyMap(String)
public void addNodeListener(TriMesh.NodeListener nl)
nl
- the node listener.public void removeNodeListener(TriMesh.NodeListener nl)
nl
- the node listener.public void addTriListener(TriMesh.TriListener tl)
tl
- the tri listener.public void removeTriListener(TriMesh.TriListener tl)
tl
- the tri listener.public int countNodes()
public int countTris()
public long getVersion()
public boolean addNode(TriMesh.Node node)
node
- the node to add.public boolean removeNode(TriMesh.Node node)
node
- the node to remove.public boolean moveNode(TriMesh.Node node, float x, float y)
node
- a node in the mesh.x
- the x coordinate of the moved node.y
- the y coordinate of the moved node.public TriMesh.Node findNodeNearest(float x, float y)
x
- the x coordinate.y
- the y coordinate.public TriMesh.Edge findEdge(TriMesh.Node na, TriMesh.Node nb)
na
- a node.nb
- a node.public TriMesh.Tri findTri(TriMesh.Node node)
node
- the node.public TriMesh.Tri findTri(TriMesh.Node na, TriMesh.Node nb)
na
- a node.nb
- a node.public TriMesh.Tri findTri(TriMesh.Node na, TriMesh.Node nb, TriMesh.Node nc)
na
- a node.nb
- a node.nc
- a node.public TriMesh.PointLocation locatePoint(float x, float y)
x
- the x coordinate.y
- the y coordinate.TriMesh.PointLocation
.public TriMesh.NodeIterator getNodes()
public TriMesh.TriIterator getTris()
public TriMesh.EdgeIterator getEdgesOnHull()
public TriMesh.Node[] getNodeNabors(TriMesh.Node node)
node
- the node for which to get nabors.public void getNodeNabors(TriMesh.Node node, TriMesh.NodeList nabors)
node
- the node for which to get nabors.nabors
- the list to which nabors are appended.public TriMesh.NodeStepList getNodeNabors(TriMesh.Node node, int stepMax)
node
- the node for which to get nabors.stepMax
- the maximum number of steps; must not exceed 256.public TriMesh.Tri[] getTriNabors(TriMesh.Node node)
node
- the node for which to get nabors.public void getTriNabors(TriMesh.Node node, TriMesh.TriList nabors)
node
- the node for which to get nabors.nabors
- the list to which nabors are appended.public TriMesh.Tri[] getTriNabors(TriMesh.Edge edge)
edge
- the edge for which to get nabors.public void getTriNabors(TriMesh.Edge edge, TriMesh.TriList nabors)
edge
- the edge for which to get nabors.nabors
- the list to which nabors are appended.public TriMesh.Edge[] getEdgeNabors(TriMesh.Node node)
node
- the node for which to get nabors.public void getEdgeNabors(TriMesh.Node node, TriMesh.EdgeList nabors)
This method is the most efficient way to get the nabors, because it does not create a new array. However, it throws an exception if the specified array has insufficient length to store all of the nabors.
node
- the node for which to get nabors.nabors
- the array in which to store the nabors.public void setOuterBox(float xmin, float ymin, float xmax, float ymax)
The outer box is typically set to be slightly larger than the bounding box of the convex hull of the mesh, so that outer tris lie near the convex hull. These outer tris tend to have poor quality, and are often ignored in iterations over tris.
xmin
- minimum x coordinate of box.ymin
- minimum y coordinate of box.xmax
- maximum x coordinate of box.ymax
- maximum y coordinate of box.public void enableOuterBox()
public void disableOuterBox()
public boolean isInner(TriMesh.Node node)
public boolean isOuter(TriMesh.Node node)
public boolean isInner(TriMesh.Tri tri)
public boolean isOuter(TriMesh.Tri tri)
public boolean isInner(TriMesh.Edge edge)
public boolean isOuter(TriMesh.Edge edge)
public final void mark(TriMesh.Node node)
node
- the node to mark (red).public final void markRed(TriMesh.Node node)
node
- the node to mark red.public final void markBlue(TriMesh.Node node)
node
- the node to mark blue.public final boolean isMarked(TriMesh.Node node)
node
- the node.public final boolean isMarkedRed(TriMesh.Node node)
node
- the node.public final boolean isMarkedBlue(TriMesh.Node node)
node
- the node.public void clearNodeMarks()
public final void mark(TriMesh.Tri tri)
tri
- the tri to mark (red).public final void markRed(TriMesh.Tri tri)
tri
- the tri to mark red.public final void markBlue(TriMesh.Tri tri)
tri
- the tri to mark blue.public final boolean isMarked(TriMesh.Tri tri)
tri
- the tri.public final boolean isMarkedRed(TriMesh.Tri tri)
tri
- the tri.public final boolean isMarkedBlue(TriMesh.Tri tri)
tri
- the tri.public void clearTriMarks()
public void validate()
java.lang.RuntimeException
- if the mesh is invalid.protected void init()
public TriMesh.Node findNodeNearestSlow(float x, float y)