per_edge_normals.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "all_edges.h"
  2. #include "doublearea.h"
  3. #include "per_edge_normals.h"
  4. #include "per_face_normals.h"
  5. #include "unique_simplices.h"
  6. #include <vector>
  7. template <
  8. typename DerivedV,
  9. typename DerivedF,
  10. typename DerivedN,
  11. typename DerivedE,
  12. typename DerivedEMAP>
  13. IGL_INLINE void igl::per_edge_normals(
  14. const Eigen::PlainObjectBase<DerivedV>& V,
  15. const Eigen::PlainObjectBase<DerivedF>& F,
  16. Eigen::PlainObjectBase<DerivedN> & N,
  17. Eigen::PlainObjectBase<DerivedE> & E,
  18. Eigen::PlainObjectBase<DerivedEMAP> & EMAP)
  19. {
  20. using namespace Eigen;
  21. using namespace std;
  22. assert(F.cols() == 3 && "Faces must be triangles");
  23. // number of faces
  24. const int m = F.rows();
  25. // All occurances of directed edges
  26. MatrixXi allE;
  27. all_edges(F,allE);
  28. // Find unique undirected edges and mapping
  29. VectorXi _;
  30. unique_simplices(allE,E,_,EMAP);
  31. // now sort(allE,2) == E(EMAP,:), that is, if EMAP(i) = j, then E.row(j) is
  32. // the undirected edge corresponding to the directed edge allE.row(i).
  33. MatrixXd FN;
  34. per_face_normals(V,F,FN);
  35. VectorXd dblA;
  36. doublearea(V,F,dblA);
  37. N.setConstant(E.rows(),3,0);
  38. for(int f = 0;f<m;f++)
  39. {
  40. for(int c = 0;c<3;c++)
  41. {
  42. N.row(EMAP(f+c*m)) += dblA(f) * FN.row(f);
  43. }
  44. }
  45. N.rowwise().normalize();
  46. }
  47. #ifdef IGL_STATIC_LIBRARY
  48. // Explicit template instanciation
  49. template void igl::per_edge_normals<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<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  50. #endif