JTS Topology Suite version 1.12

com.vividsolutions.jts.triangulate.quadedge
Class QuadEdgeTriangle

java.lang.Object
  extended by com.vividsolutions.jts.triangulate.quadedge.QuadEdgeTriangle

public class QuadEdgeTriangle
extends java.lang.Object

Models a triangle formed from QuadEdges in a QuadEdgeSubdivision which forms a triangulation. The class provides methods to access the topological and geometric properties of the triangle and its neighbours in the triangulation. Triangle vertices are ordered in CCW orientation in the structure.

QuadEdgeTriangles support having an external data attribute attached to them. Alternatively, this class can be subclassed and attributes can be defined in the subclass. Subclasses will need to define their own BuilderVisitor class and createOn method.

Version:
1.0
Author:
Martin Davis

Constructor Summary
QuadEdgeTriangle(QuadEdge[] edge)
          Creates a new triangle from the given edges.
 
Method Summary
 boolean contains(Coordinate pt)
           
static boolean contains(QuadEdge[] tri, Coordinate pt)
          Tests whether the point pt is contained in the triangle defined by 3 QuadEdgees.
static boolean contains(Vertex[] tri, Coordinate pt)
          Tests whether the point pt is contained in the triangle defined by 3 Vertexes.
static java.util.List createOn(QuadEdgeSubdivision subdiv)
          Creates QuadEdgeTriangles for all facets of a QuadEdgeSubdivision representing a triangulation.
 QuadEdgeTriangle getAdjacentTriangleAcrossEdge(int edgeIndex)
           
 int getAdjacentTriangleEdgeIndex(int i)
           
 Coordinate getCoordinate(int i)
           
 Coordinate[] getCoordinates()
           
 java.lang.Object getData()
          Gets the external data value for this triangle.
 QuadEdge getEdge(int i)
           
 int getEdgeIndex(QuadEdge e)
          Gets the index for the given edge of this triangle
 int getEdgeIndex(Vertex v)
          Gets the index for the edge that starts at vertex v.
 QuadEdge[] getEdges()
           
 void getEdgeSegment(int i, LineSegment seg)
           
 Polygon getGeometry(GeometryFactory fact)
           
 QuadEdgeTriangle[] getNeighbours()
          Gets the neighbours of this triangle.
 java.util.List getTrianglesAdjacentToVertex(int vertexIndex)
          Gets the triangles which are adjacent (include) to a given vertex of this triangle.
 Vertex getVertex(int i)
           
 Vertex[] getVertices()
          Gets the vertices for this triangle.
 boolean isBorder()
          Tests whether this triangle is adjacent to the outside of the subdivision.
 boolean isBorder(int i)
           
 boolean isLive()
           
 void kill()
           
static int nextIndex(int index)
          Finds the next index around the triangle.
 void setData(java.lang.Object data)
          Sets the external data value for this triangle.
static Geometry toPolygon(QuadEdge[] e)
           
static Geometry toPolygon(Vertex[] v)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QuadEdgeTriangle

public QuadEdgeTriangle(QuadEdge[] edge)
Creates a new triangle from the given edges.

Parameters:
edge - an array of the edges of the triangle in CCW order
Method Detail

createOn

public static java.util.List createOn(QuadEdgeSubdivision subdiv)
Creates QuadEdgeTriangles for all facets of a QuadEdgeSubdivision representing a triangulation. The data attributes of the QuadEdges in the subdivision will be set to point to the triangle which contains that edge. This allows tracing the neighbour triangles of any given triangle.

Parameters:
subdiv - the QuadEdgeSubdivision to create the triangles on.
Returns:
a List of the created QuadEdgeTriangles

contains

public static boolean contains(Vertex[] tri,
                               Coordinate pt)
Tests whether the point pt is contained in the triangle defined by 3 Vertexes.

Parameters:
tri - an array containing at least 3 Vertexes
pt - the point to test
Returns:
true if the point is contained in the triangle

contains

public static boolean contains(QuadEdge[] tri,
                               Coordinate pt)
Tests whether the point pt is contained in the triangle defined by 3 QuadEdgees.

Parameters:
tri - an array containing at least 3 QuadEdges
pt - the point to test
Returns:
true if the point is contained in the triangle

toPolygon

public static Geometry toPolygon(Vertex[] v)

toPolygon

public static Geometry toPolygon(QuadEdge[] e)

nextIndex

public static int nextIndex(int index)
Finds the next index around the triangle. Index may be an edge or vertex index.

Parameters:
index -
Returns:

setData

public void setData(java.lang.Object data)
Sets the external data value for this triangle.

Parameters:
data - an object containing external data

getData

public java.lang.Object getData()
Gets the external data value for this triangle.

Returns:
the data object

kill

public void kill()

isLive

public boolean isLive()

getEdges

public QuadEdge[] getEdges()

getEdge

public QuadEdge getEdge(int i)

getVertex

public Vertex getVertex(int i)

getVertices

public Vertex[] getVertices()
Gets the vertices for this triangle.

Returns:
a new array containing the triangle vertices

getCoordinate

public Coordinate getCoordinate(int i)

getEdgeIndex

public int getEdgeIndex(QuadEdge e)
Gets the index for the given edge of this triangle

Parameters:
e - a QuadEdge
Returns:
the index of the edge in this triangle

getEdgeIndex

public int getEdgeIndex(Vertex v)
Gets the index for the edge that starts at vertex v.

Parameters:
v - the vertex to find the edge for
Returns:
the index of the edge starting at the vertex

getEdgeSegment

public void getEdgeSegment(int i,
                           LineSegment seg)

getCoordinates

public Coordinate[] getCoordinates()

contains

public boolean contains(Coordinate pt)

getGeometry

public Polygon getGeometry(GeometryFactory fact)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isBorder

public boolean isBorder()
Tests whether this triangle is adjacent to the outside of the subdivision.

Returns:
true if the triangle is adjacent to the subdivision exterior

isBorder

public boolean isBorder(int i)

getAdjacentTriangleAcrossEdge

public QuadEdgeTriangle getAdjacentTriangleAcrossEdge(int edgeIndex)

getAdjacentTriangleEdgeIndex

public int getAdjacentTriangleEdgeIndex(int i)

getTrianglesAdjacentToVertex

public java.util.List getTrianglesAdjacentToVertex(int vertexIndex)
Gets the triangles which are adjacent (include) to a given vertex of this triangle.

Parameters:
vertexIndex - the vertex to query
Returns:
a list of the vertex-adjacent triangles

getNeighbours

public QuadEdgeTriangle[] getNeighbours()
Gets the neighbours of this triangle. If there is no neighbour triangle, the array element is null

Returns:
an array containing the 3 neighbours of this triangle

JTS Topology Suite version 1.12