per_vertex_normals.cpp 749 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "per_vertex_normals.h"
  2. #include "per_face_normals.h"
  3. #include "normalize_rows.h"
  4. IGL_INLINE void igl::per_vertex_normals(
  5. const Eigen::MatrixXd & V,
  6. const Eigen::MatrixXi & F,
  7. Eigen::MatrixXd & N)
  8. {
  9. Eigen::MatrixXd PFN;
  10. igl::per_face_normals(V,F,PFN);
  11. // Resize for output
  12. N.resize(V.rows(),3);
  13. // loop over vertices, setting normalize to 0
  14. for(int i = 0; i < N.rows();i++)
  15. {
  16. N(i,0) = 0;
  17. N(i,1) = 0;
  18. N(i,2) = 0;
  19. }
  20. // loop over faces
  21. for(int i = 0; i < F.rows();i++)
  22. {
  23. // throw normal at each corner
  24. for(int j = 0; j < 3;j++)
  25. {
  26. N(F(i,j),0) += PFN(i,0);
  27. N(F(i,j),1) += PFN(i,1);
  28. N(F(i,j),2) += PFN(i,2);
  29. }
  30. }
  31. // normalize each row
  32. igl::normalize_rows(N,N);
  33. }