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

Commit b7e845e4 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

Merge branch 'master' into psychology

parents 7335797d 314b32e2
Pipeline #267886 passed with stages
in 140 minutes and 49 seconds
This diff is collapsed.
descartes
PyYAML
scipy
lxml
utm
numpy
gitpython
\ No newline at end of file
This diff is collapsed.
<osm>
<node id="1" visible="true" version="11" changeset="10291545" timestamp="2012-01-04T14:39:37Z" user="mawi42" uid="42393" lat="1.1" lon="1.2"/>
<node id="2" visible="true" version="9" changeset="2270948" timestamp="2009-08-26T20:02:36Z" user="pfui_osm_korinthenkacker" uid="36809" lat="2.1" lon="2.2"/>
<node id="3" visible="true" version="10" changeset="6745590" timestamp="2010-12-23T14:00:32Z" user="mawi42" uid="42393" lat="3.1" lon="3.2"/>
</osm>
\ No newline at end of file
This diff is collapsed.
descartes
PyYAML
scipy
lxml
utm
numpy
gitpython
\ No newline at end of file
from lxml import etree
import osm2vadere
import unittest
import utm
class TestOsm2vadere(unittest.TestCase):
def test_utm_conversion(self):
# tests if the distances of the Allianz Arena match up
# from the website https://allianz-arena.com/de/die-arena/fakten/allgemeine-informationen: Dimension Stadion: 258 m x 227 m x 52 m (Bruttorauminhalt)
# the stadion isn't alligned horizontal, therefore the calculated distances are bigger.
base_allianz_arena = (48.21762, 11.62305)
end_allianz_arena = (48.22001, 11.62628)
base_cartesian = utm.from_latlon(base_allianz_arena[0], base_allianz_arena[1])
end_cartesian = utm.from_latlon(end_allianz_arena[0], end_allianz_arena[1])
x_distance = end_cartesian[0] - base_cartesian[0]
y_distance = end_cartesian[1] - base_cartesian[1]
#print(end_cartesian[0] - base_cartesian[0], end_cartesian[1] - base_cartesian[1])
self.assertTrue(x_distance > 227 and x_distance < 235)
self.assertTrue(y_distance > 258 and y_distance < 275)
def test_extract_latitude_and_longitude_for_each_xml_node(self):
xml_tree = etree.parse("maps/unit_test_map.osm")
nodes_dictionary_with_lat_and_lon = osm2vadere.extract_latitude_and_longitude_for_each_xml_node(xml_tree)
self.assertTrue(nodes_dictionary_with_lat_and_lon.get("1")[0] == "1.1")
self.assertTrue (nodes_dictionary_with_lat_and_lon.get("1")[1] == "1.2")
self.assertTrue (nodes_dictionary_with_lat_and_lon.get("2")[0] == "2.1")
self.assertTrue (nodes_dictionary_with_lat_and_lon.get("2")[1] == "2.2")
self.assertTrue (nodes_dictionary_with_lat_and_lon.get("3")[0] == "3.1")
self.assertTrue (nodes_dictionary_with_lat_and_lon.get("3")[1] == "3.2")
def test_find_width_and_height(self):
building_normal = [(1, 1), (3, 1), (1, 3), (3, 3)]
building_negative_coordinates = [(-1, 4), (-3, 2), (10, 2)]
building_with_floating_points = [(2.3, 1.4), (-10.5, 7), (9.99, 3), (5, 7.1), (3, 4)]
buildings_cartesian = [building_normal, building_negative_coordinates, building_with_floating_points]
width, height = osm2vadere.find_width_and_height(buildings_cartesian)
self.assertTrue(width == 10)
self.assertTrue(height == 8) # 7.1 is the maximum but the function returns math.ceil
def test_find_new_basepoint(self):
building_normal = [(1, 1), (3, 1), (1, 3), (3, 3)]
building_negative_coordinates = [(-1, 4), (-3, 2), (10, 2)]
building_with_floating_points = [(2.3, 1.4), (-10.5, 7), (9.99, 3), (5, 7.1), (3, 4)]
buildings_cartesian = [building_normal, building_negative_coordinates, building_with_floating_points]
new_base_point = osm2vadere.find_new_basepoint(buildings_cartesian)
self.assertTrue(new_base_point == (-10.5, 1))
building_negative_coordinates.append((3, -5))
new_base_point = osm2vadere.find_new_basepoint(buildings_cartesian)
self.assertTrue(new_base_point == (-10.5, -5))
buildings_cartesian_only_positive = [[(1, 3), (1, 2), (2, 2)], [(2, 4), (7, 7), (6, 6)]]
new_base_point = osm2vadere.find_new_basepoint(buildings_cartesian_only_positive)
self.assertTrue(new_base_point == (1, 2))
def test_shift_points(self):
buildings_cartesian = [[(1, 3), (-1, 2), (2.2, 2)], [(2, 4), (7, 7), (6, 6)]]
buildings_cartesian_shifted_by_one_and_two = osm2vadere.shift_points(buildings_cartesian, 1, 2)
self.assertTrue(buildings_cartesian_shifted_by_one_and_two == [[(2, 5), (0, 4), (3.2, 4)], [(3, 6), (8, 9), (7, 8)]])
if __name__ == "__main__":
unittest.main()
{
"attributes" : {
"bounds" : {
"x" : 0.0,
"y" : 0.0,
"width" : $width,
"height" : $height
},
"boundingBoxWidth" : 0.5,
"bounded" : true,
"referenceCoordinateSystem" : null
},
"obstacles" : [ $obstacles ],
"measurementAreas" : [ ],
"stairs" : [ ],
"targets" : [ ],
"targetChangers" : [ ],
"absorbingAreas" : [ ],
"sources" : [ ],
"dynamicElements" : [ ],
"attributesPedestrian" : {
"radius" : 0.2,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.5,
"maximumSpeed" : 2.2,
"acceleration" : 2.0,
"footstepHistorySize" : 4,
"searchRadius" : 1.0,
"walkingDirectionCalculation" : "BY_TARGET_CENTER",
"walkingDirectionSameIfAngleLessOrEqual" : 45.0
},
"teleporter" : null,
"attributesCar" : {
"id" : -1,
"radius" : 0.2,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.5,
"maximumSpeed" : 2.2,
"acceleration" : 2.0,
"footstepHistorySize" : 4,
"searchRadius" : 1.0,
"walkingDirectionCalculation" : "BY_TARGET_CENTER",
"walkingDirectionSameIfAngleLessOrEqual" : 45.0,
"length" : 4.5,
"width" : 1.7,
"direction" : {
"x" : 1.0,
"y" : 0.0
}
}
}
......@@ -136,6 +136,7 @@ ProjectView.chooseFile=Chose file
ProjectView.ScenarioChecker.title=Scenario Checker
ProjectView.ScenarioChecker.deactive.text=ScenarioChecker deactivated. Project > Activate ScenarioChecker
ProjectView.ScenarioChecker.active.text=The following problems where found
ProjectView.btnGenerateMesh.tooltip=Generate background mesh
SaveBeforeClosing.text=Do you want to save the current project before closing?
......@@ -364,6 +365,7 @@ TopographyCreator.PlaceRandomPedestrians.couldNotPlaceAllPeds.requested.text=Req
TopographyCreator.PlaceRandomPedestrians.couldNotPlaceAllPeds.placed.text=Placed pedestrians
TopographyCreator.btnChecker.tooltip=Show Topography Checker Messages
TopographyCreator.btnGenerateIds.tooltip=Generate missing Ids for sources, targets, ...
TopographyCreator.btnGenerateMesh.tooltip=Generate background mesh
select_shape_tooltip=Select Shape
......
......@@ -137,6 +137,7 @@ ProjectView.label.simResults=Simulationsergebniss
ProjectView.ScenarioChecker.title=Scenario Checker
ProjectView.ScenarioChecker.deactive.text=ScenarioChecker deaktiviert. Projekt > ScenarioChecker aktivieren
ProjectView.ScenarioChecker.active.text=Probleme gefunden
ProjectView.btnGenerateMesh.tooltip=Generiere Hintergrundgitter
SaveBeforeClosing.text=Aktuelles Projekt vor dem Beenden speichern?
......@@ -356,7 +357,7 @@ TopographyCreator.PlaceRandomPedestrians.couldNotPlaceAllPeds.requested.text=Ang
TopographyCreator.PlaceRandomPedestrians.couldNotPlaceAllPeds.placed.text=Platzierte Fu\u00dfg\u00e4nger
TopographyCreator.btnChecker.tooltip=Topography Linter Nachrichten
TopographyCreator.btnGenerateIds.tooltip=Erzeuge fehlende Ids f\u00fcr Quellen, Ziele, ...
TopographyCreator.btnGenerateMesh.tooltip=Generiere Hintergrundgitter
# tab titles Topography creator / postvis
Tab.Simulation.title=Simulation
......
package org.vadere.gui.components.control;
import org.apache.commons.configuration2.Configuration;
import org.jetbrains.annotations.NotNull;
import org.vadere.gui.components.control.simulation.ActionGeneratePNG;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.gui.topographycreator.view.ActionTranslateTopographyDialog;
import org.vadere.meshing.mesh.gen.PFace;
import org.vadere.meshing.mesh.gen.PHalfEdge;
import org.vadere.meshing.mesh.gen.PVertex;
import org.vadere.meshing.mesh.impl.PSLG;
import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.meshing.utils.MeshConstructor;
import org.vadere.meshing.utils.io.poly.MeshPolyWriter;
import org.vadere.simulator.utils.pslg.PSLGConverter;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.io.IOUtils;
import org.vadere.util.logging.Logger;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import javax.swing.*;
public class ActionGenerateMesh extends AbstractAction {
private static Logger logger = Logger.getLogger(ActionGenerateMesh.class);
private final ProjectViewModel model;
public ActionGenerateMesh(final String name, Icon icon, final ProjectViewModel model) {
super(name, icon);
this.model = model;
}
@Override
public void actionPerformed(final ActionEvent e) {
/*JFileChooser fileChooser = new JFileChooser(CONFIG.getString("SettingsDialog.snapshotDirectory.path"));
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(CONFIG.getString("SettingsDialog.dataFormat"));
String formattedDate = formatter.format(todaysDate);*/
ActionTranslateTopographyDialog dialog = new ActionTranslateTopographyDialog(0.5, 5.0, "hmin, hmax");
if (dialog.getValue()){
double hmin = dialog.getX();
double hmax = dialog.getY();
PSLGConverter pslgConverter = new PSLGConverter();
PSLG pslg = pslgConverter.toPSLG(model.getCurrentScenario().getTopography());
logger.info("generate poly");
MeshConstructor constructor = new MeshConstructor();
CompletableFuture.supplyAsync(
() -> constructor.pslgToAdaptivePMesh(pslg, hmin, hmax, true)).thenAccept(mesh -> saveFloorFieldMesh(mesh,""))
.exceptionally( ex -> {
ex.printStackTrace();
return null;
});
CompletableFuture.supplyAsync(
() -> constructor.pslgToCoarsePMesh(pslg, true)).thenAccept(mesh -> saveFloorFieldMesh(mesh,IOUtils.BACKGROUND_MESH_ENDING))
.exceptionally( ex -> {
ex.printStackTrace();
return null;
});
}
}
private void saveFloorFieldMesh(@NotNull final IMesh<PVertex, PHalfEdge, PFace> mesh, final String ending) {
logger.info("generate mesh");
File meshDir = new File(model.getCurrentProjectPath().concat("/" + IOUtils.SCENARIO_DIR + "/" + IOUtils.MESH_DIR));
File outputFile = new File(meshDir.getAbsoluteFile() + "/" + model.getCurrentScenario().getName() + ending + ".poly");
MeshPolyWriter<PVertex, PHalfEdge, PFace> meshPolyWriter = new MeshPolyWriter<>();
String meshString = meshPolyWriter.to2DPoly(mesh);
if(!meshDir.exists()) {
meshDir.mkdir();
}
if(!outputFile.exists()) {
try {
outputFile.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
}
try(FileWriter fileWriter = new FileWriter(outputFile)) {
fileWriter.write(meshString);
logger.info("generate new mesh file: " + outputFile.getAbsolutePath());
} catch (IOException ex) {
logger.error(ex.getMessage());
ex.printStackTrace();
}
}
}
......@@ -51,7 +51,7 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends
return config;
}
public IMesh<?, ?, ?> getDiscretization() {
public IMesh<?, ?, ?> getFloorFieldMesh() {
return new PMesh();
}
......
......@@ -673,7 +673,10 @@ public abstract class DefaultRenderer {
@NotNull final Graphics2D g,
@NotNull final IMesh<?, ?, ?> mesh,
@NotNull final VRectangle bound) {
MeshRenderer<?, ?, ?> meshRenderer = new MeshRenderer<>(mesh);
MeshRenderer<?, ?, ?> meshRenderer = new MeshRenderer<>(mesh, false);
meshRenderer.renderPostTransform(g, bound);
//meshRenderer.renderGraphics(g, bound);
}
......
......@@ -108,7 +108,7 @@ public abstract class SimulationRenderer extends DefaultRenderer {
}
if(model.config.isShowTargetPotentielFieldMesh()) {
renderMesh(graphics, model.getDiscretization(), new VRectangle(model.getTopographyBound()));
renderMesh(graphics, model.getFloorFieldMesh(), new VRectangle(model.getTopographyBound()));
}
renderSimulationContent(graphics);
......
......@@ -9,6 +9,7 @@ import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.simulator.control.simulation.PassiveCallback;
import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.simulator.projects.Domain;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VRectangle;
......@@ -25,7 +26,7 @@ public class OnlineVisualization implements PassiveCallback {
*/
public class ObservationAreaSnapshotData {
public final double simTimeInSec;
public final Topography scenario;
public final Domain domain;
public final IPotentialField potentialFieldTarget;
public final Agent selectedAgent;
public final IPotentialField potentialField;
......@@ -33,13 +34,13 @@ public class OnlineVisualization implements PassiveCallback {
public ObservationAreaSnapshotData(
final double simTimeInSec,
@NotNull final Topography scenario,
@NotNull final Domain scenario,
@Nullable final IPotentialField potentialFieldTarget,
@Nullable final IPotentialField potentialField,
@Nullable final Agent selectedAgent,
@Nullable final Function<Agent, IMesh<?, ?, ?>> discretizations) {
this.simTimeInSec = simTimeInSec;
this.scenario = scenario;
this.domain = scenario;
this.potentialFieldTarget = potentialFieldTarget;
this.potentialField = potentialField;
this.selectedAgent = selectedAgent;
......@@ -50,7 +51,7 @@ public class OnlineVisualization implements PassiveCallback {
private MainPanel window;
private OnlineVisualisationWindow onlineVisualisationPanel;
private OnlineVisualizationModel model;
private Topography scenario;
private Domain domain;
/**
* Target potential.
......@@ -75,8 +76,8 @@ public class OnlineVisualization implements PassiveCallback {
}
@Override
public void setTopography(final Topography scenario) {
this.scenario = scenario;
public void setDomain(final Domain domain) {
this.domain = domain;
}
@Override
......@@ -146,7 +147,7 @@ public class OnlineVisualization implements PassiveCallback {
pedPotentialField = IPotentialField.copyAgentField(potentialField, selectedAgent, new VRectangle(model.getTopographyBound()), 0.1);
}
ObservationAreaSnapshotData data = new ObservationAreaSnapshotData(simTimeInSec, scenario.clone(), pft, pedPotentialField, selectedAgent, discretizations);
ObservationAreaSnapshotData data = new ObservationAreaSnapshotData(simTimeInSec, domain.clone(), pft, pedPotentialField, selectedAgent, discretizations);
model.pushObservationAreaSnapshot(data);
}
}
......
......@@ -14,9 +14,11 @@ import org.vadere.gui.components.model.AgentColoring;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.onlinevisualization.OnlineVisualization;
import org.vadere.meshing.mesh.gen.AMesh;
import org.vadere.meshing.mesh.gen.PMesh;
import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.projects.Domain;
import org.vadere.state.scenario.*;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.voronoi.VoronoiDiagram;
......@@ -38,8 +40,6 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
private IPotentialField potentialField = null;
private Function<Agent, IMesh<?, ?, ?>> discretizations = null;
private Agent agent = null;
/**
......@@ -63,7 +63,7 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
* The observation area to display. Updated by popDrawData() with the latest
* observation area snapshot.
*/
private Topography topography;
private Domain domain;
public OnlineVisualizationModel() {
super(new DefaultSimulationConfig());
......@@ -75,21 +75,21 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
@Override
public Collection<Agent> getAgents() {
if (topography == null) {
if (domain == null || domain.getTopography() == null) {
return new ArrayList<>();
}
Collection<Agent> result = new LinkedList<>();
result.addAll(topography.getElements(Agent.class));
result.addAll(domain.getTopography().getElements(Agent.class));
return result;
}
@Override
public Collection<Pedestrian> getPedestrians() {
if (topography == null) {
if (domain == null) {
return new ArrayList<>();
}
Collection<Pedestrian> result = new LinkedList<>();
result.addAll(topography.getElements(Pedestrian.class));
result.addAll(domain.getTopography().getElements(Pedestrian.class));
return result;
}
......@@ -100,15 +100,18 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
@Override
public Topography getTopography() {
return topography;
if(domain == null) {
return null;
}
return domain.getTopography();
}
@Override
public Iterator<ScenarioElement> iterator() {
if (topography == null) {
if (domain == null) {
return new ArrayList<ScenarioElement>().iterator();
}
return new TopographyIterator(topography);
return new TopographyIterator(domain.getTopography());
}
/**
......@@ -130,7 +133,6 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
potentialFieldTarget = observationAreaSnapshot.potentialFieldTarget;
potentialField = observationAreaSnapshot.potentialField;
agent = observationAreaSnapshot.selectedAgent;
discretizations = observationAreaSnapshot.discretizations;
/*
* if(topography == null ||
......@@ -139,30 +141,30 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
* }
*/
if (topography == null) {
topography = observationAreaSnapshot.scenario;
if (domain == null) {
domain = observationAreaSnapshot.domain;
// recalculate GUI (fireChangeViewportEvent will synchronize on model which is also
// needed by some awt event. Therefore do this in EDT (Event Dispatching Thread)
EventQueue.invokeLater(() -> {
fireChangeViewportEvent(new Rectangle2D.Double(topography.getBounds().x, topography.getBounds().y,
topography.getBounds().width, topography.getBounds().height));
fireChangeViewportEvent(new Rectangle2D.Double(getTopography().getBounds().x, getTopography().getBounds().y,
getTopography().getBounds().width, getTopography().getBounds().height));
});
} else {
topography = observationAreaSnapshot.scenario;
domain = observationAreaSnapshot.domain;
}
if (getSelectedElement() instanceof Car) {
int carId = getSelectedElement().getId();
Car car = topography.getElement(Car.class, carId);
Car car = domain.getTopography().getElement(Car.class, carId);
setSelectedElement(car);
} else if (getSelectedElement() instanceof Pedestrian) {
int pedId = getSelectedElement().getId();
Pedestrian ped = topography.getElement(Pedestrian.class, pedId);
Pedestrian ped = domain.getTopography().getElement(Pedestrian.class, pedId);
setSelectedElement(ped);
}
if (isVoronoiDiagramAvailable() && isVoronoiDiagramVisible()) {
getVoronoiDiagram().computeVoronoiDiagram(topography.getPedestrianDynamicElements().getElements()
getVoronoiDiagram().computeVoronoiDiagram(domain.getTopography().getPedestrianDynamicElements().getElements()
.stream()
.map(ped -> ped.getPosition())
.collect(Collectors.toList()));
......@@ -186,7 +188,7 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
selectedElement = null;
voronoiDiagram = null;
topography = null;
domain = null;
simTimeInSec = 0.0;
}
......@@ -225,12 +227,12 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
}
@Override
public IMesh<?, ?, ?> getDiscretization() {
if(agent != null && discretizations != null && config.isShowTargetPotentielFieldMesh() && agent.equals(getSelectedElement())) {
return discretizations.apply(agent);
public IMesh<?, ?, ?> getFloorFieldMesh() {
if(domain.getFloorFieldMesh() != null) {
return domain.getFloorFieldMesh();
} else {
return new AMesh();
}
return new PMesh();
}