Commit 17ea3e8c authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

Merge branch 'dev/MeshPlotting' into 'master'

Dev/mesh plotting

See merge request !133
parents d77a1a8d 290ae70a
Pipeline #266819 passed with stages
in 145 minutes and 18 seconds
......@@ -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(ActionGeneratePNG.class);
private static final Configuration CONFIG = VadereConfig.getConfig();
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,""));
CompletableFuture.supplyAsync(() -> constructor.pslgToCoarsePMesh(pslg, true)).thenAccept(mesh -> saveFloorFieldMesh(mesh,IOUtils.BACKGROUND_MESH_ENDING));
}
}
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();
}
@Override
......@@ -263,6 +265,6 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
@Override
public boolean isAlive(int pedId) {
return topography.getPedestrianDynamicElements().idExists(pedId);
return domain.getTopography().getPedestrianDynamicElements().idExists(pedId);
}
}
......@@ -256,7 +256,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
tabbedPane.removeTabAt(tabbedPane.indexOfComponent(topographyCreatorView));
}
topographyCreatorView = new TopographyWindow(scenario);
topographyCreatorView = new TopographyWindow(scenario, model);
tabbedPane.addTab(Messages.getString("Tab.TopographyCreator.title"), topographyCreatorView);
tabbedPane.validate();
tabbedPane.repaint();
......
......@@ -19,8 +19,13 @@ public class ActionTranslateTopographyDialog {
private final double xOld;
private final double yOld;
private boolean valid;
private final String label;
public ActionTranslateTopographyDialog(final double x, double y){
this(x, y, "x, y");
}
public ActionTranslateTopographyDialog(final double x, double y, final String label){
this.textField = new JTextField(30);
this.textField.setText(String.format(Locale.ENGLISH, "%f, %f", x, y));
......@@ -30,6 +35,7 @@ public class ActionTranslateTopographyDialog {
this.y = y;
this.xOld = x;
this.yOld = y;
this.label = label;
}
public double getX() {
......@@ -44,7 +50,7 @@ public class ActionTranslateTopographyDialog {
return JOptionPane.showConfirmDialog(
ProjectView.getMainWindow(),
textField,
"x, y",
label,
JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION;
}
......
......@@ -3,6 +3,8 @@ package org.vadere.gui.topographycreator.view;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import org.jetbrains.annotations.NotNull;
import org.vadere.gui.components.control.ActionGenerateMesh;
import org.vadere.gui.components.control.ActionGeneratePoly;
import org.vadere.gui.components.control.IViewportChangeListener;
import org.vadere.gui.components.control.JViewportChangeListener;
......@@ -14,6 +16,7 @@ import org.vadere.gui.components.view.InfoPanel;
import org.vadere.gui.components.view.ScenarioElementView;
import org.vadere.gui.components.view.ScenarioToolBar;
import org.vadere.gui.projectview.control.ActionDeselect;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.gui.projectview.view.JsonValidIndicator;
import org.vadere.gui.topographycreator.control.ActionBasic;
import org.vadere.gui.topographycreator.control.ActionCopyElement;
......@@ -81,7 +84,7 @@ public class TopographyWindow extends JPanel {
private UndoableEditSupport undoSupport;
private UndoManager undoManager;
public TopographyWindow(final Scenario currentScenario) {
public TopographyWindow(final Scenario currentScenario, @NotNull final ProjectViewModel model) {
toolbar = new ScenarioToolBar("Toolbar");
int toolbarSize = VadereConfig.getConfig().getInt("Gui.toolbar.size");
......@@ -99,7 +102,7 @@ public class TopographyWindow extends JPanel {
undoManager = new UndoManager();
undoSupport.addUndoableEditListener(new UndoAdaptor(undoManager));
setTopography(new TopographyCreatorModel(currentScenario));
setTopography(new TopographyCreatorModel(currentScenario), model);
}
private static JButton addActionToToolbar(final JToolBar toolbar, final Action action,
......@@ -120,7 +123,7 @@ public class TopographyWindow extends JPanel {
return button;
}
private void setTopography(final TopographyCreatorModel panelModel) {
private void setTopography(final TopographyCreatorModel panelModel, @NotNull final ProjectViewModel model) {
this.panelModel = panelModel;
this.panelModel.setMouseSelectionMode(new SelectElementMode(panelModel, undoSupport));
......@@ -423,6 +426,10 @@ public class TopographyWindow extends JPanel {
resources.getIcon("camera_poly.png", iconWidth, iconHeight),
panelModel);
AbstractAction generateMesh = new ActionGenerateMesh(Messages.getString("ProjectView.btnGenerateMesh.tooltip"),
resources.getIcon("generate_mesh.png", iconWidth, iconHeight),
model);
/* create toolbar*/
addActionToToolbar(toolbar, selectShape, "select_shape_tooltip");
......@@ -468,6 +475,7 @@ public class TopographyWindow extends JPanel {
addActionToToolbar(toolbar, resetScenarioAction, "TopographyCreator.btnNewTopography.tooltip");
addActionToToolbar(toolbar, saveScenarioAction, "TopographyCreator.btnQuickSave.tooltip");
addActionToToolbar(toolbar, polyImg, "TopographyCreator.btnGeneratePoly.tooltip");
addActionToToolbar(toolbar, generateMesh, "TopographyCreator.btnGenerateMesh.tooltip");
toolbar.addSeparator(new Dimension(5, 50));
addActionToToolbar(toolbar, undoAction, "TopographyCreator.btnUndo.tooltip");
......
......@@ -46,6 +46,7 @@ public class SimulationCommandHandlerTest extends CommandHandlerTest {
} catch (IOException e) {
throw e;
}
TraCIGetCommand cmd = (TraCIGetCommand) getFirstCommand(TraCIGetCacheHashCommand.build(
TraCICmd.GET_SIMULATION_VALUE, elementID, varID, varType, data));
RemoteManager rm = new TestRemoteManager() {
......
# nVertices dimension nAttributes boundaryMarker
19 2 0 0
18 2 0 0
# vertexId x y
1 10.068317 15.240938
2 0.500000 12.473684
3 49.500000 49.500000
4 49.500000 0.500000
5 7.711478 10.030659
6 0.500000 45.907735
7 0.500000 42.907735
8 32.129121 5.936819
9 0.500000 49.500000
10 3.888684 20.251412
11 1.463889 42.907735
12 1.821300 11.082842
13 23.463889 45.907735
14 49.500000 5.936819
15 15.459378 12.808810
16 20.931872 10.544835
17 29.892589 0.500000
18 49.500000 42.506680
19 31.295924 42.506680
2 49.500000 49.500000
3 49.500000 0.500000
4 7.711478 10.030659
5 0.500000 45.907735
6 32.129121 5.936819
7 0.500000 49.500000
8 3.888684 20.251412
9 0.985522 42.000000
10 0.500000 11.318871
11 23.463889 45.907735
12 49.500000 5.936819
13 15.459378 12.808810
14 29.892589 0.500000
15 20.931872 10.544835
16 49.500000 42.506680
17 0.500000 42.000000
18 31.295924 42.506680
#
# nSegments boundaryMarker
19 0
18 0
# lineId vertexId1 vertexId2
1 4 14
2 14 8
3 8 16
4 16 19
5 19 18
6 18 3