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

add triangulation into the postvis view such that we can see the result

parent c0499af8
......@@ -4,13 +4,15 @@ import javax.swing.*;
import org.vadere.gui.components.control.*;
import org.vadere.gui.components.view.ISelectScenarioElementListener;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.scenario.Topography;
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.triangulation.adaptive.PSDistmesh;
import org.vadere.util.voronoi.VoronoiDiagram;
import java.awt.*;
......@@ -66,6 +68,8 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
public Collection<? extends VTriangle> triangulation;
protected boolean triangulationTriggered = false;
public DefaultModel(final T config) {
this.config = config;
this.scaleFactor = 50;
......@@ -85,7 +89,7 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
@Override
public Color getScenarioElementColor(final ScenarioElementType elementType) {
Color c = null;
Color c;
switch (elementType) {
case OBSTACLE:
c = getConfig().getObstacleColor();
......@@ -504,17 +508,37 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
/*
* returns the adaptive triangulation (see persson-2004 'A Simple Mesh Generator in MATLAB.')
*/
public Collection<? extends 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.getTriangles();
public void startTriangulation() {
if(!triangulationTriggered) {
triangulationTriggered = true;
VRectangle bound = new VRectangle(getTopographyBound());
Collection<Obstacle> obstacles = Topography.createObstacleBoundary(getTopography());
obstacles.addAll(getTopography().getObstacles());
PSDistmesh psDistmesh = new PSDistmesh(
bound,
obstacles.stream().map(obstacle -> obstacle.getShape()).collect(Collectors.toList()),
Math.max(0.1, Math.max(bound.getWidth(), bound.getHeight())) / 100,
false
);
Thread t = new Thread(
() -> {
while (!psDistmesh.hasConverged() && !psDistmesh.hasMaximalSteps()) {
psDistmesh.step();
synchronized (triangulation) {
triangulation = psDistmesh.getTriangles();
setChanged();
fireChangeViewportEvent(bound);
}
}
});
t.start();
}
}
public Collection<? extends VTriangle> getTriangulation() {
return triangulation;
}
}
......@@ -94,6 +94,7 @@ public abstract class SimulationRenderer extends DefaultRenderer {
}
if(model.isTriangulationVisible()) {
model.startTriangulation();
renderTriangulation(graphics, model.getTriangulation());
}
......
......@@ -137,6 +137,10 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
}
public void init(final Scenario vadere, final String projectPath) {
// avoid the long computation
this.hideTriangulation();
this.triangulationTriggered = false;
this.vadere = vadere;
this.agentsByStep = new HashMap<>();
this.steps = new ArrayList<>();
......
......@@ -28,14 +28,7 @@ public class OfflineTopographyController {
// add bounding box
protected void prepareTopography() {
if (this.topography.isBounded() && !this.topography.hasBoundary()) {
VPolygon boundary = new VPolygon(this.topography.getBounds());
double width = this.topography.getBoundingBoxWidth();
Collection<VPolygon> boundingBoxObstacleShapes = boundary
.borderAsShapes(width, width / 2.0, 0.0001);
for (VPolygon obstacleShape : boundingBoxObstacleShapes) {
AttributesObstacle obstacleAttributes = new AttributesObstacle(
-1, obstacleShape);
Obstacle obstacle = new Obstacle(obstacleAttributes);
for(Obstacle obstacle : Topography.createObstacleBoundary(topography)) {
this.topography.addBoundary(obstacle);
}
}
......
......@@ -2,6 +2,7 @@ package org.vadere.state.scenario;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RectangularShape;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
......@@ -17,9 +18,11 @@ import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.attributes.scenario.AttributesCar;
import org.vadere.state.attributes.scenario.AttributesDynamicElement;
import org.vadere.state.attributes.scenario.AttributesObstacle;
import org.vadere.state.attributes.scenario.AttributesTopography;
import org.vadere.util.geometry.LinkedCellsGrid;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VShape;
public class Topography {
......@@ -349,18 +352,18 @@ public class Topography {
for (Obstacle obstacle : this.getObstacles()) {
if (boundaryObstacles.contains(obstacle))
s.addBoundary((Obstacle) obstacle.clone());
s.addBoundary(obstacle.clone());
else
s.addObstacle((Obstacle) obstacle.clone());
s.addObstacle(obstacle.clone());
}
for (Stairs stairs : getStairs()) {
s.addStairs(stairs);
}
for (Target target : getTargets()) {
s.addTarget((Target) target.clone());
s.addTarget(target.clone());
}
for (Source source : getSources()) {
s.addSource((Source) source.clone());
s.addSource(source.clone());
}
for (Pedestrian pedestrian : getElements(Pedestrian.class)) {
s.addElement(pedestrian);
......@@ -376,7 +379,7 @@ public class Topography {
}
if (hasTeleporter()) {
s.setTeleporter((Teleporter) teleporter.clone());
s.setTeleporter(teleporter.clone());
}
for (DynamicElementAddListener<Pedestrian> pedestrianAddListener : this.pedestrians.getElementAddedListener()) {
......@@ -443,4 +446,21 @@ public class Topography {
allOtherAttributes.forEach(a -> a.seal());
}
public static Collection<Obstacle> createObstacleBoundary(final Topography topography) {
List<Obstacle> obstacles = new ArrayList<>();
VPolygon boundary = new VPolygon(topography.getBounds());
double width = topography.getBoundingBoxWidth();
Collection<VPolygon> boundingBoxObstacleShapes = boundary
.borderAsShapes(width, width / 2.0, 0.0001);
for (VPolygon obstacleShape : boundingBoxObstacleShapes) {
AttributesObstacle obstacleAttributes = new AttributesObstacle(
-1, obstacleShape);
Obstacle obstacle = new Obstacle(obstacleAttributes);
obstacles.add(obstacle);
}
return obstacles;
}
}
......@@ -23,6 +23,7 @@ public class PSDistmesh {
private IEdgeLengthFunction relativeDesiredEdgeLengthFunc;
private VRectangle regionBoundingBox;
private Collection<? extends VShape> obstacles;
private int steps;
// Parameters
private double initialEdgeLen;
......@@ -71,6 +72,7 @@ public class PSDistmesh {
this.deps = 1.4901e-8 * initialEdgeLen;
this.triangulation = new ArrayList<>();
this.obstacles = obstacles;
this.steps = 0;
}
public void execute() {
......@@ -82,11 +84,22 @@ public class PSDistmesh {
}
}
public boolean hasConverged() {
double test = qualityCheck();
System.out.println("quality: " + test);
return test > Parameters.qualityMeasurement;
}
public boolean hasMaximalSteps() {
return steps >= Parameters.MAX_NUMBER_OF_STEPS;
}
/*
Stellt den Verlauf der Iterationen dar. Innerhalb der while(true) passiert eine Iteration des Algorithmus
*/
public void step()
{
steps++;
if(firstStep || maxMovementLen / initialEdgeLen > Parameters.TOL) {
maxMovementLen = 0;
bowyerWatson = new BowyerWatson<>(points, (x, y) -> new MPoint(x, y, -1), (a, b, c) -> new VTriangle(a, b, c));
......
......@@ -17,4 +17,5 @@ public class Parameters {
final static int SAMPLENUMBER = 10;
final static int SAMPLEDIVISION = 10;
static final int SEGMENTDIVISION = 0;
final static int MAX_NUMBER_OF_STEPS = 20;
}
......@@ -19,7 +19,7 @@ public class TestEnhancedVersion extends JFrame {
{
// VRectangle bbox = new VRectangle(0,0,100,100);
// ArrayList<VRectangle> obs = new ArrayList<VRectangle>() {{ add(new VRectangle(20,20,20,20));}};
double h0 = 0.1;
double h0 = 1.0;
long now = System.currentTimeMillis();
......
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