Commit fb2355df authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

triangulation can now be activated via the gui

parent 65033203
......@@ -233,6 +233,7 @@ View.btnShowWalkingDirection.tooltip=Show the walking direction of all pedestria
View.btnShowPedestrian.tooltip=Show Pedestrians
View.btnShowPotentialfield.tooltip=Show Potential Field (only possible after adding potential field file)
View.btnShowTrajectories.tooltip=Show Trajectories
View.btnShowTriangulation.tooltip=Show Triangulation
View.btnShowGrid.tooltip=Show Grid
View.btnShowDensity.tooltip=Show Density
View.btnSettings.tooltip=Settings
......
......@@ -233,6 +233,7 @@ View.btnShowWalkingDirection.tooltip=Gehrichtung aller Fu\u00dfg\u00e4nger anzei
View.btnShowPedestrian.tooltip=Fu\u00dfg\u00e4nger anzeigen
View.btnShowPotentialfield.tooltip=Potenzialfeld anzeigen (nur m\u00f6glich, nachdem eine Datei f\u00fcr das Potenzialfeld hinzugef\u00fcgt wurde)
View.btnShowTrajectories.tooltip=Trajektorien anzeigen
View.btnShowTriangulation.tooltip=Triangulierung anzeigen
View.btnShowGrid.tooltip=Gitter anzeigen
View.btnShowDensity.tooltip=Dichte anzeigen
View.btnSettings.tooltip=Einstellungen
......
......@@ -7,7 +7,10 @@ import org.vadere.gui.components.view.ISelectScenarioElementListener;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.types.ScenarioElementType;
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.VTriangle;
import org.vadere.util.triangulation.adaptive.PerssonStrangDistmesh;
import org.vadere.util.voronoi.VoronoiDiagram;
import java.awt.*;
......@@ -15,6 +18,7 @@ import java.awt.geom.Rectangle2D;
import java.util.*;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
......@@ -36,6 +40,8 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
private boolean showVoroniDiagram;
private boolean showTriangulation;
private VPoint cursorWorldPosition;
private VPoint startSelectionPoint;
......@@ -58,6 +64,8 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
public T config;
public List<VTriangle> triangulation;
public DefaultModel(final T config) {
this.config = config;
this.scaleFactor = 50;
......@@ -67,10 +75,12 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
this.selectScenarioElementListener = new LinkedList<>();
this.voronoiDiagram = null;
this.showVoroniDiagram = false;
this.showTriangulation = false;
this.showSelection = false;
this.mouseSelectionMode = new DefaultSelectionMode(this);
this.viewportChangeListeners = new ArrayList<>();
this.scaleChangeListeners = new ArrayList<>();
this.triangulation = new ArrayList<>();
}
@Override
......@@ -145,6 +155,10 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
}
}
public boolean isTriangulationVisible() {
return showTriangulation;
}
@Override
public void notifyScaleListeners() {
for (IScaleChangeListener listener : scaleChangeListeners) {
......@@ -334,6 +348,18 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
setChanged();
}
@Override
public void showTriangulation() {
showTriangulation = true;
setChanged();
}
@Override
public void hideTriangulation() {
showTriangulation = false;
setChanged();
}
@Override
public void showSelection() {
showSelection = true;
......@@ -474,4 +500,21 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
public T getConfig() {
return config;
}
/*
* returns the adaptive triangulation (see persson-2004 'A Simple Mesh Generator in MATLAB.')
*/
public Collection<VTriangle> getTriangulation() {
if(triangulation.isEmpty()) {
PerssonStrangDistmesh psd = new PerssonStrangDistmesh(
new VRectangle(getTopographyBound()),
getTopography().getObstacles().stream().map(obs -> obs.getShape()).collect(Collectors.toList()),
1.0,
false,
l -> 0.0,
"Distmesh");
triangulation = psd.getTriangulation().getVTriangles();
}
return triangulation;
}
}
......@@ -295,5 +295,9 @@ public interface IDefaultModel<T extends DefaultConfig> extends Iterable<Scenari
*/
void notifyObservers(final Object args);
void hideTriangulation();
void showTriangulation();
T getConfig();
}
......@@ -7,6 +7,7 @@ import java.awt.Stroke;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.Collection;
import java.util.stream.Stream;
import org.apache.log4j.LogManager;
......@@ -17,6 +18,7 @@ import org.vadere.gui.components.utils.ColorHelper;
import org.vadere.gui.components.utils.Resources;
import org.vadere.state.scenario.Agent;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VTriangle;
public abstract class SimulationRenderer extends DefaultRenderer {
......@@ -91,6 +93,10 @@ public abstract class SimulationRenderer extends DefaultRenderer {
renderVoronoiDiagram(graphics, model.getVoronoiDiagram());
}
if(model.isTriangulationVisible()) {
renderTriangulation(graphics, model.getTriangulation());
}
renderSimulationContent(graphics);
if (model.isElementSelected()) {
......@@ -133,6 +139,12 @@ public abstract class SimulationRenderer extends DefaultRenderer {
// g.setStroke(stroke);
}
protected void renderTriangulation(final Graphics2D g, final Collection<VTriangle> triangleList) {
g.setColor(Color.GRAY);
g.setStroke(new BasicStroke(getGridLineWidth()));
triangleList.stream().forEach(triangle -> g.draw(triangle));
}
private void renderDensity(final Graphics2D g) {
CLGaussianCalculator densityCalculator = new CLGaussianCalculator(model, model.config.getDensityScale(),
model.config.getDensityMeasurementRadius(),
......@@ -192,4 +204,8 @@ public abstract class SimulationRenderer extends DefaultRenderer {
}
protected abstract void renderSimulationContent(final Graphics2D g);
private float getGridLineWidth() {
return (float) (0.5 / model.getScaleFactor());
}
}
......@@ -193,6 +193,25 @@ public class PostvisualizationWindow extends JPanel implements Observer {
;
}, "View.btnShowTrajectories.tooltip");
addActionToToolbar(toolbar,
new ActionVisualization("show_triangulation",
resources.getIcon("triangulation.png", iconWidth, iconHeight), model) {
@Override
public void actionPerformed(ActionEvent e) {
if(model.isTriangulationVisible()) {
model.hideTriangulation();
}
else {
model.showTriangulation();
}
model.notifyObservers();
}
;
}, "View.btnShowTriangulation.tooltip"
);
addActionToToolbar(toolbar,
new ActionVisualization("show_direction",
resources.getIcon("walking_direction.png", iconWidth, iconHeight), model) {
......
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