Commit 843993c6 authored by hm-schuhba1's avatar hm-schuhba1

Merge branch 'master' into 151_diff_origin

parents 6a64416d ecb24671
...@@ -242,7 +242,8 @@ OnlineVis.msgDialogShowPotentialfield.target=Target Potential Field ...@@ -242,7 +242,8 @@ OnlineVis.msgDialogShowPotentialfield.target=Target Potential Field
OnlineVis.msgDialogShowPotentialfield.overall=Potential Field (OSM only) OnlineVis.msgDialogShowPotentialfield.overall=Potential Field (OSM only)
OnlineVis.msgDialogShowPotentialfield.none=None OnlineVis.msgDialogShowPotentialfield.none=None
TopographyBoundDialog.title = Set Topography Bounds TopographyBoundDialog.title=Width x Height
TopographyBoundDialog.tooltip=Set topography bounds
InformationDialogError.title=Internal Error InformationDialogError.title=Internal Error
InformationDialogFileError=Could not load file! InformationDialogFileError=Could not load file!
...@@ -267,6 +268,7 @@ SettingsDialog.lblPedestrianNoTarget.text=Without Target (-1) ...@@ -267,6 +268,7 @@ SettingsDialog.lblPedestrianNoTarget.text=Without Target (-1)
ProjectView.menuOpenFloorFieldFile.title=Add Floor Field File... ProjectView.menuOpenFloorFieldFile.title=Add Floor Field File...
ProjectView.btnDrawVoronoiDiagram.tooltip=Draw and display a Voronoi Diagram ProjectView.btnDrawVoronoiDiagram.tooltip=Draw and display a Voronoi Diagram
ProjectView.btnDrawMesh.tooltip=Draw and display a mesh
SettingsDialog.chbLogo.text=Show the Vadere logo SettingsDialog.chbLogo.text=Show the Vadere logo
ProjectView.btnShowWalkingDirection.tooltip=Show the walking direction of all pedestrians ProjectView.btnShowWalkingDirection.tooltip=Show the walking direction of all pedestrians
ProjectView.btnShowGroupInformation.tooltip=Draw pedestrians within one group with same shape and color ProjectView.btnShowGroupInformation.tooltip=Draw pedestrians within one group with same shape and color
......
...@@ -237,7 +237,8 @@ OnlineVis.msgDialogShowPotentialfield.target=Zielpotential ...@@ -237,7 +237,8 @@ OnlineVis.msgDialogShowPotentialfield.target=Zielpotential
OnlineVis.msgDialogShowPotentialfield.overall=Potential (OSM only) OnlineVis.msgDialogShowPotentialfield.overall=Potential (OSM only)
OnlineVis.msgDialogShowPotentialfield.none=Keines OnlineVis.msgDialogShowPotentialfield.none=Keines
TopographyBoundDialog.title = Setze Topographie Grenzen TopographyBoundDialog.title=Breite x H\u00F6he
TopographyBoundDialog.tooltip=Setze Topographie-Gr\u00F6\u00DFe
InformationDialogError.title=Interner Fehelr InformationDialogError.title=Interner Fehelr
InformationDialogFileError=Datei konnte nicht geladen werden! InformationDialogFileError=Datei konnte nicht geladen werden!
...@@ -273,6 +274,8 @@ ProjectView.btnShowDensity.tooltip=Dichte anzeigen ...@@ -273,6 +274,8 @@ ProjectView.btnShowDensity.tooltip=Dichte anzeigen
ProjectView.btnSettings.tooltip=Einstellungen ProjectView.btnSettings.tooltip=Einstellungen
ProjectView.btnOk=OK ProjectView.btnOk=OK
ProjectView.btnCancel=Abbrechen ProjectView.btnCancel=Abbrechen
ProjectView.btnDrawVoronoiDiagram.tooltip=Voronoi-Diagramm zeichnen und anzeigen
ProjectView.btnDrawMesh.tooltip=Mesh zeichnen und anzeigen
TopographyCreator.btnMergeObstacles.tooltip=Hindernisse zusammenf\u00fchren TopographyCreator.btnMergeObstacles.tooltip=Hindernisse zusammenf\u00fchren
TopographyCreator.btnMinimizeTopography.tooltip=Select Viewport area TopographyCreator.btnMinimizeTopography.tooltip=Select Viewport area
......
...@@ -6,40 +6,17 @@ import org.apache.log4j.LogManager; ...@@ -6,40 +6,17 @@ import org.apache.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.vadere.gui.components.control.*; import org.vadere.gui.components.control.*;
import org.vadere.gui.components.view.ISelectScenarioElementListener; import org.vadere.gui.components.view.ISelectScenarioElementListener;
import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.PotentialFieldDistancesBruteForce;
import org.vadere.simulator.utils.TexGraphGenerator;
import org.vadere.state.attributes.models.AttributesFloorField;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.ScenarioElement; import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.scenario.Topography;
import org.vadere.state.types.ScenarioElementType; import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape; import org.vadere.util.geometry.shapes.VShape;
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.inter.IIncrementalTriangulation;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VTriangle;
import org.vadere.util.data.cellgrid.CellGrid;
import org.vadere.util.data.cellgrid.CellState;
import org.vadere.util.data.cellgrid.PathFindingTag;
import org.vadere.util.math.DistanceFunction;
import org.vadere.util.math.IDistanceFunction;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.EikMeshPoint;
import org.vadere.meshing.mesh.triangulation.improver.eikmesh.impl.PEikMesh;
import org.vadere.util.voronoi.VoronoiDiagram; import org.vadere.util.voronoi.VoronoiDiagram;
import java.awt.*; import java.awt.*;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
...@@ -63,8 +40,6 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i ...@@ -63,8 +40,6 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
private boolean showVoroniDiagram; private boolean showVoroniDiagram;
private boolean showTriangulation;
private VPoint cursorWorldPosition; private VPoint cursorWorldPosition;
private VPoint startSelectionPoint; private VPoint startSelectionPoint;
...@@ -87,12 +62,6 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i ...@@ -87,12 +62,6 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
public T config; public T config;
private IIncrementalTriangulation<EikMeshPoint, PVertex<EikMeshPoint>, PHalfEdge<EikMeshPoint>, PFace<EikMeshPoint>> triangulation;
private Collection<VTriangle> triangles;
protected boolean triangulationTriggered = false;
public DefaultModel(final T config) { public DefaultModel(final T config) {
this.config = config; this.config = config;
this.scaleFactor = 50; this.scaleFactor = 50;
...@@ -101,13 +70,11 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i ...@@ -101,13 +70,11 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
this.cursorWorldPosition = VPoint.ZERO; this.cursorWorldPosition = VPoint.ZERO;
this.selectScenarioElementListener = new LinkedList<>(); this.selectScenarioElementListener = new LinkedList<>();
this.voronoiDiagram = null; this.voronoiDiagram = null;
this.showTriangulation = false;
this.showVoroniDiagram = true; this.showVoroniDiagram = true;
this.showSelection = false; this.showSelection = false;
this.mouseSelectionMode = new DefaultSelectionMode(this); this.mouseSelectionMode = new DefaultSelectionMode(this);
this.viewportChangeListeners = new ArrayList<>(); this.viewportChangeListeners = new ArrayList<>();
this.scaleChangeListeners = new ArrayList<>(); this.scaleChangeListeners = new ArrayList<>();
this.triangulation = null;
} }
@Override @Override
...@@ -192,10 +159,6 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i ...@@ -192,10 +159,6 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
} }
} }
public boolean isTriangulationVisible() {
return showTriangulation;
}
@Override @Override
public void notifyScaleListeners() { public void notifyScaleListeners() {
for (IScaleChangeListener listener : scaleChangeListeners) { for (IScaleChangeListener listener : scaleChangeListeners) {
...@@ -385,18 +348,6 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i ...@@ -385,18 +348,6 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
setChanged(); setChanged();
} }
@Override
public void showTriangulation() {
showTriangulation = true;
setChanged();
}
@Override
public void hideTriangulation() {
showTriangulation = false;
setChanged();
}
@Override @Override
public void showSelection() { public void showSelection() {
showSelection = true; showSelection = true;
...@@ -543,95 +494,6 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i ...@@ -543,95 +494,6 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
return config; return config;
} }
/*
* returns the adaptive triangulation (see persson-2004 'A Simple Mesh Generator in MATLAB.')
*/
public void startTriangulation() {
if(!triangulationTriggered) {
triangulationTriggered = true;
VRectangle bound = new VRectangle(getTopographyBound());
Collection<Obstacle> obstacles = Topography.createObstacleBoundary(getTopography());
obstacles.addAll(getTopography().getObstacles());
List<VShape> shapes = obstacles.stream().map(obstacle -> obstacle.getShape()).collect(Collectors.toList());
IPotentialField distanceField = new PotentialFieldDistancesBruteForce(
getTopography().getObstacles().stream().map(obs -> obs.getShape()).collect(Collectors.toList()),
new VRectangle(getTopography().getBounds()),
new AttributesFloorField());
Function<IPoint, Double> obstacleDistance = p -> distanceField.getPotential(p, null);
IDistanceFunction distanceFunc = new DistanceFunction(bound, shapes);
CellGrid cellGrid = new CellGrid(bound.getWidth(), bound.getHeight(), 0.1, new CellState(), bound.getMinX(), bound.getMinY());
cellGrid.pointStream().forEach(p -> cellGrid.setValue(p, new CellState(distanceFunc.apply(cellGrid.pointToCoord(p)), PathFindingTag.Reachable)));
Function<IPoint, Double> interpolationFunction = cellGrid.getInterpolationFunction();
IDistanceFunction approxDistance = p -> interpolationFunction.apply(p);
/*PPSMeshing meshImprover = new PPSMeshing(
distanceFunc,
p -> Math.min(1.0 + Math.pow(Math.max(-distanceFunc.apply(p), 0)*0.8, 2), 6.0),
0.3,
bound, getTopography().getObstacles().stream().map(obs -> obs.getShape()).collect(Collectors.toList()));*/
PEikMesh meshImprover = new PEikMesh(
distanceFunc,
p -> Math.min(1.0 + Math.max(approxDistance.apply(p)*approxDistance.apply(p), 0)*0.3, 5.0),
0.35,
bound, getTopography().getObstacles().stream().map(obs -> obs.getShape()).collect(Collectors.toList()));
/*PPSMeshing meshImprover = new PPSMeshing(
distanceFunc,
p -> 1.0,
1.0,
bound, getTopography().getObstacles().stream().map(obs -> obs.getShape()).collect(Collectors.toList()));*/
triangulation = meshImprover.getTriangulation();
Thread t = new Thread(() -> {
while(!meshImprover.isFinished()) {
meshImprover.improve();
/*try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}*/
setChanged();
notifyObservers();
}
//meshImprover.improve();
Function<PFace<EikMeshPoint>, Color> colorFunction = f -> {
float grayScale = (float) meshImprover.faceToQuality(f);
return triangulation.isValid(f) ? new Color(grayScale, grayScale, grayScale) : Color.RED;
};
log.info(TexGraphGenerator.toTikz(meshImprover.getMesh(), colorFunction, 1.0f));
log.info("number of points = " + meshImprover.getMesh().getVertices().size());
log.info("number of triangle = " + meshImprover.getMesh().getFaces().size());
log.info("avg-quality = " + meshImprover.getQuality());
log.info("min-quality = " + meshImprover.getMinQuality());
});
t.start();
}
}
public Collection<VTriangle> getTriangles() {
if(triangulation == null) {
return Collections.EMPTY_LIST;
}
synchronized (triangulation.getMesh()) {
return triangulation.streamTriangles().collect(Collectors.toList());
}
}
public Collection<VPolygon> getHoles() {
if(triangulation == null) {
return Collections.EMPTY_LIST;
}
synchronized (triangulation.getMesh()) {
return triangulation.getMesh().streamHoles().map(f -> triangulation.getMesh().toPolygon(f)).collect(Collectors.toList());
}
}
/*public void startTriangulation() { /*public void startTriangulation() {
if(!triangulationTriggered) { if(!triangulationTriggered) {
triangulationTriggered = true; triangulationTriggered = true;
......
...@@ -26,6 +26,7 @@ public class DefaultSimulationConfig extends DefaultConfig { ...@@ -26,6 +26,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
private boolean showPedestrians = true; private boolean showPedestrians = true;
private boolean showWalkdirection = false; private boolean showWalkdirection = false;
private boolean showTargetPotentialField = false; private boolean showTargetPotentialField = false;
private boolean showTargetPotentielFieldMesh = false;
private boolean showPotentialField = false; private boolean showPotentialField = false;
private boolean showTrajectories = false; private boolean showTrajectories = false;
private boolean showGrid = false; private boolean showGrid = false;
...@@ -64,6 +65,7 @@ public class DefaultSimulationConfig extends DefaultConfig { ...@@ -64,6 +65,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
this.showStairs = config.showStairs; this.showStairs = config.showStairs;
this.showGroups = config.showGroups; this.showGroups = config.showGroups;
this.showPotentialField = config.showPotentialField; this.showPotentialField = config.showPotentialField;
this.showTargetPotentielFieldMesh = config.showTargetPotentielFieldMesh;
} }
public boolean isShowGroups() { public boolean isShowGroups() {
...@@ -110,6 +112,15 @@ public class DefaultSimulationConfig extends DefaultConfig { ...@@ -110,6 +112,15 @@ public class DefaultSimulationConfig extends DefaultConfig {
return showTargets; return showTargets;
} }
public void setShowTargetPotentielFieldMesh(final boolean showTargetPotentielFieldMesh) {
this.showTargetPotentielFieldMesh = showTargetPotentielFieldMesh;
setChanged();
}
public boolean isShowTargetPotentielFieldMesh() {
return showTargetPotentielFieldMesh;
}
public void setShowTargets(boolean showTargets) { public void setShowTargets(boolean showTargets) {
this.showTargets = showTargets; this.showTargets = showTargets;
setChanged(); setChanged();
......
...@@ -297,9 +297,5 @@ public interface IDefaultModel<T extends DefaultConfig> extends Iterable<Scenari ...@@ -297,9 +297,5 @@ public interface IDefaultModel<T extends DefaultConfig> extends Iterable<Scenari
*/ */
void notifyObservers(final Object args); void notifyObservers(final Object args);
void hideTriangulation();
void showTriangulation();
T getConfig(); T getConfig();
} }
...@@ -4,7 +4,11 @@ package org.vadere.gui.components.model; ...@@ -4,7 +4,11 @@ package org.vadere.gui.components.model;
import java.util.Collection; import java.util.Collection;
import java.util.function.Function; import java.util.function.Function;
import org.vadere.meshing.mesh.gen.PMesh;
import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.simulator.models.potential.solver.calculators.mesh.PotentialPoint;
import org.vadere.state.scenario.Agent; import org.vadere.state.scenario.Agent;
import org.vadere.util.data.cellgrid.IPotentialPoint;
import org.vadere.util.geometry.shapes.IPoint; import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
...@@ -38,8 +42,8 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends ...@@ -38,8 +42,8 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends
return config; return config;
} }
public double getPotential(final int x, final int y) { public IMesh<? extends IPotentialPoint, ?, ?, ?> getDiscretization() {
return getPotentialField().apply(pixelToWorld(new VPoint(x, y))); return new PMesh<IPotentialPoint>((x,y) -> new PotentialPoint(x,y));
} }
/*public double getPotential(final int x, final int y) { /*public double getPotential(final int x, final int y) {
......
...@@ -2,9 +2,12 @@ package org.vadere.gui.components.view; ...@@ -2,9 +2,12 @@ package org.vadere.gui.components.view;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.vadere.gui.components.model.IDefaultModel; import org.vadere.gui.components.model.IDefaultModel;
import org.vadere.meshing.mesh.gen.MeshRenderer;
import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.state.scenario.Agent; import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.ScenarioElement; import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.scenario.Stairs; import org.vadere.state.scenario.Stairs;
import org.vadere.util.data.cellgrid.IPotentialPoint;
import org.vadere.util.geometry.shapes.Vector2D; import org.vadere.util.geometry.shapes.Vector2D;
import org.vadere.util.geometry.shapes.VCircle; import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.VLine; import org.vadere.util.geometry.shapes.VLine;
...@@ -63,7 +66,6 @@ public abstract class DefaultRenderer { ...@@ -63,7 +66,6 @@ public abstract class DefaultRenderer {
targetGraphics2D.dispose(); targetGraphics2D.dispose();
} }
public void renderGraphics(final Graphics2D targetGraphics2D, final int width, final int height) { public void renderGraphics(final Graphics2D targetGraphics2D, final int width, final int height) {
targetGraphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); targetGraphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
...@@ -594,6 +596,14 @@ public abstract class DefaultRenderer { ...@@ -594,6 +596,14 @@ public abstract class DefaultRenderer {
} }
} }
protected void renderMesh(
@NotNull final Graphics2D g,
@NotNull final IMesh<? extends IPotentialPoint, ?, ?, ?> mesh,
@NotNull final VRectangle bound) {
MeshRenderer<? extends IPotentialPoint, ?, ?, ?> meshRenderer = new MeshRenderer<>(mesh);
meshRenderer.renderGraphics(g, bound);
}
protected void renderVoronoiDiagram(final Graphics2D g, final VoronoiDiagram voronoiDiagram) { protected void renderVoronoiDiagram(final Graphics2D g, final VoronoiDiagram voronoiDiagram) {
synchronized (voronoiDiagram) { synchronized (voronoiDiagram) {
if (voronoiDiagram != null) { if (voronoiDiagram != null) {
......
...@@ -99,6 +99,10 @@ public abstract class SimulationRenderer extends DefaultRenderer { ...@@ -99,6 +99,10 @@ public abstract class SimulationRenderer extends DefaultRenderer {
renderVoronoiDiagram(graphics, model.getVoronoiDiagram()); renderVoronoiDiagram(graphics, model.getVoronoiDiagram());
} }
if(model.config.isShowTargetPotentielFieldMesh()) {
renderMesh(graphics, model.getDiscretization(), new VRectangle(model.getTopographyBound()));
}
renderSimulationContent(graphics); renderSimulationContent(graphics);
if (model.isElementSelected()) { if (model.isElementSelected()) {
...@@ -177,7 +181,7 @@ public abstract class SimulationRenderer extends DefaultRenderer { ...@@ -177,7 +181,7 @@ public abstract class SimulationRenderer extends DefaultRenderer {
private void renderPotentialFieldOnViewport(final Graphics2D g, final int xPos, final int yPos, final int width, final int height) { private void renderPotentialFieldOnViewport(final Graphics2D g, final int xPos, final int yPos, final int width, final int height) {
logger.info("resolution = " + width + ", " + height); //logger.info("resolution = " + width + ", " + height);
/* /*
* This calculation we need since the viewport.y = 0 if the user scrolls to the bottom * This calculation we need since the viewport.y = 0 if the user scrolls to the bottom
*/ */
......
...@@ -7,13 +7,17 @@ import org.jetbrains.annotations.Nullable; ...@@ -7,13 +7,17 @@ import org.jetbrains.annotations.Nullable;
import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel; import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel;
import org.vadere.gui.onlinevisualization.view.MainPanel; import org.vadere.gui.onlinevisualization.view.MainPanel;
import org.vadere.gui.onlinevisualization.view.OnlineVisualisationWindow; import org.vadere.gui.onlinevisualization.view.OnlineVisualisationWindow;
import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.simulator.control.PassiveCallback; import org.vadere.simulator.control.PassiveCallback;
import org.vadere.simulator.models.potential.fields.IPotentialField; import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget; import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.state.scenario.Agent; import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Topography; import org.vadere.state.scenario.Topography;
import org.vadere.util.data.cellgrid.IPotentialPoint;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
import java.util.function.Function;
public class OnlineVisualization implements PassiveCallback { public class OnlineVisualization implements PassiveCallback {
/** /**
...@@ -28,18 +32,21 @@ public class OnlineVisualization implements PassiveCallback { ...@@ -28,18 +32,21 @@ public class OnlineVisualization implements PassiveCallback {
public final IPotentialField potentialFieldTarget; public final IPotentialField potentialFieldTarget;
public final Agent selectedAgent; public final Agent selectedAgent;
public final IPotentialField potentialField; public final IPotentialField potentialField;
public final Function<Agent, IMesh<? extends IPotentialPoint, ?, ?, ?>> discretizations;
public ObservationAreaSnapshotData( public ObservationAreaSnapshotData(
final double simTimeInSec, final double simTimeInSec,
@NotNull final Topography scenario, @NotNull final Topography scenario,
@Nullable final IPotentialField potentialFieldTarget, @Nullable final IPotentialField potentialFieldTarget,
@Nullable final IPotentialField potentialField, @Nullable final IPotentialField potentialField,
@Nullable final Agent selectedAgent) { @Nullable final Agent selectedAgent,
@Nullable final Function<Agent, IMesh<? extends IPotentialPoint, ?, ?, ?>> discretizations) {
this.simTimeInSec = simTimeInSec; this.simTimeInSec = simTimeInSec;
this.scenario = scenario; this.scenario = scenario;
this.potentialFieldTarget = potentialFieldTarget; this.potentialFieldTarget = potentialFieldTarget;
this.potentialField = potentialField; this.potentialField = potentialField;
this.selectedAgent = selectedAgent; this.selectedAgent = selectedAgent;
this.discretizations = discretizations;
} }
} }
...@@ -117,15 +124,19 @@ public class OnlineVisualization implements PassiveCallback { ...@@ -117,15 +124,19 @@ public class OnlineVisualization implements PassiveCallback {
synchronized (model.getDataSynchronizer()) { synchronized (model.getDataSynchronizer()) {
/* Push new snapshot of the observation area to the draw thread. */ /* Push new snapshot of the observation area to the draw thread. */
IPotentialField pft = (model.config.isShowTargetPotentialField() && potentialFieldTarget != null) ? potentialFieldTarget.getSolution() : null; IPotentialField pft = (model.config.isShowTargetPotentialField() && potentialFieldTarget != null) ? potentialFieldTarget.getSolution() : null;
Function<Agent, IMesh<? extends IPotentialPoint, ?, ?, ?>> discretizations = (model.config.isShowTargetPotentielFieldMesh() && potentialFieldTarget != null) ? potentialFieldTarget.getDiscretization() : null;
IPotentialField pedPotentialField = null; IPotentialField pedPotentialField = null;
Agent selectedAgent = null; Agent selectedAgent = null;
if(model.config.isShowPotentialField() && model.getSelectedElement() instanceof Agent && potentialField != null) { if(model.getSelectedElement() instanceof Agent){
selectedAgent = (Agent)model.getSelectedElement(); selectedAgent = (Agent)model.getSelectedElement();
}
if(model.config.isShowPotentialField() && selectedAgent != null && potentialField != null) {
pedPotentialField = IPotentialField.copyAgentField(potentialField, selectedAgent, new VRectangle(model.getTopographyBound()), 0.1); pedPotentialField = IPotentialField.copyAgentField(potentialField, selectedAgent, new VRectangle(model.getTopographyBound()), 0.1);
} }
ObservationAreaSnapshotData data = new ObservationAreaSnapshotData(simTimeInSec, scenario.clone(), pft, pedPotentialField, selectedAgent); ObservationAreaSnapshotData data = new ObservationAreaSnapshotData(simTimeInSec, scenario.clone(), pft, pedPotentialField, selectedAgent, discretizations);
model.pushObservationAreaSnapshot(data); model.pushObservationAreaSnapshot(data);
} }
} }
......
package org.vadere.gui.onlinevisualization.control;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.components.control.simulation.ActionVisualization;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import java.awt.event.ActionEvent;
import javax.swing.*;
public class ActionShowMesh extends ActionVisualization {
private static Logger logger = LogManager.getLogger(ActionShowMesh.class);
public ActionShowMesh(final String name, Icon icon, final SimulationModel<? extends DefaultSimulationConfig> model) {
super(name, icon, model);
}
@Override
public void actionPerformed(final ActionEvent e) {
model.config.setShowTargetPotentielFieldMesh(!model.config.isShowTargetPotentielFieldMesh());
model.notifyObservers();
super.actionPerformed(e);
}
}
...@@ -11,8 +11,12 @@ import java.util.stream.Collectors; ...@@ -11,8 +11,12 @@ import java.util.stream.Collectors;
import org.vadere.gui.components.model.DefaultSimulationConfig; import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel; import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.onlinevisualization.OnlineVisualization; import org.vadere.gui.onlinevisualization.OnlineVisualization;
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.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.solver.calculators.mesh.PotentialPoint;
import org.vadere.state.scenario.*; import org.vadere.state.scenario.*;
import org.vadere.util.data.cellgrid.IPotentialPoint;
import org.vadere.util.geometry.shapes.IPoint; import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.voronoi.VoronoiDiagram; import org.vadere.util.voronoi.VoronoiDiagram;
...@@ -33,6 +37,8 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC ...@@ -33,6 +37,8 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
private IPotentialField potentialField = null; private IPotentialField potentialField = null;
private Function<Agent, IMesh<? extends IPotentialPoint, ?, ?, ?>> discretizations = null;
private Agent agent = null; private Agent agent = null;
/** /**
...@@ -112,6 +118,7 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC ...@@ -112,6 +118,7 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
potentialFieldTarget = observationAreaSnapshot.potentialFieldTarget; potentialFieldTarget = observationAreaSnapshot.potentialFieldTarget;
potentialField = observationAreaSnapshot.potentialField; potentialField = observationAreaSnapshot.potentialField;
agent = observationAreaSnapshot.selectedAgent; agent = observationAreaSnapshot.selectedAgent;
discretizations = observationAreaSnapshot.discretizations;
/* /*
* if(topography == null || * if(topography == null ||
...@@ -188,7 +195,7 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC ...@@ -188,7 +195,7 @@ public class OnlineVisualizationModel extends SimulationModel<DefaultSimulationC
public Function<IPoint, Double> getPotentialField() { public Function<IPoint, Double> getPotentialField() {
Function<IPoint, Double> f = pos -> 0.0; Function<IPoint, Double> f = pos -> 0.0;
if(potentialField != null && config.isShowPotentialField() && agent.equals(getSelectedElement())) { if(agent != null && potentialField != null && config.isShowPotentialField() && agent.equals(getSelectedElement())) {
f = pos -> potentialField.getPotential(pos, agent); f = pos -> potentialField.getPotential(pos, agent);