per_face_normals.cpp 1.4 KB

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