|
@@ -32,12 +32,20 @@ namespace igl {
|
|
|
// i, and A is the area of triangle (i,j,k). ^R90 represent a rotation of
|
|
|
// 90 degrees
|
|
|
//
|
|
|
- void grad(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::VectorXd &X, Eigen::MatrixXd &G );
|
|
|
+ template <typename T>
|
|
|
+ inline void grad(const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &V,
|
|
|
+ const Eigen::MatrixXi &F,
|
|
|
+ const Eigen::Matrix<T, Eigen::Dynamic, 1>&X,
|
|
|
+ Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &G );
|
|
|
}
|
|
|
|
|
|
-inline void igl::grad(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::VectorXd &X, Eigen::MatrixXd &G)
|
|
|
+template <typename T>
|
|
|
+inline void igl::grad(const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &V,
|
|
|
+ const Eigen::MatrixXi &F,
|
|
|
+ const Eigen::Matrix<T, Eigen::Dynamic, 1>&X,
|
|
|
+ Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &G )
|
|
|
{
|
|
|
- G = Eigen::MatrixXd::Zero(F.rows(),3);
|
|
|
+ G = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>::Zero(F.rows(),3);
|
|
|
for (int i = 0; i<F.rows(); ++i)
|
|
|
{
|
|
|
// renaming indices of vertices of triangles for convenience
|
|
@@ -46,28 +54,28 @@ inline void igl::grad(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const
|
|
|
int i3 = F(i,2);
|
|
|
|
|
|
// #F x 3 matrices of triangle edge vectors, named after opposite vertices
|
|
|
- Eigen::RowVector3d v32 = V.row(i3) - V.row(i2);
|
|
|
- Eigen::RowVector3d v13 = V.row(i1) - V.row(i3);
|
|
|
- Eigen::RowVector3d v21 = V.row(i2) - V.row(i1);
|
|
|
+ Eigen::Matrix<T, 1, 3> v32 = V.row(i3) - V.row(i2);
|
|
|
+ Eigen::Matrix<T, 1, 3> v13 = V.row(i1) - V.row(i3);
|
|
|
+ Eigen::Matrix<T, 1, 3> v21 = V.row(i2) - V.row(i1);
|
|
|
|
|
|
// area of parallelogram is twice area of triangle
|
|
|
// area of parallelogram is || v1 x v2 ||
|
|
|
- Eigen::RowVector3d n = v32.cross(v13);
|
|
|
+ Eigen::Matrix<T, 1, 3> n = v32.cross(v13);
|
|
|
|
|
|
// This does correct l2 norm of rows, so that it contains #F list of twice
|
|
|
// triangle areas
|
|
|
double dblA = std::sqrt(n.dot(n));
|
|
|
|
|
|
// now normalize normals to get unit normals
|
|
|
- Eigen::RowVector3d u = n / dblA;
|
|
|
+ Eigen::Matrix<T, 1, 3> u = n / dblA;
|
|
|
|
|
|
// rotate each vector 90 degrees around normal
|
|
|
double norm21 = std::sqrt(v21.dot(v21));
|
|
|
double norm13 = std::sqrt(v13.dot(v13));
|
|
|
- Eigen::RowVector3d eperp21 = u.cross(v21);
|
|
|
+ Eigen::Matrix<T, 1, 3> eperp21 = u.cross(v21);
|
|
|
eperp21 = eperp21 / std::sqrt(eperp21.dot(eperp21));
|
|
|
eperp21 *= norm21;
|
|
|
- Eigen::RowVector3d eperp13 = u.cross(v13);
|
|
|
+ Eigen::Matrix<T, 1, 3> eperp13 = u.cross(v13);
|
|
|
eperp13 = eperp13 / std::sqrt(eperp13.dot(eperp13));
|
|
|
eperp13 *= norm13;
|
|
|
|