Changeset 18263 in josm for trunk/src


Ignore:
Timestamp:
2021-10-09T20:42:32+02:00 (3 years ago)
Author:
Don-vip
Message:

see #16472 - draw direction arrow of 360 images

Location:
trunk/src/org/openstreetmap/josm/gui/layer/geoimage
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r18248 r18263  
    6363import org.openstreetmap.josm.gui.layer.Layer;
    6464import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
     65import org.openstreetmap.josm.gui.util.imagery.Vector3D;
    6566import org.openstreetmap.josm.tools.ImageProvider;
    6667import org.openstreetmap.josm.tools.Utils;
     
    452453            if (e != null && e.getPos() != null) {
    453454                Point p = mv.getPoint(e.getPos());
    454 
    455                 int imgWidth;
    456                 int imgHeight;
    457                 if (useThumbs && e.hasThumbnail()) {
    458                     Dimension d = scaledDimension(e.getThumbnail());
    459                     if (d != null) {
    460                         imgWidth = d.width;
    461                         imgHeight = d.height;
    462                     } else {
    463                         imgWidth = -1;
    464                         imgHeight = -1;
    465                     }
    466                 } else {
    467                     imgWidth = selectedIcon.getIconWidth();
    468                     imgHeight = selectedIcon.getIconHeight();
    469                 }
     455                Dimension imgDim = getImageDimension(e);
    470456
    471457                if (e.getExifImgDir() != null) {
    472                     // Multiplier must be larger than sqrt(2)/2=0.71.
    473                     double arrowlength = Math.max(25, Math.max(imgWidth, imgHeight) * 0.85);
    474                     double arrowwidth = arrowlength / 1.4;
    475 
    476                     double dir = e.getExifImgDir();
    477                     // Rotate 90 degrees CCW
    478                     double headdir = (dir < 90) ? dir + 270 : dir - 90;
    479                     double leftdir = (headdir < 90) ? headdir + 270 : headdir - 90;
    480                     double rightdir = (headdir > 270) ? headdir - 270 : headdir + 90;
    481 
    482                     double ptx = p.x + Math.cos(Utils.toRadians(headdir)) * arrowlength;
    483                     double pty = p.y + Math.sin(Utils.toRadians(headdir)) * arrowlength;
    484 
    485                     double ltx = p.x + Math.cos(Utils.toRadians(leftdir)) * arrowwidth/2;
    486                     double lty = p.y + Math.sin(Utils.toRadians(leftdir)) * arrowwidth/2;
    487 
    488                     double rtx = p.x + Math.cos(Utils.toRadians(rightdir)) * arrowwidth/2;
    489                     double rty = p.y + Math.sin(Utils.toRadians(rightdir)) * arrowwidth/2;
    490 
    491                     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    492                     g.setColor(new Color(255, 255, 255, 192));
    493                     int[] xar = {(int) ltx, (int) ptx, (int) rtx, (int) ltx};
    494                     int[] yar = {(int) lty, (int) pty, (int) rty, (int) lty};
    495                     g.fillPolygon(xar, yar, 4);
    496                     g.setColor(Color.black);
    497                     g.setStroke(new BasicStroke(1.2f));
    498                     g.drawPolyline(xar, yar, 3);
     458                    Vector3D imgRotation = ImageViewerDialog.getInstance().getRotation(e);
     459                    drawDirectionArrow(g, p, e.getExifImgDir()
     460                            + (imgRotation != null ? Utils.toDegrees(imgRotation.getPolarAngle()) : 0d), imgDim);
    499461                }
    500462
    501463                if (useThumbs && e.hasThumbnail()) {
    502464                    g.setColor(new Color(128, 0, 0, 122));
    503                     g.fillRect(p.x - imgWidth / 2, p.y - imgHeight / 2, imgWidth, imgHeight);
     465                    g.fillRect(p.x - imgDim.width / 2, p.y - imgDim.height / 2, imgDim.width, imgDim.height);
    504466                } else {
    505467                    selectedIcon.paintIcon(mv, g,
    506                             p.x - imgWidth / 2,
    507                             p.y - imgHeight / 2);
    508                 }
    509             }
    510         }
     468                            p.x - imgDim.width / 2,
     469                            p.y - imgDim.height / 2);
     470                }
     471            }
     472        }
     473    }
     474
     475    protected Dimension getImageDimension(ImageEntry e) {
     476        if (useThumbs && e.hasThumbnail()) {
     477            Dimension d = scaledDimension(e.getThumbnail());
     478            return d != null ? d : new Dimension(-1, -1);
     479        } else {
     480            return new Dimension(selectedIcon.getIconWidth(), selectedIcon.getIconHeight());
     481        }
     482    }
     483
     484    protected static void drawDirectionArrow(Graphics2D g, Point p, double dir, Dimension imgDim) {
     485        System.out.println(dir);
     486        // Multiplier must be larger than sqrt(2)/2=0.71.
     487        double arrowlength = Math.max(25, Math.max(imgDim.width, imgDim.height) * 0.85);
     488        double arrowwidth = arrowlength / 1.4;
     489
     490        // Rotate 90 degrees CCW
     491        double headdir = (dir < 90) ? dir + 270 : dir - 90;
     492        double leftdir = (headdir < 90) ? headdir + 270 : headdir - 90;
     493        double rightdir = (headdir > 270) ? headdir - 270 : headdir + 90;
     494
     495        double ptx = p.x + Math.cos(Utils.toRadians(headdir)) * arrowlength;
     496        double pty = p.y + Math.sin(Utils.toRadians(headdir)) * arrowlength;
     497
     498        double ltx = p.x + Math.cos(Utils.toRadians(leftdir)) * arrowwidth/2;
     499        double lty = p.y + Math.sin(Utils.toRadians(leftdir)) * arrowwidth/2;
     500
     501        double rtx = p.x + Math.cos(Utils.toRadians(rightdir)) * arrowwidth/2;
     502        double rty = p.y + Math.sin(Utils.toRadians(rightdir)) * arrowwidth/2;
     503
     504        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     505        g.setColor(new Color(255, 255, 255, 192));
     506        int[] xar = {(int) ltx, (int) ptx, (int) rtx, (int) ltx};
     507        int[] yar = {(int) lty, (int) pty, (int) rty, (int) lty};
     508        g.fillPolygon(xar, yar, 4);
     509        g.setColor(Color.black);
     510        g.setStroke(new BasicStroke(1.2f));
     511        g.drawPolyline(xar, yar, 3);
    511512    }
    512513
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java

    r18246 r18263  
    3232import org.openstreetmap.josm.data.preferences.IntegerProperty;
    3333import org.openstreetmap.josm.gui.MainApplication;
     34import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable;
    3435import org.openstreetmap.josm.gui.layer.geoimage.viewers.projections.IImageViewer;
    3536import org.openstreetmap.josm.gui.layer.geoimage.viewers.projections.ImageProjectionRegistry;
     
    3738import org.openstreetmap.josm.gui.layer.imagery.ImageryFilterSettings.FilterChangeListener;
    3839import org.openstreetmap.josm.gui.util.GuiHelper;
     40import org.openstreetmap.josm.gui.util.imagery.Vector3D;
    3941import org.openstreetmap.josm.spi.preferences.Config;
    4042import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
     
    510512                    }
    511513                }
    512                 // We have to update the mousePointInImg for 360 image panning, as otherwise the panning
    513                 // never stops.
     514                // We have to update the mousePointInImg for 360 image panning, as otherwise the panning never stops.
    514515                // This does not work well with the perspective viewer at this time (2021-08-26).
    515                 if (entry != null && Projections.EQUIRECTANGULAR == entry.getProjectionType()) {
     516                boolean is360panning = entry != null && Projections.EQUIRECTANGULAR == entry.getProjectionType();
     517                if (is360panning) {
    516518                    this.mousePointInImg = p;
    517519                }
    518520                ImageDisplay.this.repaint();
     521                if (is360panning) {
     522                    // repaint direction arrow
     523                    MainApplication.getLayerManager().getLayersOfType(GeoImageLayer.class).forEach(AbstractMapViewPaintable::invalidate);
     524                }
    519525            }
    520526
     
    983989
    984990    /**
     991     * Get the rotation in the image viewer for an entry
     992     * @param entry The entry to get the rotation for. May be {@code null}.
     993     * @return the current rotation in the image viewer, or {@code null}
     994     * @since 18263
     995     */
     996    public Vector3D getRotation(IImageEntry<?> entry) {
     997        return entry != null ? getIImageViewer(entry).getRotation() : null;
     998    }
     999
     1000    /**
    9851001     * Ensure that a rectangle isn't zoomed in too much
    9861002     * @param rectangle The rectangle to get (typically the visible area)
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r18247 r18263  
    2222import java.util.concurrent.Future;
    2323import java.util.stream.Collectors;
     24
    2425import javax.swing.AbstractAction;
    2526import javax.swing.Box;
     
    4950import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    5051import org.openstreetmap.josm.gui.layer.imagery.ImageryFilterSettings;
     52import org.openstreetmap.josm.gui.util.imagery.Vector3D;
    5153import org.openstreetmap.josm.tools.ImageProvider;
    5254import org.openstreetmap.josm.tools.Logging;
     
    123125        JButton btn = new JButton(action);
    124126        btn.setPreferredSize(buttonDim);
    125         btn.addPropertyChangeListener("enabled", propertyChangeEvent -> action.setEnabled(Boolean.TRUE.equals(propertyChangeEvent.getNewValue())));
     127        btn.addPropertyChangeListener("enabled", e -> action.setEnabled(Boolean.TRUE.equals(e.getNewValue())));
    126128        return btn;
    127129    }
     
    626628
    627629    /**
     630     * Returns the rotation of the currently displayed image.
     631     * @param entry The entry to get the rotation for. May be {@code null}.
     632     * @return the rotation of the currently displayed image, or {@code null}
     633     * @since 18263
     634     */
     635    public Vector3D getRotation(IImageEntry<?> entry) {
     636        return imgDisplay.getRotation(entry);
     637    }
     638
     639    /**
    628640     * Returns whether the center view is currently active.
    629641     * @return {@code true} if the center view is active, {@code false} otherwise
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/viewers/projections/Equirectangular.java

    r18246 r18263  
    5656
    5757    @Override
    58     public double getRotation() {
    59         return this.cameraPlane.getRotation().getAzimuthalAngle();
     58    public Vector3D getRotation() {
     59        return this.cameraPlane.getRotation();
    6060    }
    6161
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/viewers/projections/IImageViewer.java

    r18246 r18263  
    1313import org.openstreetmap.josm.data.imagery.street_level.Projections;
    1414import org.openstreetmap.josm.gui.layer.geoimage.ImageDisplay;
     15import org.openstreetmap.josm.gui.util.imagery.Vector3D;
    1516
    1617/**
     
    4546     * Get the current rotation in the image viewer
    4647     * @return The rotation
     48     * @since 18263
    4749     */
    48     default double getRotation() {
    49         return 0;
     50    default Vector3D getRotation() {
     51        return null;
    5052    }
    5153
Note: See TracChangeset for help on using the changeset viewer.