Browse Source

fast winding for signing distance

Thomas Davies 6 years ago
parent
commit
61878ade62
2 changed files with 39 additions and 5 deletions
  1. 32 0
      include/igl/signed_distance.cpp
  2. 7 5
      include/igl/signed_distance.h

+ 32 - 0
include/igl/signed_distance.cpp

@@ -13,6 +13,7 @@
 #include "per_vertex_normals.h"
 #include "per_vertex_normals.h"
 #include "point_mesh_squared_distance.h"
 #include "point_mesh_squared_distance.h"
 #include "pseudonormal_test.h"
 #include "pseudonormal_test.h"
+#include "fast_winding_number.h"
 
 
 
 
 template <
 template <
@@ -66,6 +67,15 @@ IGL_INLINE void igl::signed_distance(
   Eigen::Matrix<typename DerivedF::Scalar,Eigen::Dynamic,2> E;
   Eigen::Matrix<typename DerivedF::Scalar,Eigen::Dynamic,2> E;
   Eigen::Matrix<typename DerivedF::Scalar,Eigen::Dynamic,1> EMAP;
   Eigen::Matrix<typename DerivedF::Scalar,Eigen::Dynamic,1> EMAP;
   WindingNumberAABB<RowVector3S,DerivedV,DerivedF> hier3;
   WindingNumberAABB<RowVector3S,DerivedV,DerivedF> hier3;
+  igl::FastWindingNumberBVH fwn_bvh;
+  Eigen::VectorXf W;
+
+  // This is not correct, but I don't understand explicit templating...
+  // we just ensure type is all good for input to fast_winding_number...
+  Eigen::MatrixXd tV = V.template cast<double>(); //ideally tV would be V.template cast<float>() 
+  Eigen::MatrixXi tF = F.template cast<int>();
+  Eigen::MatrixXd tP = V.template cast<double>();
+
   switch(sign_type)
   switch(sign_type)
   {
   {
     default:
     default:
@@ -87,6 +97,17 @@ IGL_INLINE void igl::signed_distance(
           break;
           break;
       }
       }
       break;
       break;
+    case SIGNED_DISTANCE_TYPE_FAST_WINDING_NUMBER:
+      switch(dim)
+      {
+        default:
+        case 3:
+          //pre compute
+          igl::fast_winding_number(tV.cast<float>(), tF, 2, fwn_bvh);
+        case 2:
+          //is this correct?
+          break;
+      }
     case SIGNED_DISTANCE_TYPE_PSEUDONORMAL:
     case SIGNED_DISTANCE_TYPE_PSEUDONORMAL:
       switch(dim)
       switch(dim)
       {
       {
@@ -182,10 +203,21 @@ IGL_INLINE void igl::signed_distance(
           {
           {
             assert(!V.derived().IsRowMajor);
             assert(!V.derived().IsRowMajor);
             assert(!F.derived().IsRowMajor);
             assert(!F.derived().IsRowMajor);
+            std::cout << "HERE" <<winding_number(V,F,q2) << std::endl;
             s = 1.-2.*winding_number(V,F,q2);
             s = 1.-2.*winding_number(V,F,q2);
           }
           }
           break;
           break;
         }
         }
+        case SIGNED_DISTANCE_TYPE_FAST_WINDING_NUMBER:
+        {
+          //TODO: once again just doing this avoid compile complaints...
+          MatrixXf tq3 = q3.template cast<float>();
+          if (dim == 3){
+            Scalar w = fast_winding_number(fwn_bvh,2,tq3);
+            s = 1.f-2.f*w;
+          }          
+          break;
+        }
         case SIGNED_DISTANCE_TYPE_PSEUDONORMAL:
         case SIGNED_DISTANCE_TYPE_PSEUDONORMAL:
         {
         {
           RowVector3S n3;
           RowVector3S n3;

+ 7 - 5
include/igl/signed_distance.h

@@ -11,6 +11,7 @@
 #include "igl_inline.h"
 #include "igl_inline.h"
 #include "AABB.h"
 #include "AABB.h"
 #include "WindingNumberAABB.h"
 #include "WindingNumberAABB.h"
+#include "fast_winding_number.h"
 #include <Eigen/Core>
 #include <Eigen/Core>
 #include <vector>
 #include <vector>
 namespace igl
 namespace igl
@@ -18,11 +19,12 @@ namespace igl
   enum SignedDistanceType
   enum SignedDistanceType
   {
   {
     // Use fast pseudo-normal test [Bærentzen & Aanæs 2005]
     // 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_UNSIGNED       = 3,
-    NUM_SIGNED_DISTANCE_TYPE            = 4
+    SIGNED_DISTANCE_TYPE_PSEUDONORMAL         = 0,
+    SIGNED_DISTANCE_TYPE_WINDING_NUMBER       = 1,
+    SIGNED_DISTANCE_TYPE_DEFAULT              = 2,
+    SIGNED_DISTANCE_TYPE_UNSIGNED             = 3,
+    SIGNED_DISTANCE_TYPE_FAST_WINDING_NUMBER  = 4,
+    NUM_SIGNED_DISTANCE_TYPE                  = 5
   };
   };
   // Computes signed distance to a mesh
   // Computes signed distance to a mesh
   //
   //