Alec Jacobson 6 лет назад
Родитель
Сommit
ca92a3b514
2 измененных файлов с 68 добавлено и 3 удалено
  1. 3 3
      include/igl/signed_distance.cpp
  2. 65 0
      tests/include/igl/signed_distance.cpp

+ 3 - 3
include/igl/signed_distance.cpp

@@ -193,9 +193,9 @@ IGL_INLINE void igl::signed_distance(
           Eigen::Matrix<typename DerivedV::Scalar,1,2>  n2;
           dim==3 ?
             pseudonormal_test(V,F,FN,VN,EN,EMAP,q3,i,c3,s,n3):
-            // This should use (V,F), not (V,E) since E is auxiliary for 3D
-            // case, not the input "F"acets.
-            pseudonormal_test(V,F,EN,VN,q2,i,c2,s,n2);
+            // This should use (V,F,FN), not (V,E,EN) since E is auxiliary for
+            // 3D case, not the input "F"acets.
+            pseudonormal_test(V,F,FN,VN,q2,i,c2,s,n2);
           Eigen::Matrix<typename DerivedN::Scalar,1,Eigen::Dynamic>  n;
           (dim==3 ? n = n3.template cast<typename DerivedN::Scalar>() : n = n2.template cast<typename DerivedN::Scalar>());
           N.row(p) = n.template cast<typename DerivedN::Scalar>();

+ 65 - 0
tests/include/igl/signed_distance.cpp

@@ -0,0 +1,65 @@
+#include <test_common.h>
+#include <igl/signed_distance.h>
+
+TEST_CASE("signed_distance: single_tet", "[igl]")
+{
+  Eigen::MatrixXd V(4,3);
+  V<<
+    0,0,0,
+    1,0,0,
+    0,1,0,
+    0,0,1;
+  Eigen::MatrixXi F(4,3);
+  F<<
+    0,1,3,
+    0,2,1,
+    0,3,2,
+    1,2,3;
+  Eigen::MatrixXd P(1,3);
+  P<<0.5,0.5,0.5;
+  for(const igl::SignedDistanceType type :
+      {
+      igl::SIGNED_DISTANCE_TYPE_PSEUDONORMAL  ,
+      igl::SIGNED_DISTANCE_TYPE_WINDING_NUMBER,
+      igl::SIGNED_DISTANCE_TYPE_DEFAULT       ,
+      igl::SIGNED_DISTANCE_TYPE_UNSIGNED      })
+  {
+    Eigen::VectorXd S;
+    Eigen::VectorXi I;
+    Eigen::MatrixXd C,N;
+    igl::signed_distance( P,V,F,type,S,I,C,N);
+    Eigen::VectorXd Sexact (1,1);Sexact<<sqrt(1./12.);
+    test_common::assert_near(S,Sexact,1e-15);
+  }
+}
+
+TEST_CASE("signed_distance: single_triangle", "[igl]")
+{
+  Eigen::MatrixXd V(3,2);
+  V<<
+    0,0,
+    1,0,
+    0,1;
+  Eigen::MatrixXi F(3,2);
+  F<<
+    0,1,
+    1,2,
+    2,0;
+  Eigen::MatrixXd P(1,2);
+  P<<1,1;
+  for(const igl::SignedDistanceType type :
+      {
+      igl::SIGNED_DISTANCE_TYPE_PSEUDONORMAL  ,
+      //igl::SIGNED_DISTANCE_TYPE_WINDING_NUMBER,
+      //igl::SIGNED_DISTANCE_TYPE_DEFAULT       ,
+      igl::SIGNED_DISTANCE_TYPE_UNSIGNED      
+      })
+  {
+    Eigen::VectorXd S;
+    Eigen::VectorXi I;
+    Eigen::MatrixXd C,N;
+    igl::signed_distance( P,V,F,type,S,I,C,N);
+    //Eigen::VectorXd Sexact (1,1);Sexact<<sqrt(2.)/2.;
+    //test_common::assert_near(S,Sexact,1e-15);
+  }
+}