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