Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Reduce memory allocations in MapillaryLayer
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Aug 3, 2023
1 parent 8619a39 commit 373b269
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.stream.Stream;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
Expand Down Expand Up @@ -138,11 +139,11 @@ public final class MapillaryLayer extends MVTLayer implements ActiveLayerChangeL
private final ColorScale dateScale = ColorScale.createFixedScale(
// Really old color
new Color[] { ColorHelper.html2color("e17155"),
// Old color
ColorHelper.html2color("fbc01b"),
// New color
MapillaryColorScheme.SEQ_UNSELECTED
}).addTitle(tr("Time"));
// Old color
ColorHelper.html2color("fbc01b"),
// New color
MapillaryColorScheme.SEQ_UNSELECTED })
.addTitle(tr("Time"));

/** The color scale used when drawing using direction */
private final ColorScale directionScale = ColorScale.createCyclicScale(256).setIntervalCount(4)
Expand Down Expand Up @@ -361,14 +362,14 @@ private void paintWithLock(final Graphics2D g, final MapView mv, final Bounds bo
drawSequence(g, mv, way, selectedImage, originalTransform, distPer100Pixel);
for (INode n : way.getNodes()) {
if (n != selectedImage) {
drawImageMarker(originalTransform, selectedImage, g, n, distPer100Pixel, false);
drawImageMarker(originalTransform, selectedImage, g, n, distPer100Pixel, false, null);
}
}
}
// Paint selected images last. Not particularly worried about painting too much, since most people don't
// select thousands of images.
drawImageMarker(originalTransform, selectedImage, g, selectedImage, distPer100Pixel,
OffsetUtils.getOffset(selectedImage) != 0);
OffsetUtils.getOffset(selectedImage) != 0, null);
}
}

Expand Down Expand Up @@ -402,21 +403,19 @@ private void drawSequence(final Graphics2D g, final MapView mv, final IWay<?> se
g.setColor(forcedColor != null ? forcedColor : getColor(current));
}
if (previous != null && (mv.contains(currentPoint) || mv.contains(previousPoint))) {
// FIXME get the right color for the line segment
final boolean visibleNode = zoom >= 14 && sequence.isVisible() && MapillaryImageUtils.isImage(previous);
g.drawLine(previousPoint.x, previousPoint.y, currentPoint.x, currentPoint.y);
if (visibleNode) {
// FIXME draw the image here (avoid calculating the points twice)
drawImageMarker(originalTransform, selectedImage, g, previous, distPer100Pixel, false);
drawImageMarker(originalTransform, selectedImage, g, previous, distPer100Pixel, false,
previousPoint);
}
}
previous = current;
previousPoint = currentPoint;
}
final boolean visibleNode = zoom >= 14 && sequence.isVisible() && MapillaryImageUtils.isImage(previous);
if (visibleNode) {
// FIXME draw the image here (avoid calculating the points twice)
drawImageMarker(originalTransform, selectedImage, g, previous, distPer100Pixel, false);
drawImageMarker(originalTransform, selectedImage, g, previous, distPer100Pixel, false, previousPoint);
}
g.setComposite(AlphaComposite.SrcOver);
}
Expand Down Expand Up @@ -487,11 +486,12 @@ private static double calculateVelocity(@Nonnull INode node) {
* @param selectedImg Currently selected nodes
* @param g the Graphics context
* @param img the image to be drawn onto the Graphics context
* @param imgPoint The point where the image is located in the graphics space
* @param dist100Pixel The distance per 100 px
* @param offset {@code true} if we may be painting the offset for an image
*/
private void drawImageMarker(final AffineTransform originalTransform, final INode selectedImg, final Graphics2D g,
final INode img, final double dist100Pixel, final boolean offset) {
final INode img, final double dist100Pixel, final boolean offset, @Nullable final Point imgPoint) {
if (img == null || !img.isLatLonKnown()) {
Logging.warn("An image is not painted, because it is null or has no LatLon!");
return;
Expand Down Expand Up @@ -531,7 +531,7 @@ private void drawImageMarker(final AffineTransform originalTransform, final INod
}
MapView mv = MainApplication.getMap().mapView;

final Point p = mv.getPoint(img.getEastNorth());
final Point p = imgPoint != null ? imgPoint : mv.getPoint(img.getEastNorth());
paintDirectionIndicator(g, directionC, img, originalTransform, p, i);
this.paintHighlight(g, img, selectedImg);

Expand Down

0 comments on commit 373b269

Please sign in to comment.