Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 2d5d4900 authored by Christina Maria Mayr's avatar Christina Maria Mayr
Browse files

Merge branch 'target_changer_prob_list_MD' into 'master'

Visualize contacts in post-visualization

See merge request !126
parents d06e01a9 04cc8d24
Pipeline #257242 passed with stages
in 145 minutes and 2 seconds
......@@ -15,6 +15,10 @@
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "overlapCount.txt",
"processors" : [ 4 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestriansNearbyIdOutputFile",
"filename" : "pedsNearby.txt",
"processors" : [ 8 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
......@@ -32,6 +36,9 @@
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.FootStepTargetIDProcessor",
"id" : 6
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestriansNearbyProcessor",
"id" : 8
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
......
{
"name" : "Liddle_osm_v4",
"description" : "",
"release" : "1.12",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.EventtimePedestrianIdOutputFile",
"filename" : "postvis.traj",
"processors" : [ 1, 2 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "overlap.csv",
"processors" : [ 3 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "overlapCount.txt",
"processors" : [ 4 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestriansNearbyIdOutputFile",
"filename" : "contacts.txt",
"processors" : [ 5 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.FootStepProcessor",
"id" : 1
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.FootStepTargetIDProcessor",
"id" : 2
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
"id" : 3
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor",
"attributes" : {
"pedestrianOverlapProcessorId" : 3
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestriansNearbyProcessor",
"id" : 5,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianNearbyProcessor",
"attributes" : {
"maxDistanceForANearbyPedestrian" : 1.5,
"sampleEveryNthStep" : 1,
"allowedAbsenceTimestepsIfContactReturns" : 0,
"minTimespanOfContactTimesteps" : 1
}
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
},
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesOSM" : {
"stepCircleResolution" : 4,
"numberOfCircles" : 1,
"optimizationType" : "NELDER_MEAD",
"varyStepDirection" : false,
"movementType" : "ARBITRARY",
"stepLengthIntercept" : 0.4625,
"stepLengthSlopeSpeed" : 0.2345,
"stepLengthSD" : 0.036,
"movementThreshold" : 0.0,
"minStepLength" : 0.1,
"minimumStepLength" : true,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : true,
"updateType" : "EVENT_DRIVEN",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompactSoftshell",
"obstaclePotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldObstacleCompactSoftshell",
"submodels" : [ ]
},
"org.vadere.state.attributes.models.AttributesPotentialCompactSoftshell" : {
"pedPotentialIntimateSpaceWidth" : 0.45,
"pedPotentialPersonalSpaceWidth" : 1.2,
"pedPotentialHeight" : 50.0,
"obstPotentialWidth" : 0.8,
"obstPotentialHeight" : 6.0,
"intimateSpaceFactor" : 1.2,
"personalSpacePower" : 1,
"intimateSpacePower" : 1
},
"org.vadere.state.attributes.models.AttributesFloorField" : {
"createMethod" : "HIGH_ACCURACY_FAST_MARCHING",
"potentialFieldResolution" : 0.1,
"obstacleGridPenalty" : 0.1,
"targetAttractionStrength" : 1.0,
"cacheType" : "NO_CACHE",
"cacheDir" : "",
"timeCostAttributes" : {
"standardDeviation" : 0.7,
"type" : "UNIT",
"obstacleDensityWeight" : 3.5,
"pedestrianSameTargetDensityWeight" : 3.5,
"pedestrianOtherTargetDensityWeight" : 3.5,
"pedestrianWeight" : 3.5,
"queueWidthLoading" : 1.0,
"pedestrianDynamicWeight" : 6.0,
"loadingType" : "CONSTANT",
"width" : 0.2,
"height" : 1.0
}
}
},
"attributesSimulation" : {
"finishTime" : 30.0,
"simTimeStepLength" : 0.4,
"realTimeSimTimeRatio" : 0.5,
"writeSimulationData" : true,
"visualizationEnabled" : true,
"printFPS" : false,
"digitsPerCoordinate" : 2,
"useFixedSeed" : false,
"fixedSeed" : 1,
"simulationSeed" : 0
},
"attributesPsychology" : {
"usePsychologyLayer" : false,
"psychologyLayer" : {
"perception" : "SimplePerceptionModel",
"cognition" : "CooperativeCognitionModel"
}
},
"topography" : {
"attributes" : {
"bounds" : {
"x" : 0.0,
"y" : 0.0,
"width" : 20.0,
"height" : 15.0
},
"boundingBoxWidth" : 0.5,
"bounded" : true,
"referenceCoordinateSystem" : null
},
"obstacles" : [ {
"shape" : {
"x" : 3.0,
"y" : 9.0,
"width" : 5.0,
"height" : 6.0,
"type" : "RECTANGLE"
},
"id" : 1
}, {
"shape" : {
"x" : 3.0,
"y" : 0.0,
"width" : 5.0,
"height" : 6.0,
"type" : "RECTANGLE"
},
"id" : 2
} ],
"measurementAreas" : [ {
"shape" : {
"x" : 8.5,
"y" : 6.0,
"width" : 1.0,
"height" : 3.0,
"type" : "RECTANGLE"
},
"id" : 1
}, {
"shape" : {
"x" : 8.0,
"y" : 5.6,
"width" : 2.0,
"height" : 4.0,
"type" : "RECTANGLE"
},
"id" : 2
} ],
"stairs" : [ ],
"targets" : [ {
"id" : 1,
"absorbing" : true,
"shape" : {
"x" : 1.0,
"y" : 6.8,
"width" : 1.4,
"height" : 1.4,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
} ],
"targetChangers" : [ ],
"absorbingAreas" : [ ],
"sources" : [ {
"id" : 3,
"shape" : {
"x" : 14.0,
"y" : 2.5,
"width" : 5.0,
"height" : 10.0,
"type" : "RECTANGLE"
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"spawnNumber" : 100,
"maxSpawnNumberTotal" : -1,
"startTime" : 0.0,
"endTime" : 0.0,
"spawnAtRandomPositions" : true,
"spawnAtGridPositionsCA" : false,
"useFreeSpaceOnly" : true,
"targetIds" : [ 1 ],
"groupSizeDistribution" : [ 1.0 ],
"dynamicElementType" : "PEDESTRIAN",
"attributesPedestrian" : null
} ],
"dynamicElements" : [ ],
"attributesPedestrian" : {
"radius" : 0.195,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.01,
"maximumSpeed" : 5.0,
"acceleration" : 2.0,
"footstepHistorySize" : 4,
"searchRadius" : 1.0,
"walkingDirectionCalculation" : "BY_TARGET_CENTER",
"walkingDirectionSameIfAngleLessOrEqual" : 45.0
},
"teleporter" : null,
"attributesCar" : null
},
"stimulusInfos" : [ ]
}
}
\ No newline at end of file
......@@ -32,6 +32,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
private boolean showMeasurementArea = true;
private boolean showStairs = true;
private boolean showPedestrians = true;
private boolean showContacts = true;
private boolean showWalkdirection = false;
private boolean showTargetPotentialField = false;
private boolean showTargetPotentielFieldMesh = false;
......@@ -73,6 +74,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
this.showWalkdirection = config.showWalkdirection;
this.showGrid = config.showGrid;
this.showPedestrians = config.showPedestrians;
this.showContacts = config.showContacts;
this.showLogo = config.showLogo;
this.showStairs = config.showStairs;
this.showGroups = config.showGroups;
......@@ -103,6 +105,11 @@ public class DefaultSimulationConfig extends DefaultConfig {
return showPedestrians;
}
public boolean isShowContacts() {
return showContacts;
}
public boolean isShowWalkdirection() {
return showWalkdirection;
}
......@@ -121,6 +128,11 @@ public class DefaultSimulationConfig extends DefaultConfig {
setChanged();
}
public void setShowContacts(boolean showContacts) {
this.showContacts = showContacts;
setChanged();
}
public boolean isShowTargets() {
return showTargets;
}
......
......@@ -80,7 +80,6 @@ public class ActionOpenFile extends ActionVisualization {
IOUtils.getFirstFile(scenarioOutputDir, IOUtils.TRAJECTORY_FILE_EXTENSION);
Optional<File> snapshotFile =
IOUtils.getFirstFile(scenarioOutputDir, IOUtils.SCENARIO_FILE_EXTENSION);
if (trajectoryFile.isPresent() && snapshotFile.isPresent()) {
Scenario vadere = IOOutput.readScenario(snapshotFile.get().toPath());
model.init(IOOutput.readTrajectories(trajectoryFile.get().toPath()), vadere, trajectoryFile.get().getParent());
......
package org.vadere.gui.postvisualization.model;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.io.ColumnNames;
import tech.tablesaw.api.*;
import java.util.ArrayList;
import java.util.List;
/**
* The {@link ContactData}
*/
public class ContactData {
private final Table contactsDataFrame;
private final List<Integer> rowsWithPedIds;
private static final double SIM_STEP_LENGTH = 0.4;
// columns, TODO: this is hard coded!
public final int startTimeStepCol;
public final int firstPedIdCol;
public final int secondPedIdCol;
public final int durationCol;
public final int xPathCol;
public final int yPathCol;
/**
* Default constructor.
*
* @param dataFrame the whole table containing all trajectories of all contacts for all times
*/
public ContactData(@NotNull final Table dataFrame) {
// get all ids of all columns
// 1. mandatory columns:
ColumnNames columnNames = ColumnNames.getInstance();
startTimeStepCol = columnNames.getStartTimeCol(dataFrame);
firstPedIdCol = columnNames.getPedestrianIdCol(dataFrame);
secondPedIdCol = columnNames.getSecondPedestrianIdCol(dataFrame);
durationCol = columnNames.getDurationCol(dataFrame);
xPathCol = columnNames.getStartXCol(dataFrame);
yPathCol = columnNames.getStartYCol(dataFrame);
this.contactsDataFrame = dataFrame;
StringColumn startTimes = getStartTimeStep(contactsDataFrame);
rowsWithPedIds = new ArrayList<>();
for (int i = 0; i < startTimes.size(); i++) {
if (!startTimes.get(i).equals("-")) {
rowsWithPedIds.add(i);
}
}
}
public List<Integer> getRowsWithPedIds() {
return rowsWithPedIds;
}
private StringColumn getStartTimeStep(@NotNull final Table table) {
return table.stringColumn(startTimeStepCol);
}
private StringColumn getFirstPedIdCol(@NotNull final Table table) {
return table.stringColumn(firstPedIdCol);
}
private StringColumn getSecondPedIdCol(@NotNull final Table table) {
return table.stringColumn(secondPedIdCol);
}
private StringColumn getDurationCol(@NotNull final Table table) {
return table.stringColumn(durationCol);
}
private DoubleColumn getXPathCol(@NotNull final Table table) {
return table.doubleColumn(xPathCol);
}
private DoubleColumn getYPathCol(@NotNull final Table table) {
return table.doubleColumn(yPathCol);
}
public List<Table> getTrajectoriesOfContactsUntil(double simTime) {
List<Table> result = new ArrayList<>();
for (Integer rowIndex: rowsWithPedIds) {
double contactStartTime = Double.parseDouble(getStartTimeStep(contactsDataFrame).get(rowIndex)) * SIM_STEP_LENGTH;
int durationTimeSteps = Integer.parseInt(getDurationCol(contactsDataFrame).get(rowIndex));
double contactDurationTime = durationTimeSteps * SIM_STEP_LENGTH;
boolean contactStartedBeforeSimTime = contactStartTime < simTime;
if (contactStartedBeforeSimTime) {
boolean contactHasNotEndedAtSimTime = simTime < contactStartTime + contactDurationTime;
int currentTimeStep = (int)Math.round(simTime);
int diffContactStartToCurrentTimestep = currentTimeStep - (int)contactStartTime;
if (diffContactStartToCurrentTimestep == 0) {
diffContactStartToCurrentTimestep = 1;
}
try {
DoubleColumn xCol = getXPathCol(contactsDataFrame).inRange(rowIndex, Math.min(rowIndex + durationTimeSteps, rowIndex + diffContactStartToCurrentTimestep));
DoubleColumn yCol = getYPathCol(contactsDataFrame).inRange(rowIndex, Math.min(rowIndex + durationTimeSteps, rowIndex + diffContactStartToCurrentTimestep));
Table trajectoryOfSingleContact = Table.create(xCol, yCol);
result.add(trajectoryOfSingleContact);
} catch (Exception e) {
System.out.println("yeet");
}
}
}
return result;
}
public Table getPairsOfPedestriansInContactAt(double simTime) {
IntColumn ped1IDs = IntColumn.create("ped1Ids");
IntColumn ped2IDs = IntColumn.create("ped2Ids");
for (Integer rowIndex: rowsWithPedIds) {
double contactStartTime = Double.parseDouble(getStartTimeStep(contactsDataFrame).get(rowIndex)) * SIM_STEP_LENGTH;
int durationTimeSteps = Integer.parseInt(getDurationCol(contactsDataFrame).get(rowIndex));
double contactDurationTime = durationTimeSteps * SIM_STEP_LENGTH;
boolean contactAtSimTime = contactStartTime < simTime && simTime < contactStartTime + contactDurationTime;
if (contactAtSimTime) {
int firstPedId = Integer.parseInt(getFirstPedIdCol(contactsDataFrame).get(rowIndex));
int secondPedId = Integer.parseInt(getSecondPedIdCol(contactsDataFrame).get(rowIndex));
ped1IDs.append(firstPedId);
ped2IDs.append(secondPedId);
}
}
return Table.create(ped1IDs, ped2IDs);
}
}
......@@ -63,6 +63,8 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
private TableTrajectoryFootStep trajectories;
private ContactData contactData;
private String outputPath;
private AttributesAgent attributesAgent;
......@@ -72,6 +74,7 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
public PostvisualizationModel() {
super(new PostvisualizationConfig());
this.trajectories = new TableTrajectoryFootStep(Table.create());
this.contactData = null;
this.scenario = new Scenario("");
this.topographyId = 0;
this.potentialContainer = null;
......@@ -82,8 +85,11 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
this.outputChanged = false;
}
public synchronized void init(final Table trajectories, final Table contactTrajectories, final Scenario scenario, final String projectPath) {
init(trajectories, contactTrajectories, scenario, projectPath, new AttributesAgent());
}
public synchronized void init(final Table trajectories, final Scenario scenario, final String projectPath) {
init(trajectories, scenario, projectPath, new AttributesAgent());
init(trajectories, null, scenario, projectPath, new AttributesAgent());
}
/**
......@@ -93,10 +99,13 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
* This scenario will not contain any agents.
* @param projectPath the path to the project.
*/
public synchronized void init(final Table trajectories, final Scenario scenario, final String projectPath, final AttributesAgent attributesAgent) {
public synchronized void init(final Table trajectories, final Table contactTrajectories, final Scenario scenario, final String projectPath, final AttributesAgent attributesAgent) {
this.scenario = scenario;
this.simTimeStepLength = scenario.getAttributesSimulation().getSimTimeStepLength();
this.trajectories = new TableTrajectoryFootStep(trajectories);
if (contactTrajectories != null) {
this.contactData = new ContactData(contactTrajectories);
}
this.visTime = 0;
this.attributesAgent = attributesAgent;
this.outputPath = projectPath;
......@@ -193,6 +202,9 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
public synchronized TableTrajectoryFootStep getTrajectories() {
return trajectories;
}
public synchronized ContactData getContactData() {
return contactData;
}
public synchronized Table getAgentTable() {
return trajectories.getAgentsWithDisappearedAgents(getSimTimeInSec());
......
......@@ -2,34 +2,42 @@ package org.vadere.gui.postvisualization.view;
import org.vadere.gui.components.view.DefaultRenderer;
import org.vadere.gui.components.view.SimulationRenderer;
import org.vadere.gui.postvisualization.model.ContactData;
import org.vadere.gui.postvisualization.model.PostvisualizationModel;
import org.vadere.gui.postvisualization.model.TableTrajectoryFootStep;
import org.vadere.gui.renderer.agent.AgentRender;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.simulation.FootStep;
import org.vadere.util.geometry.shapes.VPoint;
import tech.tablesaw.api.Row;
import tech.tablesaw.api.Table;
import org.vadere.util.logging.Logger;
import org.vadere.util.visualization.ColorHelper;
import java.awt.*;
import java.awt.geom.Path2D;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.List;
import tech.tablesaw.api.Row;
import tech.tablesaw.api.Table;
public class PostvisualizationRenderer extends SimulationRenderer {
private static final double MIN_ARROW_LENGTH = 0.1;
private static Logger logger = Logger.getLogger(PostvisualizationRenderer.class);
private PostvisualizationModel model;
private final Map<Integer, VPoint> lastPedestrianPositions;
private final Map<Integer, VPoint> pedestrianDirections;
private ColorHelper colorHelper;
public PostvisualizationRenderer(final PostvisualizationModel model) {
super(model);
this.model = model;
this.pedestrianDirections = new HashMap<>();
this.lastPedestrianPositions = new HashMap<>();
this.colorHelper = new ColorHelper(model.getStepCount());
}
public PostvisualizationModel getModel() {
......@@ -38,40 +46,81 @@ public class PostvisualizationRenderer extends SimulationRenderer {
@Override
protected void renderSimulationContent(final Graphics2D g) {
this.colorHelper = new ColorHelper(model.getStepCount());
renderPedestrians(g, null);
}
private void renderPedestrians(final Graphics2D g, final Color color) {
if (!model.isEmpty()) {
Color savedColor = g.getColor();
Table slice = (model.config.isShowAllTrajectories()) ? model.getAppearedPedestrians() : model.getAlivePedestrians() ;
Collection<Pedestrian> pedestrians = model.getPedestrians();
Map<Integer, Color> pedestrianColors = new HashMap<>();
pedestrians.forEach(ped -> pedestrianColors.put(ped.getId(), getPedestrianColor(ped)));
renderTrajectories(g, slice, pedestrianColors);
renderPedestrians(g, pedestrians, pedestrianColors);
renderTrajectories(g);
if (model.config.isShowContacts() && model.getContactData() != null) {
renderConnectingLinesByContact(g);
}
}
}
g.setColor(savedColor);
private void renderConnectingLinesByContact(Graphics2D g) {
if (!model.config.isShowAllTrajectories()) return;
Color color = g.getColor();
Stroke stroke = g.getStroke();
g.setStroke(new BasicStroke(getLineWidth() / 4.0f));
g.setColor(Color.red);
Collection<Pedestrian> agents = model.getPedestrians();
Map<Integer, VPoint> pedPositions = new HashMap<>();
agents.forEach(a -> pedPositions.put(a.getId(), a.getPosition()));
Table pairs = model.getContactData().getPairsOfPedestriansInContactAt(model.getSimTimeInSec());
for (Row row: pairs) {
int id1 = row.getInt(0);
int id2 = row.getInt(1);