Commit c5de664c authored by Maxim Dudin's avatar Maxim Dudin
Browse files

#304 added a crude visualisation possibility for PedestriansNearbyProcessor.java

parent 17348905
Pipeline #240548 failed with stages
in 2 minutes and 34 seconds
{
"name" : "mf_base",
"description" : "",
"release" : "1.11",
"release" : "1.12",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.EventtimePedestrianIdOutputFile",
......
{
"name" : "mf_detailed",
"description" : "",
"release" : "1.11",
"release" : "1.12",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.EventtimePedestrianIdOutputFile",
......
{
"name" : "mf_underground",
"description" : "",
"release" : "1.11",
"release" : "1.12",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.EventtimePedestrianIdOutputFile",
......
{
"name" : "roVerTest002",
"description" : "",
"release" : "1.11",
"release" : "1.12",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.EventtimePedestrianIdOutputFile",
......
{
"name" : "scenario001",
"description" : "",
"release" : "1.11",
"release" : "1.12",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.EventtimePedestrianIdOutputFile",
......
{
"name" : "scenario002",
"description" : "",
"release" : "1.11",
"release" : "1.12",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.EventtimePedestrianIdOutputFile",
......
{
"name" : "separation_slow_fast",
"description" : "",
"release" : "1.11",
"release" : "1.12",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.EventtimePedestrianIdOutputFile",
......
......@@ -14,6 +14,7 @@ public class PedestriansNearbyData {
private int startTimestep;
private List<VPoint> trajectory;
private boolean printTrajectory;
private boolean printForPostVis; // is an ugly one time thing that shouldn't be merged
......@@ -30,13 +31,14 @@ public class PedestriansNearbyData {
return startTimestep;
}
public PedestriansNearbyData(int ped1, int ped2, final int durationTimesteps, int startTimestep, List<VPoint> contactTrajectory, boolean printTrajectory){
public PedestriansNearbyData(int ped1, int ped2, final int durationTimesteps, int startTimestep, List<VPoint> contactTrajectory, boolean printTrajectory, boolean printForPostVis){
this.pedId1 = Math.min(ped1, ped2);
this.pedId2 = Math.max(ped1, ped2);
this.durationTimesteps = durationTimesteps;
this.startTimestep = startTimestep;
this.trajectory = contactTrajectory;
this.printTrajectory = printTrajectory;
this.printForPostVis = printForPostVis;
}
public int getPedId1() {
......@@ -51,6 +53,10 @@ public class PedestriansNearbyData {
return durationTimesteps;
}
public boolean isPrintForPostVis() {
return printForPostVis;
}
public List<VPoint> getTrajectory() {
return trajectory;
}
......@@ -64,11 +70,30 @@ public class PedestriansNearbyData {
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);
return new PedestriansNearbyData(getPedId1(), getPedId2(), getDurationTimesteps() + sampleEveryNthStep, getStartTimestep(),traj, printTrajectory, printForPostVis);
}
public String[] toStrings(){
// printForPostVis is an ugly one time thing that shouldn't be merged
if (printForPostVis) {
StringBuilder ret = new StringBuilder();
List<VPoint> traj = getTrajectory();
for (int i = 0; i < traj.size(); i++) {
VPoint p = traj.get(i);
VPoint pNext;
if (i != traj.size() -1) {
pNext = traj.get(i + 1);
} else {
pNext = traj.get(i);
}
ret.append(hashCode()).append(" ").append(startTimestep*0.4 + i*0.4).append(" ").append(startTimestep*0.4 + (i+1)*0.4).append(" ").append(p.x).append(" ").append(p.y).append(" ").append(pNext.x).append(" ").append(pNext.y).append(" 9999");
if (i != traj.size() -1) {
ret.append("\n");
}
}
return new String[]{ret.toString()};
}
if (!printTrajectory) {
return new String[]{Integer.toString(durationTimesteps)};
}
......
......@@ -13,12 +13,14 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
private final int timeStep;
private final int pedId1; //smaller id
private final int pedId2; //bigger id
private final boolean printForPostVis;
public TimestepPedestriansNearbyIdKey(int timeStep, int pedA, int pedB) {
public TimestepPedestriansNearbyIdKey(int timeStep, int pedA, int pedB, boolean printForPostVis) {
this.timeStep = timeStep;
this.pedId1 = Math.min(pedA, pedB);
this.pedId2 = Math.max(pedA, pedB);
this.printForPostVis = printForPostVis; // is an ugly one time thing that shouldn't be merged
}
......@@ -39,6 +41,11 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
}
public String[] toStrings(){
// printForPostVis is an ugly one time thing that shouldn't be merged
if (printForPostVis) {
//return new String[]{Integer.toString(999), Double.toString(timeStep*0.4), Double.toString(timeStep*0.4 + 0.4)};
return new String[]{};
}
return new String[]{Integer.toString(timeStep), Integer.toString(pedId1), Integer.toString(pedId2)};
}
......@@ -49,8 +56,7 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
(other.getStartTimestep() + other.getDurationTimesteps() + toleranceTimesteps >= getTimeStep());
}
public boolean isAccountedForBy(PedestriansNearbyData other) {
return equals(other) ||
(other.getPedId1() == getPedId1() &&
return (other.getPedId1() == getPedId1() &&
other.getPedId2() == getPedId2() &&
getTimeStep() >= other.getStartTimestep() &&
getTimeStep() < other.getStartTimestep() + other.getDurationTimesteps());
......
......@@ -26,6 +26,8 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian
private int allowedAbsenceTimestepsIfContactReturns;
private int minTimespanOfContactTimesteps;
private boolean printContacTrajectories;
private boolean printForPostVis;
public PedestriansNearbyProcessor() {
......@@ -49,12 +51,15 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian
.parallelStream()
.filter(p -> ped.getId() != p.getId())
.map(p -> {
VPoint pointOfContact = new VPoint(ped.getPosition().getX() - p.getPosition().getX(), ped.getPosition().getY() - p.getPosition().getY());
double xAverage = (ped.getPosition().getX() + p.getPosition().getX())/2.;
double yAverage = (ped.getPosition().getY() + p.getPosition().getY())/2.;
System.out.println("x1= " + ped.getPosition().getX() + "y1= " + ped.getPosition().getY() + "x2= " + p.getPosition().getX() + "y2= " + p.getPosition().getY() + "xAver= " + xAverage + "yAver= " + yAverage);
VPoint pointOfContact = new VPoint(xAverage, yAverage);
List<VPoint> trajectory = new ArrayList<>();
trajectory.add(pointOfContact);
return new PedestriansNearbyData(ped.getId(), p.getId(), sampleEveryNthStep, timeStep, trajectory, printContacTrajectories);})
return new PedestriansNearbyData(ped.getId(), p.getId(), sampleEveryNthStep, timeStep, trajectory, printContacTrajectories, printForPostVis);})
.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(), printForPostVis), o));
}
}
......@@ -98,6 +103,8 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian
allowedAbsenceTimestepsIfContactReturns = att.getAllowedAbsenceTimestepsIfContactReturns();
minTimespanOfContactTimesteps = att.getMinTimespanOfContactTimesteps();
printContacTrajectories = att.getPrintContactTrajectories();
printForPostVis = att.getPrintForPostVis();
}
private List<DynamicElement> getDynElementsAtPosition(final Topography topography, VPoint sourcePosition, double radius) {
......
......@@ -11,6 +11,8 @@ public class AttributesPedestrianNearbyProcessor extends AttributesProcessor {
private int allowedAbsenceTimestepsIfContactReturns = 0;
private int minTimespanOfContactTimesteps = 1;
private boolean printContactTrajectories = false;
private boolean printForPostVis = false;
public double getMaxDistanceForANearbyPedestrian() {
return maxDistanceForANearbyPedestrian;
......@@ -31,4 +33,8 @@ public class AttributesPedestrianNearbyProcessor extends AttributesProcessor {
public boolean getPrintContactTrajectories() {
return printContactTrajectories;
}
public boolean getPrintForPostVis() {
return printForPostVis;
}
}
Markdown is supported
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