Skip to content

Commit 56b8ad8

Browse files
committed
Drop velocity rendering due to point deduplication
Signed-off-by: Taylor Smock <tsmock@meta.com>
1 parent ed23a33 commit 56b8ad8

File tree

3 files changed

+23
-49
lines changed

3 files changed

+23
-49
lines changed

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/layer/MapillaryLayer.java

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@
1414
import java.awt.RenderingHints;
1515
import java.awt.Stroke;
1616
import java.awt.geom.AffineTransform;
17-
import java.awt.geom.Ellipse2D;
18-
import java.awt.geom.Line2D;
1917
import java.awt.geom.Point2D;
2018
import java.time.Instant;
2119
import java.time.temporal.ChronoUnit;
22-
import java.time.temporal.TemporalUnit;
23-
import java.util.ArrayList;
2420
import java.util.Collection;
2521
import java.util.Collections;
2622
import java.util.Comparator;
@@ -137,9 +133,6 @@ public final class MapillaryLayer extends MVTLayer implements ActiveLayerChangeL
137133
private static final ImageIcon SELECTED_IMAGE = new ImageProvider(IMAGE_SPRITE_DIR, "current-ca")
138134
.setMaxWidth(ImageProvider.ImageSizes.MAP.getAdjustedHeight()).get();
139135

140-
private static final Ellipse2D IMAGE_CIRCLE = new Ellipse2D.Double(-IMG_MARKER_RADIUS, -IMG_MARKER_RADIUS,
141-
2 * IMG_MARKER_RADIUS, 2 * IMG_MARKER_RADIUS);
142-
143136
/** The color scale used when drawing using velocity */
144137
private final ColorScale velocityScale = ColorScale.createHSBScale(256);
145138
/** The color scale used when drawing using date */
@@ -152,12 +145,11 @@ public final class MapillaryLayer extends MVTLayer implements ActiveLayerChangeL
152145

153146
/** The color scale used when drawing using direction */
154147
private final ColorScale directionScale = ColorScale.createCyclicScale(256).setIntervalCount(4)
155-
.addTitle(tr("Direction"));;
148+
.addTitle(tr("Direction"));
156149

157150
/** The nearest images to the selected image from different sequences sorted by distance from selection. */
158151
// Use ArrayList instead of an array, since there will not be thousands of instances, and allows for better
159152
// synchronization
160-
private final List<INode> nearestImages = Collections.synchronizedList(new ArrayList<>(2));
161153

162154
/** The images that have been viewed since the last upload */
163155
private final ConcurrentHashMap<DataSet, Set<INode>> imageViewedMap = new ConcurrentHashMap<>(1);
@@ -198,7 +190,8 @@ private MapillaryLayer() {
198190
private void setupColorScales() {
199191
this.dateScale.setNoDataColor(MapillaryColorScheme.SEQ_UNSELECTED);
200192
// ChronoUnit.YEARS isn't supported since a year can be either 365 or 366.
201-
this.dateScale.setRange(Instant.now().minus(4 * 365L, ChronoUnit.DAYS).toEpochMilli(), Instant.now().toEpochMilli());
193+
this.dateScale.setRange(Instant.now().minus(4 * 365L, ChronoUnit.DAYS).toEpochMilli(),
194+
Instant.now().toEpochMilli());
202195
this.directionScale.setNoDataColor(MapillaryColorScheme.SEQ_UNSELECTED);
203196
this.velocityScale.setNoDataColor(MapillaryColorScheme.SEQ_UNSELECTED);
204197
}
@@ -347,20 +340,6 @@ private void paintWithLock(final Graphics2D g, final MapView mv, final Bounds bo
347340
MapillaryProperties.UNSELECTED_OPACITY.get().floatValue());
348341

349342
final INode selectedImage = this.image;
350-
synchronized (this) {
351-
for (int i = 0; i < this.nearestImages.size(); i++) {
352-
if (i % 2 == 0) {
353-
g.setColor(Color.RED);
354-
} else {
355-
g.setColor(Color.BLUE);
356-
}
357-
if (selectedImage != null) {
358-
final Point selected = mv.getPoint(selectedImage);
359-
final Point p = mv.getPoint(this.nearestImages.get(i));
360-
g.draw(new Line2D.Double(p.getX(), p.getY(), selected.getX(), selected.getY()));
361-
}
362-
}
363-
}
364343

365344
// Draw sequence line
366345
g.setStroke(new BasicStroke(2));
@@ -398,31 +377,19 @@ private void drawSequence(final Graphics2D g, final MapView mv, final IWay<?> se
398377
if (selectedImage != null && !nodes.contains(selectedImage)) {
399378
g.setComposite(fadeComposite);
400379
}
401-
// START OLD IMAGE BITS FIXME
380+
final Color forcedColor;
402381
if (sequence.getNodes().contains(selectedImage)) {
403-
g.setColor(!MapillarySequenceUtils.hasKey(sequence) ? MapillaryColorScheme.SEQ_IMPORTED_SELECTED
404-
: MapillaryColorScheme.SEQ_SELECTED);
382+
forcedColor = !MapillarySequenceUtils.hasKey(sequence) ? MapillaryColorScheme.SEQ_IMPORTED_SELECTED
383+
: MapillaryColorScheme.SEQ_SELECTED;
405384
} else {
406-
final Color color;
407-
if (MapillarySequenceUtils.hasKey(sequence)) {
408-
final INode toCheck = sequence.getNodes().stream()
409-
.filter(inode -> !Instant.EPOCH.equals(MapillaryImageUtils.getDate(inode))).map(INode.class::cast)
410-
.findFirst().orElse(sequence.firstNode());
411-
color = getColor(toCheck);
412-
} else {
413-
color = MapillaryColorScheme.SEQ_IMPORTED_UNSELECTED;
414-
}
415-
g.setColor(color);
416-
if (selectedImage != null) {
417-
g.setComposite(fadeComposite);
418-
}
385+
forcedColor = null;
419386
}
420-
// END OLD IMAGE BITS FIXME
421387
final int zoom = getZoomLevel();
422388
INode previous = null;
423389
Point previousPoint = null;
424390
for (INode current : nodes) {
425391
final Point currentPoint = mv.getPoint(current);
392+
g.setColor(forcedColor != null ? forcedColor : getColor(current));
426393
if (previous != null && (mv.contains(currentPoint) || mv.contains(previousPoint))) {
427394
// FIXME get the right color for the line segment
428395
g.drawLine(previousPoint.x, previousPoint.y, currentPoint.x, currentPoint.y);
@@ -493,7 +460,7 @@ private static double calculateVelocity(@Nonnull INode node) {
493460
final long dt = MapillaryImageUtils.getDate(second).toEpochMilli()
494461
- MapillaryImageUtils.getDate(first).toEpochMilli();
495462
final double dd = second.greatCircleDistance(first);
496-
return dd / dt;
463+
return dd / (dt / 1000d);
497464
}
498465
}
499466
return Double.NaN;
@@ -588,13 +555,13 @@ private static void paintDirectionIndicator(Graphics2D g, Color directionC, INod
588555
scale.scale(2, 2);
589556
g.setTransform(scale);
590557
g.setComposite(fadeComposite);
591-
g.fill(IMAGE_CIRCLE);
558+
g.fillOval(-IMG_MARKER_RADIUS, -IMG_MARKER_RADIUS, 2 * IMG_MARKER_RADIUS, 2 * IMG_MARKER_RADIUS);
592559
g.setComposite(currentComposite);
593560
}
594561
final AffineTransform translate = AffineTransform.getTranslateInstance(p.x, p.y);
595562
translate.preConcatenate(originalTransform);
596563
g.setTransform(translate);
597-
g.fill(IMAGE_CIRCLE);
564+
g.fillOval(-IMG_MARKER_RADIUS, -IMG_MARKER_RADIUS, 2 * IMG_MARKER_RADIUS, 2 * IMG_MARKER_RADIUS);
598565
if (i != null) {
599566
// This _must_ be set after operations complete (see JOSM #19516 for more information)
600567
// convert the angle to radians from degrees

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/preferences/display/MapillaryGPXSettingsPanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public MapillaryGPXSettingsPanel(Collection<MapillaryLayer> layers) {
6161

6262
add(new JLabel(tr("Track and Point Coloring")), GBC.eol().insets(20, 0, 0, 0));
6363
add(colorTypeDefault, GBC.eol().insets(40, 0, 0, 0));
64-
add(colorTypeVelocity, GBC.std().insets(40, 0, 0, 0));
65-
add(colorTypeVelocityTune, GBC.eop().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
64+
// add(colorTypeVelocity, GBC.std().insets(40, 0, 0, 0));
65+
// add(colorTypeVelocityTune, GBC.eop().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
6666
add(colorTypeDirection, GBC.eol().insets(40, 0, 0, 0));
6767
add(colorTypeTrackTime, GBC.eol().insets(40, 0, 0, 0));
6868

src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/MapillarySequenceUtils.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,20 @@ public static INode getNextOrPrevious(@Nonnull INode node, @Nullable NextOrPrevi
6767
nodes.addAll(0, newNodes);
6868
}
6969
}
70-
nodes.removeIf(n -> !MapillaryImageUtils.isDownloadable(n));
7170
final INode nodeOnCurrentSequence;
7271
int index = nodes.indexOf(node);
7372
if (next == NextOrPrevious.NEXT && index + 1 < nodes.size()) {
74-
nodeOnCurrentSequence = nodes.get(index + 1);
73+
INode expectedNext = nodes.get(++index);
74+
while (!MapillaryImageUtils.isImage(expectedNext) && index < nodes.size() - 1) {
75+
expectedNext = nodes.get(++index);
76+
}
77+
nodeOnCurrentSequence = expectedNext;
7578
} else if (next == NextOrPrevious.PREVIOUS && index > 0) {
76-
nodeOnCurrentSequence = nodes.get(index - 1);
79+
INode expectedPrevious = nodes.get(--index);
80+
while (!MapillaryImageUtils.isImage(expectedPrevious) && index > 0) {
81+
expectedPrevious = nodes.get(--index);
82+
}
83+
nodeOnCurrentSequence = expectedPrevious;
7784
} else {
7885
nodeOnCurrentSequence = null;
7986
}

0 commit comments

Comments
 (0)