Search in sources :

Example 1 with TriangleConsumer

use of com.revolsys.elevation.tin.TriangleConsumer in project com.revolsys.open by revolsys.

the class QuadEdgeDelaunayTinBuilder method newTriangulatedIrregularNetwork.

@Override
public final TriangulatedIrregularNetwork newTriangulatedIrregularNetwork() {
    buildTin();
    final BoundingBox boundingBox = getBoundingBox();
    final AtomicInteger triangleCounter = new AtomicInteger();
    forEachTriangle((x1, y1, z1, x2, y2, z2, x3, y3, z3) -> {
        triangleCounter.incrementAndGet();
    });
    final int triangleCount = triangleCounter.get();
    final int[] triangleXCoordinates = new int[triangleCount * 3];
    final int[] triangleYCoordinates = new int[triangleCount * 3];
    final int[] triangleZCoordinates = new int[triangleCount * 3];
    forEachTriangle(new TriangleConsumer() {

        private int coordinateIndex = 0;

        @Override
        public void accept(final double x1, final double y1, final double z1, final double x2, final double y2, final double z2, final double x3, final double y3, final double z3) {
            final double scaleX = QuadEdgeDelaunayTinBuilder.this.scaleX;
            final double scaleY = QuadEdgeDelaunayTinBuilder.this.scaleY;
            final double scaleZ = QuadEdgeDelaunayTinBuilder.this.scaleZ;
            triangleXCoordinates[this.coordinateIndex] = (int) Math.round(x1 * scaleX);
            triangleYCoordinates[this.coordinateIndex] = (int) Math.round(y1 * scaleY);
            triangleZCoordinates[this.coordinateIndex++] = (int) Math.round(z1 * scaleZ);
            triangleXCoordinates[this.coordinateIndex] = (int) Math.round(x2 * scaleX);
            triangleYCoordinates[this.coordinateIndex] = (int) Math.round(y2 * scaleY);
            triangleZCoordinates[this.coordinateIndex++] = (int) Math.round(z2 * scaleZ);
            triangleXCoordinates[this.coordinateIndex] = (int) Math.round(x3 * scaleX);
            triangleYCoordinates[this.coordinateIndex] = (int) Math.round(y3 * scaleY);
            triangleZCoordinates[this.coordinateIndex++] = (int) Math.round(z3 * scaleZ);
        }
    });
    return new IntArrayScaleTriangulatedIrregularNetwork(this.geometryFactory, boundingBox, triangleCount, triangleXCoordinates, triangleYCoordinates, triangleZCoordinates);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BoundingBox(com.revolsys.geometry.model.BoundingBox) TriangleConsumer(com.revolsys.elevation.tin.TriangleConsumer) IntArrayScaleTriangulatedIrregularNetwork(com.revolsys.elevation.tin.IntArrayScaleTriangulatedIrregularNetwork) Point(com.revolsys.geometry.model.Point)

Aggregations

IntArrayScaleTriangulatedIrregularNetwork (com.revolsys.elevation.tin.IntArrayScaleTriangulatedIrregularNetwork)1 TriangleConsumer (com.revolsys.elevation.tin.TriangleConsumer)1 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 Point (com.revolsys.geometry.model.Point)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1