Commit 22e3131c authored by BZoennchen's avatar BZoennchen

Merge branch 'dev/disableInterpolation' into 'master'

[GUI] Visualization: make interpolation configurable.

See merge request !89
parents f248f23c 3bd216e2
Pipeline #173100 passed with stages
in 125 minutes and 43 seconds
......@@ -214,6 +214,7 @@ ProjectView.mntmRunOutput.text=Run offline again
ProjectView.OpenInExplorer.text=Open in Explorer
ProjectView.mntmCopyOutputDir.text=Copy output path to clipboard
SettingsDialog.chbInterpolatePositions.text=Interpolate Positions
SettingsDialog.chbShowPedestrianIds.text=Show PedestrianIds
PostVis.chShowEvacTimeColor.text=Coloring by Evacuation Times
PostVis.chShowCriteriaColor.text=Coloring by Predicate
......
......@@ -216,6 +216,7 @@ ProjectView.mntmRunOutput.text=Offline erneut starten
ProjectView.OpenInExplorer.text=In Explorer \u00F6ffnen
ProjectView.mntmCopyOutputDir.text=Kopiere Output Pfad in Zwischenablage
SettingsDialog.chbInterpolatePositions.text=Interpoliere Positionen
SettingsDialog.chbShowPedestrianIds.text=Fu\u00dfg\u00E4nger-Ids anzeigen
PostVis.additional.border.text=PostVis
PostVis.chShowEvacTimeColor.text=F\u00e4rbe nach Evakuierungszeit
......
......@@ -20,6 +20,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
private double densityStandardDerivation = CONFIG.getDouble("Density.standardDeviation");
private double pedestrianTorso = CONFIG.getDouble("Pedestrian.radius") * 2;
private boolean interpolatePositions = true;
private boolean showPedestrianIds = false;
private boolean showTargets = true;
private boolean showTargetChangers = true;
......@@ -293,7 +294,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
return randomColors.get(pedId);
}
public void setGridWidth(double gridWidth) {
public void setGridWidth(final double gridWidth) {
this.gridWidth = gridWidth;
}
......@@ -321,4 +322,13 @@ public class DefaultSimulationConfig extends DefaultConfig {
return false;
}
public boolean isInterpolatePositions() {
return interpolatePositions;
}
public void setInterpolatePositions(final boolean interpolatePositions) {
this.interpolatePositions = interpolatePositions;
setChanged();
}
}
......@@ -32,6 +32,8 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends
public abstract Collection<Agent> getAgents();
public abstract Collection<Pedestrian> getPedestrians();
public abstract int getTopographyId();
public abstract double getSimTimeInSec();
......
......@@ -331,10 +331,11 @@ public class SettingsDialog extends JDialog {
BorderFactory.createTitledBorder(Messages.getString("SettingsDialog.additional.border.text")));
FormLayout otherSettingsLayout = new FormLayout(createCellsWithSeparators(4), // col
createCellsWithSeparators(15)); // rows
createCellsWithSeparators(16)); // rows
otherSettingsPane.setLayout(otherSettingsLayout);
// For each scenario element, add a checkbox to toggle its visibility.
JCheckBox chInterpolatePositions = new JCheckBox((Messages.getString("SettingsDialog.chbInterpolatePositions.text")));
JCheckBox chShowObstacles = new JCheckBox((Messages.getString("SettingsDialog.chbShowObstacles.text")));
JCheckBox chShowTargets = new JCheckBox((Messages.getString("SettingsDialog.chbShowTargets.text")));
JCheckBox chShowSources = new JCheckBox((Messages.getString("SettingsDialog.chbShowSources.text")));
......@@ -343,9 +344,14 @@ public class SettingsDialog extends JDialog {
JCheckBox chShowStairs = new JCheckBox((Messages.getString("SettingsDialog.chbShowStairs.text")));
JCheckBox chShowTargetChangers = new JCheckBox((Messages.getString("SettingsDialog.chbShowTargetChangers.text")));
JCheckBox chShowPedIds = new JCheckBox((Messages.getString("SettingsDialog.chbShowPedestrianIds.text")));
JCheckBox chHideVoronoiDiagram = new JCheckBox((Messages.getString("SettingsDialog.chbHideVoronoiDiagram.text")));
chInterpolatePositions.setSelected(model.config.isInterpolatePositions());
chInterpolatePositions.addItemListener(e -> {
model.config.setInterpolatePositions(!model.config.isInterpolatePositions());
model.notifyObservers();
});
chHideVoronoiDiagram.setSelected(!model.isVoronoiDiagramVisible());
chHideVoronoiDiagram.addItemListener(e -> {
if (model.isVoronoiDiagramVisible()) {
......@@ -410,6 +416,7 @@ public class SettingsDialog extends JDialog {
int colSpan = 5;
CellConstraints cc = new CellConstraints();
otherSettingsPane.add(chInterpolatePositions, cc.xyw(column, row += NEXT_CELL, colSpan));
otherSettingsPane.add(chHideVoronoiDiagram, cc.xyw(column, row += NEXT_CELL, colSpan));
otherSettingsPane.add(chShowObstacles, cc.xyw(column, row += NEXT_CELL, colSpan));
otherSettingsPane.add(chShowTargets, cc.xyw(column, row += NEXT_CELL, colSpan));
......
......@@ -128,11 +128,11 @@ public abstract class SimulationRenderer extends DefaultRenderer {
graphics.dispose();
}
protected void renderTrajectory(final Graphics2D g, final java.util.List<VPoint> points, final Agent pedestrain) {
protected void renderTrajectory(final Graphics2D g, final java.util.List<VPoint> points, final Pedestrian pedestrain) {
renderTrajectory(g, points.stream(), pedestrain);
}
protected void renderTrajectory(final Graphics2D g, final Stream<VPoint> points, final Agent pedestrain) {
protected void renderTrajectory(final Graphics2D g, final Stream<VPoint> points, final Pedestrian pedestrain) {
Color color = g.getColor();
Stroke stroke = g.getStroke();
......@@ -143,8 +143,10 @@ public abstract class SimulationRenderer extends DefaultRenderer {
g.setStroke(new BasicStroke(getLineWidth() / 4.0f));
}
VPoint endPos = model.config.isInterpolatePositions() ? pedestrain.getInterpolatedFootStepPosition(model.getSimTimeInSec()) : pedestrain.getPosition();
Path2D.Double path = new Path2D.Double();
path.moveTo(pedestrain.getPosition().getX(), pedestrain.getPosition().getY());
path.moveTo(
endPos.getX(), endPos.getY());
points.forEachOrdered(
p -> path.lineTo(p.getX(), p.getY()));
......
......@@ -69,6 +69,7 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
this.drawDataSynchronizer = new Object();
this.voronoiSnapshots = new LinkedList<>();
this.observationAreaSnapshots = new LinkedList<>();
this.config.setInterpolatePositions(false);
}
@Override
......@@ -81,6 +82,16 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
return result;
}
@Override
public Collection<Pedestrian> getPedestrians() {
if (topography == null) {
return new ArrayList<>();
}
Collection<Pedestrian> result = new LinkedList<>();
result.addAll(topography.getElements(Pedestrian.class));
return result;
}
@Override
public int getTopographyId() {
return 0;
......
......@@ -60,7 +60,7 @@ public class OnlinevisualizationRenderer extends SimulationRenderer {
private void renderPedestrians(final Graphics2D g) {
AgentRender agentRender = getAgentRender();
for (Agent ped : model.getAgents()) {
for (Pedestrian ped : model.getPedestrians()) {
Color agentColor = getPedestrianColor(ped);
g.setColor(agentColor);
VPoint position = ped.getPosition();
......@@ -71,7 +71,15 @@ public class OnlinevisualizationRenderer extends SimulationRenderer {
}
// reverse the point order
pedestrianPositions.get(ped.getId()).addFirst(ped.getPosition());
if(!model.config.isInterpolatePositions()) {
pedestrianPositions.get(ped.getId()).addFirst(ped.getPosition());
} else {
if(ped.getFootstepHistory().getCapacity() > 0) {
pedestrianPositions.get(ped.getId()).addFirst(ped.getFootstepHistory().getYoungestFootStep().getStart());
} else {
pedestrianPositions.get(ped.getId()).addFirst(ped.getPosition());
}
}
if (model.config.isShowTrajectories()) {
renderTrajectory(g, pedestrianPositions.get(ped.getId()), ped);
......
......@@ -179,6 +179,16 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
return agentList;
}
@Override
public Collection<Pedestrian> getPedestrians() {
Table agents = getAgentTable();
List<Pedestrian> agentList = new ArrayList<>(agents.rowCount());
for(Row agentRow : agents) {
agentList.add(toAgent(agentRow));
}
return agentList;
}
public synchronized TableTrajectoryFootStep getTrajectories() {
return trajectories;
}
......@@ -195,7 +205,7 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
return trajectories.getAgentDataFrame();
}
private Agent toAgent(final Row row) {
private Pedestrian toAgent(final Row row) {
int pedId = row.getInt(trajectories.pedIdCol);
double startTime = row.getDouble(trajectories.startTimeCol);
double endTime = row.getDouble(trajectories.endTimeCol);
......@@ -205,7 +215,7 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
double endY = row.getDouble(trajectories.endYCol);
VPoint position;
if(startTime <= getSimTimeInSec() && endTime >= getSimTimeInSec()) {
if(config.isInterpolatePositions() && (startTime <= getSimTimeInSec() && endTime >= getSimTimeInSec())) {
position = FootStep.interpolateFootStep(startX, startY, endX, endY, startTime, endTime, getSimTimeInSec());
} else {
position = new VPoint(endX, endY);
......
package org.vadere.gui.postvisualization.view;
import org.vadere.gui.components.view.SettingsDialog;
import org.vadere.gui.postvisualization.model.PostvisualizationModel;
public class PostVisSettingsDialog extends SettingsDialog {
public PostVisSettingsDialog(PostvisualizationModel model) {
super(null);
}
}
......@@ -6,6 +6,7 @@ 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.Agent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.simulation.FootStep;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.logging.Logger;
......@@ -70,7 +71,7 @@ public class PostvisualizationRenderer extends SimulationRenderer {
slice = model.getAlivePedestrians();
}
Collection<Agent> agents = model.getAgents();
Collection<Pedestrian> agents = model.getPedestrians();
Map<Integer, Color> agentColors = new HashMap<>();
agents.forEach(agent -> agentColors.put(agent.getId(), getPedestrianColor(agent)));
......@@ -85,7 +86,7 @@ public class PostvisualizationRenderer extends SimulationRenderer {
double endX = row.getDouble(trajectories.endXCol);
double endY = row.getDouble(trajectories.endYCol);
if(isLastStep) {
if(isLastStep && model.config.isInterpolatePositions()) {
VPoint interpolatedPos = FootStep.interpolateFootStep(startX, startY, endX, endY, row.getDouble(trajectories.startTimeCol), row.getDouble(trajectories.endTimeCol), model.getSimTimeInSec());
endX = interpolatedPos.getX();
endY = interpolatedPos.getY();
......@@ -117,7 +118,7 @@ public class PostvisualizationRenderer extends SimulationRenderer {
// render agents i.e. circles
if (model.config.isShowPedestrians()) {
for(Agent agent : agents) {
for(Pedestrian agent : agents) {
if (model.config.isShowFaydedPedestrians() || model.isAlive(agent.getId())) {
agentRender.render(agent, agentColors.get(agent.getId()), g);
if (model.config.isShowPedestrianIds()) {
......
......@@ -6,6 +6,7 @@ import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.components.view.DefaultRenderer;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.logging.Logger;
......@@ -59,12 +60,17 @@ public class AgentRender implements Renderer {
private void renderDefault(final ScenarioElement element, Graphics2D g, Color c) {
g.setColor(c);
VShape shape = element.getShape();
if(model.config.isInterpolatePositions()) {
VPoint pos = ((Pedestrian)element).getInterpolatedFootStepPosition(model.getSimTimeInSec());
shape = shape.translate(pos.subtract(((Pedestrian)element).getPosition()));
}
/*VCircle circle = (VCircle) element.getShape();
Pedestrian ped = (Pedestrian) element;
Ellipse2D.Float ellipse = new Ellipse2D.Float((float)ped.getPosition().x, (float)ped.getPosition().y, (float)ped.getRadius() * 2, (float)ped.getRadius() * 2);
Rectangle2D.Double rect = new Rectangle2D.Double(ped.getPosition().x, ped.getPosition().y, ped.getRadius() * 2, ped.getRadius() * 2);*/
//g.fill(new VCircle(ped.getPosition(), ped.getRadius()));
DefaultRenderer.fill(element.getShape(), g);
DefaultRenderer.fill(shape, g);
//g.draw(ellipse);
//DefaultRenderer.fill(ellipse, g);
//g.fill(ellipse);
......@@ -72,12 +78,19 @@ public class AgentRender implements Renderer {
}
public VShape getShape(Pedestrian ped) {
VShape shape = ped.getShape();
VPoint pos = ped.getPosition();
if(model.config.isInterpolatePositions()) {
pos = ped.getInterpolatedFootStepPosition(model.getSimTimeInSec());
shape = shape.translate(pos.subtract(ped.getPosition()));
}
if (ped.getGroupIds().isEmpty() || (!ped.getGroupSizes().isEmpty() && ped.getGroupSizes().getFirst() == 1)) {
return ped.getShape();
return shape;
} else if (ped.getGroupIds().getFirst() == 1) {
return ped.getShape();
return shape;
} else {
return FormHelper.getShape(ped.getGroupIds().getFirst(), ped.getPosition(), ped.getRadius());
return FormHelper.getShape(ped.getGroupIds().getFirst(), pos, ped.getRadius());
}
}
}
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