From 8f6a4c4c07f9e180d0214fe418413948c6c22c10 Mon Sep 17 00:00:00 2001 From: vskhitkov Date: Thu, 21 Jun 2018 16:04:48 +0300 Subject: [PATCH 1/3] bugfix: principal_curvature returns boolean instead of segfault --- include/igl/principal_curvature.cpp | 6 +++++- include/igl/principal_curvature.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/igl/principal_curvature.cpp b/include/igl/principal_curvature.cpp index 5712130a0..0204d55ff 100644 --- a/include/igl/principal_curvature.cpp +++ b/include/igl/principal_curvature.cpp @@ -780,7 +780,7 @@ template < typename DerivedPD2, typename DerivedPV1, typename DerivedPV2> -IGL_INLINE void igl::principal_curvature( +IGL_INLINE bool igl::principal_curvature( const Eigen::PlainObjectBase& V, const Eigen::PlainObjectBase& F, Eigen::PlainObjectBase& PD1, @@ -817,6 +817,8 @@ IGL_INLINE void igl::principal_curvature( // Compute cc.computeCurvature(); + if (!cc.curvatureComputed) + return false; // Copy it back for (unsigned i=0; i -IGL_INLINE void principal_curvature( +IGL_INLINE bool principal_curvature( const Eigen::PlainObjectBase& V, const Eigen::PlainObjectBase& F, Eigen::PlainObjectBase& PD1, From dca5f4e8a2fd755ae8b1914385caab5d5dc0d17a Mon Sep 17 00:00:00 2001 From: vskhitkov Date: Thu, 21 Jun 2018 17:07:10 +0300 Subject: [PATCH 2/3] Fixed my own fix --- include/igl/principal_curvature.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/igl/principal_curvature.cpp b/include/igl/principal_curvature.cpp index 0204d55ff..1747fde5f 100644 --- a/include/igl/principal_curvature.cpp +++ b/include/igl/principal_curvature.cpp @@ -852,7 +852,7 @@ IGL_INLINE bool igl::principal_curvature( #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation // generated by autoexplicit.sh -template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); -template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); -template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); +template bool igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); +template bool igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); +template bool igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); #endif From 0914f34a915d679cf83e034e974a61d974502e71 Mon Sep 17 00:00:00 2001 From: vskhitkov Date: Thu, 21 Jun 2018 19:21:35 +0300 Subject: [PATCH 3/3] Replace return value by vector of indices of bad vertices --- include/igl/principal_curvature.cpp | 65 +++++++++++++++++------------ include/igl/principal_curvature.h | 15 ++++--- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/include/igl/principal_curvature.cpp b/include/igl/principal_curvature.cpp index 1747fde5f..aede8191e 100644 --- a/include/igl/principal_curvature.cpp +++ b/include/igl/principal_curvature.cpp @@ -692,8 +692,8 @@ IGL_INLINE void CurvatureCalculator::computeCurvature() 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) { - 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) { @@ -780,7 +780,7 @@ template < typename DerivedPD2, typename DerivedPV1, typename DerivedPV2> -IGL_INLINE bool igl::principal_curvature( +IGL_INLINE std::vector igl::principal_curvature( const Eigen::PlainObjectBase& V, const Eigen::PlainObjectBase& F, Eigen::PlainObjectBase& PD1, @@ -790,6 +790,8 @@ IGL_INLINE bool igl::principal_curvature( unsigned radius, bool useKring) { + std::vector bad_vertices; + if (radius < 2) { radius = 2; @@ -817,42 +819,51 @@ IGL_INLINE bool igl::principal_curvature( // Compute cc.computeCurvature(); - if (!cc.curvatureComputed) - return false; // Copy it back for (unsigned i=0; i 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; } - - PV1(i) = cc.curv[i][0]; - PV2(i) = cc.curv[i][1]; - - 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; - } } - return true; + return bad_vertices; } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation // generated by autoexplicit.sh -template bool igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); -template bool igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); -template bool igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); +template std::vector igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); +template std::vector igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); +template std::vector igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); #endif diff --git a/include/igl/principal_curvature.h b/include/igl/principal_curvature.h index 34c26df94..cb14e4fb4 100644 --- a/include/igl/principal_curvature.h +++ b/include/igl/principal_curvature.h @@ -12,6 +12,8 @@ #include #include +#include + #include "igl_inline.h" //#include //#include @@ -35,6 +37,9 @@ namespace igl // PV1 #V by 1 maximal 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 // // 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 // GraVisMa, 2010 template < - typename DerivedV, + typename DerivedV, typename DerivedF, - typename DerivedPD1, - typename DerivedPD2, - typename DerivedPV1, + typename DerivedPD1, + typename DerivedPD2, + typename DerivedPV1, typename DerivedPV2> -IGL_INLINE bool principal_curvature( +IGL_INLINE std::vector principal_curvature( const Eigen::PlainObjectBase& V, const Eigen::PlainObjectBase& F, Eigen::PlainObjectBase& PD1,