Search in sources :

Example 6 with Triangle

use of com.revolsys.geometry.model.Triangle in project com.revolsys.open by revolsys.

the class TriangleLinearRing method forEachVertex.

@Override
public void forEachVertex(final Consumer3Double action) {
    if (!isEmpty()) {
        final Triangle triangle = this.triangle;
        for (int i = 0; i < 3; i++) {
            final double x = triangle.getX(i);
            final double y = triangle.getY(i);
            final double z = triangle.getZ(i);
            action.accept(x, y, z);
        }
    }
}
Also used : Triangle(com.revolsys.geometry.model.Triangle)

Example 7 with Triangle

use of com.revolsys.geometry.model.Triangle in project com.revolsys.open by revolsys.

the class TriangleLinearRing method findSegment.

@Override
public <R> R findSegment(final Function4Double<R> action) {
    if (!isEmpty()) {
        final Triangle triangle = this.triangle;
        final double x1 = triangle.getX(0);
        final double y1 = triangle.getY(0);
        final double x2 = triangle.getX(1);
        final double y2 = triangle.getY(1);
        final double x3 = triangle.getX(2);
        final double y3 = triangle.getY(2);
        R result = action.accept(x1, y1, x2, y2);
        if (result == null) {
            result = action.accept(x2, y2, x3, y3);
            if (result == null) {
                result = action.accept(x3, y3, x1, y1);
            }
        }
    }
    return null;
}
Also used : Triangle(com.revolsys.geometry.model.Triangle)

Example 8 with Triangle

use of com.revolsys.geometry.model.Triangle in project com.revolsys.open by revolsys.

the class TriangulationVisualization method displayTin.

public static void displayTin(final TriangulatedIrregularNetwork tin) {
    BoundingBox boundingBox = tin.getBoundingBox();
    double mapWidth = boundingBox.getWidth() + 4;
    double mapHeight = boundingBox.getHeight() + 4;
    if (mapHeight > mapWidth) {
        boundingBox = boundingBox.expand((mapHeight - mapWidth) / 2, 0);
        mapWidth = boundingBox.getWidth();
    } else if (mapHeight < mapWidth) {
        boundingBox = boundingBox.expand(0, (mapWidth - mapHeight) / 2);
        mapHeight = boundingBox.getHeight();
    }
    final AffineTransform transform = new AffineTransform();
    final double pixelsPerXUnit = 800 / mapWidth;
    final double pixelsPerYUnit = -800 / mapHeight;
    final double originX = boundingBox.getMinX() - 2;
    final double originY = boundingBox.getMaxY() + 2;
    transform.concatenate(AffineTransform.getScaleInstance(pixelsPerXUnit, pixelsPerYUnit));
    transform.concatenate(AffineTransform.getTranslateInstance(-originX, -originY));
    SwingUtilities.invokeLater(() -> {
        final JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(850, 850);
        frame.setVisible(true);
        frame.setLayout(new BorderLayout());
        frame.add(new JPanel() {

            /**
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void paint(final Graphics graphics) {
                final Graphics2D g2 = (Graphics2D) graphics;
                g2.setPaint(WebColors.White);
                g2.fillRect(0, 0, 800, 800);
                final AffineTransform oldTransform = g2.getTransform();
                g2.transform(transform);
                synchronized (tin) {
                    g2.setStroke(new BasicStroke((float) (1 / pixelsPerXUnit)));
                    tin.forEachTriangle((triangle) -> {
                        g2.setPaint(WebColors.newAlpha(WebColors.Aqua, 25));
                        g2.fill(triangle);
                        g2.setColor(WebColors.Black);
                        g2.draw(triangle);
                    });
                    if (showCircumcircle) {
                        tin.forEachTriangle((triangle) -> {
                            final double x1 = triangle.getX(1);
                            final double x2 = triangle.getY(1);
                            final double[] centre = Triangle.getCircumcentreCoordinates(triangle.getX(0), triangle.getY(0), x1, x2, triangle.getX(2), triangle.getY(2));
                            final double centreX = centre[0];
                            final double centreY = centre[1];
                            final double size = 7;
                            final double half = size / 2;
                            final Ellipse2D.Double shape = new Ellipse2D.Double(centreX - half / pixelsPerXUnit, centreY - half / pixelsPerXUnit, size / pixelsPerXUnit, size / pixelsPerXUnit);
                            g2.setPaint(WebColors.Yellow);
                            g2.fill(shape);
                            g2.setColor(WebColors.Black);
                            g2.draw(shape);
                        });
                        tin.forEachTriangle((triangle) -> {
                            final double x1 = triangle.getX(1);
                            final double x2 = triangle.getY(1);
                            final double[] centre = Triangle.getCircumcentreCoordinates(triangle.getX(0), triangle.getY(0), x1, x2, triangle.getX(2), triangle.getY(2));
                            final Circle circle = triangle.getCircumcircle();
                            final double centreX = centre[0];
                            final double centreY = centre[1];
                            final double radius = circle.getRadius();
                            final Ellipse2D ellipse = new Ellipse2D.Double(centreX - radius, centreY - radius, radius * 2, radius * 2);
                            g2.setColor(WebColors.Red);
                            g2.draw(ellipse);
                        });
                    }
                // for (int vertexIndex = 0; vertexIndex < tin.getVertexCount(); vertexIndex++) {
                // final Point point = tin.getVertex(vertexIndex);
                // final double x = point.getX();
                // final double y = point.getY();
                // final double size = 7;
                // final double half = size / 2;
                // final Ellipse2D.Double shape = new Ellipse2D.Double(x - half / pixelsPerXUnit,
                // y - half / pixelsPerXUnit, size / pixelsPerXUnit, size / pixelsPerXUnit);
                // g2.setPaint(WebColors.Yellow);
                // g2.fill(shape);
                // g2.setColor(WebColors.Black);
                // g2.draw(shape);
                // }
                // {
                // final Point point = pointHolder.getValue();
                // if (point != null) {
                // g2.setPaint(WebColors.Red);
                // final double x = point.getX();
                // final double y = point.getY();
                // final double size = 9;
                // final double half = size / 2;
                // g2.fill(new Ellipse2D.Double(x - half / pixelsPerXUnit, y - half / pixelsPerXUnit,
                // size / pixelsPerXUnit, size / pixelsPerXUnit));
                // }
                // }
                // g2.setTransform(oldTransform);
                // g2.translate(0, 800);
                // g2.setPaint(WebColors.Green);
                // for (int vertexIndex = 0; vertexIndex < tin.getVertexCount(); vertexIndex++) {
                // final Point point = tin.getVertex(vertexIndex);
                // final double x = point.getX();
                // final double y = point.getY();
                // final int screenX = (int)((x + 2) * pixelsPerXUnit);
                // final int screenY = (int)((y + 2) * pixelsPerYUnit);
                // g2.drawString(Integer.toString(vertexIndex), screenX + 5, screenY);
                // }
                }
            }
        }, BorderLayout.CENTER);
    });
}
Also used : BasicStroke(java.awt.BasicStroke) LasPointCloud(com.revolsys.elevation.cloud.las.LasPointCloud) PathResource(com.revolsys.spring.resource.PathResource) AffineTransform(java.awt.geom.AffineTransform) ArrayList(java.util.ArrayList) WebColors(com.revolsys.awt.WebColors) List(java.util.List) SwingUtilities(javax.swing.SwingUtilities) TriangulatedIrregularNetwork(com.revolsys.elevation.tin.TriangulatedIrregularNetwork) Ellipse2D(java.awt.geom.Ellipse2D) Triangle(com.revolsys.geometry.model.Triangle) Graphics2D(java.awt.Graphics2D) PointCloud(com.revolsys.elevation.cloud.PointCloud) Circle(com.revolsys.geometry.model.impl.Circle) Graphics(java.awt.Graphics) QuadEdgeDelaunayTinBuilder(com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder) BasicStroke(java.awt.BasicStroke) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JPanel(javax.swing.JPanel) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) JPanel(javax.swing.JPanel) Circle(com.revolsys.geometry.model.impl.Circle) Ellipse2D(java.awt.geom.Ellipse2D) Graphics2D(java.awt.Graphics2D) Graphics(java.awt.Graphics) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) BoundingBox(com.revolsys.geometry.model.BoundingBox) AffineTransform(java.awt.geom.AffineTransform)

Example 9 with Triangle

use of com.revolsys.geometry.model.Triangle in project com.revolsys.open by revolsys.

the class BaseCompactTriangulatedIrregularNetwork method forEachTriangle.

@Override
public void forEachTriangle(final Consumer<? super Triangle> action) {
    for (int i = 0; i < this.triangleCount; i++) {
        final Triangle triangle = newTriangle(i);
        action.accept(triangle);
    }
}
Also used : AbstractTriangle(com.revolsys.geometry.model.impl.AbstractTriangle) Triangle(com.revolsys.geometry.model.Triangle) Point(com.revolsys.geometry.model.Point)

Example 10 with Triangle

use of com.revolsys.geometry.model.Triangle in project com.revolsys.open by revolsys.

the class IntArrayScaleTriangulatedIrregularNetwork method forEachTriangle.

@Override
public void forEachTriangle(final double x, final double y, final Consumer<? super Triangle> action) {
    if (this.spatialIndexUseTriangles) {
        final QuadTree<Triangle> index = getTriangleSpatialIndex();
        index.forEach(x, y, triangle -> {
            action.accept(triangle);
        });
    } else {
        final QuadTree<Integer> index = getTriangleIdSpatialIndex();
        index.forEach(x, y, triangleIndex -> {
            final Triangle triangle = newTriangle(triangleIndex);
            if (triangle != null) {
                action.accept(triangle);
            }
        });
    }
}
Also used : AbstractTriangle(com.revolsys.geometry.model.impl.AbstractTriangle) Triangle(com.revolsys.geometry.model.Triangle)

Aggregations

Triangle (com.revolsys.geometry.model.Triangle)16 Point (com.revolsys.geometry.model.Point)6 BoundingBox (com.revolsys.geometry.model.BoundingBox)5 AbstractTriangle (com.revolsys.geometry.model.impl.AbstractTriangle)5 ArrayList (java.util.ArrayList)5 Geometry (com.revolsys.geometry.model.Geometry)4 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)3 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)3 TriangleDoubleXYZ (com.revolsys.geometry.model.impl.TriangleDoubleXYZ)3 LineSegment (com.revolsys.geometry.model.segment.LineSegment)3 LineSegmentDoubleGF (com.revolsys.geometry.model.segment.LineSegmentDoubleGF)3 List (java.util.List)3 Lists (com.revolsys.collection.list.Lists)2 MapEx (com.revolsys.collection.map.MapEx)2 TriangulatedIrregularNetwork (com.revolsys.elevation.tin.TriangulatedIrregularNetwork)2 ScaledIntegerTriangulatedIrregularNetwork (com.revolsys.elevation.tin.compactbinary.ScaledIntegerTriangulatedIrregularNetwork)2 AsciiTin (com.revolsys.elevation.tin.tin.AsciiTin)2 GeometryFactoryProxy (com.revolsys.geometry.model.GeometryFactoryProxy)2 LineString (com.revolsys.geometry.model.LineString)2 BoundingBoxDoubleXY (com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)2