The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit 123457aa authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

add feature: it is now possible to display the target potential field of a...

add feature: it is now possible to display the target potential field of a specific agent if the main model is a potential field model.
parent 16e03511
......@@ -205,6 +205,8 @@ 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
InformationDialogError.title=Internal Error
InformationDialogFileError=Could not load file!
LoadingDialog.title=Loading...
......
......@@ -86,7 +86,6 @@ ProjectView.mntmNew_1.text=Neu
ProjectView.mntmNew_1.shortcut=C
ProjectView.mntmGenerateScenario.text=Scenario aus Output generieren
ProjectView.mntmGenerateScenario.shortcut=G
ProjectView.pauseTests.shortcut=P
ProjectView.mntmRename.text=Umbenennen
ProjectView.mntmSaveAs.text=Speichern unter...
ProjectView.mntmSaveAs.shortcut=S
......@@ -205,6 +204,8 @@ 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
InformationDialogError.title=Interner Fehelr
InformationDialogFileError=Datei konnte nicht geladen werden!
LoadingDialog.title=Lade...
......
......@@ -3,6 +3,7 @@ package org.vadere.gui.components.model;
import java.awt.Point;
import java.util.Collection;
import java.util.Optional;
import java.util.function.Function;
import org.vadere.state.scenario.Agent;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -24,7 +25,7 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends
public abstract double getSimTimeInSec();
public abstract Optional<CellGrid> getPotentialField();
public abstract Function<VPoint, Double> getPotentialField();
public abstract boolean isFloorFieldAvailable();
......@@ -33,45 +34,48 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends
}
public double getPotential(final int x, final int y) {
double result = 0.0;
return getPotentialField().apply(pixelToWorld(new VPoint(x, y)));
}
VPoint pos = pixelToWorld(new VPoint(x, y));
// VPoint pos = new VPoint(x,y);
/*public double getPotential(final int x, final int y) {
double result = 0.0;
Optional<CellGrid> optPotentialField = getPotentialField();
VPoint pos = pixelToWorld(new VPoint(x, y));
// VPoint pos = new VPoint(x,y);
if (optPotentialField.isPresent()) {
CellGrid potentialField = optPotentialField.get();
int incX = 1;
int incY = 1;
Optional<Function<VPoint, Double>> optPotentialField = getPotentialField();
Point gridPoint = potentialField.getNearestPointTowardsOrigin(pos);
if (optPotentialField.isPresent()) {
CellGrid potentialField = optPotentialField.get();
int incX = 1;
int incY = 1;
if (gridPoint.x + 1 >= potentialField.getNumPointsX()) {
incX = 0;
}
Point gridPoint = potentialField.getNearestPointTowardsOrigin(pos);
if (gridPoint.y + 1 >= potentialField.getNumPointsY()) {
incY = 0;
}
if (gridPoint.x + 1 >= potentialField.getNumPointsX()) {
incX = 0;
}
if (gridPoint.y + 1 >= potentialField.getNumPointsY()) {
incY = 0;
}
VPoint gridPointCoord = potentialField.pointToCoord(gridPoint);
double z1 = potentialField.getValue(gridPoint).potential;
double z2 = potentialField.getValue(new Point(gridPoint.x + incX, gridPoint.y)).potential;
double z3 = potentialField.getValue(new Point(gridPoint.x + incX, gridPoint.y + incY)).potential;
double z4 = potentialField.getValue(new Point(gridPoint.x, gridPoint.y + incY)).potential;
VPoint gridPointCoord = potentialField.pointToCoord(gridPoint);
double t = (pos.x - gridPointCoord.x) / potentialField.getResolution();
double u = (pos.y - gridPointCoord.y) / potentialField.getResolution();
double z1 = potentialField.getValue(gridPoint).potential;
double z2 = potentialField.getValue(new Point(gridPoint.x + incX, gridPoint.y)).potential;
double z3 = potentialField.getValue(new Point(gridPoint.x + incX, gridPoint.y + incY)).potential;
double z4 = potentialField.getValue(new Point(gridPoint.x, gridPoint.y + incY)).potential;
/* Interpolate the known (potential < Double.MAX_VALUE) values. */
result = InterpolationUtil.bilinearInterpolation(z1, z2, z3, z4, t, u);
}
double t = (pos.x - gridPointCoord.x) / potentialField.getResolution();
double u = (pos.y - gridPointCoord.y) / potentialField.getResolution();
return result;
}
result = InterpolationUtil.bilinearInterpolation(z1, z2, z3, z4, t, u);
}
return result;
}*/
@Override
public void notifyObservers() {
......
......@@ -13,11 +13,14 @@ import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.Collection;
import java.util.function.Function;
import org.vadere.gui.components.model.IDefaultModel;
import org.vadere.simulator.models.potential.fields.PotentialFieldTarget;
import org.vadere.state.scenario.Agent;
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.VRectangle;
import org.vadere.util.math.MathUtil;
import org.vadere.util.potential.CellGrid;
......@@ -226,6 +229,77 @@ public abstract class DefaultRenderer {
return (float) (2.0 / defaultModel.getScaleFactor());
}
/*protected void paintPotentialField(final Graphics2D g, final Function<VPoint, Double> potentialField, final VRectangle bound) {
float norm;
if (potentialField == null) {
return;
}
double pixToW = 1.0 / defaultModel.getScaleFactor();
double potOld, maxPotential = 0, invPotential;
double maxBorder = Math.max(bound.getWidth(), bound.getHeight());
for (double y = bound.getMinY(); y < bound.getMaxY(); y += pixToW) {
for (double x = bound.getMinX(); x < bound.getMaxX(); x += pixToW) {
potOld = potentialField.apply(new VPoint(x,y));
if ((potOld > maxPotential) && (potOld != Double.MAX_VALUE)) {
maxPotential = potOld;
}
}
}
for (double y = bound.getMinY(); y < bound.getMaxY(); y += pixToW) {
for (double x = bound.getMinX(); x < bound.getMaxX(); x += pixToW) {
double contourDist = 0.02f;
boolean isContourLine = false;
double potential[] = new double[3];
if (!isContourLine) {
invPotential = 1 - potential[0];
if (invPotential < 1 / 7.0) {
norm = (float) (invPotential * 6.0);
g.setColor(new Color(0.14285f - norm * 7 / 6.0f * 0.14285f, 0.14285f - norm * 7 / 6.0f
* 0.14285f, norm + 0.14285f));
}
else if (invPotential < 2 / 7.0) {
norm = (float) ((invPotential - 1.0 / 7.0) * 6.0 + 0.14285f);
g.setColor(new Color(norm, 0, 1.0f));
}
else if (invPotential < 3 / 7.0) {
norm = (float) ((invPotential - 2.0 / 7.0) * 7.0);
g.setColor(new Color(1.0f, 0, 1.0f - norm));
}
else if (invPotential < 4 / 7.0) {
norm = (float) ((invPotential - 3.0 / 7.0) * 7.0);
g.setColor(new Color(1.0f, norm, 0));
}
else if (invPotential < 5 / 7.0) {
norm = (float) ((invPotential - 4.0 / 7.0) * 7.0);
g.setColor(new Color(1.0f - norm, 1.0f, 0));
}
else if (invPotential < 6 / 7.0) {
norm = (float) ((invPotential - 5.0 / 7.0) * 7.0);
g.setColor(new Color(0, 1.0f, norm));
}
else {
norm = (float) ((invPotential - 6.0 / 7.0) * 7.0);
g.setColor(new Color(norm, 1.0f, 1.0f));
}
}
else {
g.setColor(new Color(0.3f, 0.3f, 0.3f));
}
g.fill(new Rectangle2D.Double(x, y, pixToW, pixToW));
}
}
}*/
protected void paintPotentialField(final Graphics2D g, final CellGrid potentialField) {
float norm;
......
......@@ -2,11 +2,15 @@ package org.vadere.gui.onlinevisualization;
import javax.swing.JPanel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel;
import org.vadere.gui.onlinevisualization.view.MainPanel;
import org.vadere.gui.onlinevisualization.view.OnlineVisualisationWindow;
import org.vadere.gui.onlinevisualization.view.OnlinevisualizationRenderer;
import org.vadere.simulator.control.PassiveCallback;
import org.vadere.simulator.models.potential.fields.PotentialFieldTarget;
import org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid;
import org.vadere.state.scenario.Topography;
public class OnlineVisualization implements PassiveCallback {
......@@ -20,10 +24,12 @@ public class OnlineVisualization implements PassiveCallback {
public class ObservationAreaSnapshotData {
public final double simTimeInSec;
public final Topography scenario;
public final PotentialFieldTarget potentialFieldTarget;
public ObservationAreaSnapshotData(double simTimeInSec, Topography scenario) {
public ObservationAreaSnapshotData(double simTimeInSec, @NotNull Topography scenario, @Nullable PotentialFieldTarget potentialFieldTarget) {
this.simTimeInSec = simTimeInSec;
this.scenario = scenario;
this.potentialFieldTarget = potentialFieldTarget;
}
}
......@@ -31,6 +37,7 @@ public class OnlineVisualization implements PassiveCallback {
private OnlineVisualisationWindow onlineVisualisationPanel;
private OnlineVisualizationModel model;
private Topography scenario;
private PotentialFieldTarget potentialFieldTarget;
private boolean enableVisualization;
public OnlineVisualization(boolean enableVisualization) {
......@@ -48,6 +55,11 @@ public class OnlineVisualization implements PassiveCallback {
this.scenario = scenario;
}
@Override
public void setPotentialFieldTarget(final PotentialFieldTarget potentialFieldTarget) {
this.potentialFieldTarget = potentialFieldTarget;
}
@Override
public void preLoop(double simTimeInSec) {
onlineVisualisationPanel.setVisible(this.enableVisualization);
......@@ -80,7 +92,7 @@ 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()));
new ObservationAreaSnapshotData(simTimeInSec, scenario.clone(), model.config.isShowPotentialField() ? potentialFieldTarget.clone() : null));
}
}
......
package org.vadere.gui.onlinevisualization.control;
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.view.SimulationRenderer;
import org.vadere.gui.onlinevisualization.view.IRendererChangeListener;
import javax.swing.*;
import java.awt.event.ActionEvent;
/**
* @author Benedikt Zoennchen
*/
public class ActionShowPotentialField extends AbstractAction implements IRendererChangeListener {
private static Logger logger = LogManager.getLogger(ActionShowPotentialField.class);
private final SimulationModel<? extends DefaultSimulationConfig> model;
public ActionShowPotentialField(final String name, final Icon icon, final SimulationModel<? extends DefaultSimulationConfig> model) {
super(name, icon);
this.model = model;
}
@Override
public void actionPerformed(ActionEvent e) {
model.config.setShowPotentialField(!model.config.isShowPotentialField());
model.notifyObservers();
}
@Override
public void update(SimulationRenderer renderer) {}
}
......@@ -6,16 +6,16 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Optional;
import java.util.function.Function;
import org.apache.tools.ant.taskdefs.Tar;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.onlinevisualization.OnlineVisualization;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Car;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.scenario.Topography;
import org.vadere.state.scenario.TopographyIterator;
import org.vadere.simulator.models.potential.fields.PotentialFieldTarget;
import org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid;
import org.vadere.state.scenario.*;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.potential.CellGrid;
import org.vadere.util.voronoi.VoronoiDiagram;
......@@ -24,7 +24,6 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
/**
* Lists for thread safe data exchange between main and draw thread.
*/
private LinkedList<CellGrid> potentialFieldSnapshots;
private LinkedList<VoronoiDiagram> voronoiSnapshots;
private LinkedList<OnlineVisualization.ObservationAreaSnapshotData> observationAreaSnapshots;
......@@ -33,7 +32,7 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
* pontetial field of a certain pedestrian. See 'Simulation' for more
* information. For debug purposes. Updated by popDrawData().
*/
private CellGrid potentialField = null;
private PotentialFieldTarget potentialField = null;
/**
* Latest snapshot of the jts diagram to be displayed. Updated by
......@@ -61,7 +60,6 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
public OnlineVisualizationModel() {
super(new DefaultSimulationConfig());
this.drawDataSynchronizer = new Object();
this.potentialFieldSnapshots = new LinkedList<>();
this.voronoiSnapshots = new LinkedList<>();
this.observationAreaSnapshots = new LinkedList<>();
}
......@@ -109,6 +107,9 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
observationAreaSnapshots.getFirst();
simTimeInSec = observationAreaSnapshot.simTimeInSec;
// potentialField might be null!
potentialField = observationAreaSnapshot.potentialFieldTarget;
/*
* if(topography == null ||
* !topography.getBounds().equals(observationAreaSnapshot.scenario.getBounds())) {
......@@ -134,20 +135,15 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
setSelectedElement(ped);
}
if (!potentialFieldSnapshots.isEmpty()) {
potentialField = potentialFieldSnapshots.getFirst();
}
if (!voronoiSnapshots.isEmpty()) {
voronoiDiagram = voronoiSnapshots.getFirst();
}
return true;
}
}
public void pushObersavtionAreaSnapshot(
final OnlineVisualization.ObservationAreaSnapshotData observationAreaSnapshotData) {
public void pushObersavtionAreaSnapshot(final OnlineVisualization.ObservationAreaSnapshotData observationAreaSnapshotData) {
if (observationAreaSnapshots.size() > 0) {
observationAreaSnapshots.pop();
}
......@@ -156,7 +152,6 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
}
public void reset() {
potentialFieldSnapshots.clear();
voronoiSnapshots.clear();
observationAreaSnapshots.clear();
selectedElement = null;
......@@ -175,15 +170,6 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
return drawDataSynchronizer;
}
/**
* Returns the list of potential field snapshots. Used for thread safe data
* exchange between main thread and draw thread.
*/
public LinkedList<CellGrid> getPotentialFieldSnapshots() {
return potentialFieldSnapshots;
}
/**
* Returns the list of jts diagram snapshots. Used for thread safe data
* exchange between main thread and draw thread.
......@@ -193,13 +179,22 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
}
@Override
public Optional<CellGrid> getPotentialField() {
return Optional.ofNullable(potentialField);
public Function<VPoint, Double> getPotentialField() {
Function<VPoint, Double> f = pos -> 0.0;
if(potentialField != null) {
if(getSelectedElement() instanceof Agent) {
Agent selectedAgent = (Agent)getSelectedElement();
f = pos -> potentialField.getTargetPotential(pos, selectedAgent);
}
}
return f;
}
@Override
public boolean isFloorFieldAvailable() {
return getPotentialField().isPresent();
return true;
}
public double getSimTimeInSec() {
......
......@@ -17,6 +17,7 @@ import org.vadere.gui.components.view.ScenarioScrollPane;
import org.vadere.gui.components.view.SimulationInfoPanel;
import org.vadere.gui.onlinevisualization.control.ActionGeneratePNG;
import org.vadere.gui.onlinevisualization.control.ActionGenerateSVG;
import org.vadere.gui.onlinevisualization.control.ActionShowPotentialField;
import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel;
import java.awt.*;
......@@ -149,8 +150,14 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
new OnlinevisualizationRenderer(model),
model);
ActionShowPotentialField showPotentialField = new ActionShowPotentialField(
"showPotentialField",
resources.getIcon("potentialField.png", iconWidth, iconHeight),
model);
mainPanel.addRendererChangeListener(generatePNG);
mainPanel.addRendererChangeListener(generateSVG);
mainPanel.addRendererChangeListener(showPotentialField);
SwingUtils.addActionToToolbar(toolbar, paintPedestriansAction,
......@@ -169,6 +176,7 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
SwingUtils.addActionToToolbar(toolbar, generatePNG, Messages.getString("PostVis.btnPNGSnapshot.tooltip"));
SwingUtils.addActionToToolbar(toolbar, generateSVG, Messages.getString("PostVis.btnSVGSnapshot.tooltip"));
SwingUtils.addActionToToolbar(toolbar, showPotentialField, Messages.getString("OnlineVis.btnShowPotentialfield.tooltip"));
add(toolbar, cc.xyw(2, 2, 3));
add(scrollPane, cc.xy(2, 4));
......
package org.vadere.gui.postvisualization.model;
import java.awt.Color;
import java.awt.*;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
......@@ -11,6 +11,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -27,6 +28,7 @@ import org.vadere.state.scenario.TopographyIterator;
import org.vadere.state.simulation.Step;
import org.vadere.state.simulation.Trajectory;
import org.vadere.state.util.StateJsonConverter;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.io.parser.JsonLogicParser;
import org.vadere.util.io.parser.VPredicate;
import org.vadere.util.potential.CellGrid;
......@@ -166,23 +168,23 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
}
@Override
public Optional<CellGrid> getPotentialField() {
if (potentialContainer == null || step == null) {
return Optional.empty();
} else {
try {
return Optional.ofNullable(potentialContainer.getPotentialField(step.getStepNumber()));
} catch (IOException e) {
e.printStackTrace();
logger.error("could not load potential field "+ e.getMessage());
return Optional.empty();
}
}
public Function<VPoint, Double> getPotentialField() {
Function<VPoint, Double> f = p -> 0.0;
try {
if (potentialContainer != null && step != null) {
final CellGrid potentialField = potentialContainer.getPotentialField(step.getStepNumber());
f = potentialField.getInterpolationFunction();
}
} catch (IOException e) {
logger.warn("could not load potential field from file.");
e.printStackTrace();
}
return f;
}
@Override
public boolean isFloorFieldAvailable() {
return getPotentialField().isPresent();
return potentialContainer != null && step != null;
}
@Override
......
......@@ -4,14 +4,7 @@
"release" : "0.2",
"processWriters" : {
"files" : [ ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.EvacuationTimeProcessor",
"id" : 1,
"attributesType" : "org.vadere.state.attributes.processor.AttributesEvacuationTimeProcessor",
"attributes" : {
"pedestrianEvacuationTimeProcessorId" : 1
}
} ],
"processors" : [ ],
"isTimestamped" : true
},
"scenario" : {
......
......@@ -61,7 +61,7 @@
"pedestrianOtherTargetDensityWeight" : 3.5,
"pedestrianWeight" : 3.5,
"queueWidthLoading" : 5.0,
"pedestrianDynamicWeight" : 6.0,
"pedestrianDynamicWeight" : 1.0,
"loadingType" : "CONSTANT"
}
}
......
package org.vadere.simulator.control;
import org.vadere.simulator.models.potential.fields.PotentialFieldTarget;
import org.vadere.state.scenario.Topography;
/**
......@@ -18,4 +19,6 @@ public interface PassiveCallback {
void postUpdate(double simTimeInSec);
void setTopography(Topography scenario);
default void setPotentialFieldTarget(PotentialFieldTarget potentialFieldTarget){}
}
......@@ -5,6 +5,8 @@ import org.apache.log4j.Logger;
import org.vadere.simulator.models.DynamicElementFactory;
import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.models.Model;
import org.vadere.simulator.models.potential.PotentialFieldModel;
import org.vadere.simulator.models.potential.fields.PotentialFieldTarget;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.state.attributes.AttributesSimulation;
......@@ -84,8 +86,17 @@ public class Simulation {
this.topographyController = new TopographyController(topography, dynamicElementFactory);
PotentialFieldTarget pft = null;
if(mainModel instanceof PotentialFieldModel) {
pft = ((PotentialFieldModel) mainModel).getPotentialFieldTarget();
}