|
@@ -2,11 +2,12 @@
|
|
#include <Eigen/Geometry>
|
|
#include <Eigen/Geometry>
|
|
|
|
|
|
#define SQRT_ONE_OVER_THREE 0.57735026918962573
|
|
#define SQRT_ONE_OVER_THREE 0.57735026918962573
|
|
-template <typename DerivedV, typename DerivedF>
|
|
|
|
|
|
+template <typename DerivedV, typename DerivedF, typename DerivedZ, typename DerivedN>
|
|
IGL_INLINE void igl::per_face_normals(
|
|
IGL_INLINE void igl::per_face_normals(
|
|
const Eigen::PlainObjectBase<DerivedV>& V,
|
|
const Eigen::PlainObjectBase<DerivedV>& V,
|
|
const Eigen::PlainObjectBase<DerivedF>& F,
|
|
const Eigen::PlainObjectBase<DerivedF>& F,
|
|
- Eigen::PlainObjectBase<DerivedV> & N)
|
|
|
|
|
|
+ const Eigen::PlainObjectBase<DerivedZ> & Z,
|
|
|
|
+ Eigen::PlainObjectBase<DerivedN> & N)
|
|
{
|
|
{
|
|
N.resize(F.rows(),3);
|
|
N.resize(F.rows(),3);
|
|
// loop over faces
|
|
// loop over faces
|
|
@@ -17,20 +18,30 @@ IGL_INLINE void igl::per_face_normals(
|
|
Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v1 = V.row(F(i,1)) - V.row(F(i,0));
|
|
Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v1 = V.row(F(i,1)) - V.row(F(i,0));
|
|
Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v2 = V.row(F(i,2)) - V.row(F(i,0));
|
|
Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v2 = V.row(F(i,2)) - V.row(F(i,0));
|
|
N.row(i) = v1.cross(v2);//.normalized();
|
|
N.row(i) = v1.cross(v2);//.normalized();
|
|
- if(N.row(i).sum() == 0)
|
|
|
|
|
|
+ typename DerivedV::Scalar r = N.row(i).norm();
|
|
|
|
+ if(r == 0)
|
|
{
|
|
{
|
|
- N(i,0) = SQRT_ONE_OVER_THREE;
|
|
|
|
- N(i,1) = SQRT_ONE_OVER_THREE;
|
|
|
|
- N(i,2) = SQRT_ONE_OVER_THREE;
|
|
|
|
|
|
+ N.row(i) = Z;
|
|
}else
|
|
}else
|
|
{
|
|
{
|
|
- N.row(i) = N.row(i).normalized().eval();
|
|
|
|
|
|
+ N.row(i) /= r;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+template <typename DerivedV, typename DerivedF, typename DerivedN>
|
|
|
|
+IGL_INLINE void igl::per_face_normals(
|
|
|
|
+ const Eigen::PlainObjectBase<DerivedV>& V,
|
|
|
|
+ const Eigen::PlainObjectBase<DerivedF>& F,
|
|
|
|
+ Eigen::PlainObjectBase<DerivedN> & N)
|
|
|
|
+{
|
|
|
|
+ using namespace Eigen;
|
|
|
|
+ Matrix<typename DerivedN::Scalar,3,1> Z(0,0,0);
|
|
|
|
+ return per_face_normals(V,F,Z,N);
|
|
|
|
+}
|
|
|
|
+
|
|
#ifndef IGL_HEADER_ONLY
|
|
#ifndef IGL_HEADER_ONLY
|
|
// Explicit template specialization
|
|
// Explicit template specialization
|
|
-// generated by autoexplicit.sh
|
|
|
|
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> >&);
|
|
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> >&);
|
|
-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> >&);
|
|
|
|
|
|
+template void igl::per_face_normals<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, -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, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
|
|
#endif
|
|
#endif
|