Commit a0a195e2 authored by Numanoglu's avatar Numanoglu
Browse files

Merge remote-tracking branch 'origin/120-portierung-sweep-algorithmen' into...

Merge remote-tracking branch 'origin/120-portierung-sweep-algorithmen' into 120-portierung-sweep-algorithmen
parents c6f23035 11f09fca
package de.hft.stuttgart.citydoctor2.healing;
import de.hft.stuttgart.citydoctor2.datastructure.Edge;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.math.Plane;
import de.hft.stuttgart.citydoctor2.math.Vector3d;
public class SweepEdge {
private Edge edge;
private Vector3d refPt;
private Vector3d dir; //todo: falls es eine extra Klasse für einheitsvektoren gibt, diese Klasse benutzen
boolean bValid = false;
public SweepEdge(Edge e, Polygon p, double epsPointDist) {
edge = e;
//todo: falls geschickter --> Ring statt Polygon uebergeben
//todo: Wenn die Kante nicht zu kurz ist (epsPointDist)
// --> Anfangs- oder Endpunkt als Referenzpunkt, je nachdem welcher Punkt zum Polygon gehoert
// --> Richtungsvektor dir als Einheitsvektor berechnen
// --> valid = true;
}
public boolean valid() {
return bValid;
}
public boolean intersection(Plane plane, Vector3d ipt, double eps) {
//todo: Schnittpunkt berechnen
return false;
}
public boolean isOnEdge (Vector3d pt) {
//todo: pruefen ob pt zwischen Anfangs- und Endpunkt liegt
return false;
}
}
package de.hft.stuttgart.citydoctor2.healing;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Collections;
import java.util.HashSet;
import de.hft.stuttgart.citydoctor2.check.ModificationListener;
import de.hft.stuttgart.citydoctor2.check.error.NonPlanarPolygonDistancePlaneError;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.math.Plane;
import de.hft.stuttgart.citydoctor2.math.Vector3d;
/* todo: in HealPlanarPolygonSweep visit-Methode austauschen
public boolean visit(NonPlanarPolygonDistancePlaneError err, ModificationListener l) {
logger.debug("Executing Repair for NonPlanarPolygonDistancePlaneError");
SweepUtilities utils = new SweepUtilities(err);
todo: Epsilon-Werte setzen
utils.initialize();
if ( utils.calculate() ) {
utils.doHeal();
return true;
}
else {
logger.debug("Repair by Sweep not possible");
return false;
}
}
*/
public class SweepUtilities {
private Plane targetPlane;
private Polygon pol;
//todo: weitere Attribute hinzufuegen (fuer collectOutgoingEdges, ...)
// todo: Epsilons passend initialisieren
private double epsPointDist = 0.001; //Mindestlaenge einer Kante
private double epsPlaneDist = 0.001; //Maximalabstand zur Ebene
private double epsIntersection = 0.001; //Epsilon fuer Winkel zwischen Kante und Ebene
private List<SweepVertex> verts;
public SweepUtilities(NonPlanarPolygonDistancePlaneError err) {
targetPlane = err.getPlane();
pol = err.getPolygon();
}
public void initialize() {
int nVerts = countSweepVertices(pol);
verts = new ArrayList<>(nVerts);
collectSweepVertices(pol);
for (SweepVertex v : verts) {
v.collectOutgoingEdges(pol/* todo: weitere Uebergabeparameter hinzufuegen */, epsPointDist);
v.initStatus(targetPlane, epsPlaneDist);
}
}
public boolean calculate() {
// if there are no vertices --> no calculations
if ( null == verts )
return false;
//if there is already an error vertex --> no calculations
if ( !canHeal() )
return false;
boolean bError = false;
//todo spaeter: Anzahl der Ecken mit mehr als einer outging Edge zaehlen
// Wenn es alle diese Ecken auf der Zielebene liegen --> weiter
// Wenn es maximal drei solche Ecken gibt: Zielebene neu berechnen
// Wenn es mehr als drei solche Ecken gibt: diese Ecken bekommen den ERROR-Status,
// bError = true;
/*
// If there is a new target plane, new initialization of status is necessary:
for (SweepVertex v : verts) {
v.initStatus(targetPlane, epsPlaneDist);
}
*/
if ( !bError ) {
for (SweepVertex v : verts) {
v.calculateNewPoint(targetPlane, pol, epsPointDist);
}
}
return canHeal();
}
public void doHeal() {
for (SweepVertex v : verts) {
v.doHeal();
}
}
private boolean canHeal() {
for (SweepVertex v : verts) {
SweepVertexStatus status = v.getStatus();
if ( SweepVertexStatus.ERROR == status || SweepVertexStatus.NONE == status )
return false;
}
return true;
}
private int countSweepVertices(Polygon p) {
int nVerts = p.getExteriorRing().getVertices().size();
for (LinearRing lr : p.getInnerRings()) {
nVerts += lr.getVertices().size();
}
return nVerts;
}
private void collectSweepVertices(Polygon p) {
collectSweepVertices(p.getExteriorRing());
for (LinearRing lr : p.getInnerRings()) {
collectSweepVertices(lr);
}
}
private void collectSweepVertices(LinearRing ring) {
for (Vertex v : ring.getVertices()) {
verts.add(new SweepVertex(v));
}
}
}
package de.hft.stuttgart.citydoctor2.healing;
import java.util.LinkedList;
import java.util.List;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.datastructure.Edge;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.math.Plane;
import de.hft.stuttgart.citydoctor2.math.Vector3d;
enum SweepVertexStatus {
NONE,
ON_PLANE,
SWEEP,
PROJECT,
ERROR
}
public class SweepVertex {
private SweepVertexStatus status = SweepVertexStatus.NONE;
private Vertex vert;
private Vector3d newPoint;
private List<Edge> outgoingEdges = new LinkedList<>();
public SweepVertex(Vertex v) {
vert = v;
}
//todo: weitere Uebergabeparameter hinzufuegen
public void collectOutgoingEdges(Polygon pol/* todo: weitere Uebergabeparameter hinzufuegen */, double epsPointDist) {
//todo: Liste outgoingEdges fuellen
}
public void initStatus (Plane targetPlane, double distPlaneEps) {
if ( targetPlane.getDistance(vert) < distPlaneEps ) {
status = SweepVertexStatus.ON_PLANE;
}
else if ( outgoingEdges.size() < 1 ) {
status = SweepVertexStatus.PROJECT;
}
/*
* todo spaeter:
* else {
* status = SweepVertexStatus.SWEEP;
* }
*
* zunaechst Ecken mit mehr als einer outgoing Edge nicht beruecksichtigen:
*/
else if ( outgoingEdges.size() == 1 )
status = SweepVertexStatus.SWEEP;
else
status = SweepVertexStatus.ERROR;
}
public void calculateNewPoint (Plane targetPlane, Polygon p, double epsPointDist) {
if ( SweepVertexStatus.PROJECT == status ) {
newPoint = targetPlane.projectPointToPlane(vert);
}
else if ( SweepVertexStatus.SWEEP == status ) {
if ( 1 != getNoOutgoingEdges() ) {
status = SweepVertexStatus.ERROR;
}
else {
SweepEdge e = new SweepEdge(outgoingEdges.getFirst(), p, epsPointDist);
//todo: Schnittpunkt der outgoing Edge mit der targePlane berechnen
//todo: dafuer Hilfsklasse SweepEdge fuer Parameterdarstellung usw. nutzen
//todo: Parameter des Schnittpunkts auf der Edge berechnen
// --> wenn die Edge "umkippt" oder zum Punkt degeneriert (epsPointDist): status = SweepVertexStatus.ERROR
}
}
}
public void doHeal () {
if ( SweepVertexStatus.SWEEP == status || SweepVertexStatus.PROJECT == status ) {
vert.setX(newPoint.getX());
vert.setY(newPoint.getY());
vert.setZ(newPoint.getZ());
}
}
public SweepVertexStatus getStatus () {
return status;
}
public int getNoOutgoingEdges () {
return outgoingEdges.size();
}
}
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