per_vertex_normals.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "per_vertex_normals.h"
  9. #include "per_face_normals.h"
  10. template <typename DerivedV, typename DerivedF>
  11. IGL_INLINE void igl::per_vertex_normals(
  12. const Eigen::PlainObjectBase<DerivedV>& V,
  13. const Eigen::PlainObjectBase<DerivedF>& F,
  14. Eigen::PlainObjectBase<DerivedV> & N)
  15. {
  16. Eigen::PlainObjectBase<DerivedV> PFN;
  17. igl::per_face_normals(V,F,PFN);
  18. return igl::per_vertex_normals(V,F,PFN,N);
  19. }
  20. template <typename DerivedV, typename DerivedF>
  21. IGL_INLINE void igl::per_vertex_normals(
  22. const Eigen::PlainObjectBase<DerivedV>& V,
  23. const Eigen::PlainObjectBase<DerivedF>& F,
  24. const Eigen::PlainObjectBase<DerivedV>& FN,
  25. Eigen::PlainObjectBase<DerivedV> & N)
  26. {
  27. // Resize for output
  28. N.setZero(V.rows(),3);
  29. // loop over faces
  30. const int Frows = F.rows();
  31. //// Minimum number of iterms per openmp thread
  32. //#ifndef IGL_OMP_MIN_VALUE
  33. //# define IGL_OMP_MIN_VALUE 1000
  34. //#endif
  35. //#pragma omp parallel for if (Frows>IGL_OMP_MIN_VALUE)
  36. for(int i = 0; i < Frows;i++)
  37. {
  38. // throw normal at each corner
  39. for(int j = 0; j < 3;j++)
  40. {
  41. // Does this need to be critical?
  42. //#pragma omp critical
  43. N.row(F(i,j)) += FN.row(i);
  44. }
  45. }
  46. N.rowwise().normalize();
  47. }
  48. #ifndef IGL_HEADER_ONLY
  49. // Explicit template specialization
  50. // generated by autoexplicit.sh
  51. 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> >&);
  52. 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> >&);
  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> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  54. #endif