소스 검색

[curvature] Added a test before calling fit to avoid exit instruction

For the time being, the code exits if data is not valid.
exit instruction in fit function is not desirable when using principal_curvature in a program.
Ideally, one should raise an exception.
If data is not valid, we return a default Quadric object


Former-commit-id: 78cc9effc3d19a791c0e751bff0894e84aeb4c61
Guillaume Jacquenot 7 년 전
부모
커밋
938dc61824
1개의 변경된 파일9개의 추가작업 그리고 1개의 파일을 삭제
  1. 9 1
      include/igl/principal_curvature.cpp

+ 9 - 1
include/igl/principal_curvature.cpp

@@ -348,7 +348,15 @@ IGL_INLINE void CurvatureCalculator::fitQuadric(const Eigen::Vector3d& v, const
     double z = vTang.dot(ref[2]);
     points.push_back(Eigen::Vector3d (x,y,z));
   }
-  *q = Quadric::fit (points);
+  if (points.size() < 5)
+  {
+    std::cerr << "ASSERT FAILED! fit function requires at least 5 points: Only " << points.size() << " were given." << std::endl;
+    *q = Quadric(0,0,0,0,0);
+  }
+  else
+  {
+    *q = Quadric::fit (points);
+  }
 }
 
 IGL_INLINE void CurvatureCalculator::finalEigenStuff(int i, const std::vector<Eigen::Vector3d>& ref, Quadric& q)