Commit 30792585 authored by Matthias Betz's avatar Matthias Betz
Browse files

correctly integrate edge intersection algorithm

parent 03bb154f
Pipeline #5706 passed with stage
in 3 minutes and 5 seconds
......@@ -20,7 +20,9 @@ package de.hft.stuttgart.citydoctor2.checks.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -44,8 +46,9 @@ import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.edge.EdgePolygon;
import de.hft.stuttgart.citydoctor2.edge.IntersectPlanarPolygons;
import de.hft.stuttgart.citydoctor2.edge.MeshSurface;
import de.hft.stuttgart.citydoctor2.edge.MeshSurfaceUtils;
import de.hft.stuttgart.citydoctor2.edge.PolygonPolygonIntersection;
import de.hft.stuttgart.citydoctor2.math.MovedPolygon;
import de.hft.stuttgart.citydoctor2.math.MovedRing;
......@@ -75,8 +78,6 @@ public class SelfIntersectionUtil {
private static final Logger logger = LogManager.getLogger(SelfIntersectionUtil.class);
private static boolean useEdge = true;
private static GeometryFactory factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING));
private SelfIntersectionUtil() {
......@@ -90,21 +91,18 @@ public class SelfIntersectionUtil {
public static List<PolygonIntersection> doesSolidSelfIntersect2(Geometry g) {
List<Polygon> polygons = g.getPolygons();
List<PolygonIntersection> intersections = new ArrayList<>();
if (useEdge) {
MeshSurface meshSurface = MeshSurface.of(g);
List<PolygonPolygonIntersection> selfIntersects = MeshSurfaceUtils.selfIntersects(meshSurface, 0.000001, 0.001);
if (!selfIntersects.isEmpty()) {
PolygonPolygonIntersection polygonPolygonIntersection = selfIntersects.get(0);
Polygon p1 = polygonPolygonIntersection.getPolygon1().getOriginal();
Polygon p2 = polygonPolygonIntersection.getPolygon2().getOriginal();
intersections.add(PolygonIntersection.lines(Collections.emptyList(), p1, p2));
}
MeshSurface meshSurface = MeshSurface.of(g);
Map<Polygon, EdgePolygon> edgePolyMap = new IdentityHashMap<>();
for (EdgePolygon poly : meshSurface.getPolygons()) {
edgePolyMap.put(poly.getOriginal(), poly);
}
for (int i = 0; i < polygons.size() - 1; i++) {
Polygon p1 = polygons.get(i);
for (int j = i + 1; j < polygons.size(); j++) {
Polygon p2 = polygons.get(j);
if (useEdge && p1.getInnerRings().isEmpty() && p2.getInnerRings().isEmpty()) {
if (p1.getInnerRings().isEmpty() && p2.getInnerRings().isEmpty()) {
// if no polygon has inner rings use edge intersection
performEdgeSelfIntersection(intersections, edgePolyMap, p1, p2);
} else {
PolygonIntersection intersect = polygonIntersection(p1, p2, 0.1, 0.01);
if (intersect.getType() != IntersectionType.NONE) {
......@@ -116,6 +114,17 @@ public class SelfIntersectionUtil {
return intersections;
}
private static void performEdgeSelfIntersection(List<PolygonIntersection> intersections, Map<Polygon, EdgePolygon> edgePolyMap,
Polygon p1, Polygon p2) {
EdgePolygon edgeP1 = edgePolyMap.get(p1);
EdgePolygon edgeP2 = edgePolyMap.get(p2);
List<PolygonPolygonIntersection> result = IntersectPlanarPolygons.intersectPolygons(edgeP1, edgeP2, 0.000001, 0.001);
if (!result.isEmpty()) {
// at least one intersection happened
intersections.add(PolygonIntersection.lines(Collections.emptyList(), p1, p2));
}
}
/**
* Checks if two polygons are intersecting. Result may be nothing, a line or a
* polygon if they are planar and intersecting.
......
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