Browse Source

more overloads

Former-commit-id: 516474cea8590c4f6c7921c6800341df1c3e0848
Alec Jacobson 10 years ago
parent
commit
1618c18430
4 changed files with 72 additions and 1 deletions
  1. 26 1
      include/igl/find.cpp
  2. 6 0
      include/igl/find.h
  3. 28 0
      include/igl/unique.cpp
  4. 12 0
      include/igl/unique.h

+ 26 - 1
include/igl/find.cpp

@@ -52,7 +52,7 @@ IGL_INLINE void igl::find(
   Eigen::PlainObjectBase<DerivedJ> & J,
   Eigen::PlainObjectBase<DerivedV> & V)
 {
-  const int nnz = X.template cast<bool>().template cast<int>().sum();
+  const int nnz = X.count();
   I.resize(nnz,1);
   J.resize(nnz,1);
   V.resize(nnz,1);
@@ -73,6 +73,31 @@ IGL_INLINE void igl::find(
     }
   }
 }
+
+template <
+  typename DerivedX,
+  typename DerivedI>
+IGL_INLINE void igl::find(
+  const Eigen::PlainObjectBase<DerivedX>& X,
+  Eigen::PlainObjectBase<DerivedI> & I)
+{
+  const int nnz = X.count();
+  I.resize(nnz,1);
+  {
+    int k = 0;
+    for(int j = 0;j<X.cols();j++)
+    {
+      for(int i = 0;i<X.rows();i++)
+      {
+        if(X(i,j))
+        {
+          I(k) = i+X.rows()*j;
+          k++;
+        }
+      }
+    }
+  }
+}
   
 template <typename T>
 IGL_INLINE void igl::find(

+ 6 - 0
include/igl/find.h

@@ -45,6 +45,12 @@ namespace igl
     Eigen::PlainObjectBase<DerivedI> & I,
     Eigen::PlainObjectBase<DerivedJ> & J,
     Eigen::PlainObjectBase<DerivedV> & V);
+  template <
+    typename DerivedX,
+    typename DerivedI>
+  IGL_INLINE void find(
+    const Eigen::PlainObjectBase<DerivedX>& X,
+    Eigen::PlainObjectBase<DerivedI> & I);
   // Find the non-zero entries and there respective indices in a sparse vector.
   // Similar to matlab's [I,J,V] = find(X), but instead of [I,J] being
   // subscripts into X, since X is a vector we just return I, a list of indices

+ 28 - 0
include/igl/unique.cpp

@@ -63,6 +63,15 @@ IGL_INLINE void igl::unique(
 
 }
 
+template <typename T>
+IGL_INLINE void igl::unique(
+  const std::vector<T> & A,
+  std::vector<T> & C)
+{
+  std::vector<size_t> IA,IC;
+  return igl::unique(A,C,IA,IC);
+}
+
 template <
   typename DerivedA,
   typename DerivedC,
@@ -86,6 +95,25 @@ IGL_INLINE void igl::unique(
   list_to_matrix(vIC,IC);
 }
 
+template <
+  typename DerivedA,
+  typename DerivedC,
+  typename DerivedIA,
+  typename DerivedIC>
+IGL_INLINE void igl::unique(
+    const Eigen::PlainObjectBase<DerivedA> & A,
+    Eigen::PlainObjectBase<DerivedC> & C)
+{
+  using namespace std;
+  using namespace Eigen;
+  vector<typename DerivedA::Scalar > vA;
+  vector<typename DerivedC::Scalar > vC;
+  vector<size_t> vIA,vIC;
+  matrix_to_list(A,vA);
+  unique(vA,vC,vIA,vIC);
+  list_to_matrix(vC,C);
+}
+
 // Obsolete slow version converting to vectors
 // template <typename DerivedA, typename DerivedIA, typename DerivedIC>
 // IGL_INLINE void igl::unique_rows(

+ 12 - 0
include/igl/unique.h

@@ -29,6 +29,10 @@ namespace igl
     std::vector<T> & C,
     std::vector<size_t> & IA,
     std::vector<size_t> & IC);
+  template <typename T>
+  IGL_INLINE void unique(
+    const std::vector<T> & A,
+    std::vector<T> & C);
   template <
     typename DerivedA,
     typename DerivedC,
@@ -39,6 +43,14 @@ namespace igl
       Eigen::PlainObjectBase<DerivedC> & C,
       Eigen::PlainObjectBase<DerivedIA> & IA,
       Eigen::PlainObjectBase<DerivedIC> & IC);
+  template <
+    typename DerivedA,
+    typename DerivedC,
+    typename DerivedIA,
+    typename DerivedIC>
+  IGL_INLINE void unique(
+      const Eigen::PlainObjectBase<DerivedA> & A,
+      Eigen::PlainObjectBase<DerivedC> & C);
   // Act like matlab's [C,IA,IC] = unique(X,'rows')
   //
   // Templates: