Commit 4b31e44d authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

fixing the problem with non-acute triangles for the FMM

parent d4a24c6d
package org.vadere.util.geometry.shapes;
import org.jetbrains.annotations.NotNull;
import org.omg.CORBA.portable.ValueOutputStream;
import org.vadere.util.geometry.GeometryUtils;
/**
......@@ -48,6 +47,7 @@ public class VCone {
/*
* TODO: test
*/
public boolean overlapLineSegment(final VLine line) {
VPoint a = new VPoint(line.getX1(), line.getY1());
VPoint b = new VPoint(line.getX2(), line.getY2());
......@@ -61,7 +61,7 @@ public class VCone {
VPoint v3 = new VPoint(-direction.getY(), direction.getX());
double t1 = v2.crossProduct(v1) / v2.scalarProduct(v3);
double t2 = v1.scalarProduct(v3) / v2.scalarProduct(v3);
assert Double.isFinite(t1) && Double.isFinite(t2);
// the line segment from a to b intersect the cone?
......
package org.vadere.util.potential.calculators;
public class EikonalSolverFMMAcuteTriangulation implements EikonalSolver {
@Override
public void initialize() {
......
......@@ -2,7 +2,10 @@ package org.vadere.util.triangulation;
import org.vadere.util.geometry.shapes.IPoint;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -29,7 +32,9 @@ public class UniformTriangulation<P extends IPoint> extends DelaunayTriangulatio
this.minTriangleSideLength = minTriangleSideLength;
this.pointConstructor = pointConstructor;
for(P point : generatePointSet()) {
List<P> pointList = new ArrayList<P>(generatePointSet());
Collections.shuffle(pointList);
for(P point : pointList) {
insert(point);
}
}
......
......@@ -19,6 +19,7 @@ public interface IEdgeLengthFunction extends Function<IPoint,Double> {
return new DensityEdgeLenFunction(densityFunc, regionBoundingBox);
}
static IEdgeLengthFunction create(final VRectangle regionBoundingBox,
final Collection<? extends VShape> obstacles,
final IDistanceFunction distanceFunc){
......
package org.vadere.util.geometry;
import org.apache.commons.lang3.tuple.Triple;
import org.junit.Before;
import org.junit.Test;
import org.vadere.util.geometry.data.DAG;
import org.vadere.util.geometry.data.HalfEdge;
import org.vadere.util.triangulation.DelaunayTriangulation;
import org.vadere.util.triangulation.DAGElement;
import org.vadere.util.geometry.data.Face;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VTriangle;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class TestBoyerWatson {
@Before
public void setUp() throws Exception {}
@Test
public void testFaceIterator() {
VPoint p1 = new VPoint(0,0);
VPoint p2 = new VPoint(50, 0);
VPoint p3 = new VPoint(50, 50);
VPoint p4 = new VPoint(0, 50);
VPoint p6 = new VPoint(50, 50);
VPoint p5 = new VPoint(25, 25);
Set<VPoint> points = new HashSet<>();
points.add(p1);
points.add(p2);
points.add(p3);
points.add(p4);
points.add(p6);
DelaunayTriangulation<VPoint> boyerWatsonImproved = new DelaunayTriangulation<>(points, (x, y) -> new VPoint(x, y));
boyerWatsonImproved.compute();
Collection<VTriangle> triangulation = boyerWatsonImproved.getTriangles();
triangulation.forEach(System.out::print);
}
/* TODO: reimplement it
@Test
public void testSplit() {
VPoint p1 = new VPoint(0,0);
VPoint p2 = new VPoint(50, 0);
VPoint p3 = new VPoint(25, 25);
VPoint centerPoint = new VPoint(25, 10);
Set<VPoint> points = new HashSet<>();
points.add(p1);
points.add(p2);
points.add(p3);
Face<VPoint> face = Face.of(p1,p2,p3);
DAG<DAGElement<VPoint>> dag = new DAG<>(new DAGElement<>(face, Triple.of(p1,p2,p3)));
DelaunayTriangulation<VPoint> boyerWatsonImproved = new DelaunayTriangulation<>(points, (x, y) -> new VPoint(x, y));
HalfEdge<VPoint> result = boyerWatsonImproved.split(centerPoint, dag);
Set<VTriangle> triangulation = new HashSet<>(result.collectLeafs().stream().map(dagElement -> dagElement.getTriangle()).collect(Collectors.toList()));
Set<VTriangle> expectedResult = new HashSet<>(Arrays.asList(new VTriangle(p1, p2, centerPoint), new VTriangle(p2, p3, centerPoint), new VTriangle(p1, p3, centerPoint)));
assertTrue(testTriangulationEquality(triangulation, expectedResult));
}*/
@Test
public void testPerformance() {
Set<VPoint> points = new HashSet<>();
int width = 300;
int height = 300;
Random r = new Random();
int numberOfPoints = 100000;
for(int i=0; i< numberOfPoints; i++) {
VPoint point = new VPoint(width*r.nextDouble(), height*r.nextDouble());
points.add(point);
}
long ms = System.currentTimeMillis();
DelaunayTriangulation<VPoint> bw = new DelaunayTriangulation<>(points, (x, y) -> new VPoint(x, y));
bw.compute();
System.out.println("runtime of the BowyerWatson for " + numberOfPoints + " vertices =" + (System.currentTimeMillis() - ms));
}
private static boolean testTriangulationEquality(final Set<VTriangle> triangulation1, final Set<VTriangle> triangulation2) {
if(triangulation1.size() != triangulation2.size())
return false;
for (VTriangle triangle1 : triangulation1) {
boolean found = false;
for (VTriangle triangle2 : triangulation2) {
if(TestBoyerWatson.testTriangleEquality(triangle1, triangle2)){
found = true;
}
}
if(!found)
return false;
}
return true;
}
private static boolean testTriangleEquality(final VTriangle triangle1, final VTriangle triangle2) {
return (triangle2.p1.equals(triangle1.p1) && triangle2.p2.equals(triangle1.p2) && triangle2.p3.equals(triangle1.p3)) ||
(triangle2.p1.equals(triangle1.p1) && triangle2.p2.equals(triangle1.p3) && triangle2.p3.equals(triangle1.p2)) ||
(triangle2.p1.equals(triangle1.p2) && triangle2.p2.equals(triangle1.p1) && triangle2.p3.equals(triangle1.p3)) ||
(triangle2.p1.equals(triangle1.p2) && triangle2.p2.equals(triangle1.p3) && triangle2.p3.equals(triangle1.p1)) ||
(triangle2.p1.equals(triangle1.p3) && triangle2.p2.equals(triangle1.p2) && triangle2.p3.equals(triangle1.p1)) ||
(triangle2.p1.equals(triangle1.p3) && triangle2.p2.equals(triangle1.p1) && triangle2.p3.equals(triangle1.p2));
}
}
......@@ -15,8 +15,6 @@ public class TestCone {
// 90 degree cone
VCone cone = new VCone(new VPoint(0,0), new VPoint(1, 1), Math.PI/2);
assertTrue(cone.contains(new VPoint(1, 1)));
assertTrue(cone.contains(new VPoint(5, 7)));
assertTrue(cone.contains(new VPoint(5, 7000)));
assertTrue(cone.contains(new VPoint(1, 0.00001)));
assertTrue(cone.contains(new VPoint(0.00001, 1)));
......
package org.vadere.util.triangulation;
import org.apache.commons.lang3.tuple.Triple;
import org.junit.Before;
import org.junit.Test;
import org.vadere.util.geometry.mesh.impl.PFace;
import org.vadere.util.geometry.mesh.inter.IMesh;
import org.vadere.util.geometry.mesh.impl.PHalfEdge;
import org.vadere.util.geometry.mesh.impl.PMesh;
import org.vadere.util.geometry.mesh.triangulations.IncrementalTriangulation;
import org.vadere.util.geometry.data.DAG;
import org.vadere.util.geometry.data.Face;
import org.vadere.util.geometry.data.HalfEdge;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VTriangle;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class TestBoyerWatson {
private IMesh<VPoint, PHalfEdge<VPoint>, PFace<VPoint>> mesh;
@Before
public void setUp() throws Exception {
mesh = new PMesh<>((x, y) -> new VPoint(x, y));
}
public void setUp() throws Exception {}
@Test
public void testFaceIterator() {
VPoint p1 = mesh.createVertex(0, 0);
VPoint p2 = mesh.createVertex(50, 0);
VPoint p3 = mesh.createVertex(50, 50);
VPoint p4 = mesh.createVertex(0, 50);
VPoint p1 = new VPoint(0,0);
VPoint p2 = new VPoint(50, 0);
VPoint p3 = new VPoint(50, 50);
VPoint p4 = new VPoint(0, 50);
VPoint p6 = mesh.createVertex(50, 50);
VPoint p5 = mesh.createVertex(25, 25);
VPoint p6 = new VPoint(50, 50);
VPoint p5 = new VPoint(25, 25);
Set<VPoint> points = new HashSet<>();
points.add(p1);
......@@ -44,70 +39,34 @@ public class TestBoyerWatson {
points.add(p3);
points.add(p4);
points.add(p6);
points.add(p5);
IncrementalTriangulation<VPoint, PHalfEdge<VPoint>, PFace<VPoint>> delaunayTriangulation = new IncrementalTriangulation<>(mesh, points, (x, y) -> new VPoint(x, y));
delaunayTriangulation.compute();
//delaunayTriangulation.finalize();
Set<VTriangle> triangulation = new HashSet<>(delaunayTriangulation.getTriangles());
Set<VPoint> triangle1 = new HashSet<>();
triangle1.add(p1);
triangle1.add(p5);
triangle1.add(p4);
Set<VPoint> triangle2 = new HashSet<>();
triangle2.add(p1);
triangle2.add(p2);
triangle2.add(p5);
Set<VPoint> triangle3 = new HashSet<>();
triangle3.add(p2);
triangle3.add(p3);
triangle3.add(p5);
Set<VPoint> triangle4 = new HashSet<>();
triangle4.add(p4);
triangle4.add(p5);
triangle4.add(p3);
Set<Set<VPoint>> pointSets = triangulation.stream().map(t -> new HashSet<>(t.getPoints())).collect(Collectors.toSet());
Set<Set<VPoint>> expextedPointSets = new HashSet<>();
expextedPointSets.add(triangle1);
expextedPointSets.add(triangle2);
expextedPointSets.add(triangle3);
expextedPointSets.add(triangle4);
assertTrue(expextedPointSets.equals(pointSets));
triangulation.forEach(System.out::println);
DelaunayTriangulation<VPoint> boyerWatsonImproved = new DelaunayTriangulation<>(points, (x, y) -> new VPoint(x, y));
boyerWatsonImproved.compute();
Collection<VTriangle> triangulation = boyerWatsonImproved.getTriangles();
triangulation.forEach(System.out::print);
}
@Test
public void testSplitTriangle() {
VPoint p1 = mesh.createVertex(0, 0);
VPoint p2 = mesh.createVertex(50, 0);
VPoint p3 = mesh.createVertex(25, 25);
VPoint centerPoint = mesh.createVertex(25, 10);
public void testSplit() {
VPoint p1 = new VPoint(0,0);
VPoint p2 = new VPoint(50, 0);
VPoint p3 = new VPoint(25, 25);
VPoint centerPoint = new VPoint(25, 10);
Set<VPoint> points = new HashSet<>();
points.add(p1);
points.add(p2);
points.add(p3);
IncrementalTriangulation<VPoint, PHalfEdge<VPoint>, PFace<VPoint>> delaunayTriangulation = new IncrementalTriangulation<>(mesh, points, (x, y) -> new VPoint(x, y));
delaunayTriangulation.compute();
PFace<VPoint> face = delaunayTriangulation.locate(centerPoint).get();
Face<VPoint> face = Face.of(p1,p2,p3);
DAG<DAGElement<VPoint>> dag = new DAG<>(new DAGElement<>(face, Triple.of(p1,p2,p3)));
delaunayTriangulation.splitTriangle(face, centerPoint);
delaunayTriangulation.finalize();
DelaunayTriangulation<VPoint> boyerWatsonImproved = new DelaunayTriangulation<>(points, (x, y) -> new VPoint(x, y));
HalfEdge<VPoint> result = boyerWatsonImproved.split(centerPoint, dag);
Set<VTriangle> triangles = new HashSet<>(delaunayTriangulation.getTriangles());
Set<VTriangle> triangulation = new HashSet<>(result.collectLeafs().stream().map(dagElement -> dagElement.getTriangle()).collect(Collectors.toList()));
Set<VTriangle> expectedResult = new HashSet<>(Arrays.asList(new VTriangle(p1, p2, centerPoint), new VTriangle(p2, p3, centerPoint), new VTriangle(p1, p3, centerPoint)));
assertTrue(testTriangulationEquality(triangles, expectedResult));
assertTrue(testTriangulationEquality(triangulation, expectedResult));
}
@Test
......@@ -117,17 +76,16 @@ public class TestBoyerWatson {
int height = 300;
Random r = new Random();
int numberOfPoints = 1000;
int numberOfPoints = 100000;
for(int i=0; i< numberOfPoints; i++) {
VPoint point = mesh.createVertex(width*r.nextDouble(), height*r.nextDouble());
VPoint point = new VPoint(width*r.nextDouble(), height*r.nextDouble());
points.add(point);
}
long ms = System.currentTimeMillis();
IncrementalTriangulation<VPoint, PHalfEdge<VPoint>, PFace<VPoint>> delaunayTriangulation = new IncrementalTriangulation<>(mesh, points, (x, y) -> new VPoint(x, y));
delaunayTriangulation.compute();
DelaunayTriangulation<VPoint> bw = new DelaunayTriangulation<>(points, (x, y) -> new VPoint(x, y));
bw.compute();
System.out.println("runtime of the BowyerWatson for " + numberOfPoints + " vertices =" + (System.currentTimeMillis() - ms));
}
......
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