Forráskód Böngészése

signed distance from pre computed fast winding number bvh

Thomas Davies 6 éve
szülő
commit
2f570a0e97
2 módosított fájl, 32 hozzáadás és 31 törlés
  1. 13 12
      include/igl/signed_distance.cpp
  2. 19 19
      include/igl/signed_distance.h

+ 13 - 12
include/igl/signed_distance.cpp

@@ -476,42 +476,42 @@ IGL_INLINE void igl::signed_distance_winding_number(
 
 //Multi point by parrallel for on single point
 template <
+  typename DerivedP,
   typename DerivedV,
   typename DerivedF,
-  typename DerivedP,
   typename DerivedS>
 IGL_INLINE void igl::signed_distance_fast_winding_number(
-    const AABB<DerivedV,3> & tree,
+    const Eigen::MatrixBase<DerivedP> & P,
     const Eigen::MatrixBase<DerivedV> & V,
     const Eigen::MatrixBase<DerivedF> & F,
+    const AABB<DerivedV,3> & tree,
     const igl::FastWindingNumberBVH & fwn_bvh,
-    const Eigen::MatrixBase<DerivedP> & P,
-    const Eigen::PlainObjectBase<DerivedS> & S)
+    Eigen::PlainObjectBase<DerivedS> & S)
   {
     typedef Eigen::Matrix<typename DerivedV::Scalar,1,3> RowVector3S;
-
+    S.resize(P.rows(),1);
     int min_parallel = 10000; //using default seen elsewhere...
     parallel_for(P.rows(), [&](const int p)
     {
       RowVector3S q;
       q.head(P.row(p).size()) = P.row(p);
       // get sdf for single point, update result matrix
-      S(p) = signed_distance_fast_winding_number(tree, V, F, fwn_bvh, q);
+      S(p) = signed_distance_fast_winding_number(q, V, F, tree,fwn_bvh);
     }
     ,min_parallel);  
   }
 
 //Single Point
 template <
+  typename Derivedq,
   typename DerivedV,
-  typename DerivedF,
-  typename Derivedq>
+  typename DerivedF>
 IGL_INLINE typename DerivedV::Scalar igl::signed_distance_fast_winding_number(
-    const AABB<DerivedV,3> & tree,
+    const Eigen::MatrixBase<Derivedq> & q,
     const Eigen::MatrixBase<DerivedV> & V,
     const Eigen::MatrixBase<DerivedF> & F,
-    const igl::FastWindingNumberBVH & fwn_bvh,
-    const Eigen::MatrixBase<Derivedq> & q)
+    const AABB<DerivedV,3> & tree,
+    const igl::FastWindingNumberBVH & fwn_bvh)
   {
     typedef typename DerivedV::Scalar Scalar;
     Scalar s,sqrd;
@@ -519,7 +519,8 @@ IGL_INLINE typename DerivedV::Scalar igl::signed_distance_fast_winding_number(
     int i = -1;
     sqrd = tree.squared_distance(V,F,q,i,c);
     Scalar w = fast_winding_number(fwn_bvh,2,q.template cast<float>());
-    return 1.-2.*w;
+    //0.5 is on surface
+    return sqrt(sqrd)*(1.-2.*w);
   }
 
 #ifdef IGL_STATIC_LIBRARY

+ 19 - 19
include/igl/signed_distance.h

@@ -260,39 +260,39 @@ namespace igl
   // Calculates signed distance at query points P, using fast winding number
   //   for sign.
   //
-  // NOTE: form of inputs matches first overide for general case, not the other
-  //           sign type specific funcs... I don't like their seperation of 
-  //           s and sqrd.
+  // Usage:
+  //     VectorXd S;  
+  //     VectorXd V, P; //where V is mesh vertices, P are query points
+  //     VectorXi F;  
+  //     igl::FastWindingNumberBVH fwn_bvh;
+  //     igl::fast_winding_number(V.cast<float>(), F, 2, fwn_bvh);
+  //     igl::signed_distance_fast_winding_number(P,V,F,tree,fwn_bvh,S);
   //
   // Inputs:
-  //   tree  AABB acceleration tree (see AABB.h)
+  //   P  #P by 3 list of query point positions
   //   V  #V by 3 list of triangle indices
   //   F  #F by 3 list of triangle normals 
+  //   tree  AABB acceleration tree (see AABB.h)
   //   bvh fast winding precomputation (see Fast_Winding_Number.h)   
-  //   P  #P by 3 list of query point positions
   // Outputs:
   //   S  #P list of signed distances of each point in P
   template <
+    typename DerivedP,
     typename DerivedV,
     typename DerivedF,
-    typename DerivedP,
     typename DerivedS>
   IGL_INLINE void signed_distance_fast_winding_number(
-    const AABB<DerivedV,3> & tree,
+    const Eigen::MatrixBase<DerivedP> & P,
     const Eigen::MatrixBase<DerivedV> & V,
     const Eigen::MatrixBase<DerivedF> & F,
+    const AABB<DerivedV,3> & tree,
     const igl::FastWindingNumberBVH & fwn_bvh,
-    const Eigen::MatrixBase<DerivedP> & P,
-    const Eigen::PlainObjectBase<DerivedS> & S
+    Eigen::PlainObjectBase<DerivedS> & S
   );
 
-    // Calculates signed distance at query point q, using fast winding number
+  // Calculates signed distance at query point q, using fast winding number
   //   for sign.
   //
-  // NOTE: form of inputs matches first overide for general case, not the other
-  //           sign type specific funcs... I don't like their seperation of 
-  //           s and sqrd.
-  //
   // Inputs:
   //   tree  AABB acceleration tree (see AABB.h)
   //   V  #V by 3 list of triangle indices
@@ -302,15 +302,15 @@ namespace igl
   // Outputs:
   //   S  #P list of signed distances of each point in P
   template <
+    typename Derivedq,
     typename DerivedV,
-    typename DerivedF,
-    typename Derivedq>
+    typename DerivedF>
   IGL_INLINE typename DerivedV::Scalar signed_distance_fast_winding_number(
-    const AABB<DerivedV,3> & tree,
+    const Eigen::MatrixBase<Derivedq> & q,
     const Eigen::MatrixBase<DerivedV> & V,
     const Eigen::MatrixBase<DerivedF> & F,
-    const igl::FastWindingNumberBVH & fwn_bvh,
-    const Eigen::MatrixBase<Derivedq> & q
+    const AABB<DerivedV,3> & tree,
+    const igl::FastWindingNumberBVH & fwn_bvh
   );
 }