Bläddra i källkod

better asserts and docs

Former-commit-id: c086567f60314af4d6b63ac846c12dfd43a772cb
Alec Jacobson 10 år sedan
förälder
incheckning
c5a0ef19a3

+ 1 - 1
include/igl/AABB.h

@@ -726,7 +726,7 @@ inline void igl::AABB<DerivedV,DIM>::leaf_squared_distance(
       // point-segment distance
       // number of edges
       size_t ne = ss==3?3:1;
-      for(int x = 0;x<ne;x++)
+      for(size_t x = 0;x<ne;x++)
       {
         const size_t e1 = Ele(m_primitive,(x+1)%ss);
         const size_t e2 = Ele(m_primitive,(x+2)%ss);

+ 8 - 4
include/igl/point_mesh_squared_distance.h

@@ -17,14 +17,18 @@ namespace igl
   // Inputs:
   //   P  #P by 3 list of query point positions
   //   V  #V by 3 list of vertex positions
-  //   F  #F by 3 list of triangle indices
+  //   F  #F by (3|2|1) list of (triangle|edge|point) indices
   // Outputs:
   //   sqrD  #P list of smallest squared distances
-  //   I  #P list of facet indices corresponding to smallest distances
+  //   I  #P list of primitive indices corresponding to smallest distances
   //   C  #P by 3 list of closest points
   //
-  // Known bugs: This only computes distances to triangles. So unreferenced
-  // vertices and degenerate triangles (segments) are ignored.
+  // Known bugs: This only computes distances to given primitivess. So
+  // unreferenced vertices are ignored. However, degenerate primitives are
+  // handled correctly: triangle [1 2 2] is treated as a segment [1 2], and
+  // triangle [1 1 1] is treated as a point. So one _could_ add extra
+  // combinatorially degenerate rows to Ele for all unreferenced vertices to
+  // also get distances to points.
   template <
     typename DerivedP,
     typename DerivedV,

+ 12 - 1
include/igl/signed_distance.cpp

@@ -27,7 +27,11 @@ IGL_INLINE void igl::signed_distance(
   using namespace std;
   assert(V.cols() == 3 && "V should have 3d positions");
   assert(P.cols() == 3 && "P should have 3d positions");
-  assert(F.cols() == 3 && "F should have triangles");
+  // Only unsigned distance is supported for non-triangles
+  if(sign_type != SIGNED_DISTANCE_TYPE_UNSIGNED)
+  {
+    assert(F.cols() == 3 && "F should have triangles");
+  }
 
   // Prepare distance computation
   AABB<MatrixXd,3> tree;
@@ -41,6 +45,9 @@ IGL_INLINE void igl::signed_distance(
   {
     default:
       assert(false && "Unknown SignedDistanceType");
+    case SIGNED_DISTANCE_TYPE_UNSIGNED:
+      // do nothing
+      break;
     case SIGNED_DISTANCE_TYPE_DEFAULT:
     case SIGNED_DISTANCE_TYPE_WINDING_NUMBER:
       hier.set_mesh(V,F);
@@ -70,6 +77,10 @@ IGL_INLINE void igl::signed_distance(
     {
       default:
         assert(false && "Unknown SignedDistanceType");
+      case SIGNED_DISTANCE_TYPE_UNSIGNED:
+        s = 1.;
+        sqrd = tree.squared_distance(V,F,q,i,c);
+        break;
       case SIGNED_DISTANCE_TYPE_DEFAULT:
       case SIGNED_DISTANCE_TYPE_WINDING_NUMBER:
         signed_distance_winding_number(tree,V,F,hier,q,s,sqrd,i,c);

+ 5 - 3
include/igl/signed_distance.h

@@ -16,10 +16,11 @@ namespace igl
 {
   enum SignedDistanceType
   {
+    // Use fast pseudo-normal test [Bærentzen & Aanæs 2005]
     SIGNED_DISTANCE_TYPE_PSEUDONORMAL   = 0,
     SIGNED_DISTANCE_TYPE_WINDING_NUMBER = 1,
     SIGNED_DISTANCE_TYPE_DEFAULT        = 2,
-    SIGNED_DISTANCE_TYPE_IGNORE         = 3,
+    SIGNED_DISTANCE_TYPE_UNSIGNED       = 3,
     NUM_SIGNED_DISTANCE_TYPE            = 4
   };
   // Computes signed distance to a mesh
@@ -27,8 +28,9 @@ namespace igl
   // Inputs:
   //   P  #P by 3 list of query point positions
   //   V  #V by 3 list of vertex positions
-  //   F  #F by 3 list of triangle indices
-  //   sign_type  method for computing distance _sign_ (see signed_distance.h)
+  //   F  #F by ss list of triangle indices, ss should be 3 unless sign_type ==
+  //     SIGNED_DISTANCE_TYPE_UNSIGNED
+  //   sign_type  method for computing distance _sign_ S
   // Outputs:
   //   S  #P list of smallest signed distances
   //   I  #P list of facet indices corresponding to smallest distances