Commit 041df0c1 authored by Maxim Dudin's avatar Maxim Dudin
Browse files

added a possibility to print the array of middle points for each contact,...

added a possibility to print the array of middle points for each contact, attribute is adjustable over json
parent 9f8b8855
package org.vadere.simulator.projects.dataprocessing.datakey; package org.vadere.simulator.projects.dataprocessing.datakey;
import org.vadere.state.scenario.DynamicElement; import org.vadere.state.scenario.DynamicElement;
import org.vadere.util.geometry.shapes.VPoint;
public class PedestriansNearbyData { import java.util.ArrayList;
import java.util.List;
public static final PedestriansNearbyData noOverLap = new PedestriansNearbyData(); public class PedestriansNearbyData {
private final int pedId1; private final int pedId1;
private final int pedId2; private final int pedId2;
private int durationTimesteps; private int durationTimesteps;
private int startTimestep; private int startTimestep;
private List<VPoint> trajectory;
private boolean printTrajectory;
private PedestriansNearbyData() { /*private PedestriansNearbyData() {
this.pedId1 = -1; this.pedId1 = -1;
this.pedId2 = -1; this.pedId2 = -1;
this.durationTimesteps = 1; this.durationTimesteps = 1;
this.startTimestep = 1; this.startTimestep = 1;
} this.trajectory = new ArrayList<>();
}*/
public int getStartTimestep() { public int getStartTimestep() {
return startTimestep; return startTimestep;
} }
public PedestriansNearbyData(int ped1, int ped2, final int durationTimesteps, int startTimestep){ public PedestriansNearbyData(int ped1, int ped2, final int durationTimesteps, int startTimestep, List<VPoint> contactTrajectory, boolean printTrajectory){
this.pedId1 = Math.min(ped1, ped2); this.pedId1 = Math.min(ped1, ped2);
this.pedId2 = Math.max(ped1, ped2); this.pedId2 = Math.max(ped1, ped2);
this.durationTimesteps = durationTimesteps; this.durationTimesteps = durationTimesteps;
this.startTimestep = startTimestep; this.startTimestep = startTimestep;
this.trajectory = contactTrajectory;
this.printTrajectory = printTrajectory;
} }
public int getPedId1() { public int getPedId1() {
...@@ -43,13 +51,37 @@ public class PedestriansNearbyData { ...@@ -43,13 +51,37 @@ public class PedestriansNearbyData {
return durationTimesteps; return durationTimesteps;
} }
public PedestriansNearbyData getDataWithIncrementedDuration(int increment) { public List<VPoint> getTrajectory() {
return new PedestriansNearbyData(getPedId1(), getPedId2(), getDurationTimesteps() + increment, getStartTimestep()); return trajectory;
}
public void addToContactTrajectory(VPoint point) {
trajectory.add(point);
}
public void addToContactTrajectory(List<VPoint> points) {
trajectory.addAll(points);
}
public PedestriansNearbyData getUpdatedData(PedestriansNearbyData newData, int sampleEveryNthStep) {
List<VPoint> traj = getTrajectory();
traj.addAll(newData.getTrajectory());
return new PedestriansNearbyData(getPedId1(), getPedId2(), getDurationTimesteps() + sampleEveryNthStep, getStartTimestep(),traj, printTrajectory);
} }
public String[] toStrings(){ public String[] toStrings(){
if (!printTrajectory) {
return new String[]{Integer.toString(durationTimesteps)}; return new String[]{Integer.toString(durationTimesteps)};
} }
StringBuilder ret = new StringBuilder();
List<VPoint> traj = getTrajectory();
for (int i = 0; i < traj.size(); i++) {
VPoint p = traj.get(i);
ret.append(p.x).append(" ").append(p.y).append("\n");
if (i != traj.size() -1) {
ret.append("- - - - ");
}
}
return new String[]{Integer.toString(durationTimesteps), ret.toString()};
}
} }
...@@ -5,7 +5,6 @@ import org.vadere.simulator.control.simulation.SimulationState; ...@@ -5,7 +5,6 @@ import org.vadere.simulator.control.simulation.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager; import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestriansNearbyData; import org.vadere.simulator.projects.dataprocessing.datakey.PedestriansNearbyData;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestriansNearbyIdKey; import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestriansNearbyIdKey;
import org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor;
import org.vadere.state.attributes.processor.AttributesPedestrianNearbyProcessor; import org.vadere.state.attributes.processor.AttributesPedestrianNearbyProcessor;
import org.vadere.state.scenario.DynamicElement; import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.Pedestrian; import org.vadere.state.scenario.Pedestrian;
...@@ -26,10 +25,11 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian ...@@ -26,10 +25,11 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian
private int sampleEveryNthStep; private int sampleEveryNthStep;
private int allowedAbsenceTimestepsIfContactReturns; private int allowedAbsenceTimestepsIfContactReturns;
private int minTimespanOfContactTimesteps; private int minTimespanOfContactTimesteps;
private boolean printContacTrajectories;
public PedestriansNearbyProcessor() { public PedestriansNearbyProcessor() {
super("durationTimesteps"); super("durationTimesteps", "xCoord-Contact", "yCoord-Contact");
setAttributes(new AttributesPedestrianNearbyProcessor()); setAttributes(new AttributesPedestrianNearbyProcessor());
} }
...@@ -48,7 +48,11 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian ...@@ -48,7 +48,11 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian
List<PedestriansNearbyData> pedsNearby = dynElemNneighbours List<PedestriansNearbyData> pedsNearby = dynElemNneighbours
.parallelStream() .parallelStream()
.filter(p -> ped.getId() != p.getId()) .filter(p -> ped.getId() != p.getId())
.map(p -> new PedestriansNearbyData(ped.getId(), p.getId(), sampleEveryNthStep, timeStep)) .map(p -> {
VPoint pointOfContact = new VPoint(ped.getPosition().getX() - p.getPosition().getX(), ped.getPosition().getY() - p.getPosition().getY());
List<VPoint> trajectory = new ArrayList<>();
trajectory.add(pointOfContact);
return new PedestriansNearbyData(ped.getId(), p.getId(), sampleEveryNthStep, timeStep, trajectory, printContacTrajectories);})
.collect(Collectors.toList()); .collect(Collectors.toList());
pedsNearby.forEach(o -> this.putValue(new TimestepPedestriansNearbyIdKey(timeStep, o.getPedId1(), o.getPedId2()), o)); pedsNearby.forEach(o -> this.putValue(new TimestepPedestriansNearbyIdKey(timeStep, o.getPedId1(), o.getPedId2()), o));
} }
...@@ -78,7 +82,7 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian ...@@ -78,7 +82,7 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian
if (key.isAccountedForBy(currentVal)) { if (key.isAccountedForBy(currentVal)) {
return; return;
} else if (key.isContinuationOf(currentVal, allowedAbsenceTimestepsIfContactReturns)) { } else if (key.isContinuationOf(currentVal, allowedAbsenceTimestepsIfContactReturns)) {
super.putValue(alreadyExisting, currentVal.getDataWithIncrementedDuration(sampleEveryNthStep)); super.putValue(alreadyExisting, currentVal.getUpdatedData(value, sampleEveryNthStep));
return; return;
} }
} }
...@@ -93,6 +97,7 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian ...@@ -93,6 +97,7 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian
sampleEveryNthStep = att.getSampleEveryNthStep(); sampleEveryNthStep = att.getSampleEveryNthStep();
allowedAbsenceTimestepsIfContactReturns = att.getAllowedAbsenceTimestepsIfContactReturns(); allowedAbsenceTimestepsIfContactReturns = att.getAllowedAbsenceTimestepsIfContactReturns();
minTimespanOfContactTimesteps = att.getMinTimespanOfContactTimesteps(); minTimespanOfContactTimesteps = att.getMinTimespanOfContactTimesteps();
printContacTrajectories = att.getPrintContactTrajectories();
} }
private List<DynamicElement> getDynElementsAtPosition(final Topography topography, VPoint sourcePosition, double radius) { private List<DynamicElement> getDynElementsAtPosition(final Topography topography, VPoint sourcePosition, double radius) {
......
...@@ -10,6 +10,7 @@ public class AttributesPedestrianNearbyProcessor extends AttributesProcessor { ...@@ -10,6 +10,7 @@ public class AttributesPedestrianNearbyProcessor extends AttributesProcessor {
private int sampleEveryNthStep = 1; private int sampleEveryNthStep = 1;
private int allowedAbsenceTimestepsIfContactReturns = 0; private int allowedAbsenceTimestepsIfContactReturns = 0;
private int minTimespanOfContactTimesteps = 1; private int minTimespanOfContactTimesteps = 1;
private boolean printContactTrajectories = false;
public double getMaxDistanceForANearbyPedestrian() { public double getMaxDistanceForANearbyPedestrian() {
return maxDistanceForANearbyPedestrian; return maxDistanceForANearbyPedestrian;
...@@ -26,4 +27,8 @@ public class AttributesPedestrianNearbyProcessor extends AttributesProcessor { ...@@ -26,4 +27,8 @@ public class AttributesPedestrianNearbyProcessor extends AttributesProcessor {
public int getMinTimespanOfContactTimesteps() { public int getMinTimespanOfContactTimesteps() {
return minTimespanOfContactTimesteps; return minTimespanOfContactTimesteps;
} }
public boolean getPrintContactTrajectories() {
return printContactTrajectories;
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment