per_vertex_normals.cpp 2.2 KB

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