Przeglądaj źródła

QuickHull3: Refactoring

Mugen87 8 lat temu
rodzic
commit
152077b57c
3 zmienionych plików z 5 dodań i 252 usunięć
  1. 1 4
      src/constants.js
  2. 1 120
      src/math/convexhull/Face.js
  3. 3 128
      src/math/convexhull/QuickHull3.js

+ 1 - 4
src/constants.js

@@ -124,7 +124,4 @@ export var RGBDEncoding = 3006;
 export var BasicDepthPacking = 3200;
 export var RGBADepthPacking = 3201;
 export var Visible = 0;
-export var NonConvex = 1;
-export var Deleted = 2;
-export var MergeNonConvexLargerFace = 0;
-export var MergeNonConvex
+export var Deleted = 1;

+ 1 - 120
src/math/convexhull/Face.js

@@ -1,7 +1,7 @@
 import { HalfEdge } from './HalfEdge';
 import { Vector3 } from '../Vector3';
 import { Triangle } from '../Triangle';
-import { Visible, NonConvex, Deleted } from '../../constants';
+import { Visible, Deleted } from '../../constants';
 
 /**
  * @author Mugen87 / https://github.com/Mugen87
@@ -101,125 +101,6 @@ Object.assign( Face.prototype, {
 
     return this.normal.dot( point ) - this.constant;
 
-  },
-
-  // Connects two edges assuming that prev.head().point === next.tail().point
-
-  connectHalfEdges: function ( prev, next ) {
-
-    var discardedFace;
-
-    if ( prev.twin.face === next.twin.face ) {
-
-      var oppositeFace = next.twin.face;
-      var twinEdge;
-
-      if ( prev === this.edge ) {
-
-        this.edge = next;
-
-      }
-
-      twinEdge = next.twin.prev.twin;
-      oppositeFace.mark = Deleted;
-      discardedFace = oppositeFace;
-
-      next.prev = prev.prev;
-      next.prev.next = next;
-
-      next.setTwin( twinEdge );
-
-      oppositeFace.compute();
-
-    } else {
-
-      prev.next = next;
-      next.prev = prev;
-
-    }
-
-    return discardedFace;
-
-  },
-
-  mergeAdjacentFaces: function( adjacentEdge, discardedFaces ) {
-
-    var twinEdge = adjacentEdge.twin;
-    var oppositeFace = twinEdge.face;
-
-    discardedFaces.push( oppositeFace );
-    oppositeFace.mark = Deleted;
-
-    // find the chain of edges whose opposite face is 'oppositeFace'
-
-    var adjacentEdgePrev = adjacentEdge.prev;
-    var adjacentEdgeNext = adjacentEdge.next;
-    var twinEdgePrev = twinEdge.prev;
-    var twinEdgeNext = twinEdge.next;
-
-    // left edge
-
-    while ( adjacentEdgePrev.twin.face === oppositeFace ) {
-
-      adjacentEdgePrev = adjacentEdgePrev.prev;
-      twinEdgeNext = twinEdgeNext.next;
-
-   }
-
-   // right edge
-
-   while ( adjacentEdgeNext.twin.face === oppositeFace ) {
-
-     adjacentEdgeNext = adjacentEdgeNext.next;
-     twinEdgePrev = twinEdgePrev.prev;
-
-   }
-
-   // fix the face reference of all the twin edges that are not part of
-   // the edges whose opposite face is not 'face' i.e. all the edges that
-   // 'face' and 'oppositeFace' do not have in common
-
-   var edge = twinEdgeNext;
-
-   do {
-
-     edge.face = this;
-
-     edge = edge.next;
-
-   } while ( edge !== twinEdgePrev.next );
-
-   // make sure that 'face.edge' is not one of the edges to be destroyed
-   // Note: it's important for it to be a 'next' edge since 'prev' edges
-   // might be destroyed on 'connectHalfEdges'
-
-   this.edge = adjacentEdgeNext;
-
-   // connect the extremes
-   // Note: it might be possible that after connecting the edges a triangular face might be redundant
-
-   var discardedFace;
-
-   discardedFace = this.connectHalfEdges( twinEdgePrev, adjacentEdgeNext );
-
-   if ( discardedFace !== undefined ) {
-
-     discardedFaces.push( discardedFace );
-
-   }
-
-   discardedFace = this.connectHalfEdges( adjacentEdgePrev, twinEdgeNext );
-
-   if ( discardedFace !== undefined ) {
-
-     discardedFaces.push( discardedFace );
-
-   }
-
-   this.compute();
-
-   return discardedFaces;
-
   }
 
 } );

+ 3 - 128
src/math/convexhull/QuickHull3.js

@@ -4,8 +4,7 @@ import { Face } from './Face';
 import { Vector3 } from '../Vector3';
 import { Line3 } from '../Line3';
 import { Plane } from '../Plane';
-import { Visible, NonConvex, Deleted } from '../../constants';
-import { MergeNonConvexLargerFace, MergeNonConvex } from '../../constants';
+import { Visible, Deleted } from '../../constants';
 
 /**
  * @author Mugen87 / https://github.com/Mugen87
@@ -703,10 +702,10 @@ Object.assign( QuickHull3.prototype, {
 
 				}
 
-				edge = edge.next;
-
 			}
 
+			edge = edge.next;
+
 		} while ( edge !== crossEdge );
 
 	},
@@ -771,98 +770,6 @@ Object.assign( QuickHull3.prototype, {
 
 	},
 
-	// Computes the distance from 'edge' opposite face's centroid to 'edge.face'
-
-	oppositeFaceDistance: function ( edge ) {
-
-		// The result is:
-		//
-		// - a positive number when the midpoint of the opposite face is above the face i.e. when the faces are concave
-		// - a negative number when the midpoint of the opposite face is below the face i.e. when the faces are convex
-
-		return edge.face.distanceToPoint( edge.twin.face.midpoint );
-
-	},
-
-	// Merges a face with none/any/all its neighbors according to the given strategy
-
-	doAdjacentMerge: function ( face, mergeType ) {
-
-		var edge = face.edge;
-		var convex = true;
-
-		do {
-
-			var oppositeFace = edge.twin.face;
-			var merge = false;
-
-			if ( mergeType === MergeNonConvex ) {
-
-				if ( this.oppositeFaceDistance( edge ) > - this.tolerance ||
-				this.oppositeFaceDistance( edge.twin ) > - this.tolerance ) {
-
-					merge = true;
-
-				}
-
-			} else {
-
-				if ( face.area > oppositeFace.area ) {
-
-					if ( this.oppositeFaceDistance( edge ) > - this.tolerance ) {
-
-						merge = true;
-
-					} else if ( this.oppositeFaceDistance( edge.twin ) > - this.tolerance ) {
-
-						convex = false;
-
-					}
-
-				} else {
-
-					if ( this.oppositeFaceDistance( edge.twin ) > - this.tolerance ) {
-
-            merge = true;
-
-          } else if ( this.oppositeFaceDistance( edge ) > - this.tolerance ) {
-
-            convex = false;
-
-          }
-
-				}
-
-				if ( merge === true ) {
-
-					var discardedFaces = face.mergeAdjacentFaces( edge, [] );
-
-					for ( var i = 0; i < discardedFaces.length; i ++ ) {
-
-						this.deleteFaceVertices( discardedFaces[ i ], face );
-
-					}
-
-					return true;
-
-				}
-
-			}
-
-			edge = edge.next;
-
-		} while ( edge !== face.edge );
-
-		if ( convex === false ) {
-
-			face.mark = NonConvex;
-
-		}
-
-		return false;
-
-	},
-
 	// Adds a vertex to the hull
 
 	addVertexToHull: function ( eyeVertex ) {
@@ -880,38 +787,6 @@ Object.assign( QuickHull3.prototype, {
 
 		this.addNewFaces( eyeVertex, horizon );
 
-		// first merge pass.
-    // do the merge with respect to the larger face
-
-    for ( i = 0; i < this.newFaces.length; i ++ ) {
-
-      face = this.newFaces[ i ];
-
-      if ( face.mark === Visible ) {
-
-        // while ( this.doAdjacentMerge( face, MergeNonConvexLargerFace ) ) {}
-
-      }
-
-    }
-
-		// second merge pass.
-    // do the merge on non convex faces (a face is marked as non convex in the first pass)
-
-		for ( i = 0; i < this.newFaces.length; i ++ ) {
-
-      face = this.newFaces[ i ];
-
-      if ( face.mark === NonConvex ) {
-
-				face.mark = Visible;
-
-        // while ( this.doAdjacentMerge( face, MergeNonConvex ) ) {}
-
-      }
-
-    }
-
 		// reassign 'unassigned' vertices to the new faces
 
 	 this.resolveUnassignedPoints( this.newFaces );