Commit 6fac4803 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

improve the resolvement of the special case of walking inside trinagles.

parent 6c45179a
......@@ -51,7 +51,7 @@ public class ConstrainedTriangulation<P extends IPoint, V extends IVertex<P>, E
if(optFace.isPresent()) {
F startFace = optFace.get();
boolean startFaceIsInvalid = faceIntersectsLine(startFace, new VPoint(line.x1, line.y1), new VPoint(line.x2, line.y2));
LinkedList<F> invalidFaces = straightGatherWalk2D(line.x2, line.y2, startFace);
LinkedList<E> invalidFaces = straightGatherWalk2D(line.x2, line.y2, startFace);
if(!startFaceIsInvalid) {
invalidFaces.removeFirst();
......
......@@ -350,6 +350,17 @@ public interface IMesh<P extends IPoint, V extends IVertex<P>, E extends IHalfEd
*/
boolean isHole(@NotNull F face);
/**
* Returns true if the edge is a hole edge i.e. part of a hole in O(1) (there might be multiple holes
* and each hole is a boundary).
*
* @param edge the edge
* @return true if the edge is a hole edge, false otherwise
*/
default boolean isHole(@NotNull E edge) {
return isHole(getFace(edge));
}
/**
* Returns true if the vertex is a boundary vertex in O(d) worst case where d
* is the degree of the vertex. In general this should only cost O(1) if the data
......
......@@ -826,16 +826,47 @@ public interface IPolyConnectivity<P extends IPoint, V extends IVertex<P>, E ext
* Does not change the connectivity.
*
* @param p1 the first point of the undirected line
* @param p2 the first point of the undirected line
* @param p2 the second point of the undirected line
* @param edge the half-edge defining the line-segment
* @return true if the line-segment defined by the half-edge intersects the line (p1, p2)
*/
default boolean intersects(final IPoint p1, final IPoint p2, E edge) {
V v1 = getMesh().getVertex(getMesh().getPrev(edge));
V v2 = getMesh().getVertex(edge);
return intersects(p1, p2, v1, v2);
}
/**
* Tests if the line-segment defined by the (v1,v2) intersects the line defined by p1 and p2 in O(1).
*
* Does not change the connectivity.
*
* @param p1 the first point of the undirected line
* @param p2 the second point of the undirected line
* @param v1 the first point of the line-segment
* @param v2 the second point of the line-segment
* @return true if the line-segment defined by (v1,v2) intersects the line (p1, p2)
*/
default boolean intersects(final IPoint p1, final IPoint p2, V v1, V v2) {
return GeometryUtils.intersectLine(p1.getX(), p1.getY(), p2.getX(), p2.getY(), v1.getX(), v1.getY(), v2.getX(), v2.getY());
}
/**
* Tests if the half-line-segment starting at p1 in the direction (p2-p1) intersects the line-segment defined by the half-edge in O(1).
*
* Does not change the connectivity.
*
* @param p1 the start point of the directed half-line-segment
* @param p2 the second point of the directed half-line-segment of direction (p2-p1).
* @param edge the half-edge defining the line-segment
* @return true if the half-line-segment starting at p1 in the direction (p2-p1) intersects the line-segment defined by the half-edge, false otherwise
*/
default boolean intersectsDirectional(final IPoint p1, final IPoint p2, E edge) {
V v1 = getMesh().getVertex(getMesh().getPrev(edge));
V v2 = getMesh().getVertex(edge);
return GeometryUtils.intersectHalfLineSegment(p1.getX(), p1.getY(), p2.getX(), p2.getY(), v1.getX(), v1.getY(), v2.getX(), v2.getY());
}
/*default void fill_hole (final V v, final List<E> deletedEdges)
{
......
......@@ -56,7 +56,7 @@ public class TestVisual {
Set<VPoint> points = new HashSet<>();
Random r = new Random();
Random r = new Random(1);
for(int i=0; i< 20; i++) {
VPoint point = new VPoint(width*r.nextDouble(), height*r.nextDouble());
points.add(point);
......@@ -67,7 +67,7 @@ public class TestVisual {
VPTriangulation triangulation = IIncrementalTriangulation.createVPTriangulation(bound);
triangulation.insert(points);
triangulation.finish();
//triangulation.finish();
Set<VLine> edges = triangulation.getEdges();
JFrame window = new JFrame();
......
......@@ -12,11 +12,9 @@ import org.vadere.meshing.mesh.inter.IMesh;
import org.vadere.meshing.mesh.inter.IIncrementalTriangulation;
import org.vadere.meshing.mesh.inter.IVertex;
import org.vadere.util.geometry.shapes.IPoint;
import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.VCone;
import org.vadere.util.geometry.shapes.VLine;
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.math.InterpolationUtil;
......@@ -29,7 +27,6 @@ import org.vadere.meshing.mesh.iterators.FaceIterator;
import org.vadere.util.math.IDistanceFunction;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
......@@ -412,7 +409,7 @@ public class EikonalSolverFMMTriangulation<P extends IPotentialPoint, V extends
Predicate<E> isEdgeInCone = e -> isPointInCone.test(e) || isPointInCone.test(getMesh().getPrev(e));
LinkedList<F> visitedFaces = triangulation.straightWalk2DGather(halfEdge, face, direction2, isEdgeInCone);
LinkedList<F> visitedFaces = triangulation.straightWalk2DGatherDirectional(halfEdge, face, direction2, isEdgeInCone);
F destination = visitedFaces.getLast();
SimpleTriCanvas canvas = SimpleTriCanvas.simpleCanvas(getMesh());
......@@ -451,7 +448,7 @@ public class EikonalSolverFMMTriangulation<P extends IPotentialPoint, V extends
return mesh.isAtBoundary(e) || feasableEdgePred.test(e) || Utils.isRightOf(midPoint, midPoint.add(direction1), mesh.toPoint(e));
};
F newFace = triangulation.straightWalk2D(halfEdge, direction1, stopCondition);
F newFace = triangulation.straightWalk2DDirectional(halfEdge, direction1, stopCondition);
if(!mesh.isBoundary(newFace)) {
return mesh.streamVertices(newFace).filter(v -> feasableVertexPred.test(v)).map(v -> mesh.getPoint(v)).findAny();
......
......@@ -82,7 +82,6 @@ public class TestFFMNonUniformTriangulation {
return eikMesh;
}
@Ignore
@Test
public void testTriangulationFMM() {
......@@ -101,14 +100,8 @@ public class TestFFMNonUniformTriangulation {
triangulation = meshGenerator.getTriangulation();
Predicate<PFace<PotentialPoint>> nonAccute = f -> triangulation.getMesh().toTriangle(f).isNonAcute();
MeshPanel meshPanel = new MeshPanel(meshGenerator.getMesh(), nonAccute, 1000, 1000, bbox);
meshPanel.display();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//MeshPanel meshPanel = new MeshPanel(meshGenerator.getMesh(), nonAccute, 1000, 1000, bbox);
//meshPanel.display();
//targetPoints.add(new MeshPoint(0, 0, false));
......
......@@ -418,6 +418,12 @@ public class GeometryUtils {
return (ccw1 < 0 && ccw2 > 0) || (ccw1 > 0 && ccw2 < 0);
}
public static boolean intersectLine(final double pX, final double pY, final double qX, final double qY, final double p1X, final double p1Y, final double p2X, final double p2Y, final double eps) {
double ccw1 = ccw(pX, pY, qX, qY, p1X, p1Y);
double ccw2 = ccw(pX, pY, qX, qY, p2X, p2Y);
return (ccw1-eps < 0 && ccw2+eps > 0) || (ccw1+eps > 0 && ccw2-eps < 0);
}
public static VPoint getIncenter(@NotNull final IPoint p1, @NotNull final IPoint p2, @NotNull final IPoint p3) {
double a = p1.distance(p2);
double b = p2.distance(p3);
......@@ -441,14 +447,18 @@ public class GeometryUtils {
* @return true if the line-segment intersects the half-line-segment defined, otherwise false.
*/
public static boolean intersectHalfLineSegment(@NotNull final IPoint p, @NotNull final IPoint q, @NotNull final IPoint p1, @NotNull final IPoint p2) {
double ccw1 = ccw(p, q, p1);
double ccw2 = ccw(p, q, p2);
return intersectHalfLineSegment(p.getX(), p.getY(), q.getX(), q.getY(), p1.getX(), p1.getY(), p2.getX(), p2.getY());
}
public static boolean intersectHalfLineSegment(final double pX, final double pY, final double qX, final double qY, final double p1X, final double p1Y, final double p2X, final double p2Y) {
double ccw1 = ccw(pX, pY, qX, qY, p1X, p1X);
double ccw2 = ccw(pX, pY, qX, qY, p2X, p2Y);
if((ccw1 < 0 && ccw2 > 0)) {
return isCCW(p, p2, p1);
return isCCW(pX, pY, p2X, p2Y, p1X, p1Y);
}
else if((ccw1 > 0 && ccw2 < 0)) {
return isCCW(p, p1, p2);
return isCCW(pX, pY, p1X, p1Y, p2X, p2Y);
}
else {
return false;
......
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