per_vertex_normals.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. return igl::per_vertex_normals(V,F,PFN,N);
  13. //// Resize for output
  14. //N = Eigen::PlainObjectBase<DerivedV>::Zero(V.rows(),3);
  15. //// loop over faces
  16. //for(int i = 0; i < F.rows();i++)
  17. //{
  18. // // throw normal at each corner
  19. // for(int j = 0; j < 3;j++)
  20. // {
  21. // N.row(F(i,j)) += PFN.row(i);
  22. // }
  23. //}
  24. //// normalize each row
  25. //igl::normalize_row_lengths(N,N);
  26. }
  27. template <typename DerivedV, typename DerivedF>
  28. IGL_INLINE void igl::per_vertex_normals(
  29. const Eigen::PlainObjectBase<DerivedV>& V,
  30. const Eigen::PlainObjectBase<DerivedF>& F,
  31. const Eigen::PlainObjectBase<DerivedV>& FN,
  32. Eigen::PlainObjectBase<DerivedV> & N)
  33. {
  34. // Resize for output
  35. N.setZero(V.rows(),3);
  36. // loop over faces
  37. int Frows = F.rows();
  38. #pragma omp parallel for
  39. for(int i = 0; i < Frows;i++)
  40. {
  41. // throw normal at each corner
  42. for(int j = 0; j < 3;j++)
  43. {
  44. N.row(F(i,j)) += FN.row(i);
  45. }
  46. }
  47. // normalize each row
  48. igl::normalize_row_lengths(N,N);
  49. }
  50. #ifndef IGL_HEADER_ONLY
  51. // Explicit template specialization
  52. // generated by autoexplicit.sh
  53. 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> >&);
  54. 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> >&);
  55. 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> >&);
  56. #endif