Skip to content

Commit d8580c0

Browse files
types/map/ScatterPointsElement: Tweaked vehicle tail for better display.
1 parent 45352ea commit d8580c0

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

src/java/pt/lsts/neptus/renderer2d/StateRenderer2D.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import java.awt.image.BufferedImage;
6565
import java.text.NumberFormat;
6666
import java.util.Collection;
67+
import java.util.Date;
6768
import java.util.Enumeration;
6869
import java.util.HashSet;
6970
import java.util.Hashtable;
@@ -570,6 +571,8 @@ public MapGroup getMapGroup() {
570571
*/
571572
public void vehicleStateChanged(String systemId, SystemPositionAndAttitude state, boolean repaint) {
572573
if (state == null) {
574+
NeptusLog.pub().warn(">>>>>>>>>> Tail for {} state was null, clearing tail!! (was {}) <<<<<<<<<<", systemId,
575+
vehicleTails.containsKey(systemId) ? vehicleTails.get(systemId).getNumberOfPoints() : "-");
573576
vehicleStates.remove(systemId);
574577
vehicleTails.remove(systemId);
575578
vehicles = vehicleStates.keySet().toArray(new String[0]);
@@ -605,7 +608,11 @@ public void vehicleStateChanged(String systemId, SystemPositionAndAttitude state
605608
vehicleStates.put(systemId, state);
606609

607610
//double[] distFromRef = state.getPosition().getOffsetFrom(vehicleTails.get(systemId).getCenterLocation());
608-
vehicleTails.get(systemId).addPoint(state.getPosition());
611+
if (state.getTime() > vehicleTails.get(systemId).getLastLocationTimeMillis() || vehicleTails.get(systemId).getLastLocationTimeMillis() == -1) {
612+
NeptusLog.pub().trace(">>>>>>>>>> Tail for {} ADD element. (was {}) @ {} <<<<<<<<<<", systemId,
613+
vehicleTails.get(systemId).getPoints().size(), new Date(state.getTime()));
614+
}
615+
vehicleTails.get(systemId).addPoint(state.getPosition(), state.getTime());
609616

610617
if (!repaint || System.currentTimeMillis() - lastPaintTime < minDelay) {
611618
return;

src/java/pt/lsts/neptus/types/map/ScatterPointsElement.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public class ScatterPointsElement extends AbstractElement {
8686
protected Point3d lastRemoved = null;
8787
private int gradientcolor = 0;
8888

89+
int maxDistToChangeCenterMeters = 10_000;
90+
8991
public ScatterPointsElement() {
9092
super();
9193
}
@@ -221,10 +223,34 @@ public void clearPoints() {
221223
}
222224

223225
public void addPoint(LocationType loc) {
224-
if (loc.getDistanceInMeters(getCenterLocation()) > 3000) {
226+
double distanceInMeters = loc.getDistanceInMeters(getCenterLocation());
227+
if (distanceInMeters > maxDistToChangeCenterMeters) {
228+
NeptusLog.pub().warn("Point {} is too far away ({}m) from the center location ({}). Changing center location to the new point.",
229+
loc, distanceInMeters, getCenterLocation());
230+
synchronized (points) {
231+
// Iterate from the start to the end, removing points that are too far away
232+
for (int i = 0; i < points.size(); i++) {
233+
Point3d pt = points.get(i);
234+
LocationType ptLoc = new LocationType(getCenterLocation());
235+
ptLoc.translatePosition(pt.x, pt.y, pt.z);
236+
double dist = ptLoc.getDistanceInMeters(loc);
237+
if (dist > maxDistToChangeCenterMeters * 3) {
238+
NeptusLog.pub().warn("Removing point {} at distance {}m from the new center location {}",
239+
pt, dist, loc);
240+
points.remove(i);
241+
i--; // Adjust index after removal
242+
} else {
243+
double[] offsets = ptLoc.getOffsetFrom(loc);
244+
pt.x = offsets[0];
245+
pt.y = offsets[1];
246+
pt.z = offsets[2];
247+
}
248+
}
249+
}
250+
225251
setCenterLocation(loc);
226252
addPoint(0, 0, 0);
227-
clearPoints();
253+
// clearPoints();
228254
}
229255
else {
230256
double[] offsets = loc.getOffsetFrom(getCenterLocation());

src/java/pt/lsts/neptus/types/map/VehicleTailElement.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
*/
3333
package pt.lsts.neptus.types.map;
3434

35+
import pt.lsts.neptus.NeptusLog;
36+
import pt.lsts.neptus.types.coord.LocationType;
37+
3538
import java.awt.Color;
3639

3740

@@ -41,6 +44,8 @@
4144
*/
4245
public class VehicleTailElement extends ScatterPointsElement {
4346

47+
private long lastLocationTimeMillis = -1;
48+
4449
public VehicleTailElement() {
4550
super();
4651
}
@@ -56,5 +61,33 @@ public VehicleTailElement(MapGroup mg, MapType parentMap, Color baseColor) {
5661
@Override
5762
public String getType() {
5863
return "Vehicle tail";
59-
}
64+
}
65+
66+
public void addPoint(LocationType loc, long timeMillis) {
67+
if (timeMillis <= lastLocationTimeMillis && lastLocationTimeMillis != -1) {
68+
// If the new point is older than the last one, ignore it
69+
NeptusLog.pub().trace("Received a location point with time {} older than or equal to the last one: {}",
70+
timeMillis, lastLocationTimeMillis);
71+
return;
72+
}
73+
74+
super.addPoint(loc);
75+
lastLocationTimeMillis = timeMillis;
76+
}
77+
78+
@Override
79+
public void addPoint(LocationType loc) {
80+
super.addPoint(loc);
81+
lastLocationTimeMillis = System.currentTimeMillis();
82+
}
83+
84+
@Override
85+
public void clearPoints() {
86+
super.clearPoints();
87+
lastLocationTimeMillis = -1;
88+
}
89+
90+
public long getLastLocationTimeMillis() {
91+
return lastLocationTimeMillis;
92+
}
6093
}

0 commit comments

Comments
 (0)