소스 검색

slice using bools

Former-commit-id: c146656ff1b62a539367d570a56449c84c36d119
Alec Jacobson 10 년 전
부모
커밋
c88d6be38a
2개의 변경된 파일132개의 추가작업 그리고 1개의 파일을 삭제
  1. 109 1
      include/igl/slice.cpp
  2. 23 0
      include/igl/slice.h

+ 109 - 1
include/igl/slice.cpp

@@ -143,6 +143,93 @@ 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)
+{
+  int xm = X.rows();
+  int xn = X.cols();
+  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>
 template <typename DerivedX>
 IGL_INLINE void igl::slice(
 IGL_INLINE void igl::slice(
   const Eigen::PlainObjectBase<DerivedX> & X,
   const Eigen::PlainObjectBase<DerivedX> & X,
@@ -173,11 +260,32 @@ IGL_INLINE Eigen::PlainObjectBase<DerivedX> igl::slice(
   const int dim)
   const int dim)
 {
 {
   Eigen::PlainObjectBase<DerivedX> Y;
   Eigen::PlainObjectBase<DerivedX> Y;
-  // phony column indices
   igl::slice(X,R,dim,Y);
   igl::slice(X,R,dim,Y);
   return 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 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
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
 // Explicit template specialization
 // generated by autoexplicit.sh
 // generated by autoexplicit.sh

+ 23 - 0
include/igl/slice.h

@@ -47,6 +47,19 @@ namespace igl
     const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
     const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
     Eigen::PlainObjectBase<DerivedX> & Y);
     Eigen::PlainObjectBase<DerivedX> & Y);
   template <typename DerivedX>
   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(
   IGL_INLINE void slice(
     const Eigen::PlainObjectBase<DerivedX> & X,
     const Eigen::PlainObjectBase<DerivedX> & X,
     const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
     const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
@@ -61,6 +74,16 @@ namespace igl
     const Eigen::PlainObjectBase<DerivedX>& X,
     const Eigen::PlainObjectBase<DerivedX>& X,
     const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
     const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
     const int dim);
     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
 #ifndef IGL_STATIC_LIBRARY