Commit 1e44a36c authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

Merge branch 'seedSetup' into ped_overlap

parents 696cffc9 e632da09
......@@ -227,7 +227,12 @@ PostVis.menuRecentFiles.title=Recent Files
PostVis.menuOpenFile.title=Open File...
PostVis.menuCloseFloorFieldFile.title=Remove Floor Field File
OnlineVis.btnShowPotentialfield.tooltip=Show the Target Potential Field for the selected Agent
OnlineVis.btnShowPotentialfield.tooltip=Show the different Potential Fields for the selected Agent
OnlineVis.msgDialogShowPotentialfield.title=Potentialfield visualization
OnlineVis.msgDialogShowPotentialfield.text=Choose the Potential Field to be displayed.
OnlineVis.msgDialogShowPotentialfield.target=Target Potential Field
OnlineVis.msgDialogShowPotentialfield.overall=Potential Field (OSM only)
OnlineVis.msgDialogShowPotentialfield.none=None
TopographyBoundDialog.title = Set Topography Bounds
......
......@@ -227,7 +227,12 @@ PostVis.menuRecentFiles.title=K\u00FCrzlich verwendete Dateien
PostVis.menuOpenFile.title=Datei \u00F6ffnen...
PostVis.menuCloseFloorFieldFile.title=Floor Field-Datei l\u00F6schen
OnlineVis.btnShowPotentialfield.tooltip=Zeigt das Zielpotenzialfeld des ausgew\u00E4hlten Agenten
OnlineVis.btnShowPotentialfield.tooltip=Zeige Potentialfeld des ausgew\u00E4hlten Agenten
OnlineVis.msgDialogShowPotentialfield.title=Potentialfeld visualisieren
OnlineVis.msgDialogShowPotentialfield.text=W\u00E4hle Potentialfeld
OnlineVis.msgDialogShowPotentialfield.target=Zielpotential
OnlineVis.msgDialogShowPotentialfield.overall=Potential (OSM only)
OnlineVis.msgDialogShowPotentialfield.none=Keines
TopographyBoundDialog.title = Setze Topographie Grenzen
......
......@@ -18,6 +18,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
private boolean showStairs = true;
private boolean showPedestrians = true;
private boolean showWalkdirection = false;
private boolean showTargetPotentialField = false;
private boolean showPotentialField = false;
private boolean showTrajectories = false;
private boolean showGrid = false;
......@@ -32,13 +33,14 @@ public class DefaultSimulationConfig extends DefaultConfig {
public DefaultSimulationConfig(final DefaultSimulationConfig config) {
super(config);
this.showDensity = config.showDensity;
this.showPotentialField = config.showPotentialField;
this.showTargetPotentialField = config.showTargetPotentialField;
this.showWalkdirection = config.showWalkdirection;
this.showGrid = config.showGrid;
this.showPedestrians = config.showPedestrians;
this.showLogo = config.showLogo;
this.showStairs = config.showStairs;
this.showGroups = config.showGroups;
this.showPotentialField = config.showPotentialField;
}
public boolean isShowGroups() {
......@@ -143,6 +145,11 @@ public class DefaultSimulationConfig extends DefaultConfig {
setChanged();
}
public void setShowTargetPotentialField(final boolean showTargetPotentialField) {
this.showTargetPotentialField = showTargetPotentialField;
setChanged();
}
public void setShowPotentialField(final boolean showPotentialField) {
this.showPotentialField = showPotentialField;
setChanged();
......@@ -164,6 +171,10 @@ public class DefaultSimulationConfig extends DefaultConfig {
return pedestrianTorso;
}
public boolean isShowTargetPotentialField() {
return showTargetPotentialField;
}
public boolean isShowPotentialField() {
return showPotentialField;
}
......
......@@ -48,7 +48,7 @@ public abstract class SimulationRenderer extends DefaultRenderer {
@Override
protected void renderPreTransformation(Graphics2D graphics2D, int width, int height) {
if (model.isFloorFieldAvailable() && model.config.isShowPotentialField()) {
if (model.isFloorFieldAvailable() && (model.config.isShowTargetPotentialField() || model.config.isShowPotentialField())) {
synchronized (model) {
renderPotentialField(graphics2D,
(int)(Math.min(model.getTopographyBound().width, model.getViewportBound().width) * model.getScaleFactor()),
......@@ -64,7 +64,7 @@ public abstract class SimulationRenderer extends DefaultRenderer {
// if there is no potential field than draw the default background (white)
// otherwise do not overdraw the potential field!!!
if (!model.isFloorFieldAvailable() || !model.config.isShowPotentialField()) {
if (!model.isFloorFieldAvailable() || !(model.config.isShowTargetPotentialField() || model.config.isShowPotentialField())) {
super.renderPostTransformation(graphics, width, height);
}
......
......@@ -10,7 +10,9 @@ import org.vadere.gui.onlinevisualization.view.OnlineVisualisationWindow;
import org.vadere.simulator.control.PassiveCallback;
import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VRectangle;
public class OnlineVisualization implements PassiveCallback {
......@@ -24,11 +26,20 @@ public class OnlineVisualization implements PassiveCallback {
public final double simTimeInSec;
public final Topography scenario;
public final IPotentialField potentialFieldTarget;
public ObservationAreaSnapshotData(double simTimeInSec, @NotNull Topography scenario, @Nullable IPotentialField potentialFieldTarget) {
public final Agent selectedAgent;
public final IPotentialField potentialField;
public ObservationAreaSnapshotData(
final double simTimeInSec,
@NotNull final Topography scenario,
@Nullable final IPotentialField potentialFieldTarget,
@Nullable final IPotentialField potentialField,
@Nullable final Agent selectedAgent) {
this.simTimeInSec = simTimeInSec;
this.scenario = scenario;
this.potentialFieldTarget = potentialFieldTarget;
this.potentialField = potentialField;
this.selectedAgent = selectedAgent;
}
}
......@@ -36,8 +47,17 @@ public class OnlineVisualization implements PassiveCallback {
private OnlineVisualisationWindow onlineVisualisationPanel;
private OnlineVisualizationModel model;
private Topography scenario;
private @Nullable
IPotentialFieldTarget potentialFieldTarget;
/**
* Target potential.
*/
private @Nullable IPotentialFieldTarget potentialFieldTarget;
/**
* The overall potential.
*/
private @Nullable IPotentialField potentialField;
private boolean enableVisualization;
public OnlineVisualization(boolean enableVisualization) {
......@@ -60,6 +80,11 @@ public class OnlineVisualization implements PassiveCallback {
this.potentialFieldTarget = potentialFieldTarget;
}
@Override
public void setPotentialField(final IPotentialField potentialField) {
this.potentialField = potentialField;
}
@Override
public void preLoop(double simTimeInSec) {
onlineVisualisationPanel.setVisible(this.enableVisualization);
......@@ -91,11 +116,17 @@ public class OnlineVisualization implements PassiveCallback {
synchronized (model.getDataSynchronizer()) {
/* Push new snapshot of the observation area to the draw thread. */
model.pushObersavtionAreaSnapshot(
new ObservationAreaSnapshotData(
simTimeInSec,
scenario.clone(),
(model.config.isShowPotentialField() && potentialFieldTarget != null) ? potentialFieldTarget.copyFields() : null));
IPotentialField pft = (model.config.isShowTargetPotentialField() && potentialFieldTarget != null) ? potentialFieldTarget.copyFields() : null;
IPotentialField pedPotentialField = null;
Agent selectedAgent = null;
if(model.config.isShowPotentialField() && model.getSelectedElement() instanceof Agent && potentialField != null) {
selectedAgent = (Agent)model.getSelectedElement();
pedPotentialField = IPotentialField.copyAgentField(potentialField, selectedAgent, new VRectangle(model.getTopographyBound()), 0.1);
}
ObservationAreaSnapshotData data = new ObservationAreaSnapshotData(simTimeInSec, scenario.clone(), pft, pedPotentialField, selectedAgent);
model.pushObersavtionAreaSnapshot(data);
}
}
......
......@@ -4,6 +4,7 @@ import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.view.SimulationRenderer;
import org.vadere.gui.onlinevisualization.view.IRendererChangeListener;
......@@ -24,8 +25,37 @@ public class ActionShowPotentialField extends AbstractAction implements IRendere
@Override
public void actionPerformed(ActionEvent e) {
model.config.setShowPotentialField(!model.config.isShowPotentialField());
model.notifyObservers();
String[] possibilities = {
Messages.getString("OnlineVis.msgDialogShowPotentialfield.target"),
Messages.getString("OnlineVis.msgDialogShowPotentialfield.overall"),
Messages.getString("OnlineVis.msgDialogShowPotentialfield.none")};
String s = (String)JOptionPane.showInputDialog(
null,
Messages.getString("OnlineVis.msgDialogShowPotentialfield.text"),
Messages.getString("OnlineVis.msgDialogShowPotentialfield.title"),
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
possibilities[0]);
//If a string was returned, say so.
if(possibilities[0].equals(s)) {
model.config.setShowTargetPotentialField(true);
model.config.setShowPotentialField(false);
model.notifyObservers();
}
else if(possibilities[1].equals(s)) {
model.config.setShowTargetPotentialField(false);
model.config.setShowPotentialField(true);
model.notifyObservers();
}
else {
model.config.setShowTargetPotentialField(false);
model.config.setShowPotentialField(false);
}
}
@Override
......
......@@ -11,7 +11,6 @@ import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.onlinevisualization.OnlineVisualization;
import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.state.scenario.*;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.voronoi.VoronoiDiagram;
......@@ -29,8 +28,12 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
* pontetial field of a certain pedestrian. See 'Simulation' for more
* information. For debug purposes. Updated by popDrawData().
*/
private IPotentialField potentialFieldTarget = null;
private IPotentialField potentialField = null;
private Agent agent = null;
/**
* Latest snapshot of the jts diagram to be displayed. Updated by
* popDrawData().
......@@ -104,8 +107,10 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
observationAreaSnapshots.getFirst();
simTimeInSec = observationAreaSnapshot.simTimeInSec;
// potentialField might be null!
potentialField = observationAreaSnapshot.potentialFieldTarget;
// potentialFieldTarget might be null!
potentialFieldTarget = observationAreaSnapshot.potentialFieldTarget;
potentialField = observationAreaSnapshot.potentialField;
agent = observationAreaSnapshot.selectedAgent;
/*
* if(topography == null ||
......@@ -179,10 +184,13 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
public Function<VPoint, Double> getPotentialField() {
Function<VPoint, Double> f = pos -> 0.0;
if(potentialField != null) {
if(potentialField != null && config.isShowPotentialField() && agent.equals(getSelectedElement())) {
f = pos -> potentialField.getPotential(pos, agent);
}
else if(potentialFieldTarget != null && config.isShowTargetPotentialField()) {
if(getSelectedElement() instanceof Agent) {
Agent selectedAgent = (Agent)getSelectedElement();
f = pos -> potentialField.getPotential(pos, selectedAgent);
f = pos -> potentialFieldTarget.getPotential(pos, selectedAgent);
}
}
......
......@@ -24,7 +24,7 @@ public class ActionShowPotentialField extends ActionVisualization {
@Override
public void actionPerformed(final ActionEvent event) {
if (!model.config.isShowPotentialField()) {
if (!model.config.isShowTargetPotentialField()) {
//final JFileChooser fc = new JFileChooser(resources.getProperty("View.outputDirectory.path"));
final JFileChooser fc = new JFileChooser(model.getOutputPath());
int returnVal = fc.showOpenDialog(null);
......@@ -44,7 +44,7 @@ public class ActionShowPotentialField extends ActionVisualization {
PotentialFieldContainer container = new PotentialFieldContainer(file,
topography.getBounds().getWidth(), topography.getBounds().getHeight(), false);
model.setPotentialFieldContainer(container);
model.config.setShowPotentialField(true);
model.config.setShowTargetPotentialField(true);
model.notifyObservers();
// logger.info("read: \n" + data);
} catch (Exception e) {
......@@ -65,7 +65,7 @@ public class ActionShowPotentialField extends ActionVisualization {
new Thread(runnable).start();
}
} else {
model.config.setShowPotentialField(false);
model.config.setShowTargetPotentialField(false);
model.notifyObservers();
}
}
......
......@@ -362,7 +362,7 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
e.printStackTrace();
}
}
config.setShowPotentialField(false);
config.setShowTargetPotentialField(false);
potentialContainer = null;
}
}
package org.vadere.simulator.control;
import org.jetbrains.annotations.Nullable;
import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.state.scenario.Topography;
......@@ -20,5 +22,7 @@ public interface PassiveCallback {
void setTopography(Topography scenario);
default void setPotentialFieldTarget(IPotentialFieldTarget potentialFieldTarget){}
default void setPotentialFieldTarget(@Nullable IPotentialFieldTarget potentialFieldTarget){}
default void setPotentialField(@Nullable IPotentialField potentialField) {}
}
......@@ -6,7 +6,9 @@ import org.vadere.simulator.control.factory.SourceControllerFactory;
import org.vadere.simulator.models.DynamicElementFactory;
import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.models.Model;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.simulator.models.potential.PotentialFieldModel;
import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
......@@ -88,17 +90,27 @@ public class Simulation {
this.passiveCallbacks = passiveCallbacks;
this.topographyController = new TopographyController(topography, dynamicElementFactory);
IPotentialFieldTarget pft = null;
if(mainModel instanceof PotentialFieldModel) {
pft = ((PotentialFieldModel) mainModel).getPotentialFieldTarget();
}
// ::start:: this code is to visualize the potential fields. It may be refactored later.
IPotentialFieldTarget pft = null;
IPotentialField pt = null;
if(mainModel instanceof PotentialFieldModel) {
pft = ((PotentialFieldModel) mainModel).getPotentialFieldTarget();
pt = (pos, agent) -> {
if(agent instanceof PedestrianOSM) {
return ((PedestrianOSM)agent).getPotential(pos);
}
else {
return 0.0;
}
};
}
for (PassiveCallback pc : this.passiveCallbacks) {
pc.setTopography(topography);
if(pft != null) {
pc.setPotentialFieldTarget(pft);
}
pc.setPotentialFieldTarget(pft);
pc.setPotentialField(pt);
}
// ::end::
// create source and target controllers
for (Source source : topography.getSources()) {
......
package org.vadere.simulator.models.potential.fields;
import org.jetbrains.annotations.NotNull;
import org.vadere.state.scenario.Agent;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.math.InterpolationUtil;
/**
* @author Benedikt Zoennchen
......@@ -17,4 +20,51 @@ public interface IPotentialField {
* @return a potential at pos for the agent
*/
double getPotential(final VPoint pos, final Agent agent);
static IPotentialField copyAgentField(final @NotNull IPotentialField potentialField, final @NotNull Agent agent, final @NotNull VRectangle bound, final double steps) {
final int gridWidth = (int)Math.ceil(bound.getWidth() / steps)+1;
final int gridHeight = (int)Math.ceil(bound.getHeight() / steps)+1;
final double[][] potentialFieldApproximation = new double[gridHeight][gridWidth];
for(int row = 0; row < gridHeight; row++) {
for(int col = 0; col < gridWidth; col++) {
double x = col*steps;
double y = row*steps;
potentialFieldApproximation[row][col] = potentialField.getPotential(new VPoint(x, y), agent);
}
}
return (pos, ped) -> {
if(ped.equals(agent)) {
int incX = 1;
int incY = 1;
int col = (int)(pos.getX() / steps);
int row = (int)(pos.getY() / steps);
if (col + 1 >= gridWidth) {
incX = 0;
}
if (row + 1 >= gridHeight) {
incY = 0;
}
VPoint gridPointCoord = new VPoint(col * steps, row * steps);
double z1 = potentialFieldApproximation[row][col];
double z2 = potentialFieldApproximation[row][col + incX];
double z3 = potentialFieldApproximation[row + incY][col + incX];
double z4 = potentialFieldApproximation[row + incY][col];
double t = (pos.x - gridPointCoord.x) / steps;
double u = (pos.y - gridPointCoord.y) / steps;
return InterpolationUtil.bilinearInterpolation(z1, z2, z3, z4, t, u);
}
else {
return 0.0;
}
};
}
}
......@@ -47,20 +47,20 @@ public class NumberOverlapsProcessor extends DataProcessor<NoDataKey, Long> {
public void postLoop(final SimulationState state) {
this.pedOverlapProc.postLoop(state);
long numberOverlaps = 0;
long numberOverlaps = this.pedOverlapProc.getValues().stream().mapToInt(val -> val.intValue()).sum() / 2;
if (this.pedOverlapProc.getValues().size() > 0) {
numberOverlaps = this.pedOverlapProc.getValues().stream().filter(i -> i == 1).count();
}
/* // Uncomment this code if you want to get the info box with the number of overlaps
if (numberOverlaps > 0 ) {
NumberOverlapsProcessor.infoBox(numberOverlaps + " Overlaps have occured during the simulation!", "Number Overlaps");
System.out.println("* CAREFUL *: " + numberOverlaps + " Overlaps have occured during the simulation!");
}
}else{
NumberOverlapsProcessor.infoBox("No Overlaps have occured during the simulation :)", "Number Overlaps");
}
*/
this.putValue(NoDataKey.key(), numberOverlaps);
}
......
......@@ -26,6 +26,7 @@ public class PedestrianOverlapProcessor extends DataProcessor<TimestepPedestrian
@Override
protected void doUpdate(final SimulationState state) {
this.pedRadius = state.getTopography().getAttributesPedestrian().getRadius(); // in init there is no access to the state
Collection<Pedestrian> peds = state.getTopography().getElements(Pedestrian.class);
peds.forEach(p -> this.putValue(
new TimestepPedestrianIdKey(state.getStep(), p.getId()),
......@@ -41,7 +42,7 @@ public class PedestrianOverlapProcessor extends DataProcessor<TimestepPedestrian
}
private int calculateOverlaps(final Collection<Pedestrian> peds, VPoint pos) {
return (int) peds.stream().filter(p -> p.getPosition().distance(pos) < 2 * this.pedRadius).count() - 1;
return (int) peds.stream().filter(p -> p.getPosition().distance(pos) <= 2 * this.pedRadius).count() - 1;
}
@Override
......
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