// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2016 Alec Jacobson // // 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/. #include "ismember_rows.h" #include "sortrows.h" #include "unique.h" #include "unique_rows.h" #include template < typename DerivedA, typename DerivedB, typename DerivedIA, typename DerivedLOCB> IGL_INLINE void igl::ismember_rows( const Eigen::MatrixBase & A, const Eigen::MatrixBase & B, Eigen::PlainObjectBase & IA, Eigen::PlainObjectBase & LOCB) { using namespace Eigen; using namespace std; assert(A.cols() == B.cols() && "number of columns must match"); IA.resize(A.rows(),1); IA.setConstant(false); LOCB.resize(A.rows(),1); LOCB.setConstant(-1); // boring base cases if(A.size() == 0) { return; } if(B.size() == 0) { return; } // Get rid of any duplicates typedef Eigen::Matrix MatrixA; typedef Eigen::Matrix MatrixB; MatrixA uA; MatrixB uB; // Using Eigen::Index or typename DerivedA::Index for the _Scalar_ of the // types below is a big mistake. It triggers all sorts of type confusion in // the templates on windows. Until we systematically template to support int64 // etc. we should assume the inputs don't exceed 2147483647, which is // reasonable. typedef int Index; Eigen::Matrix uIA,uIuA,uIB,uIuB; unique_rows(A,uA,uIA,uIuA); unique_rows(B,uB,uIB,uIuB); // Sort both MatrixA sA; MatrixB sB; Eigen::Matrix sIA,sIB; sortrows(uA,true,sA,sIA); sortrows(uB,true,sB,sIB); Eigen::Matrix uF = Eigen::Matrix::Zero(sA.size(),1); Eigen::Matrix uLOCB = Eigen::Matrix:: Constant(sA.size(),1,-1); const auto & row_greater_than = [&sA,&sB](const int a, const int b) { for(int c = 0;c sB(b,c)) return true; if(sA(a,c) < sB(b,c)) return false; } return false; }; { int bi = 0; // loop over sA bool past = false; for(int a = 0;a=sB.rows(); } if(!past && (sA.row(a).array()==sB.row(bi).array()).all() ) { uF(sIA(a)) = true; uLOCB(sIA(a)) = uIB(sIB(bi)); } } } for(int a = 0;a, Eigen::Matrix, Eigen::Array, Eigen::Matrix>(Eigen::MatrixBase> const&, Eigen::MatrixBase> const&, Eigen::PlainObjectBase>&, Eigen::PlainObjectBase>&); // generated by autoexplicit.sh template void igl::ismember_rows, Eigen::Matrix, Eigen::Array, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::ismember_rows, Eigen::Matrix, Eigen::Array, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::ismember_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::ismember_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::ismember_rows, Eigen::Matrix, Eigen::Array, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); #endif