public Triple [ ] generateTriangleNeighbors ( Geometry geometry ) throws TopologyException { inputTriangles = geometry ; CoordinateSequenceDimensionFilter sequenceDimensionFilter = new CoordinateSequenceDimensionFilter ( ) ; geometry . apply ( sequenceDimensionFilter ) ; hasZ = sequenceDimensionFilter . getDimension ( ) == CoordinateSequenceDimensionFilter . XYZ ; Quadtree ptQuad = new Quadtree ( ) ; // In order to compute triangle neighbors we have to set a unique id to points. triangleVertex = new Triple [ geometry . getNumGeometries ( ) ] ; // Final size of tri vertex is not known at the moment. Give just an hint triVertex = new ArrayList < EnvelopeWithIndex > ( triangleVertex . length ) ; // First Loop make an index of triangle vertex for ( int idgeom = 0 ; idgeom < triangleVertex . length ; idgeom ++ ) { Geometry geomItem = geometry . getGeometryN ( idgeom ) ; if ( geomItem instanceof Polygon ) { Coordinate [ ] coords = geomItem . getCoordinates ( ) ; if ( coords . length != 4 ) { throw new TopologyException ( "Voronoi method accept only triangles" ) ; } triangleVertex [ idgeom ] = new Triple ( getOrAppendVertex ( coords [ 0 ] , ptQuad ) , getOrAppendVertex ( coords [ 1 ] , ptQuad ) , getOrAppendVertex ( coords [ 2 ] , ptQuad ) ) ; for ( int triVertexIndex : triangleVertex [ idgeom ] . toArray ( ) ) { triVertex . get ( triVertexIndex ) . addSharingTriangle ( idgeom ) ; } } else { throw new TopologyException ( "Voronoi method accept only polygons" ) ; } } // Second loop make an index of triangle neighbors ptQuad = null ; triangleNeighbors = new Triple [ geometry . getNumGeometries ( ) ] ; for ( int triId = 0 ; triId < triangleVertex . length ; triId ++ ) { Triple triangleIndex = triangleVertex [ triId ] ; triangleNeighbors [ triId ] = new Triple ( commonEdge ( triId , triVertex . get ( triangleIndex . getB ( ) ) , triVertex . get ( triangleIndex . getC ( ) ) ) , commonEdge ( triId , triVertex . get ( triangleIndex . getA ( ) ) , triVertex . get ( triangleIndex . getC ( ) ) ) , commonEdge ( triId , triVertex . get ( triangleIndex . getB ( ) ) , triVertex . get ( triangleIndex . getA ( ) ) ) ) ; } triVertex . clear ( ) ; return triangleNeighbors ; }
Given the input TIN construct a graph of triangle .