Browse Source

handle streams of arbitrary dimension triangles

Former-commit-id: e7751abb9bc5e67ab57ace87a519db4055d94954
Alec Jacobson 9 years ago
parent
commit
8eee88cd05
2 changed files with 23 additions and 14 deletions
  1. 22 6
      include/igl/doublearea.cpp
  2. 1 8
      include/igl/doublearea.h

+ 22 - 6
include/igl/doublearea.cpp

@@ -85,14 +85,30 @@ IGL_INLINE void igl::doublearea(
   const Eigen::PlainObjectBase<DerivedC> & C,
   Eigen::PlainObjectBase<DerivedD> & D)
 {
-  assert(A.cols() == 2 && "corners should be 2d");
-  assert(B.cols() == 2 && "corners should be 2d");
-  assert(C.cols() == 2 && "corners should be 2d");
+  assert((B.cols() == A.cols()) && "dimensions of A and B should match");
+  assert((C.cols() == A.cols()) && "dimensions of A and C should match");
   assert(A.rows() == B.rows() && "corners should have same length");
   assert(A.rows() == C.rows() && "corners should have same length");
-  const auto & R = A-C;
-  const auto & S = B-C;
-  D = R.col(0).array()*S.col(1).array() - R.col(1).array()*S.col(0).array();
+  switch(A.cols())
+  {
+    case 2:
+    {
+      // For 2d compute signed area
+      const auto & R = A-C;
+      const auto & S = B-C;
+      D = R.col(0).array()*S.col(1).array() - R.col(1).array()*S.col(0).array();
+      break;
+    }
+    default:
+    {
+      Eigen::Matrix<typename DerivedD::Scalar,DerivedD::RowsAtCompileTime,3> 
+        uL(A.rows(),3);
+      uL.col(0) = (B-C).rowwise().norm();
+      uL.col(1) = (C-A).rowwise().norm();
+      uL.col(2) = (A-B).rowwise().norm();
+      doublearea(uL,D);
+    }
+  }
 }
 
 template <

+ 1 - 8
include/igl/doublearea.h

@@ -33,7 +33,7 @@ namespace igl
     const Eigen::PlainObjectBase<DerivedV> & V,
     const Eigen::PlainObjectBase<DerivedF> & F,
     Eigen::PlainObjectBase<DeriveddblA> & dblA);
-  // Stream of triangles
+  // Stream of triangles, computes signed area...
   template <
     typename DerivedA,
     typename DerivedB,
@@ -56,13 +56,6 @@ namespace igl
     const Eigen::PlainObjectBase<DerivedB> & B,
     const Eigen::PlainObjectBase<DerivedC> & C);
   // Same as above but use instrinsic edge lengths rather than (V,F) mesh
-  // Templates:
-  //   DerivedV  derived type of eigen matrix for V (e.g. derived from
-  //     MatrixXd)
-  //   DerivedF  derived type of eigen matrix for F (e.g. derived from
-  //     MatrixXi)
-  //   DeriveddblA  derived type of eigen matrix for dblA (e.g. derived from
-  //     MatrixXd)
   // Inputs:
   //   l  #F by dim list of edge lengths using
   //     for triangles, columns correspond to edges 23,31,12