Commit 218d1387 authored by Luna Riegel's avatar Luna Riegel
Browse files

Refactor: Cleanup and restructure code

parent 37c28627
package de.hft.stuttgart.citydoctor2.gui; package de.hft.stuttgart.citydoctor2.gui;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import de.hft.stuttgart.citydoctor2.datastructure.Edge; import de.hft.stuttgart.citydoctor2.datastructure.Edge;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing; import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
...@@ -9,6 +13,7 @@ import de.hft.stuttgart.citydoctor2.datastructure.Vertex; ...@@ -9,6 +13,7 @@ import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType; import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.math.Triangle3d; import de.hft.stuttgart.citydoctor2.math.Triangle3d;
import de.hft.stuttgart.citydoctor2.math.Vector3d; import de.hft.stuttgart.citydoctor2.math.Vector3d;
import de.hft.stuttgart.citydoctor2.utils.CollisionRecord;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.geometry.Point3D; import javafx.geometry.Point3D;
import javafx.scene.Group; import javafx.scene.Group;
...@@ -63,25 +68,41 @@ public class HighlightController { ...@@ -63,25 +68,41 @@ public class HighlightController {
public void highlight(Polygon p, TriangulatedGeometry currentTriGeom) { public void highlight(Polygon p, TriangulatedGeometry currentTriGeom) {
clearHighlights(); clearHighlights();
addHighlight(p, currentTriGeom, Color.RED, Color.BLUE); addPolygonHighlight(p, currentTriGeom, Color.RED, Color.BLUE, Color.ORANGE);
} }
private void addHighlight(Polygon p, TriangulatedGeometry currentTriGeom, Color extColor, Color intColor) { public void highlightPolygons(List<List<Polygon>> components, TriangulatedGeometry currentTriGeom) {
if (currentTriGeom == null || p == null) { clearHighlights();
return; for (int i = 0; i < components.size(); i++) {
} Color extColor;
addHighlight(p.getExteriorRing(), currentTriGeom, extColor); Color intColor = switch (i % 3) {
for (LinearRing intRing : p.getInnerRings()) { case 1 -> {
addHighlight(intRing, currentTriGeom, intColor); extColor = Color.GREEN;
yield Color.YELLOW;
}
case 2 -> {
extColor = Color.BROWN;
yield Color.VIOLET;
}
default -> {
extColor = Color.RED;
yield Color.BLUE;
}
};
// select some color pairs for exterior and inner rings
List<Polygon> component = components.get(i);
for (Polygon p : component) {
addPolygonHighlight(p, currentTriGeom, extColor, intColor, Color.ORANGE);
}
} }
} }
public void highlight(LinearRing ring, TriangulatedGeometry currentTriGeom) { public void highlight(LinearRing ring, TriangulatedGeometry currentTriGeom) {
clearHighlights(); clearHighlights();
if (ring.getType() == LinearRingType.EXTERIOR) { if (ring.getType() == LinearRingType.EXTERIOR) {
addHighlight(ring, currentTriGeom, Color.RED); addRingHighlight(ring, currentTriGeom, Color.RED, Color.ORANGE);
} else { } else {
addHighlight(ring, currentTriGeom, Color.BLUE); addRingHighlight(ring, currentTriGeom, Color.BLUE, Color.ORANGE);
} }
} }
...@@ -89,57 +110,83 @@ public class HighlightController { ...@@ -89,57 +110,83 @@ public class HighlightController {
clearHighlights(); clearHighlights();
for (LinearRing lr : rings) { for (LinearRing lr : rings) {
if (lr.getType() == LinearRingType.EXTERIOR) { if (lr.getType() == LinearRingType.EXTERIOR) {
addHighlight(lr, currentTriGeom, Color.RED); addRingHighlight(lr, currentTriGeom, Color.RED, Color.ORANGE);
} else { } else {
addHighlight(lr, currentTriGeom, Color.BLUE); addRingHighlight(lr, currentTriGeom, Color.BLUE, Color.ORANGE);
} }
} }
} }
private void addHighlight(LinearRing ring, TriangulatedGeometry currentTriGeom, Color pointColor) { public void highlight(Edge e, TriangulatedGeometry currentTriGeom) {
clearHighlights();
addEdgeHighlight(e, currentTriGeom);
}
public void highlightEdges(List<Edge> errorEdges, TriangulatedGeometry currentTriGeom) {
clearHighlights();
for (Edge e : errorEdges) {
addEdgeHighlight(e, currentTriGeom);
}
}
public void highlight(Vertex v, TriangulatedGeometry currentTriGeom) {
clearHighlights();
addVertexHighlight(v, currentTriGeom, Color.RED);
}
public void highlight(Triangle3d t, TriangulatedGeometry currentTriGeom) {
clearHighlights();
addSegmentHighlight(t.getP1(), t.getP2(), currentTriGeom.getMovedBy(), Color.ORANGE);
addSegmentHighlight(t.getP2(), t.getP3(), currentTriGeom.getMovedBy(), Color.ORANGE);
addSegmentHighlight(t.getP3(), t.getP1(), currentTriGeom.getMovedBy(), Color.ORANGE);
}
private void addRingHighlight(LinearRing ring, TriangulatedGeometry currentTriGeom, Color pointColor, Color edgeColor) {
if (currentTriGeom == null || ring == null) { if (currentTriGeom == null || ring == null) {
return; return;
} }
Vector3d movedBy = currentTriGeom.getMovedBy(); Vector3d movedBy = currentTriGeom.getMovedBy();
for (Vertex v : ring.getVertices()) { for (Vertex v : ring.getVertices()) {
highlightPoint(movedBy, v, pointColor); addPointHighlight(movedBy, v, pointColor);
} }
for (int i = 0; i < ring.getVertices().size() - 1; i++) { for (int i = 0; i < ring.getVertices().size() - 1; i++) {
Vertex v1 = ring.getVertices().get(i); Vertex v1 = ring.getVertices().get(i);
Vertex v2 = ring.getVertices().get(i + 1); Vertex v2 = ring.getVertices().get(i + 1);
highlightEdge(v1, v2, movedBy); addSegmentHighlight(v1, v2, movedBy, edgeColor);
} }
} }
public void highlight(Edge e, TriangulatedGeometry currentTriGeom) { private void addPolygonHighlight(Polygon p, TriangulatedGeometry currentTriGeom, Color extColor, Color intColor, Color edgeColor) {
clearHighlights(); if (currentTriGeom == null || p == null) {
addHighlight(e, currentTriGeom); return;
}
addRingHighlight(p.getExteriorRing(), currentTriGeom, extColor, edgeColor);
for (LinearRing intRing : p.getInnerRings()) {
addRingHighlight(intRing, currentTriGeom, intColor, edgeColor);
}
} }
private void addHighlight(Edge e, TriangulatedGeometry currentTriGeom) {
private void addEdgeHighlight(Edge e, TriangulatedGeometry currentTriGeom) {
if (currentTriGeom == null || e == null) { if (currentTriGeom == null || e == null) {
return; return;
} }
Vector3d movedBy = currentTriGeom.getMovedBy(); Vector3d movedBy = currentTriGeom.getMovedBy();
highlightEdge(e.getFrom(), e.getTo(), movedBy); addSegmentHighlight(e.getFrom(), e.getTo(), movedBy, Color.ORANGE);
highlightPoint(movedBy, e.getFrom(), Color.RED); addPointHighlight(movedBy, e.getFrom(), Color.RED);
highlightPoint(movedBy, e.getTo(), Color.RED); addPointHighlight(movedBy, e.getTo(), Color.RED);
}
public void highlight(Vertex v, TriangulatedGeometry currentTriGeom) {
clearHighlights();
addHighlight(v, currentTriGeom, Color.RED);
} }
public void addHighlight(Vertex v, TriangulatedGeometry currentTriGeom, Color c) {
public void addVertexHighlight(Vertex v, TriangulatedGeometry currentTriGeom, Color c) {
if (currentTriGeom == null || v == null) { if (currentTriGeom == null || v == null) {
return; return;
} }
Vector3d movedBy = currentTriGeom.getMovedBy(); Vector3d movedBy = currentTriGeom.getMovedBy();
highlightPoint(movedBy, v, c); addPointHighlight(movedBy, v, c);
} }
private void highlightPoint(Vector3d movedBy, Vertex v, Color color) { private void addPointHighlight(Vector3d movedBy, Vertex v, Color color) {
Sphere sp = new Sphere(0.5); Sphere sp = new Sphere(0.5);
sp.setMaterial(new PhongMaterial(color)); sp.setMaterial(new PhongMaterial(color));
sp.setTranslateX(v.getX() - movedBy.getX()); sp.setTranslateX(v.getX() - movedBy.getX());
...@@ -153,8 +200,8 @@ public class HighlightController { ...@@ -153,8 +200,8 @@ public class HighlightController {
points.getChildren().add(sp); points.getChildren().add(sp);
} }
private void highlightEdge(Vector3d v1, Vector3d v2, Vector3d movedBy) { private void addSegmentHighlight(Vector3d v1, Vector3d v2, Vector3d movedBy, Color color) {
Point3D origin = new Point3D(v1.getX() - movedBy.getX(), v1.getY() - movedBy.getY(), Point3D origin = new Point3D(v1.getX() - movedBy.getX(), v1.getY() - movedBy.getY(),
v1.getZ() - movedBy.getZ()); v1.getZ() - movedBy.getZ());
Point3D target = new Point3D(v2.getX() - movedBy.getX(), v2.getY() - movedBy.getY(), Point3D target = new Point3D(v2.getX() - movedBy.getX(), v2.getY() - movedBy.getY(),
...@@ -172,46 +219,13 @@ public class HighlightController { ...@@ -172,46 +219,13 @@ public class HighlightController {
Rotate rotateAroundCenter = new Rotate(-Math.toDegrees(angle), axisOfRotation); Rotate rotateAroundCenter = new Rotate(-Math.toDegrees(angle), axisOfRotation);
Cylinder cy = new Cylinder(scale / 10, height); Cylinder cy = new Cylinder(scale / 10, height);
cy.setMaterial(new PhongMaterial(Color.ORANGE)); cy.setMaterial(new PhongMaterial(color));
cy.getTransforms().addAll(moveToMidpoint, rotateAroundCenter); cy.getTransforms().addAll(moveToMidpoint, rotateAroundCenter);
edges.getChildren().add(cy); edges.getChildren().add(cy);
} }
public void highlightEdges(List<Edge> errorEdges, TriangulatedGeometry currentTriGeom) { public void addPolygonHighlight(Polygon p, TriangulatedGeometry currentTriGeom) {
clearHighlights(); addPolygonHighlight(p, currentTriGeom, Color.RED, Color.BLUE, Color.ORANGE);
for (Edge e : errorEdges) {
addHighlight(e, currentTriGeom);
}
}
public void highlightPolygons(List<List<Polygon>> components, TriangulatedGeometry currentTriGeom) {
clearHighlights();
for (int i = 0; i < components.size(); i++) {
Color extColor;
Color intColor = switch (i % 3) {
case 1 -> {
extColor = Color.GREEN;
yield Color.YELLOW;
}
case 2 -> {
extColor = Color.BROWN;
yield Color.VIOLET;
}
default -> {
extColor = Color.RED;
yield Color.BLUE;
}
};
// select some color pairs for exterior and inner rings
List<Polygon> component = components.get(i);
for (Polygon p : component) {
addHighlight(p, currentTriGeom, extColor, intColor);
}
}
}
public void addHighlight(Polygon p, TriangulatedGeometry currentTriGeom) {
addHighlight(p, currentTriGeom, Color.RED, Color.BLUE);
} }
public void highlight(Triangle3d t, TriangulatedGeometry currentTriGeom) { public void highlight(Triangle3d t, TriangulatedGeometry currentTriGeom) {
......
...@@ -52,7 +52,6 @@ import de.hft.stuttgart.citydoctor2.datastructure.LinearRing; ...@@ -52,7 +52,6 @@ import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex; import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.utils.PolygonIntersection; import de.hft.stuttgart.citydoctor2.utils.PolygonIntersection;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import org.apache.commons.lang3.NotImplementedException;
public class ListErrorVisitor implements ErrorVisitor { public class ListErrorVisitor implements ErrorVisitor {
...@@ -96,7 +95,7 @@ public class ListErrorVisitor implements ErrorVisitor { ...@@ -96,7 +95,7 @@ public class ListErrorVisitor implements ErrorVisitor {
@Override @Override
public void visit(NonManifoldVertexError err) { public void visit(NonManifoldVertexError err) {
controller.highlightPolygons(err.getComponents(), geom); controller.highlightPolygons(err.getComponents(), geom);
controller.addHighlight(err.getVertex(), geom, Color.BLUEVIOLET); controller.addVertexHighlight(err.getVertex(), geom, Color.BLUEVIOLET);
} }
@Override @Override
...@@ -135,8 +134,8 @@ public class ListErrorVisitor implements ErrorVisitor { ...@@ -135,8 +134,8 @@ public class ListErrorVisitor implements ErrorVisitor {
@Override @Override
public void visit(ConsecutivePointSameError err) { public void visit(ConsecutivePointSameError err) {
controller.highlight(err.getRing(), geom); controller.highlight(err.getRing(), geom);
controller.addHighlight(err.getVertex1(), geom, Color.BLACK); controller.addVertexHighlight(err.getVertex1(), geom, Color.BLACK);
controller.addHighlight(err.getVertex2(), geom, Color.BLACK); controller.addVertexHighlight(err.getVertex2(), geom, Color.BLACK);
} }
@Override @Override
...@@ -167,7 +166,7 @@ public class ListErrorVisitor implements ErrorVisitor { ...@@ -167,7 +166,7 @@ public class ListErrorVisitor implements ErrorVisitor {
@Override @Override
public void visit(NonPlanarPolygonDistancePlaneError err) { public void visit(NonPlanarPolygonDistancePlaneError err) {
controller.highlight(err.getPolygon(), geom); controller.highlight(err.getPolygon(), geom);
controller.addHighlight(err.getVertex(), geom, Color.BLACK); controller.addVertexHighlight(err.getVertex(), geom, Color.BLACK);
} }
@Override @Override
...@@ -182,8 +181,8 @@ public class ListErrorVisitor implements ErrorVisitor { ...@@ -182,8 +181,8 @@ public class ListErrorVisitor implements ErrorVisitor {
public void visit(SolidSelfIntError err) { public void visit(SolidSelfIntError err) {
controller.clearHighlights(); controller.clearHighlights();
for (PolygonIntersection intersection : err.getIntersections()) { for (PolygonIntersection intersection : err.getIntersections()) {
controller.addHighlight(intersection.getP1(), geom); controller.addPolygonHighlight(intersection.getP1(), geom);
controller.addHighlight(intersection.getP2(), geom); controller.addPolygonHighlight(intersection.getP2(), geom);
} }
} }
...@@ -195,8 +194,8 @@ public class ListErrorVisitor implements ErrorVisitor { ...@@ -195,8 +194,8 @@ public class ListErrorVisitor implements ErrorVisitor {
@Override @Override
public void visit(RingDuplicatePointError err) { public void visit(RingDuplicatePointError err) {
controller.highlight(err.getRing(), geom); controller.highlight(err.getRing(), geom);
controller.addHighlight(err.getVertex1(), geom, Color.BLACK); controller.addVertexHighlight(err.getVertex1(), geom, Color.BLACK);
controller.addHighlight(err.getVertex2(), geom, Color.BLACK); controller.addVertexHighlight(err.getVertex2(), geom, Color.BLACK);
} }
@Override @Override
...@@ -205,13 +204,13 @@ public class ListErrorVisitor implements ErrorVisitor { ...@@ -205,13 +204,13 @@ public class ListErrorVisitor implements ErrorVisitor {
list.add(err.getEdge1()); list.add(err.getEdge1());
list.add(err.getEdge2()); list.add(err.getEdge2());
controller.highlightEdges(list, geom); controller.highlightEdges(list, geom);
controller.addHighlight(new Vertex(err.getIntersection()), geom, Color.BLACK); controller.addVertexHighlight(new Vertex(err.getIntersection()), geom, Color.BLACK);
} }
@Override @Override
public void visit(PointTouchesEdgeError err) { public void visit(PointTouchesEdgeError err) {
controller.highlight(err.getEdge(), geom); controller.highlight(err.getEdge(), geom);
controller.addHighlight(err.getVertex(), geom, Color.BLACK); controller.addVertexHighlight(err.getVertex(), geom, Color.BLACK);
} }
@Override @Override
...@@ -306,7 +305,7 @@ public class ListErrorVisitor implements ErrorVisitor { ...@@ -306,7 +305,7 @@ public class ListErrorVisitor implements ErrorVisitor {
@Override @Override
public void visit(FeatureCollisionError err){ public void visit(FeatureCollisionError err){
throw new NotImplementedException(); controller.highlightGeometryCollisions(err.getCollisionRecord(), geom);
//TODO: Implement handling of error here //TODO: Implement handling of error here
} }
} }
...@@ -536,7 +536,7 @@ public class Renderer { ...@@ -536,7 +536,7 @@ public class Renderer {
} }
public void addHighlight(Vertex vertex, Color c) { public void addHighlight(Vertex vertex, Color c) {
highlightController.addHighlight(vertex, currentTriGeom, c); highlightController.addVertexHighlight(vertex, currentTriGeom, c);
} }
public void highlight(CheckError err) { public void highlight(CheckError err) {
...@@ -560,7 +560,7 @@ public class Renderer { ...@@ -560,7 +560,7 @@ public class Renderer {
} }
public void addHighlight(Polygon p) { public void addHighlight(Polygon p) {
highlightController.addHighlight(p, currentTriGeom); highlightController.addPolygonHighlight(p, currentTriGeom);
} }
public void addHighlight(Triangle3d t) { public void addHighlight(Triangle3d t) {
......
Supports Markdown
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