per_vertex_normals.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "per_vertex_normals.h"
  2. #include "per_face_normals.h"
  3. #include "normalize_row_lengths.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_row_lengths(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_row_lengths(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. template void igl::per_vertex_normals<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&);
  52. 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> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  53. #endif