Commit 1ac3188a authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

GUI-PostVis: pedestrian colors can now depend on the number of time steps a pedestrian is alive

parent c34802ce
......@@ -176,6 +176,7 @@ ProjectView.mntmOutputToSceneario.text=Generate scenario
ProjectView.mntmRunOutput.text=Run offline again
PostVis.chbShowPedestrianIds.text=Show PedestrianIds
PostVis.chShowEvacTimeColor.text=Color Pedestrians regarding to Evacuation Times
PostVis.btnPlay.tooltip=Play
PostVis.btnPause.tooltip=Pause
PostVis.btnStop.tooltip=Stop
......
......@@ -176,6 +176,7 @@ ProjectView.mntmOutputToSceneario.text=Generiere Szenario
ProjectView.mntmRunOutput.text=Offline erneut starten
PostVis.chbShowPedestrianIds.text=Fu\u00dfg\u00E4nger-Ids anzeigen
PostVis.chShowEvacTimeColor.text=F\u00e4rbe Fu\u00dfg\u00E4nger nach ihrer Evakuierungszeit
PostVis.btnPlay.tooltip=Start
PostVis.btnPause.tooltip=Pause
PostVis.btnStop.tooltip=Stopp
......
......@@ -16,6 +16,7 @@ public class PostvisualizationConfig extends DefaultSimulationConfig {
private boolean showFaydedPedestrians = false;
private boolean showPedestrianIds = false;
private boolean loadTopographyInformationsOnly = false;
private boolean useEvacuationTimeColor = false;
private double gridWidth = Double.valueOf(resources.getProperty("PostVis.cellWidth"));
private int fps = Integer.valueOf(resources.getProperty("PostVis.framesPerSecond"));
......@@ -47,6 +48,7 @@ public class PostvisualizationConfig extends DefaultSimulationConfig {
this.loadTopographyInformationsOnly = config.loadTopographyInformationsOnly;
this.showPedestrianIds = config.showPedestrianIds;
this.observable = config.observable;
this.useEvacuationTimeColor = config.useEvacuationTimeColor;
}
public boolean isShowAllTrajectories() {
......@@ -58,6 +60,15 @@ public class PostvisualizationConfig extends DefaultSimulationConfig {
setChanged();
}
public boolean isUseEvacuationTimeColor() {
return useEvacuationTimeColor;
}
public void setUseEvacuationTimeColor(boolean useEvacuationTimeColor) {
this.useEvacuationTimeColor = useEvacuationTimeColor;
setChanged();
}
public void setGridWidth(double gridWidth) {
this.gridWidth = gridWidth;
}
......
......@@ -2,6 +2,7 @@ package org.vadere.gui.postvisualization.model;
import java.awt.Color;
import java.io.IOException;
import java.security.cert.PKIXRevocationChecker;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
......@@ -98,6 +99,7 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
public void init(final Map<Step, List<Agent>> agentsByStep, final ScenarioRunManager vadere) {
logger.info("start init postvis model");
init(vadere);
this.vadere = vadere;
this.agentsByStep = agentsByStep;
Map<Integer, Step> map = agentsByStep
......
......@@ -9,6 +9,7 @@ import java.util.stream.Stream;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.components.utils.ColorHelper;
import org.vadere.gui.components.view.DefaultRenderer;
import org.vadere.gui.components.view.SimulationRenderer;
import org.vadere.gui.postvisualization.model.PostvisualizationModel;
......@@ -27,11 +28,14 @@ public class PostvisualizationRenderer extends SimulationRenderer {
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() {
......@@ -40,6 +44,7 @@ public class PostvisualizationRenderer extends SimulationRenderer {
@Override
protected void renderSimulationContent(final Graphics2D g) {
this.colorHelper = new ColorHelper(model.getStepCount());
renderPedestrians(g, null);
}
......@@ -72,9 +77,13 @@ public class PostvisualizationRenderer extends SimulationRenderer {
int targetId = pedestrian.hasNextTarget() ? pedestrian.getNextTargetId() : -1;
// choose the color
Optional<Color> c = model.config.isUseEvacuationTimeColor() ?
Optional.of(colorHelper.numberToColor(trajectory.getLifeTime().orElse(0))) :
Optional.empty();
g.setColor(model.getColor(pedestrian)
.orElse(model.config.getColorByTargetId(targetId)
.orElseGet(model.config::getPedestrianDefaultColor)));
.orElse(c
.orElseGet(model.config::getPedestrianDefaultColor))));
// renderImage the pedestrian
if (model.config.isShowPedestrians()) {
......
......@@ -21,6 +21,9 @@ import java.util.List;
import java.util.Optional;
import java.util.prefs.Preferences;
/**
* @author Benedikt Zoennchen
*/
public class SettingsDialog extends JDialog {
private static Logger logger = LogManager.getLogger(SettingsDialog.class);
private static Resources resources = Resources.getInstance("postvisualization");
......@@ -75,7 +78,7 @@ public class SettingsDialog extends JDialog {
FormLayout additionalLayout = new FormLayout("5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu", // col
"5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu"); // rows
FormLayout colorLayout = new FormLayout("5dlu, pref, 2dlu, pref:grow, 2dlu, pref, 2dlu, pref, 5dlu", // col
"5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu"); // rows
"5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu"); // rows
colorLayeredPane.setLayout(colorLayout);
additionalLayeredPane.setLayout(additionalLayout);
......@@ -238,6 +241,14 @@ public class SettingsDialog extends JDialog {
PedestrianColorPanel pedestrianColorPanel = new PedestrianColorPanel(model.getPedestrianColorTableModel());
colorLayeredPane.add(pedestrianColorPanel, cc.xyw(2, 20, 8));
JCheckBox chShowEvacTimeColor = new JCheckBox(Messages.getString("PostVis.chShowEvacTimeColor.text"));
colorLayeredPane.add(chShowEvacTimeColor, cc.xyw(2, 22, 8));
chShowEvacTimeColor.addItemListener(e -> {
model.config.setUseEvacuationTimeColor(!model.config.isUseEvacuationTimeColor());
model.notifyObservers();
});
additionalLayeredPane.add(chCleanPed, cc.xyw(2, 2, 5));
additionalLayeredPane.add(chCleanTrajecties, cc.xyw(2, 4, 5));
additionalLayeredPane.add(chCleanSnapshot, cc.xyw(2, 6, 5));
......
......@@ -7,6 +7,7 @@ import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.math3.optim.OptimizationData;
import org.vadere.state.scenario.Agent;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -60,6 +61,12 @@ public class Trajectory {
}
}
public Optional<Integer> getLifeTime() {
return getEndStep().isPresent() && getStartStep().isPresent() ?
Optional.of(getEndStep().get().getStepNumber() - getStartStep().get().getStepNumber()) :
Optional.empty();
}
/**
* Returns the pedestrian id that specified this trajectory.
*
......
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