per_face_normals.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. #include "per_face_normals.h"
  2. #include <Eigen/Geometry>
  3. #define SQRT_ONE_OVER_THREE 0.57735026918962573
  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. typename DerivedV::Scalar r = N.row(i).norm();
  20. if (r != 0)
  21. {
  22. N.row(i) /= r;
  23. }
  24. }
  25. }
  26. #ifndef IGL_HEADER_ONLY
  27. // Explicit template specialization
  28. // generated by autoexplicit.sh
  29. 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> >&);
  30. 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> >&);
  31. #endif