Kaynağa Gözat

Replace return value by vector of indices of bad vertices

Former-commit-id: 0914f34a915d679cf83e034e974a61d974502e71
vskhitkov 7 yıl önce
ebeveyn
işleme
da3bd928dd

+ 38 - 27
include/igl/principal_curvature.cpp

@@ -692,8 +692,8 @@ IGL_INLINE void CurvatureCalculator::computeCurvature()
 
 
     if (vv.size()<6)
     if (vv.size()<6)
     {
     {
-      std::cerr << "Could not compute curvature of radius " << scaledRadius << std::endl;
-      return;
+      //std::cerr << "Could not compute curvature of radius " << scaledRadius << std::endl;
+      continue;
     }
     }
 
 
 
 
@@ -720,8 +720,8 @@ IGL_INLINE void CurvatureCalculator::computeCurvature()
     }
     }
     if (vv.size()<6)
     if (vv.size()<6)
     {
     {
-      std::cerr << "Could not compute curvature of radius " << scaledRadius << std::endl;
-      return;
+      //std::cerr << "Could not compute curvature of radius " << scaledRadius << std::endl;
+      continue;
     }
     }
     if (montecarlo)
     if (montecarlo)
     {
     {
@@ -780,7 +780,7 @@ template <
   typename DerivedPD2,
   typename DerivedPD2,
   typename DerivedPV1,
   typename DerivedPV1,
   typename DerivedPV2>
   typename DerivedPV2>
-IGL_INLINE bool igl::principal_curvature(
+IGL_INLINE std::vector<size_t> igl::principal_curvature(
   const Eigen::PlainObjectBase<DerivedV>& V,
   const Eigen::PlainObjectBase<DerivedV>& V,
   const Eigen::PlainObjectBase<DerivedF>& F,
   const Eigen::PlainObjectBase<DerivedF>& F,
   Eigen::PlainObjectBase<DerivedPD1>& PD1,
   Eigen::PlainObjectBase<DerivedPD1>& PD1,
@@ -790,6 +790,8 @@ IGL_INLINE bool igl::principal_curvature(
   unsigned radius,
   unsigned radius,
   bool useKring)
   bool useKring)
 {
 {
+  std::vector<size_t> bad_vertices;
+
   if (radius < 2)
   if (radius < 2)
   {
   {
     radius = 2;
     radius = 2;
@@ -817,42 +819,51 @@ IGL_INLINE bool igl::principal_curvature(
 
 
   // Compute
   // Compute
   cc.computeCurvature();
   cc.computeCurvature();
-  if (!cc.curvatureComputed)
-    return false;
 
 
   // Copy it back
   // Copy it back
   for (unsigned i=0; i<V.rows(); ++i)
   for (unsigned i=0; i<V.rows(); ++i)
   {
   {
-    PD1.row(i) << cc.curvDir[i][0][0], cc.curvDir[i][0][1], cc.curvDir[i][0][2];
-    PD2.row(i) << cc.curvDir[i][1][0], cc.curvDir[i][1][1], cc.curvDir[i][1][2];
-    PD1.row(i).normalize();
-    PD2.row(i).normalize();
-
-    if (std::isnan(PD1(i,0)) || std::isnan(PD1(i,1)) || std::isnan(PD1(i,2)) || std::isnan(PD2(i,0)) || std::isnan(PD2(i,1)) || std::isnan(PD2(i,2)))
+    if (!cc.curv[i].empty())
     {
     {
-      PD1.row(i) << 0,0,0;
-      PD2.row(i) << 0,0,0;
-    }
+      PD1.row(i) << cc.curvDir[i][0][0], cc.curvDir[i][0][1], cc.curvDir[i][0][2];
+      PD2.row(i) << cc.curvDir[i][1][0], cc.curvDir[i][1][1], cc.curvDir[i][1][2];
+      PD1.row(i).normalize();
+      PD2.row(i).normalize();
 
 
-    PV1(i) = cc.curv[i][0];
-    PV2(i) = cc.curv[i][1];
+      if (std::isnan(PD1(i,0)) || std::isnan(PD1(i,1)) || std::isnan(PD1(i,2)) || std::isnan(PD2(i,0)) || std::isnan(PD2(i,1)) || std::isnan(PD2(i,2)))
+      {
+        PD1.row(i) << 0,0,0;
+        PD2.row(i) << 0,0,0;
+      }
 
 
-    if (PD1.row(i) * PD2.row(i).transpose() > 10e-6)
-    {
-      std::cerr << "PRINCIPAL_CURVATURE: Something is wrong with vertex: " << i << std::endl;
-      PD1.row(i) *= 0;
-      PD2.row(i) *= 0;
+      PV1(i) = cc.curv[i][0];
+      PV2(i) = cc.curv[i][1];
+
+      if (PD1.row(i) * PD2.row(i).transpose() > 10e-6)
+      {
+        bad_vertices.push_back((size_t)i);
+
+        PD1.row(i) *= 0;
+        PD2.row(i) *= 0;
+      }
+    } else {
+      bad_vertices.push_back((size_t)i);
+
+      PV1(i) = 0;
+      PV2(i) = 0;
+      PD1.row(i) << 0,0,0;
+      PD2.row(i) << 0,0,0;
     }
     }
   }
   }
 
 
-  return true;
+  return bad_vertices;
 
 
 }
 }
 
 
 #ifdef IGL_STATIC_LIBRARY
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template instantiation
 // Explicit template instantiation
 // generated by autoexplicit.sh
 // generated by autoexplicit.sh
-template bool igl::principal_curvature<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, unsigned int, bool);
-template bool igl::principal_curvature<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, unsigned int, bool);
-template bool igl::principal_curvature<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, unsigned int, bool);
+template std::vector<size_t> igl::principal_curvature<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, unsigned int, bool);
+template std::vector<size_t> igl::principal_curvature<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, unsigned int, bool);
+template std::vector<size_t> igl::principal_curvature<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, unsigned int, bool);
 #endif
 #endif

+ 10 - 5
include/igl/principal_curvature.h

@@ -12,6 +12,8 @@
 #include <Eigen/Geometry>
 #include <Eigen/Geometry>
 #include <Eigen/Dense>
 #include <Eigen/Dense>
 
 
+#include <vector>
+
 #include "igl_inline.h"
 #include "igl_inline.h"
 //#include <igl/cotmatrix.h>
 //#include <igl/cotmatrix.h>
 //#include <igl/writeOFF.h>
 //#include <igl/writeOFF.h>
@@ -35,6 +37,9 @@ namespace igl
   //   PV1 #V by 1 maximal curvature value for each vertex.
   //   PV1 #V by 1 maximal curvature value for each vertex.
   //   PV2 #V by 1 minimal curvature value for each vertex.
   //   PV2 #V by 1 minimal curvature value for each vertex.
   //
   //
+  // Return value:
+  //   Function returns vector of indices of bad vertices if any.
+  //
   // See also: average_onto_faces, average_onto_vertices
   // See also: average_onto_faces, average_onto_vertices
   //
   //
   // This function has been developed by: Nikolas De Giorgis, Luigi Rocca and Enrico Puppo.
   // This function has been developed by: Nikolas De Giorgis, Luigi Rocca and Enrico Puppo.
@@ -43,13 +48,13 @@ namespace igl
   // Daniele Panozzo, Enrico Puppo, Luigi Rocca
   // Daniele Panozzo, Enrico Puppo, Luigi Rocca
   // GraVisMa, 2010
   // GraVisMa, 2010
 template <
 template <
-  typename DerivedV, 
+  typename DerivedV,
   typename DerivedF,
   typename DerivedF,
-  typename DerivedPD1, 
-  typename DerivedPD2, 
-  typename DerivedPV1, 
+  typename DerivedPD1,
+  typename DerivedPD2,
+  typename DerivedPV1,
   typename DerivedPV2>
   typename DerivedPV2>
-IGL_INLINE bool principal_curvature(
+IGL_INLINE std::vector<size_t> principal_curvature(
   const Eigen::PlainObjectBase<DerivedV>& V,
   const Eigen::PlainObjectBase<DerivedV>& V,
   const Eigen::PlainObjectBase<DerivedF>& F,
   const Eigen::PlainObjectBase<DerivedF>& F,
   Eigen::PlainObjectBase<DerivedPD1>& PD1,
   Eigen::PlainObjectBase<DerivedPD1>& PD1,