Search in sources :

Example 1 with TriangulatedIrregularNetwork

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

the class PointCloud method newGriddedElevationModel.

default GriddedElevationModel newGriddedElevationModel(final Map<String, ? extends Object> properties) {
    final TriangulatedIrregularNetwork tin = newTriangulatedIrregularNetwork();
    final BoundingBox boundingBox = getBoundingBox();
    final int minX = (int) Math.floor(boundingBox.getMinX());
    final int minY = (int) Math.floor(boundingBox.getMinY());
    final int maxX = (int) Math.ceil(boundingBox.getMaxX());
    final int maxY = (int) Math.ceil(boundingBox.getMaxY());
    final int width = maxX - minX;
    final int height = maxY - minY;
    final IntArrayScaleGriddedElevationModel elevationModel = new IntArrayScaleGriddedElevationModel(getGeometryFactory().convertAxisCountAndScales(3, 1000.0, 1000.0, 1000.0), minX, minY, width, height, 1);
    tin.forEachTriangle(elevationModel::setElevationsForTriangle);
    return null;
}
Also used : TriangulatedIrregularNetwork(com.revolsys.elevation.tin.TriangulatedIrregularNetwork) BoundingBox(com.revolsys.geometry.model.BoundingBox) IntArrayScaleGriddedElevationModel(com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel) Point(com.revolsys.geometry.model.Point)

Example 2 with TriangulatedIrregularNetwork

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

the class PointCloud method newTriangulatedIrregularNetwork.

default TriangulatedIrregularNetwork newTriangulatedIrregularNetwork(final Predicate<? super Point> filter) {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final QuadEdgeDelaunayTinBuilder tinBuilder = new QuadEdgeDelaunayTinBuilder(geometryFactory);
    forEachPoint((point) -> {
        if (filter.test(point)) {
            tinBuilder.insertVertex(point);
        }
    });
    final TriangulatedIrregularNetwork tin = tinBuilder.newTriangulatedIrregularNetwork();
    return tin;
}
Also used : TriangulatedIrregularNetwork(com.revolsys.elevation.tin.TriangulatedIrregularNetwork) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) QuadEdgeDelaunayTinBuilder(com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder)

Example 3 with TriangulatedIrregularNetwork

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

the class LasPointCloud method newTriangulatedIrregularNetwork.

@Override
public TriangulatedIrregularNetwork newTriangulatedIrregularNetwork() {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final QuadEdgeDelaunayTinBuilder tinBuilder = new QuadEdgeDelaunayTinBuilder(geometryFactory);
    forEachPoint((lasPoint) -> {
        tinBuilder.insertVertex(lasPoint);
    });
    final TriangulatedIrregularNetwork tin = tinBuilder.newTriangulatedIrregularNetwork();
    return tin;
}
Also used : TriangulatedIrregularNetwork(com.revolsys.elevation.tin.TriangulatedIrregularNetwork) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) QuadEdgeDelaunayTinBuilder(com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder)

Example 4 with TriangulatedIrregularNetwork

use of com.revolsys.elevation.tin.TriangulatedIrregularNetwork 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 5 with TriangulatedIrregularNetwork

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

the class TriangulationVisualization method tinVisual.

// 
// public static void testDem() throws IOException {
// final GeometryFactory geometryFactory = GeometryFactory.fixed(3005, 1000.0);
// final bcDemConfig config = new bcDemConfig();
// final Path basePath = config.getBasePath();
// final boolean processAll = false;
// final RecordDefinition extentRecordDefinition = new RecordDefinitionBuilder("extents") //
// .addField("LETTER_BLOCK", DataTypes.STRING) //
// .addField("POLYGON", DataTypes.POLYGON) //
// .setGeometryFactory(geometryFactory) //
// .getRecordDefinition();
// final Path trim25kDirectory = config.getTrim25mAlbersDirectory();
// RecordWriter writer = null;
// if (processAll) {
// writer = RecordWriter.newRecordWriter(extentRecordDefinition,
// trim25kDirectory.resolve("extents.shp"));
// }
// try (
// RecordWriter writer2 = writer) {
// 
// Files.walk(trim25kDirectory).forEach((demZipFile) -> {
// final String baseName = Paths.getBaseName(demZipFile);
// if (processAll || baseName.equals("92i-albers-elevation.asc")) {
// try {
// final String fileNameExtension = Paths.getFileNameExtension(demZipFile);
// if (fileNameExtension.equals("zip")) {
// final FileSystem fileSystem = FileSystems.newFileSystem(demZipFile, null);
// final String letterBlock = baseName.substring(0, baseName.indexOf('-'));
// final Path demFile = fileSystem.getPath(baseName);
// 
// final Map<String, Object> properties = new HashMap<>();
// properties.put(GriddedElevationModel.GEOMETRY_FACTORY, geometryFactory);
// properties.put(EsriAsciiGriddedElevation.PROPERTY_READ_DATA, !processAll);
// 
// final GriddedElevationModel sourceModel = GriddedElevationModel
// .newGriddedElevationModel(demFile, properties);
// final BoundingBox sourceBoundingBox = sourceModel.getBoundingBox();
// if (!processAll) {
// for (final RectangularMapTile targetTile : bcDemConfig.GRID_25m
// .getTiles(sourceBoundingBox)) {
// final BoundingBox targetBoundingBox = targetTile.getBoundingBox();
// final boolean contained = sourceBoundingBox.covers(targetBoundingBox);
// if (contained) {
// System.out.println(targetTile);
// } else {
// System.err.println(targetTile);
// }
// final Path targetPath = config.getGriddedElevationModelPath(3005, 25, targetTile,
// "asc");
// final GriddedElevationModel targetModel = config.getGriddedElevationModel(3005,
// 25, targetTile, "asc");
// final int targetHeight = targetModel.getHeight();
// final int targetWidth = targetModel.getWidth();
// for (int targetJ = 0; targetJ < targetHeight; targetJ++) {
// for (int targetI = 0; targetI < targetWidth; targetI++) {
// final double x = targetModel.getX(targetI);
// final double y = targetModel.getY(targetJ);
// final int sourceI = sourceModel.getCellX(x);
// final int sourceJ = sourceModel.getCellY(y);
// if (!sourceModel.isNull(sourceI, sourceJ)) {
// final short elevation = sourceModel.getElevationShort(sourceI, sourceJ);
// targetModel.setElevation(targetI, targetJ, elevation);
// }
// }
// }
// targetModel.writeGriddedElevationModel(targetPath);
// }
// }
// 
// if (writer2 != null) {
// final Record record = writer2.newRecord();
// record.setValue("LETTER_BLOCK", letterBlock);
// final BoundingBox boundingBox = sourceModel.getBoundingBox();
// record.setGeometryValue(boundingBox.toPolygon(1));
// writer2.write(record);
// }
// }
// } catch (final Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// });
// }
// }
private static void tinVisual(final GeometryFactory geometryFactory, final List<Point> points) {
    final QuadEdgeDelaunayTinBuilder tinBuilder = new QuadEdgeDelaunayTinBuilder(geometryFactory);
    tinBuilder.insertVertices(points);
    final TriangulatedIrregularNetwork tin = tinBuilder.newTriangulatedIrregularNetwork();
    displayTin(tin);
}
Also used : TriangulatedIrregularNetwork(com.revolsys.elevation.tin.TriangulatedIrregularNetwork) QuadEdgeDelaunayTinBuilder(com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder)

Aggregations

TriangulatedIrregularNetwork (com.revolsys.elevation.tin.TriangulatedIrregularNetwork)11 QuadEdgeDelaunayTinBuilder (com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)4 LasPointCloud (com.revolsys.elevation.cloud.las.LasPointCloud)2 BoundingBox (com.revolsys.geometry.model.BoundingBox)2 Point (com.revolsys.geometry.model.Point)2 Triangle (com.revolsys.geometry.model.Triangle)2 PathResource (com.revolsys.spring.resource.PathResource)2 WebColors (com.revolsys.awt.WebColors)1 PointCloud (com.revolsys.elevation.cloud.PointCloud)1 IntArrayScaleGriddedElevationModel (com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel)1 Geometry (com.revolsys.geometry.model.Geometry)1 Circle (com.revolsys.geometry.model.impl.Circle)1 BaseCloseable (com.revolsys.io.BaseCloseable)1 Resource (com.revolsys.spring.resource.Resource)1 BasicStroke (java.awt.BasicStroke)1 BorderLayout (java.awt.BorderLayout)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1 AffineTransform (java.awt.geom.AffineTransform)1