Browse Source

Add RowMajor storage order support

Former-commit-id: 7e599d37fc0d36036b683e256daa2a38b4755934
schuellc 9 years ago
parent
commit
0ea2eca5d4

+ 8 - 9
include/igl/average_onto_vertices.cpp

@@ -7,15 +7,15 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "average_onto_vertices.h"
 
-template <typename T, typename I>
-IGL_INLINE void igl::average_onto_vertices(const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &V,
-            const Eigen::Matrix<I, Eigen::Dynamic, Eigen::Dynamic> &F,
-            const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &S,
-            Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &SV)
+template<typename DerivedV,typename DerivedF,typename DerivedS>
+IGL_INLINE void igl::average_onto_vertices(const Eigen::MatrixBase<DerivedV> &V,
+  const Eigen::MatrixBase<DerivedF> &F,
+  const Eigen::MatrixBase<DerivedS> &S,
+  Eigen::MatrixBase<DerivedS> &SV)
 {
-
-  SV = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>::Zero(V.rows(),S.cols());
-  Eigen::Matrix<T, Eigen::Dynamic, 1> COUNT = Eigen::Matrix<T, Eigen::Dynamic, 1>::Zero(V.rows());
+  SV = DerivedS::Zero(V.rows(),S.cols());
+  Eigen::Matrix<DerivedF::Scalar,Eigen::Dynamic,1> COUNT(V.rows());
+  COUNT.setZero();
   for (int i = 0; i <F.rows(); ++i)
   {
     for (int j = 0; j<F.cols(); ++j)
@@ -26,7 +26,6 @@ IGL_INLINE void igl::average_onto_vertices(const Eigen::Matrix<T, Eigen::Dynamic
   }
   for (int i = 0; i <V.rows(); ++i)
     SV.row(i) /= COUNT[i];
-
 };
 
 #ifdef IGL_STATIC_LIBRARY

+ 5 - 6
include/igl/average_onto_vertices.h

@@ -21,12 +21,11 @@ namespace igl
   // 
   // Output:
   // SV: scalar field defined on vertices
-  template <typename T, typename I>
-  IGL_INLINE void average_onto_vertices(
-    const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &V,
-    const Eigen::Matrix<I, Eigen::Dynamic, Eigen::Dynamic> &F,
-    const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &S,
-    Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &SV);
+  template<typename DerivedV,typename DerivedF,typename DerivedS>
+  IGL_INLINE void average_onto_vertices(const Eigen::MatrixBase<DerivedV> &V,
+    const Eigen::MatrixBase<DerivedF> &F,
+    const Eigen::MatrixBase<DerivedS> &S,
+    Eigen::MatrixBase<DerivedS> &SV);
 }
 
 #ifndef IGL_STATIC_LIBRARY

+ 2 - 2
include/igl/boundary_loop.cpp

@@ -23,8 +23,8 @@ IGL_INLINE void igl::boundary_loop(
   if(F.rows() == 0)
     return;
 
-  MatrixXd Vdummy(F.maxCoeff()+1,1);
-  MatrixXi TT,TTi;
+  VectorXd Vdummy(F.maxCoeff()+1,1);
+  DerivedF TT,TTi;
   vector<std::vector<int> > VF, VFi;
   triangle_triangle_adjacency(Vdummy,F,TT,TTi);
   vertex_triangle_adjacency(Vdummy,F,VF,VFi);

+ 6 - 6
include/igl/list_to_matrix.cpp

@@ -15,8 +15,8 @@
 #include "max_size.h"
 #include "min_size.h"
 
-template <typename T, class Mat>
-IGL_INLINE bool igl::list_to_matrix(const std::vector<std::vector<T > > & V,Mat & M)
+template <typename T, typename Derived>
+IGL_INLINE bool igl::list_to_matrix(const std::vector<std::vector<T > > & V,Eigen::PlainObjectBase<Derived>& M)
 {
   // number of rows
   int m = V.size();
@@ -48,12 +48,12 @@ IGL_INLINE bool igl::list_to_matrix(const std::vector<std::vector<T > > & V,Mat
   return true;
 }
 
-template <typename T, class Mat>
+template <typename T, typename Derived>
 IGL_INLINE bool igl::list_to_matrix(
   const std::vector<std::vector<T > > & V,
   const int n,
   const T & padding,
-  Mat & M)
+  Eigen::PlainObjectBase<Derived>& M)
 {
   const int m = V.size();
   M.resize(m,n);
@@ -77,8 +77,8 @@ IGL_INLINE bool igl::list_to_matrix(
   return true;
 }
 
-template <typename T, class Mat>
-IGL_INLINE bool igl::list_to_matrix(const std::vector<T > & V,Mat & M)
+template <typename T, typename Derived>
+IGL_INLINE bool igl::list_to_matrix(const std::vector<T > & V,Eigen::PlainObjectBase<Derived>& M)
 {
   // number of rows
   int m = V.size();

+ 6 - 6
include/igl/list_to_matrix.h

@@ -22,10 +22,10 @@ namespace igl
   // Outputs:
   //   M  an m by n matrix
   // Returns true on success, false on errors
-  template <typename T, class Mat>
+  template <typename T, typename Derived>
   IGL_INLINE bool list_to_matrix(
     const std::vector<std::vector<T > > & V,
-    Mat & M);
+    Eigen::PlainObjectBase<Derived>& M);
   // Convert a list of row vectors of `n` or less to a matrix and pad on
   // the right with `padding`:
   //
@@ -35,15 +35,15 @@ namespace igl
   //   padding  value to fill in from right for short rows
   // Outputs:
   //   M  an m by n matrix
-  template <typename T, class Mat>
+  template <typename T, typename Derived>
   IGL_INLINE bool list_to_matrix(
     const std::vector<std::vector<T > > & V,
     const int n,
     const T & padding,
-    Mat & M);
+    Eigen::PlainObjectBase<Derived>& M);
   // Vector wrapper
-  template <typename T, class Mat>
-  IGL_INLINE bool list_to_matrix(const std::vector<T > & V,Mat & M);
+  template <typename T, typename Derived>
+  IGL_INLINE bool list_to_matrix(const std::vector<T > & V,Eigen::PlainObjectBase<Derived>& M);
 }
 
 #ifndef IGL_STATIC_LIBRARY

+ 8 - 7
include/igl/triangle_triangle_adjacency.h

@@ -27,7 +27,7 @@ namespace igl
   // Outputs:
   //   TT   #F by #3 adjacent matrix, the element i,j is the id of the triangle adjacent to the j edge of triangle i
   //   TTi  #F by #3 adjacent matrix, the element i,j is the id of edge of the triangle TT(i,j) that is adjacent with triangle i
-  // NOTE: the first edge of a triangle is [0,1] the second [1,2] and the third [2,3].
+  // NOTE: the first edge of a triangle is [0,1] the second [1,2] and the third [2,0].
   //       this convention is DIFFERENT from cotmatrix_entries.h
   // Known bug: this should not need to take V as input.
 
@@ -36,6 +36,7 @@ namespace igl
     const Eigen::PlainObjectBase<Scalar>& V,
     const Eigen::PlainObjectBase<Index>& F,
     Eigen::PlainObjectBase<Index>& TT);
+
   // Compute triangle-triangle adjacency with indices
   template <typename Scalar, typename Index>
   IGL_INLINE void triangle_triangle_adjacency(
@@ -84,8 +85,8 @@ namespace igl
   //     TT[i][c][0] is an edge-neighbor of face i incident on the edge of face
   //     TT[i][c][0] opposite corner j, and TT[i][c][1] " corner k, etc.
   template <
-    typename DerivedF, 
-    typename TTIndex, 
+    typename DerivedF,
+    typename TTIndex,
     typename TTiIndex>
     IGL_INLINE void triangle_triangle_adjacency(
       const Eigen::PlainObjectBase<DerivedF> & F,
@@ -98,8 +99,8 @@ namespace igl
   // Wrapper with bool to choose whether to compute TTi (this prototype should
   // be "hidden").
   template <
-    typename DerivedF, 
-    typename TTIndex, 
+    typename DerivedF,
+    typename TTIndex,
     typename TTiIndex>
     IGL_INLINE void triangle_triangle_adjacency(
       const Eigen::PlainObjectBase<DerivedF> & F,
@@ -113,10 +114,10 @@ namespace igl
   //   uE2E  #uE list of lists of indices into E of coexisting edges
   // See also: unique_edge_map, all_edges
   template <
-    typename DerivedE, 
+    typename DerivedE,
     typename DerivedEMAP,
     typename uE2EType,
-    typename TTIndex, 
+    typename TTIndex,
     typename TTiIndex>
     IGL_INLINE void triangle_triangle_adjacency(
       const Eigen::PlainObjectBase<DerivedE> & E,