Procházet zdrojové kódy

trivially extend to sparse matrices

Former-commit-id: fff3e2e84c543361d0158c47fc4aa1fbd0edadc8
Alec Jacobson před 8 roky
rodič
revize
03c9c841dc
2 změnil soubory, kde provedl 44 přidání a 3 odebrání
  1. 32 3
      include/igl/slice_mask.cpp
  2. 12 0
      include/igl/slice_mask.h

+ 32 - 3
include/igl/slice_mask.cpp

@@ -6,6 +6,8 @@
 // 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/.
 #include "slice_mask.h"
+#include "slice.h"
+#include "find.h"
 #include <cassert>
 
 template <typename DerivedX,typename DerivedY>
@@ -115,15 +117,42 @@ IGL_INLINE DerivedX igl::slice_mask(
   return Y;
 }
 
+
+template <typename XType, typename YType>
+IGL_INLINE void igl::slice_mask(
+  const Eigen::SparseMatrix<XType> & X,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+  const int dim,
+  Eigen::SparseMatrix<YType> & Y)
+{
+  // Cheapskate solution
+  Eigen::VectorXi Ri;
+  find(R,Ri);
+  return slice(X,Ri,dim,Y);
+}
+
+template <typename XType, typename YType>
+IGL_INLINE void igl::slice_mask(
+  const Eigen::SparseMatrix<XType> & X,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & C,
+  Eigen::SparseMatrix<YType> & Y)
+{
+  // Cheapskate solution
+  Eigen::VectorXi Ri;
+  find(R,Ri);
+  Eigen::VectorXi Ci;
+  find(C,Ci);
+  return slice(X,Ri,Ci,Y);
+}
+
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
 // generated by autoexplicit.sh
+template void igl::slice_mask<bool, bool>(Eigen::SparseMatrix<bool, 0, int> const&, Eigen::Array<bool, -1, 1, 0, -1, 1> const&, int, Eigen::SparseMatrix<bool, 0, int>&);
 template void igl::slice_mask<Eigen::Matrix<double, -1, 2, 0, -1, 2>, Eigen::Matrix<double, -1, 2, 0, -1, 2> >(Eigen::DenseBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> > const&, Eigen::Array<bool, -1, 1, 0, -1, 1> const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> >&);
-// generated by autoexplicit.sh
 template void igl::slice_mask<Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, 2, 0, -1, 2> >(Eigen::DenseBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> > const&, Eigen::Array<bool, -1, 1, 0, -1, 1> const&, int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> >&);
-// generated by autoexplicit.sh
 template void igl::slice_mask<Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::DenseBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> > const&, Eigen::Array<bool, -1, 1, 0, -1, 1> const&, int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
-// generated by autoexplicit.sh
 template void igl::slice_mask<Eigen::Array<bool, -1, 1, 0, -1, 1>, Eigen::Array<bool, -1, 1, 0, -1, 1> >(Eigen::DenseBase<Eigen::Array<bool, -1, 1, 0, -1, 1> > const&, Eigen::Array<bool, -1, 1, 0, -1, 1> const&, int, Eigen::PlainObjectBase<Eigen::Array<bool, -1, 1, 0, -1, 1> >&);
 template void igl::slice_mask<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::DenseBase<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> >&);
 template void igl::slice_mask<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::DenseBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Array<bool, -1, 1, 0, -1, 1> const&, Eigen::Array<bool, -1, 1, 0, -1, 1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);

+ 12 - 0
include/igl/slice_mask.h

@@ -52,6 +52,18 @@ namespace igl
     const Eigen::DenseBase<DerivedX> & X,
     const Eigen::Array<bool,Eigen::Dynamic,1> & R,
     const int dim);
+  template <typename XType, typename YType>
+  IGL_INLINE void slice_mask(
+    const Eigen::SparseMatrix<XType> & X,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+    const int dim,
+    Eigen::SparseMatrix<YType> & Y);
+  template <typename XType, typename YType>
+  IGL_INLINE void slice_mask(
+    const Eigen::SparseMatrix<XType> & X,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & C,
+    Eigen::SparseMatrix<YType> & Y);
 }