|
@@ -6,6 +6,7 @@
|
|
|
|
|
|
#include <algorithm>
|
|
|
#include <iostream>
|
|
|
+#include <map>
|
|
|
|
|
|
template <typename T>
|
|
|
IGL_INLINE void igl::unique(
|
|
@@ -92,9 +93,56 @@ IGL_INLINE void igl::unique_rows(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+template <typename DerivedA, typename DerivedIA, typename DerivedIC>
|
|
|
+IGL_INLINE void igl::unique_rows_many(
|
|
|
+ const Eigen::PlainObjectBase<DerivedA>& A,
|
|
|
+ Eigen::PlainObjectBase<DerivedA>& C,
|
|
|
+ Eigen::PlainObjectBase<DerivedIA>& IA,
|
|
|
+ Eigen::PlainObjectBase<DerivedIC>& IC)
|
|
|
+{
|
|
|
+ using namespace std;
|
|
|
+ // frequency map
|
|
|
+ typedef Eigen::Matrix<typename DerivedA::Scalar, Eigen::Dynamic, 1> RowVector;
|
|
|
+ IC.resize(A.rows(),1);
|
|
|
+ map<SortableRow<RowVector>, int> fm;
|
|
|
+ const int m = A.rows();
|
|
|
+ for(int i = 0;i<m;i++)
|
|
|
+ {
|
|
|
+ RowVector ri = A.row(i);
|
|
|
+ if(fm.count(SortableRow<RowVector>(ri)) == 0)
|
|
|
+ {
|
|
|
+ fm[SortableRow<RowVector>(ri)] = i;
|
|
|
+ }
|
|
|
+ IC(i) = fm[SortableRow<RowVector>(ri)];
|
|
|
+ }
|
|
|
+ IA.resize(fm.size(),1);
|
|
|
+ Eigen::VectorXi RIA(m);
|
|
|
+ C.resize(fm.size(),A.cols());
|
|
|
+ {
|
|
|
+ int i = 0;
|
|
|
+ for(typename map<SortableRow<RowVector > , int >::const_iterator fit = fm.begin();
|
|
|
+ fit != fm.end();
|
|
|
+ fit++)
|
|
|
+ {
|
|
|
+ IA(i) = fit->second;
|
|
|
+ RIA(fit->second) = i;
|
|
|
+ C.row(i) = fit->first.data;
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // IC should index C
|
|
|
+ for(int i = 0;i<m;i++)
|
|
|
+ {
|
|
|
+ IC(i) = RIA(IC(i));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#ifndef IGL_HEADER_ONLY
|
|
|
template void igl::unique<int>(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&, std::vector<size_t, std::allocator<size_t> >&, std::vector<size_t, std::allocator<size_t> >&);
|
|
|
template void igl::unique_rows<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
|
|
|
template void igl::unique_rows<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
|
|
|
template void igl::unique_rows<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
|
|
|
+template void igl::unique_rows<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
|
|
|
+template void igl::unique_rows_many<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
|
|
|
+template void igl::unique_rows_many<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
|
|
|
#endif
|