per_face_normals.cpp 1015 B

1234567891011121314151617181920212223
  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. for(int i = 0; i < F.rows();i++)
  12. {
  13. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v1 = V.row(F(i,1)) - V.row(F(i,0));
  14. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v2 = V.row(F(i,2)) - V.row(F(i,0));
  15. N.row(i) = (v1.cross(v2)).normalized();
  16. }
  17. }
  18. #ifndef IGL_HEADER_ONLY
  19. // Explicit template specialization
  20. // generated by autoexplicit.sh
  21. 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> >&);
  22. #endif