Pārlūkot izejas kodu

move slice mask to separate h,cpp

Former-commit-id: 829bff3d1b6ca15c655b3612cf1cdb975f4ae717
Alec Jacobson 10 gadi atpakaļ
vecāks
revīzija
bb9511485f
4 mainītis faili ar 175 papildinājumiem un 131 dzēšanām
  1. 0 106
      include/igl/slice.cpp
  2. 5 25
      include/igl/slice.h
  3. 113 0
      include/igl/slice_mask.cpp
  4. 57 0
      include/igl/slice_mask.h

+ 0 - 106
include/igl/slice.cpp

@@ -209,90 +209,6 @@ IGL_INLINE void igl::slice(
   }
 }
 
-template <typename DerivedX>
-IGL_INLINE void igl::slice_mask(
-  const Eigen::PlainObjectBase<DerivedX> & X,
-  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-  const Eigen::Array<bool,Eigen::Dynamic,1> & C,
-  Eigen::PlainObjectBase<DerivedX> & Y)
-{
-  int xm = X.rows();
-  int xn = X.cols();
-  int ym = R.count();
-  int yn = C.count();
-  assert(R.size() == X.rows() && "R.size() should match X.rows()");
-  assert(C.size() == X.cols() && "C.size() should match X.cols()");
-  Y.resize(ym,yn);
-  {
-    int yi = 0;
-    for(int i = 0;i<xm;i++)
-    {
-      if(R(i))
-      {
-        int yj = 0;
-        for(int j = 0;j<xn;j++)
-        {
-          if(C(j))
-          {
-            Y(yi,yj) = X(i,j);
-            yj++;
-          }
-        }
-        yi++;
-      }
-    }
-  }
-}
-
-template <typename DerivedX>
-IGL_INLINE void igl::slice_mask(
-  const Eigen::PlainObjectBase<DerivedX> & X,
-  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-  const int dim,
-  Eigen::PlainObjectBase<DerivedX> & Y)
-{
-  switch(dim)
-  {
-    case 1:
-    {
-      const int ym = R.count();
-      Y.resize(ym,X.cols());
-      assert(X.rows() == R.size() && "X.rows() should match R.size()");
-      {
-        int yi = 0;
-        for(int i = 0;i<X.rows();i++)
-        {
-          if(R(i))
-          {
-            Y.row(yi++) = X.row(i);
-          }
-        }
-      }
-      return;
-    }
-    case 2:
-    {
-      const auto & C = R;
-      const int yn = C.count();
-      Y.resize(X.rows(),yn);
-      assert(X.cols() == R.size() && "X.cols() should match R.size()");
-      {
-        int yj = 0;
-        for(int j = 0;j<X.cols();j++)
-        {
-          if(C(j))
-          {
-            Y.col(yj++) = X.col(j);
-          }
-        }
-      }
-      return;
-    }
-    default:
-      assert(false && "Unsupported dimension");
-      return;
-  }
-}
 
 template <typename DerivedX>
 IGL_INLINE void igl::slice(
@@ -328,28 +244,6 @@ IGL_INLINE Eigen::PlainObjectBase<DerivedX> igl::slice(
   return Y;
 }
 
-template <typename DerivedX>
-IGL_INLINE Eigen::PlainObjectBase<DerivedX> igl::slice_mask(
-  const Eigen::PlainObjectBase<DerivedX> & X,
-  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-  const Eigen::Array<bool,Eigen::Dynamic,1> & C)
-{
-  Eigen::PlainObjectBase<DerivedX> Y;
-  igl::slice_mask(X,R,C,Y);
-  return Y;
-}
-
-template <typename DerivedX>
-IGL_INLINE Eigen::PlainObjectBase<DerivedX> igl::slice_mask(
-  const Eigen::PlainObjectBase<DerivedX>& X,
-  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-  const int dim)
-{
-  Eigen::PlainObjectBase<DerivedX> Y;
-  igl::slice_mask(X,R,dim,Y);
-  return Y;
-}
-
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
 // generated by autoexplicit.sh

+ 5 - 25
include/igl/slice.h

@@ -9,12 +9,11 @@
 #define IGL_SLICE_H
 #include "igl_inline.h"
 
-#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
 #include <Eigen/Sparse>
-
 namespace igl
 {
-  // Act like the matlab X(row_indices,col_indices) operator
+  // Act like the matlab X(row_indices,col_indices) operator, where
+  // row_indices, col_indices are non-negative integer indices.
   // 
   // Inputs:
   //   X  m by n matrix
@@ -22,6 +21,8 @@ namespace igl
   //   C  list of column indices
   // Output:
   //   Y  #R by #C matrix
+  //
+  // See also: slice_mask
   template <typename T>
   IGL_INLINE void slice(
     const Eigen::SparseMatrix<T>& X,
@@ -46,18 +47,6 @@ namespace igl
     const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
     const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
     Eigen::PlainObjectBase<DerivedX> & Y);
-  template <typename DerivedX>
-  IGL_INLINE void slice_mask(
-    const Eigen::PlainObjectBase<DerivedX> & X,
-    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-    const Eigen::Array<bool,Eigen::Dynamic,1> & C,
-    Eigen::PlainObjectBase<DerivedX> & Y);
-  template <typename DerivedX>
-  IGL_INLINE void slice_mask(
-    const Eigen::PlainObjectBase<DerivedX> & X,
-    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-    const int dim,
-    Eigen::PlainObjectBase<DerivedX> & Y);
 
   template <typename DerivedX>
   IGL_INLINE void slice(
@@ -74,16 +63,7 @@ namespace igl
     const Eigen::PlainObjectBase<DerivedX>& X,
     const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
     const int dim);
-  template <typename DerivedX>
-  IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice_mask(
-    const Eigen::PlainObjectBase<DerivedX> & X,
-    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-    const Eigen::Array<bool,Eigen::Dynamic,1> & C);
-  template <typename DerivedX>
-  IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice_mask(
-    const Eigen::PlainObjectBase<DerivedX> & X,
-    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-    const int dim);
+
 }
 
 #ifndef IGL_STATIC_LIBRARY

+ 113 - 0
include/igl/slice_mask.cpp

@@ -0,0 +1,113 @@
+#include "slice_mask.h"
+#include <cassert>
+
+template <typename DerivedX>
+IGL_INLINE void igl::slice_mask(
+  const Eigen::PlainObjectBase<DerivedX> & X,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & C,
+  Eigen::PlainObjectBase<DerivedX> & Y)
+{
+  int xm = X.rows();
+  int xn = X.cols();
+  int ym = R.count();
+  int yn = C.count();
+  assert(R.size() == X.rows() && "R.size() should match X.rows()");
+  assert(C.size() == X.cols() && "C.size() should match X.cols()");
+  Y.resize(ym,yn);
+  {
+    int yi = 0;
+    for(int i = 0;i<xm;i++)
+    {
+      if(R(i))
+      {
+        int yj = 0;
+        for(int j = 0;j<xn;j++)
+        {
+          if(C(j))
+          {
+            Y(yi,yj) = X(i,j);
+            yj++;
+          }
+        }
+        yi++;
+      }
+    }
+  }
+}
+
+template <typename DerivedX>
+IGL_INLINE void igl::slice_mask(
+  const Eigen::PlainObjectBase<DerivedX> & X,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+  const int dim,
+  Eigen::PlainObjectBase<DerivedX> & Y)
+{
+  switch(dim)
+  {
+    case 1:
+    {
+      const int ym = R.count();
+      Y.resize(ym,X.cols());
+      assert(X.rows() == R.size() && "X.rows() should match R.size()");
+      {
+        int yi = 0;
+        for(int i = 0;i<X.rows();i++)
+        {
+          if(R(i))
+          {
+            Y.row(yi++) = X.row(i);
+          }
+        }
+      }
+      return;
+    }
+    case 2:
+    {
+      const auto & C = R;
+      const int yn = C.count();
+      Y.resize(X.rows(),yn);
+      assert(X.cols() == R.size() && "X.cols() should match R.size()");
+      {
+        int yj = 0;
+        for(int j = 0;j<X.cols();j++)
+        {
+          if(C(j))
+          {
+            Y.col(yj++) = X.col(j);
+          }
+        }
+      }
+      return;
+    }
+    default:
+      assert(false && "Unsupported dimension");
+      return;
+  }
+}
+
+template <typename DerivedX>
+IGL_INLINE Eigen::PlainObjectBase<DerivedX> igl::slice_mask(
+  const Eigen::PlainObjectBase<DerivedX> & X,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & C)
+{
+  Eigen::PlainObjectBase<DerivedX> Y;
+  igl::slice_mask(X,R,C,Y);
+  return Y;
+}
+
+template <typename DerivedX>
+IGL_INLINE Eigen::PlainObjectBase<DerivedX> igl::slice_mask(
+  const Eigen::PlainObjectBase<DerivedX>& X,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+  const int dim)
+{
+  Eigen::PlainObjectBase<DerivedX> Y;
+  igl::slice_mask(X,R,dim,Y);
+  return Y;
+}
+
+#ifdef IGL_STATIC_LIBRARY
+template void igl::slice_mask<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::Array<bool, -1, 1, 0, -1, 1> const&, int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
+#endif

+ 57 - 0
include/igl/slice_mask.h

@@ -0,0 +1,57 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License 
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+// obtain one at http://mozilla.org/MPL/2.0/.
+#ifndef IGL_SLICE_MASK_H
+#define IGL_SLICE_MASK_H
+#include "igl_inline.h"
+
+#include <Eigen/Sparse>
+namespace igl
+{
+  // Act like the matlab X(row_mask,col_mask) operator, where
+  // row_mask, col_mask are non-negative integer indices.
+  // 
+  // Inputs:
+  //   X  m by n matrix
+  //   R  m list of row bools
+  //   C  n list of column bools
+  // Output:
+  //   Y  #trues-in-R by #trues-in-C matrix
+  //
+  // See also: slice_mask
+  
+  template <typename DerivedX>
+  IGL_INLINE void slice_mask(
+    const Eigen::PlainObjectBase<DerivedX> & X,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & C,
+    Eigen::PlainObjectBase<DerivedX> & Y);
+  template <typename DerivedX>
+  IGL_INLINE void slice_mask(
+    const Eigen::PlainObjectBase<DerivedX> & X,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+    const int dim,
+    Eigen::PlainObjectBase<DerivedX> & Y);
+
+  template <typename DerivedX>
+  IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice_mask(
+    const Eigen::PlainObjectBase<DerivedX> & X,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & C);
+  template <typename DerivedX>
+  IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice_mask(
+    const Eigen::PlainObjectBase<DerivedX> & X,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+    const int dim);
+}
+
+
+#ifndef IGL_STATIC_LIBRARY
+#  include "slice_mask.cpp"
+#endif
+
+#endif