intersect.cpp 934 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "intersect.h"
  2. template <class M>
  3. IGL_INLINE void igl::intersect(const M & A, const M & B, M & C)
  4. {
  5. // Stupid O(size(A) * size(B)) to do it
  6. M dyn_C(A.size() > B.size() ? A.size() : B.size(),1);
  7. // count of intersects
  8. int c = 0;
  9. // Loop over A
  10. for(int i = 0;i<A.size();i++)
  11. {
  12. // Loop over B
  13. for(int j = 0;j<B.size();j++)
  14. {
  15. if(A(i) == B(j))
  16. {
  17. dyn_C(c) = A(i);
  18. c++;
  19. }
  20. }
  21. }
  22. // resize output
  23. C.resize(c,1);
  24. // Loop over intersects
  25. for(int i = 0;i<c;i++)
  26. {
  27. C(i) = dyn_C(i);
  28. }
  29. }
  30. template <class M>
  31. IGL_INLINE M igl::intersect(const M & A, const M & B)
  32. {
  33. M C;
  34. intersect(A,B,C);
  35. return C;
  36. }
  37. #ifndef IGL_HEADER_ONLY
  38. // Explicit template specialization
  39. template Eigen::Matrix<int, -1, 1, 0, -1, 1> igl::intersect<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&);
  40. #endif