outer_facet.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "outer_facet.h"
  2. #include "sort.h"
  3. #include "vertex_triangle_adjacency.h"
  4. template <
  5. typename DerivedV,
  6. typename DerivedF,
  7. typename DerivedN,
  8. typename DerivedI,
  9. typename f_type>
  10. IGL_INLINE void igl::outer_facet(
  11. const Eigen::PlainObjectBase<DerivedV> & V,
  12. const Eigen::PlainObjectBase<DerivedF> & F,
  13. const Eigen::PlainObjectBase<DerivedN> & N,
  14. const Eigen::PlainObjectBase<DerivedI> & I,
  15. f_type & max_f,
  16. bool & flip)
  17. {
  18. using namespace std;
  19. typedef typename DerivedV::Scalar Scalar;
  20. typedef typename DerivedV::Index Index;
  21. typedef
  22. typename Eigen::Matrix<Index, DerivedV::RowsAtCompileTime,1> VectorXI;
  23. typedef
  24. typename Eigen::Matrix<Scalar, DerivedV::RowsAtCompileTime,1> VectorXS;
  25. // "Direct repair of self-intersecting meshes" [Attene 14]
  26. const Index mi = I.size();
  27. Scalar max_x = -1e26;
  28. Index max_v = -1;
  29. Scalar max_nx = -1e26;
  30. for(Index i = 0;i<mi;i++)
  31. {
  32. const Index f = I(i);
  33. const Scalar nx = N(f,0);
  34. if(fabs(nx)>0)
  35. {
  36. for(Index c = 0;c<3;c++)
  37. {
  38. const Index v = F(f,c);
  39. if(v == max_v)
  40. {
  41. if(fabs(nx) > max_nx)
  42. {
  43. // Just update max face and normal
  44. max_f = f;
  45. max_nx = fabs(nx);
  46. flip = nx<0;
  47. }
  48. }else
  49. {
  50. const Scalar x = V(v);
  51. if(x>max_x)
  52. {
  53. // update max vertex, face and normal
  54. max_v = v;
  55. max_x = x;
  56. max_f = f;
  57. max_nx = fabs(nx);
  58. flip = nx<0;
  59. }
  60. }
  61. }
  62. }
  63. }
  64. assert(max_v >=0 && "Very degenerate case, no suitable face found.");
  65. }
  66. #ifdef IGL_STATIC_LIBRARY
  67. // Explicit template specialization
  68. template void igl::outer_facet<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<long, -1, 1, 0, -1, 1>, int>(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> > const&, Eigen::PlainObjectBase<Eigen::Matrix<long, -1, 1, 0, -1, 1> > const&, int&, bool&);
  69. #endif