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

rebase develop

parent 4de6f544
package org.vadere.util.delaunay;
import org.jetbrains.annotations.NotNull;
import org.vadere.util.geometry.shapes.VLine;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.Optional;
/**
* Created by bzoennchen on 13.11.16.
*/
public class HalfEdge {
/**
* point at the end of the half edge.
*/
private VPoint end;
/**
* next half-edge around the face.
*/
private HalfEdge next;
/**
* previous half-edge around the face.
*/
private HalfEdge previous;
/**
* oppositely oriented adjacnet half-edge. If the face is a the boundary
* there is no twin.
*/
private HalfEdge twin;
/**
* the face the half-edge borders.
*/
private Face face;
public HalfEdge (@NotNull final VPoint end, @NotNull final Face face) {
this.end = end;
this.face = face;
}
public Face getFace() {
return face;
}
public VPoint getEnd() {
return end;
}
public boolean hasNext() {
return next != null;
}
public HalfEdge getNext() {
return next;
}
public HalfEdge getPrevious() {
return previous;
}
public Optional<HalfEdge> getTwin() {
return Optional.ofNullable(twin);
}
public void setTwin(final @NotNull HalfEdge twin) {
this.twin = twin;
if(!twin.getTwin().isPresent() || twin.getTwin().get() != this) {
twin.setTwin(this);
}
}
public void setPrevious(final @NotNull HalfEdge previous) {
this.previous = previous;
if(previous.getNext() != this) {
previous.setNext(this);
}
}
public void setNext(final @NotNull HalfEdge next) {
this.next = next;
if(next.getPrevious() != this) {
next.setPrevious(this);
}
}
public VLine toLine() {
return new VLine(this.getPrevious().getEnd(), this.getEnd());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
HalfEdge halfEdge = (HalfEdge) o;
if (!end.equals(halfEdge.end)) return false;
if (next != null ? !next.equals(halfEdge.next) : halfEdge.next != null) return false;
if (previous != null ? !previous.equals(halfEdge.previous) : halfEdge.previous != null)
return false;
if (twin != null ? !twin.equals(halfEdge.twin) : halfEdge.twin != null) return false;
return face.equals(halfEdge.face);
}
@Override
public int hashCode() {
int result = end.hashCode();
result = 31 * result + (next != null ? next.hashCode() : 0);
result = 31 * result + (previous != null ? previous.hashCode() : 0);
result = 31 * result + (twin != null ? twin.hashCode() : 0);
result = 31 * result + face.hashCode();
return result;
}
}
......@@ -70,8 +70,8 @@ public class PSDistmesh {
}
private void init(final VRectangle regionBoundingBox,
final Collection<? extends VShape> obstacles,
final double initialEdgeLen) {
final Collection<? extends VShape> obstacles,
final double initialEdgeLen) {
this.regionBoundingBox = regionBoundingBox;
this.initialEdgeLen = initialEdgeLen;
this.geps = .001 * initialEdgeLen;
......@@ -104,26 +104,44 @@ public class PSDistmesh {
* Remove all triangles intersecting any obstacle shape.
*/
public void cleanUp() {
/*triangulation = triangulation.stream()
.filter(triple -> obstacles.stream().noneMatch(
obstacle ->
tripleToTriangle(triple).intersect(obstacle))).collect(Collectors.toSet());*/
//reTriangulate();
/*obstacles.stream()
.filter(shape -> shape instanceof VRectangle)
.map(shape -> (VRectangle)shape).forEach(rect -> {
triangulation.removeIf(triple -> tripleToTriangle(triple).intersects(new VLine(rect.getMinX(), rect.getMinY(), rect.getMaxX(), rect.getMaxY()))
|| tripleToTriangle(triple).intersects(new VLine(rect.getMaxX(), rect.getMinY(), rect.getMinX(), rect.getMaxY())));
}
);*/
/*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;
System.out.println("triangulation started");
bowyerWatson = new IncrementalTriangulation<>(new PMesh<>((x,y) -> new MeshPoint(x,y, false)), points, (x, y) -> new MeshPoint(x, y, false));
bowyerWatson.finalize();
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());
}
}
/*
/*
Stellt den Verlauf der Iterationen dar. Innerhalb der while(true) passiert eine Iteration des Algorithmus
*/
public void step()
......@@ -176,7 +194,7 @@ public class PSDistmesh {
}
//if(distanceFunc.apply(point.toVPoint().add(movement)) <= 0) {
point.add(movement);
point.add(movement);
//}
point.setVelocity(new VPoint(0, 0));
......
......@@ -67,7 +67,7 @@ public class TestFFMNonUniformTriangulation {
public void testFMM() {
List<VRectangle> targetAreas = new ArrayList<>();
List<IPoint> targetPoints = new ArrayList<>();
targetPoints.add(new VPoint(40, 40));
targetPoints.add(new MeshPoint(40, 40, false));
VRectangle rect = new VRectangle(width / 2, height / 2, 100, 100);
targetAreas.add(rect);
......
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