Search in sources :

Example 1 with MappedLocation

use of com.revolsys.raster.MappedLocation in project com.revolsys.open by revolsys.

the class EditGeoreferencedImageOverlay method addTiePointFinish.

private boolean addTiePointFinish(final MouseEvent event) {
    if (event == null || event.getButton() == MouseEvent.BUTTON1) {
        if (this.addTiePointFirstPoint != null) {
            if (clearOverlayAction(ACTION_TIE_POINT_ADD)) {
                try {
                    clearMapCursor(CURSOR_SOURCE_PIXEL_ADD);
                    Point mapPoint = getEventPoint();
                    final Point snapPoint = getSnapPoint();
                    if (snapPoint != null) {
                        mapPoint = snapPoint;
                    }
                    final Point sourcePoint = this.addTiePointFirstPoint;
                    final Point sourcePixel = this.layer.targetPointToSourcePixel(sourcePoint);
                    final GeometryFactory geometryFactory = getImageGeometryFactory();
                    final Point targetPoint = mapPoint.newGeometry(geometryFactory);
                    final MappedLocation mappedLocation = new MappedLocation(sourcePixel, targetPoint);
                    addUndo(new ListAddUndo(this.image.getTiePoints(), mappedLocation));
                } finally {
                    addTiePointClear();
                }
                return true;
            }
        }
    }
    return false;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) MappedLocation(com.revolsys.raster.MappedLocation) ListAddUndo(com.revolsys.swing.undo.ListAddUndo) Point(com.revolsys.geometry.model.Point)

Example 2 with MappedLocation

use of com.revolsys.raster.MappedLocation in project com.revolsys.open by revolsys.

the class EditGeoreferencedImageOverlay method moveTiePointFinish.

private boolean moveTiePointFinish(final MouseEvent event) {
    if (this.moveTiePointStarted) {
        final MappedLocation tiePoint = getMoveTiePoint();
        if (tiePoint != null) {
            Point point = getPoint(event);
            String action;
            if (this.moveTiePointSource) {
                action = ACTION_TIE_POINT_MOVE_SOURCE;
            } else {
                action = ACTION_TIE_POINT_MOVE_TARGET;
            }
            if (clearOverlayAction(action)) {
                if (this.moveTiePointSource) {
                    final Point sourcePixel = this.layer.targetPointToSourcePixel(point);
                    final SetObjectProperty setSourcePixel = new SetObjectProperty(tiePoint, "sourcePixel", tiePoint.getSourcePixel(), sourcePixel);
                    addUndo(setSourcePixel);
                } else {
                    final Point snapPoint = getSnapPoint();
                    if (snapPoint != null) {
                        point = snapPoint;
                    }
                    final GeometryFactory imageGeometryFactory = getImageGeometryFactory();
                    point = point.newGeometry(imageGeometryFactory);
                    tiePoint.setTargetPoint(point);
                    final SetObjectProperty setTargetPoint = new SetObjectProperty(tiePoint, "targetPoint", tiePoint.getTargetPoint(), point);
                    addUndo(setTargetPoint);
                }
                this.closeSourcePixelIndexes.clear();
                this.closeTargetPointIndexes.clear();
                moveTiePointClear();
                clearCachedImage();
                clearMapCursor();
                clearSnapLocations();
                if (event != null) {
                    event.consume();
                }
                repaint();
                return true;
            }
        }
    }
    return false;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) MappedLocation(com.revolsys.raster.MappedLocation) SetObjectProperty(com.revolsys.swing.undo.SetObjectProperty) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString)

Example 3 with MappedLocation

use of com.revolsys.raster.MappedLocation in project com.revolsys.open by revolsys.

the class EditGeoreferencedImageOverlay method paintComponent.

@Override
protected void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
    super.paintComponent(viewport, graphics);
    final GeoreferencedImageLayer layer = this.layer;
    final GeoreferencedImage image = this.image;
    final BoundingBox moveImageBoundingBox = this.moveImageBoundingBox;
    if (layer != null && layer.isVisible() && layer.isExists() && image != null) {
        try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
            final GeometryFactory viewportGeometryFactory = viewport.getGeometryFactory();
            final boolean showOriginalImage = layer.isShowOriginalImage();
            final BoundingBox imageBoundingBox = getImageBoundingBox();
            BoundingBox boundingBox = imageBoundingBox;
            BoundingBox outlineBoundingBox = boundingBox;
            if (moveImageBoundingBox != null) {
                if (showOriginalImage) {
                    boundingBox = moveImageBoundingBox;
                }
                outlineBoundingBox = moveImageBoundingBox;
            }
            final GeoreferencedImage cachedImage = getCachedImage(boundingBox);
            GeoreferencedImageLayerRenderer.renderAlpha(viewport, graphics, cachedImage, false, layer.getOpacity() / 255.0, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            GeoreferencedImageLayerRenderer.renderDifferentCoordinateSystem(viewport, graphics, imageBoundingBox);
            if (outlineBoundingBox != null && !outlineBoundingBox.isEmpty()) {
                final Polygon imageBoundary = outlineBoundingBox.convert(getViewportGeometryFactory()).toPolygon(1);
                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
                viewport.drawGeometryOutline(imageBoundary, STYLE_BOX_OUTLINE);
                MarkerStyleRenderer.renderMarkerVertices(viewport, graphics, imageBoundary, STYLE_BOX_CORNER);
                final List<MappedLocation> tiePoints = image.getTiePoints();
                final int tiePointCount = tiePoints.size();
                final GeometryFactory viewGeometryFactory = getGeometryFactory();
                if (tiePointCount > 0) {
                    for (final MappedLocation mappedLocation : tiePoints) {
                        LineString line = mappedLocation.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
                        if (line != null) {
                            line = line.convertGeometry(viewportGeometryFactory);
                            try (BaseCloseable transformCloseable1 = viewport.setUseModelCoordinates(graphics, true)) {
                                TIE_POINT_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, line);
                            }
                        }
                    }
                    for (final MappedLocation mappedLocation : tiePoints) {
                        LineString line = mappedLocation.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
                        if (line != null) {
                            line = line.convertGeometry(viewportGeometryFactory);
                            TIE_POINT_VERTEX_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, line);
                        }
                    }
                }
                if (!showOriginalImage) {
                    final double width = image.getImageWidth() - 1;
                    final double height = image.getImageHeight() - 1;
                    final double[] targetCoordinates = MappedLocation.toModelCoordinates(image, boundingBox, true, 0, height, width, height, width, 0, 0, 0, 0, height);
                    final LineString line = viewGeometryFactory.lineString(2, targetCoordinates);
                    GeometryStyleRenderer.renderLineString(viewport, graphics, line, STYLE_IMAGE_LINE);
                }
            }
            final MappedLocation moveTiePoint = getMoveTiePoint();
            if (moveTiePoint != null) {
                final LineString line = moveTiePoint.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
                Vertex vertex;
                if (this.moveTiePointSource) {
                    vertex = line.getVertex(0);
                } else {
                    vertex = line.getToVertex(0);
                }
                TIE_POINT_CLOSE_VERTEX_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, vertex);
            }
        }
    }
    drawXorGeometry(graphics);
}
Also used : Vertex(com.revolsys.geometry.model.vertex.Vertex) BaseCloseable(com.revolsys.io.BaseCloseable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BufferedGeoreferencedImage(com.revolsys.raster.BufferedGeoreferencedImage) GeoreferencedImage(com.revolsys.raster.GeoreferencedImage) MappedLocation(com.revolsys.raster.MappedLocation) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox) Polygon(com.revolsys.geometry.model.Polygon)

Example 4 with MappedLocation

use of com.revolsys.raster.MappedLocation in project com.revolsys.open by revolsys.

the class TiePointsPanel method getEventRowObject.

protected MappedLocation getEventRowObject() {
    final ObjectListTableModel<MappedLocation> model = getTableModel();
    final int row = getEventRow();
    final MappedLocation object = model.getObject(row);
    return object;
}
Also used : MappedLocation(com.revolsys.raster.MappedLocation)

Example 5 with MappedLocation

use of com.revolsys.raster.MappedLocation in project com.revolsys.open by revolsys.

the class TiePointsPanel method deleteTiePoint.

public void deleteTiePoint() {
    final MappedLocation tiePoint = getEventRowObject();
    this.layer.deleteTiePoint(tiePoint);
}
Also used : MappedLocation(com.revolsys.raster.MappedLocation)

Aggregations

MappedLocation (com.revolsys.raster.MappedLocation)9 Point (com.revolsys.geometry.model.Point)5 BoundingBox (com.revolsys.geometry.model.BoundingBox)4 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)4 LineString (com.revolsys.geometry.model.LineString)3 GeoreferencedImage (com.revolsys.raster.GeoreferencedImage)3 BufferedGeoreferencedImage (com.revolsys.raster.BufferedGeoreferencedImage)2 Geometry (com.revolsys.geometry.model.Geometry)1 Polygon (com.revolsys.geometry.model.Polygon)1 Vertex (com.revolsys.geometry.model.vertex.Vertex)1 BaseCloseable (com.revolsys.io.BaseCloseable)1 Project (com.revolsys.swing.map.layer.Project)1 GeoreferencedImageLayer (com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer)1 ListAddUndo (com.revolsys.swing.undo.ListAddUndo)1 SetObjectProperty (com.revolsys.swing.undo.SetObjectProperty)1 ArrayList (java.util.ArrayList)1