public static List < Geometry > triangulate ( List < LasRecord > lasPoints , Double elevThres , boolean useGround , IHMProgressMonitor pm ) { pm . beginTask ( "Triangulation..." , - 1 ) ; List < Coordinate > lasCoordinates = new ArrayList < Coordinate > ( ) ; for ( LasRecord lasRecord : lasPoints ) { lasCoordinates . add ( new Coordinate ( lasRecord . x , lasRecord . y , useGround ? lasRecord . groundElevation : lasRecord . z ) ) ; } DelaunayTriangulationBuilder triangulationBuilder = new DelaunayTriangulationBuilder ( ) ; triangulationBuilder . setSites ( lasCoordinates ) ; Geometry triangles = triangulationBuilder . getTriangles ( gf ) ; pm . done ( ) ; ArrayList < Geometry > trianglesList = new ArrayList < Geometry > ( ) ; int numTriangles = triangles . getNumGeometries ( ) ; if ( elevThres == null ) { // no true dsm to be calculated for ( int i = 0 ; i < numTriangles ; i ++ ) { Geometry geometryN = triangles . getGeometryN ( i ) ; trianglesList . add ( geometryN ) ; } } else { double pElevThres = elevThres ; numTriangles = triangles . getNumGeometries ( ) ; pm . beginTask ( "Extracting triangles based on threshold..." , numTriangles ) ; for ( int i = 0 ; i < numTriangles ; i ++ ) { pm . worked ( 1 ) ; Geometry geometryN = triangles . getGeometryN ( i ) ; Coordinate [ ] coordinates = geometryN . getCoordinates ( ) ; double z0 = coordinates [ 0 ] . z ; double z1 = coordinates [ 1 ] . z ; double z2 = coordinates [ 2 ] . z ; double diff1 = abs ( z0 - z1 ) ; if ( diff1 > pElevThres ) { continue ; } double diff2 = abs ( z0 - z2 ) ; if ( diff2 > pElevThres ) { continue ; } double diff3 = abs ( z1 - z2 ) ; if ( diff3 > pElevThres ) { continue ; } trianglesList . add ( geometryN ) ; } pm . done ( ) ; } pm . beginTask ( "Triangulation1..." , - 1 ) ; List < Coordinate > lasCoordinates2 = new ArrayList < Coordinate > ( ) ; for ( Geometry g : trianglesList ) { Coordinate [ ] c = g . getCoordinates ( ) ; lasCoordinates2 . add ( c [ 0 ] ) ; lasCoordinates2 . add ( c [ 1 ] ) ; lasCoordinates2 . add ( c [ 2 ] ) ; } trianglesList . clear ( ) ; DelaunayTriangulationBuilder triangulationBuilder1 = new DelaunayTriangulationBuilder ( ) ; triangulationBuilder1 . setSites ( lasCoordinates2 ) ; Geometry triangles1 = triangulationBuilder1 . getTriangles ( gf ) ; pm . done ( ) ; numTriangles = triangles1 . getNumGeometries ( ) ; // no true dsm to be calculated for ( int i = 0 ; i < numTriangles ; i ++ ) { Geometry geometryN = triangles1 . getGeometryN ( i ) ; trianglesList . add ( geometryN ) ; } return trianglesList ; }
Triangulates a set of las points .