per_vertex_normals.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "per_vertex_normals.h"
  2. #include "per_face_normals.h"
  3. #include "normalize_rows.h"
  4. template <typename DerivedV, typename DerivedF>
  5. IGL_INLINE void igl::per_vertex_normals(
  6. const Eigen::PlainObjectBase<DerivedV>& V,
  7. const Eigen::PlainObjectBase<DerivedF>& F,
  8. Eigen::PlainObjectBase<DerivedV> & N)
  9. {
  10. Eigen::PlainObjectBase<DerivedV> PFN;
  11. igl::per_face_normals(V,F,PFN);
  12. // Resize for output
  13. N = Eigen::PlainObjectBase<DerivedV>::Zero(V.rows(),3);
  14. // loop over faces
  15. for(int i = 0; i < F.rows();i++)
  16. {
  17. // throw normal at each corner
  18. for(int j = 0; j < 3;j++)
  19. {
  20. N.row(F(i,j)) += PFN.row(i);
  21. }
  22. }
  23. // normalize each row
  24. igl::normalize_rows(N,N);
  25. }
  26. template <typename DerivedV, typename DerivedF>
  27. IGL_INLINE void igl::per_vertex_normals(
  28. const Eigen::PlainObjectBase<DerivedV>& V,
  29. const Eigen::PlainObjectBase<DerivedF>& F,
  30. const Eigen::PlainObjectBase<DerivedV>& FN,
  31. Eigen::PlainObjectBase<DerivedV> & N)
  32. {
  33. // Resize for output
  34. N = Eigen::PlainObjectBase<DerivedV>::Zero(V.rows(),3);
  35. // loop over faces
  36. for(int i = 0; i < F.rows();i++)
  37. {
  38. // throw normal at each corner
  39. for(int j = 0; j < 3;j++)
  40. {
  41. N.row(F(i,j)) += FN.row(i);
  42. }
  43. }
  44. // normalize each row
  45. igl::normalize_rows(N,N);
  46. }
  47. #ifndef IGL_HEADER_ONLY
  48. // Explicit template specialization
  49. // generated by autoexplicit.sh
  50. template void igl::per_vertex_normals<Eigen::Matrix<double, -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> >&);
  51. #endif