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

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

parent b4d52239
......@@ -12,7 +12,7 @@ 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,7 +66,9 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
public T config;
public List<VTriangle> triangulation;
public Collection<VTriangle> triangulation;
protected boolean triangulationTriggered = false;
public DefaultModel(final T config) {
this.config = config;
......@@ -506,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.getBowyerWatson().getVTriangles();
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<VTriangle> getTriangulation() {
return triangulation;
}
}
......@@ -94,6 +94,7 @@ public abstract class SimulationRenderer extends DefaultRenderer {
}
if(model.isTriangulationVisible()) {
model.startTriangulation();
renderTriangulation(graphics, model.getTriangulation());
}
......
......@@ -139,6 +139,7 @@ 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<>();
......
......@@ -29,7 +29,6 @@ public class PSDistmesh {
private IEdgeLengthFunction relativeDesiredEdgeLengthFunc;
private VRectangle regionBoundingBox;
private Collection<? extends VShape> obstacles;
private int steps;
// Parameters
......@@ -98,46 +97,7 @@ public class PSDistmesh {
}
public boolean hasMaximalSteps() {
return steps >= 1000;
}
/**
* Remove all triangles intersecting any obstacle shape.
*/
public void cleanUp() {
/*bowyerWatson
.stream()
.map(face -> face.toTriangle())
.filter(triangle -> triangle.isNonAcute())
.map(triangle -> triangle.getCircumcenter())
.collect(Collectors.toSet())
.forEach(p -> bowyerWatson.insert(new MeshPoint(p, false)));*/
}
private void reTriangulate() {
if(firstStep || maxMovementLen / initialEdgeLen > Parameters.TOL) {
maxMovementLen = 0;
bowyerWatson = new IncrementalTriangulation<>(new PMesh<>((x, y) -> new MeshPoint(x, y, false)), points, (x, y) -> new MeshPoint(x, y, false));
System.out.println("triangulation started");
bowyerWatson.compute();
System.out.println("triangulation finished");
IMesh<MeshPoint, PHalfEdge<MeshPoint>, PFace<MeshPoint>> mesh = bowyerWatson.getMesh();
Function<PHalfEdge<MeshPoint>, MLine<MeshPoint>> toLine = edge -> new MLine<>(mesh.getVertex(mesh.getPrev(edge)), mesh.getVertex(edge));
// compute the line and points again, since we filter some triangles
lines = bowyerWatson.streamFaces()
.filter(face -> distanceFunc.apply(bowyerWatson.getMesh().toTriangle(face).midPoint()) < -geps)
.flatMap(face ->mesh.streamEdges(face).map(halfEdge -> toLine.apply(halfEdge)))
.collect(Collectors.toSet());
points = lines.stream().flatMap(line -> line.streamPoints()).collect(Collectors.toSet());
System.out.println("number of edges: " + lines.size());
System.out.println("number of points: " + points.size());
}
return steps >= Parameters.MAX_NUMBER_OF_STEPS;
}
/*
......
......@@ -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,6 @@ 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 = 1;
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