瀏覽代碼

better templates for floats

Former-commit-id: cc7834724d8bbbcedd8ae954ecfedf24404afc11
Alec Jacobson 9 年之前
父節點
當前提交
cc6d3c5c16
共有 2 個文件被更改,包括 10 次插入7 次删除
  1. 7 5
      include/igl/internal_angles.cpp
  2. 3 2
      include/igl/per_vertex_normals.cpp

+ 7 - 5
include/igl/internal_angles.cpp

@@ -18,11 +18,12 @@ IGL_INLINE void igl::internal_angles(
 {
   using namespace Eigen;
   using namespace std;
+  typedef typename DerivedV::Scalar Scalar;
   if(F.cols() == 3)
   {
     // Edge lengths
     Matrix<
-      typename DerivedV::Scalar,
+      Scalar,
       DerivedF::RowsAtCompileTime,
       DerivedF::ColsAtCompileTime> L;
     edge_lengths(V,F,L);
@@ -38,11 +39,12 @@ IGL_INLINE void igl::internal_angles(
       const Eigen::PlainObjectBase<DerivedV>& y, 
       const Eigen::PlainObjectBase<DerivedV>& z)
     {
-      Eigen::RowVector3d v1 = (x-y).normalized();
-      Eigen::RowVector3d v2 = (z-y).normalized();
+      typedef Eigen::Matrix<Scalar,1,3> RowVector3S;
+      RowVector3S v1 = (x-y).normalized();
+      RowVector3S v2 = (z-y).normalized();
       // http://stackoverflow.com/questions/10133957/signed-angle-between-two-vectors-without-a-reference-plane
-      double s = v1.cross(v2).norm();
-      double c = v1.dot(v2);
+      Scalar s = v1.cross(v2).norm();
+      Scalar c = v1.dot(v2);
       return atan2(s, c);
     };
     for(unsigned i=0; i<F.rows(); ++i)

+ 3 - 2
include/igl/per_vertex_normals.cpp

@@ -45,7 +45,8 @@ IGL_INLINE void igl::per_vertex_normals(
   // Resize for output
   N.setZero(V.rows(),3);
 
-  Eigen::MatrixXd W(F.rows(),3);
+  Eigen::Matrix<typename DerivedN::Scalar,DerivedF::RowsAtCompileTime,3> 
+    W(F.rows(),3);
   switch(weighting)
   {
     case PER_VERTEX_NORMALS_WEIGHTING_TYPE_UNIFORM:
@@ -56,7 +57,7 @@ IGL_INLINE void igl::per_vertex_normals(
     case PER_VERTEX_NORMALS_WEIGHTING_TYPE_DEFAULT:
     case PER_VERTEX_NORMALS_WEIGHTING_TYPE_AREA:
     {
-      Eigen::VectorXd A;
+      Eigen::Matrix<typename DerivedN::Scalar,DerivedF::RowsAtCompileTime,1> A;
       doublearea(V,F,A);
       W = A.replicate(1,3);
       break;