Преглед изворни кода

list to matrix with padding (poly mesh to quads)

Former-commit-id: 83db75d43ca182cae7cd7d72c3cf2d738d05e52e
Alec Jacobson пре 10 година
родитељ
комит
9a0724c2c1
2 измењених фајлова са 44 додато и 0 уклоњено
  1. 29 0
      include/igl/list_to_matrix.cpp
  2. 15 0
      include/igl/list_to_matrix.h

+ 29 - 0
include/igl/list_to_matrix.cpp

@@ -53,6 +53,35 @@ IGL_INLINE bool igl::list_to_matrix(const std::vector<std::vector<T > > & V,Mat
   return true;
 }
 
+template <typename T, class Mat>
+IGL_INLINE bool igl::list_to_matrix(
+  const std::vector<std::vector<T > > & V,
+  const int n,
+  const T & padding,
+  Mat & M)
+{
+  const int m = V.size();
+  M.resize(m,n);
+  for(int i = 0;i<m;i++)
+  {
+    const auto & row = V[i];
+    if(row.size()>n)
+    {
+      return false;
+    }
+    int j = 0;
+    for(;j<row.size();j++)
+    {
+      M(i,j) = row[j];
+    }
+    for(;j<n;j++)
+    {
+      M(i,j) = padding;
+    }
+  }
+  return true;
+}
+
 template <typename T, class Mat>
 IGL_INLINE bool igl::list_to_matrix(const std::vector<T > & V,Mat & M)
 {

+ 15 - 0
include/igl/list_to_matrix.h

@@ -26,6 +26,21 @@ namespace igl
   IGL_INLINE bool list_to_matrix(
     const std::vector<std::vector<T > > & V,
     Mat & M);
+  // Convert a list of row vectors of `n` or less to a matrix and pad on
+  // the right with `padding`:
+  //
+  // Inputs:
+  //   V  a m-long list of vectors of size <=n
+  //   n  number of columns
+  //   padding  value to fill in from right for short rows
+  // Outputs:
+  //   M  an m by n matrix
+  template <typename T, class Mat>
+  IGL_INLINE bool list_to_matrix(
+    const std::vector<std::vector<T > > & V,
+    const int n,
+    const T & padding,
+    Mat & M);
   // Vector wrapper
   template <typename T, class Mat>
   IGL_INLINE bool list_to_matrix(const std::vector<T > & V,Mat & M);