per_vertex_normals.cpp 2.6 KB

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