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

fixed numerically problems using the new basic point locator

parent 70a64a34
......@@ -346,10 +346,18 @@ public interface IMesh<P extends IPoint, E extends IHalfEdge<P>, F extends IFace
return getMemberEdge(face, x, y).isPresent();
}
default boolean isMember(F face, double x, double y, double epsilon) {
return getMemberEdge(face, x, y, epsilon).isPresent();
}
default Optional<E> getMemberEdge(F face, double x, double y) {
return streamEdges(face).filter(e -> getVertex(e).getX() == x && getVertex(e).getY() == y).findAny();
}
default Optional<E> getMemberEdge(F face, double x, double y, double epsilon) {
return streamEdges(face).filter(e -> getVertex(e).distance(x, y) <= epsilon).findAny();
}
Collection<P> getVertices();
int getNumberOfVertices();
......
......@@ -56,6 +56,7 @@ public class IncrementalTriangulation<P extends IPoint, E extends IHalfEdge<P>,
private boolean finalized;
private IMesh<P, E, F> mesh;
private IPointLocator<P, E, F> pointLocator;
private double epsilon = 0.0001;
protected F superTriangle;
private F borderFace;
......@@ -139,49 +140,38 @@ public class IncrementalTriangulation<P extends IPoint, E extends IHalfEdge<P>,
@Override
public E insert(P point) {
if(point.getX() == 15.0 && point.getY() == 112.58330249197701) {
System.out.println("steop here!");
}
Collection<F> faces = this.pointLocator.locatePoint(point, true);
faces = faces.stream().filter(f -> !getMesh().isMember(f, point.getX(), point.getY())).collect(Collectors.toList());
int numberOfFaces = faces.size();
if(faces.size() == 0) {
log.warn(point);
}
// assert leafs.size() == 2 || leafs.size() == 1 || leafs.size() > 0;
// problem due numerical calculation.
faces = faces.stream().filter(f -> !getMesh().isMember(f, point.getX(), point.getY(), epsilon)).collect(Collectors.toList());
E insertedEdge = null;
// point is inside a triangle
if(faces.size() == 1) {
if(numberOfFaces == 0) {
log.warn("no face found at " + point);
}
else if(faces.size() == 1) {
log.info("splitTriangle:" + point);
F face = faces.iterator().next();
splitTriangle(face, point, true);
return mesh.getEdge(point);
insertedEdge = mesh.getEdge(point);
} // point lies on an edge of 2 triangles
else if(faces.size() == 2) {
Iterator<F> it = faces.iterator();
log.info("splitEdge:" + point);
E halfEdge = findTwins(it.next(), it.next()).get();
E halfEdge = findTwins(it.next(), it.next()).get();
splitEdge(point, halfEdge, true);
return mesh.getEdge(point);
insertedEdge = mesh.getEdge(point);
}
else if(faces.size() == 0) {
// problem due numerical calculation.
log.warn("no triangle was found! Maybe " + point + " lies outside of the triangulation." );
return null;
log.warn("ignore insertion point, since the point " + point + " already exists or it is too close to another point!");
}
else {
log.warn(point + ":ignore insertion point, since this point already exists!");
F face = faces.iterator().next();
Optional<E> optHe = mesh.streamEdges(face).filter(he -> mesh.getVertex(he).equals(point)).findAny();
if(optHe.isPresent()) {
return optHe.get();
}
else {
return null;
}
log.error("more than 2 faces found and the point " + point + " is not a vertex jet, there is something wrong with the mesh structure!");
}
return insertedEdge;
}
/**
......
......@@ -59,20 +59,11 @@ public class VPoint implements Cloneable, IPoint {
return distance(other.getX(), other.getY());
}
public void setId(int identifier) {
this.identifier = identifier;
}
public int getId() {
return identifier;
}
@Override
public VPoint clone() {
return new VPoint(x, y);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
......
......@@ -166,6 +166,7 @@ public class VTriangle extends VPolygon {
}
public boolean isInCircumscribedCycle(final IPoint point) {
double diff = getCircumcenter().distance(point) - getCircumscribedRadius();
return getCircumcenter().distance(point) < getCircumscribedRadius();
}
......
......@@ -7,7 +7,7 @@ import org.vadere.util.geometry.ConstantLineIterator;
import org.vadere.util.geometry.mesh.inter.IFace;
import org.vadere.util.geometry.mesh.inter.IHalfEdge;
import org.vadere.util.geometry.mesh.inter.IMesh;
import org.vadere.util.triangulation.ITriangulation;
import org.vadere.util.geometry.mesh.inter.ITriangulation;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VCone;
......
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