per_face_normals.cpp 1.4 KB

123456789101112131415161718192021222324252627
  1. #include "per_face_normals.h"
  2. #include <Eigen/Geometry>
  3. #include <omp.h>
  4. template <typename DerivedV, typename DerivedF>
  5. IGL_INLINE void igl::per_face_normals(
  6. const Eigen::PlainObjectBase<DerivedV>& V,
  7. const Eigen::PlainObjectBase<DerivedF>& F,
  8. Eigen::PlainObjectBase<DerivedV> & N)
  9. {
  10. N.resize(F.rows(),3);
  11. // loop over faces
  12. int Frows = F.rows();
  13. #pragma omp parallel for
  14. for(int i = 0; i < Frows;i++)
  15. {
  16. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v1 = V.row(F(i,1)) - V.row(F(i,0));
  17. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v2 = V.row(F(i,2)) - V.row(F(i,0));
  18. N.row(i) = (v1.cross(v2)).normalized();
  19. }
  20. }
  21. #ifndef IGL_HEADER_ONLY
  22. // Explicit template specialization
  23. // generated by autoexplicit.sh
  24. template void igl::per_face_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> >&);
  25. template void igl::per_face_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> >&);
  26. #endif