Skip to content

Commit

Permalink
360: Show direction image is pointed in (relies upon image having cor…
Browse files Browse the repository at this point in the history
…rect direction)

Signed-off-by: Taylor Smock <tsmock@fb.com>
  • Loading branch information
tsmock committed Dec 2, 2020
1 parent a4822b8 commit cfbef1f
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 97 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapillary;

import java.awt.Color;
import java.awt.Image;
import static java.lang.Integer.compare;
import static java.lang.Long.compare;

import java.awt.Color;
import java.awt.Image;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
Expand All @@ -23,7 +24,6 @@
* {@link MapillaryImportedImage} and {@link MapillaryImage}.
*
* @author nokutu
*
*/
public abstract class MapillaryAbstractImage extends GpxImageEntry {
/** The common directory for the Mapillary image sprites (for Mapillary Images) */
Expand Down Expand Up @@ -56,8 +56,6 @@ public abstract class MapillaryAbstractImage extends GpxImageEntry {
private LatLon tempLatLon;

private final boolean pano;
/** Clockwise rotation from initial direction of 360 panoramic images */
private double panoTheta;

/**
* When the object is being dragged in the map, the temporal position is
Expand All @@ -81,9 +79,9 @@ public abstract class MapillaryAbstractImage extends GpxImageEntry {
/**
* Creates a new object in the given position and with the given direction.
*
* @param latLon The latitude and longitude where the picture was taken.
* @param ca The direction of the picture (0 means north).
* @param pano The property to indicate whether image is panorama or not.
* @param latLon The latitude and longitude where the picture was taken.
* @param ca The direction of the picture (0 means north).
* @param pano The property to indicate whether image is panorama or not.
*/
protected MapillaryAbstractImage(final LatLon latLon, final double ca, final boolean pano) {
super.setExifCoor(latLon);
Expand Down Expand Up @@ -150,7 +148,7 @@ public String getDateFormat() {
* Returns the date the picture was taken in the given format.
*
* @param format
* Format of the date. See {@link SimpleDateFormat}.
* Format of the date. See {@link SimpleDateFormat}.
* @return A String containing the date the picture was taken using the given
* format.
* @throws NullPointerException if parameter format is <code>null</code>
Expand Down Expand Up @@ -231,7 +229,7 @@ public LatLon getTempLatLon() {
*/
public boolean isModified() {
return this.getMovingLatLon() != null && !this.getMovingLatLon().equals(this.getExifCoor())
|| Math.abs(this.getMovingCa() - this.ca) > EPSILON;
|| Math.abs(this.getMovingCa() - this.ca) > EPSILON;
}

/**
Expand Down Expand Up @@ -313,7 +311,7 @@ public void setLatLon(final LatLon latLon) {
*
* @param sequence The MapillarySequence that contains the MapillaryImage.
* @throws IllegalArgumentException if the image is not already part of the {@link MapillarySequence}.
* Call {@link MapillarySequence#add(MapillaryAbstractImage)} first.
* Call {@link MapillarySequence#add(MapillaryAbstractImage)} first.
*/
public void setSequence(final MapillarySequence sequence) {
synchronized (this) {
Expand Down Expand Up @@ -359,18 +357,6 @@ public void setReviewed(boolean reviewed) {
this.reviewed = reviewed;
}

/**
* Rotate 360 image's point of view.
* @param theta
*/
public void rotatePano(double theta) {
this.panoTheta += theta;
}

public double getTheta() {
return this.panoTheta;
}

public abstract Color paintHighlightedAngleColour();

public abstract Color paintSelectedAngleColour();
Expand Down Expand Up @@ -404,12 +390,13 @@ public Image getDeletedImage() {
}

public void setMovingCa(double ca) {
double tCa = ca;
if (ca > 360) {
ca = ca - 360;
tCa = ca - 360;
} else if (ca < 0) {
ca = ca + 360;
tCa = ca + 360;
}
this.movingCa = ca;
this.movingCa = tCa;
}

public void setMovingLatLon(LatLon latLon) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapillary.gui.imageviewer;

import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.BasicStroke;
import java.awt.Color;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
Expand All @@ -16,21 +17,20 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import javax.swing.JPanel;

import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.layer.LayerManager;

import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryDownloadAction;
import org.openstreetmap.josm.plugins.mapillary.gui.layer.MapillaryLayer;
import org.openstreetmap.josm.plugins.mapillary.gui.layer.PointObjectLayer;
import org.openstreetmap.josm.plugins.mapillary.model.ImageDetection;
import org.openstreetmap.josm.plugins.mapillary.utils.ImageViewUtil;
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryColorScheme;
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryProperties;
import static org.openstreetmap.josm.tools.I18n.tr;

/**
*
* @author Kishan
*/
public abstract class AbstractImageViewer extends JPanel {
Expand All @@ -57,7 +57,8 @@ public AbstractImageViewer() {
setDarkMode(MapillaryProperties.DARK_MODE.get());
MainApplication.getLayerManager().addLayerChangeListener(new LayerManager.LayerChangeListener() {
@Override
public void layerAdded(LayerManager.LayerAddEvent e) { }
public void layerAdded(LayerManager.LayerAddEvent e) {
}

@Override
public void layerRemoving(LayerManager.LayerRemoveEvent e) {
Expand All @@ -67,15 +68,16 @@ public void layerRemoving(LayerManager.LayerRemoveEvent e) {
}

@Override
public void layerOrderChanged(LayerManager.LayerOrderChangeEvent e) { }
public void layerOrderChanged(LayerManager.LayerOrderChangeEvent e) {
}
});
MapillaryProperties.SHOW_DETECTION_OUTLINES.addListener(it -> repaint());
MapillaryProperties.SHOW_DETECTED_SIGNS.addListener(it -> repaint());
MapillaryProperties.DARK_MODE.addListener(it -> setDarkMode(it.getProperty().get()));
}

protected void setImage(BufferedImage image) {
this.image = image;
this.image = image;
}

public void setImage(BufferedImage image, Collection<ImageDetection> detections) {
Expand Down Expand Up @@ -137,13 +139,13 @@ public void paintComponent(Graphics g) {
}

private void paintNoImage(Graphics g) {
final String noImageStr = MapillaryLayer.hasInstance() ? tr("no image selected") : tr("Press \"{0}\" to download images", MapillaryDownloadAction.SHORTCUT.getKeyText());
final String noImageStr = MapillaryLayer.hasInstance() ? tr("no image selected")
: tr("Press \"{0}\" to download images", MapillaryDownloadAction.SHORTCUT.getKeyText());
if (noImageStr != null) {
Rectangle2D noImageSize = g.getFontMetrics(g.getFont()).getStringBounds(noImageStr, g);
Dimension size = getSize();
g.setColor(getForeground());
g.drawString(noImageStr,
(int) ((size.width - noImageSize.getWidth()) / 2),
g.drawString(noImageStr, (int) ((size.width - noImageSize.getWidth()) / 2),
(int) ((size.height - noImageSize.getHeight()) / 2));
}
}
Expand Down Expand Up @@ -181,14 +183,16 @@ private void paintDetections(Graphics g, Rectangle visibleRect) {
if (g instanceof Graphics2D) {
final Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(2));
List<PointObjectLayer> detectionLayers = MainApplication.getLayerManager().getLayersOfType(PointObjectLayer.class);
List<PointObjectLayer> detectionLayers = MainApplication.getLayerManager()
.getLayersOfType(PointObjectLayer.class);
synchronized (detections) {
paintDetections(g2d, visibleRect, detectionLayers);
}
}
}

protected abstract void paintDetections(Graphics2D g2d, Rectangle visibleRect, List<PointObjectLayer> detectionLayers);
protected abstract void paintDetections(Graphics2D g2d, Rectangle visibleRect,
List<PointObjectLayer> detectionLayers);

protected void checkAspectRatio(Rectangle zoomedRectangle) {
int hFact = zoomedRectangle.height * getSize().width;
Expand All @@ -213,16 +217,13 @@ public void zoomBestFitOrOne() {
if (zoomImage == null) {
return;
}
if (zoomVisibleRect.width != zoomImage.getWidth(null)
|| zoomVisibleRect.height != zoomImage.getHeight(null)) {
if (zoomVisibleRect.width != zoomImage.getWidth(null) || zoomVisibleRect.height != zoomImage.getHeight(null)) {
// The display is not at best fit. => Zoom to best fit
zoomVisibleRect = new Rectangle(0, 0, zoomImage.getWidth(null),
zoomImage.getHeight(null));
zoomVisibleRect = new Rectangle(0, 0, zoomImage.getWidth(null), zoomImage.getHeight(null));
} else {
// The display is at best fit => zoom to 1:1
Point center = getCenterImgCoord(zoomVisibleRect);
zoomVisibleRect = new Rectangle(center.x - getWidth() / 2, center.y
- getHeight() / 2, getWidth(), getHeight());
zoomVisibleRect = new Rectangle(center.x - getWidth() / 2, center.y - getHeight() / 2, getWidth(), getHeight());
ImageViewUtil.checkVisibleRectPos(zoomImage, zoomVisibleRect);
}
synchronized (this) {
Expand All @@ -237,21 +238,19 @@ protected static Point getCenterImgCoord(Rectangle visibleRect) {

protected Point comp2imgCoord(Rectangle visibleRect, int xComp, int yComp) {
Rectangle drawRect = calculateDrawImageRectangle(visibleRect);
return new Point(
visibleRect.x + ((xComp - drawRect.x) * visibleRect.width) / drawRect.width,
visibleRect.y + ((yComp - drawRect.y) * visibleRect.height) / drawRect.height
);
return new Point(visibleRect.x + ((xComp - drawRect.x) * visibleRect.width) / drawRect.width,
visibleRect.y + ((yComp - drawRect.y) * visibleRect.height) / drawRect.height);
}

protected Point img2compCoord(Rectangle visibleRect, int xImg, int yImg) {
Rectangle drawRect = calculateDrawImageRectangle(visibleRect);
return new Point(drawRect.x + ((xImg - visibleRect.x) * drawRect.width)
/ visibleRect.width, drawRect.y
+ ((yImg - visibleRect.y) * drawRect.height) / visibleRect.height);
return new Point(drawRect.x + ((xImg - visibleRect.x) * drawRect.width) / visibleRect.width,
drawRect.y + ((yImg - visibleRect.y) * drawRect.height) / visibleRect.height);
}

protected Rectangle calculateDrawImageRectangle(Rectangle visibleRect) {
return ImageViewUtil.calculateDrawImageRectangle(visibleRect, new Rectangle(0, 0, getSize().width, getSize().height));
return ImageViewUtil.calculateDrawImageRectangle(visibleRect,
new Rectangle(0, 0, getSize().width, getSize().height));
}

private void setDarkMode(final boolean darkMode) {
Expand All @@ -277,6 +276,7 @@ protected void checkZoom(Rectangle zoomedRectangle) {

/**
* Method for zooming.
*
* @param zoomCenterX The x coordinate in component where zoomed
* @param zoomCenterY The y coordinate in component where zoomed
* @param zoomedIn true if zoomed inwards else false
Expand All @@ -285,12 +285,14 @@ protected void checkZoom(Rectangle zoomedRectangle) {

/**
* Start dragging Image.
*
* @param p The point in component.
*/
public abstract void startPanning(Point p);

/**
* Drag Image to this point
*
* @param p The point in component.
*/
public abstract void pan(Point p);
Expand All @@ -314,4 +316,11 @@ public void disableZoomPan() {
zoomPanEnabled = false;
}
}

/**
* Get the camera plane rotation
*
* @return The rotation
*/
public abstract double getRotation();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapillary.gui.imageviewer;

import static org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils.checkIfDetectionIsFiltered;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
Expand All @@ -13,12 +15,13 @@
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.util.List;

import javax.swing.ImageIcon;

import org.openstreetmap.josm.plugins.mapillary.gui.layer.PointObjectLayer;
import org.openstreetmap.josm.plugins.mapillary.model.ImageDetection;
import org.openstreetmap.josm.plugins.mapillary.model.MapObject;
import org.openstreetmap.josm.plugins.mapillary.utils.ImageViewUtil;
import static org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils.checkIfDetectionIsFiltered;

public class MapillaryImageViewer extends AbstractImageViewer {

Expand All @@ -41,9 +44,8 @@ public Rectangle getDefaultVisibleRect() {
protected void paintImage(Graphics g, BufferedImage image, Rectangle visibleRect) {
Rectangle target = ImageViewUtil.calculateDrawImageRectangle(visibleRect,
new Rectangle(0, 0, getSize().width, getSize().height));
g.drawImage(image, target.x, target.y, target.x + target.width,
target.y + target.height, visibleRect.x, visibleRect.y,
visibleRect.x + visibleRect.width, visibleRect.y + visibleRect.height, this);
g.drawImage(image, target.x, target.y, target.x + target.width, target.y + target.height, visibleRect.x,
visibleRect.y, visibleRect.x + visibleRect.width, visibleRect.y + visibleRect.height, this);
}

@Override
Expand All @@ -69,10 +71,8 @@ public void zoom(int zoomCenterX, int zoomCenterY, boolean zoomedIn) {
checkAspectRatio(mouseVisibleRect);
ImageViewUtil.checkVisibleRectSize(mouseImage, mouseVisibleRect);
Rectangle drawRect = calculateDrawImageRectangle(mouseVisibleRect);
mouseVisibleRect.x = mousePointInImg.x
+ ((drawRect.x - zoomCenterX) * mouseVisibleRect.width) / drawRect.width;
mouseVisibleRect.y = mousePointInImg.y
+ ((drawRect.y - zoomCenterY) * mouseVisibleRect.height) / drawRect.height;
mouseVisibleRect.x = mousePointInImg.x + ((drawRect.x - zoomCenterX) * mouseVisibleRect.width) / drawRect.width;
mouseVisibleRect.y = mousePointInImg.y + ((drawRect.y - zoomCenterY) * mouseVisibleRect.height) / drawRect.height;
ImageViewUtil.checkVisibleRectPos(mouseImage, mouseVisibleRect);
synchronized (this) {
visibleRect = mouseVisibleRect;
Expand Down Expand Up @@ -113,7 +113,6 @@ public void pan(Point p) {
repaint();
}


@Override
protected void paintDetections(Graphics2D g2d, Rectangle visibleRect, List<PointObjectLayer> detectionLayers) {
final Point upperLeft = img2compCoord(visibleRect, 0, 0);
Expand Down Expand Up @@ -159,4 +158,9 @@ public void componentResized(ComponentEvent e) {
}
}
}

@Override
public double getRotation() {
return 0;
}
}
Loading

0 comments on commit cfbef1f

Please sign in to comment.