component_inside_component.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Qingnan Zhou <qnzhou@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "component_inside_component.h"
  9. #include <cassert>
  10. #include <list>
  11. #include <limits>
  12. #include <vector>
  13. #include <CGAL/AABB_tree.h>
  14. #include <CGAL/AABB_traits.h>
  15. #include <CGAL/AABB_triangle_primitive.h>
  16. #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
  17. #include "order_facets_around_edge.h"
  18. #include "assign_scalar.h"
  19. #include "points_inside_component.h"
  20. template <typename DerivedV, typename DerivedF, typename DerivedI>
  21. IGL_INLINE bool igl::copyleft::cgal::component_inside_component(
  22. const Eigen::PlainObjectBase<DerivedV>& V1,
  23. const Eigen::PlainObjectBase<DerivedF>& F1,
  24. const Eigen::PlainObjectBase<DerivedI>& I1,
  25. const Eigen::PlainObjectBase<DerivedV>& V2,
  26. const Eigen::PlainObjectBase<DerivedF>& F2,
  27. const Eigen::PlainObjectBase<DerivedI>& I2) {
  28. if (F1.rows() <= 0 || I1.rows() <= 0 || F2.rows() <= 0 || I2.rows() <= 0) {
  29. throw "Component inside test cannot be done on empty component!";
  30. }
  31. const Eigen::Vector3i& f = F1.row(I1(0, 0));
  32. const Eigen::Matrix<typename DerivedV::Scalar, 1, 3> query(
  33. (V1(f[0],0) + V1(f[1],0) + V1(f[2],0))/3.0,
  34. (V1(f[0],1) + V1(f[1],1) + V1(f[2],1))/3.0,
  35. (V1(f[0],2) + V1(f[1],2) + V1(f[2],2))/3.0);
  36. Eigen::VectorXi inside;
  37. igl::copyleft::cgal::points_inside_component(V2, F2, I2, query, inside);
  38. assert(inside.size() == 1);
  39. return inside[0];
  40. }
  41. template<typename DerivedV, typename DerivedF>
  42. IGL_INLINE bool igl::copyleft::cgal::component_inside_component(
  43. const Eigen::PlainObjectBase<DerivedV>& V1,
  44. const Eigen::PlainObjectBase<DerivedF>& F1,
  45. const Eigen::PlainObjectBase<DerivedV>& V2,
  46. const Eigen::PlainObjectBase<DerivedF>& F2) {
  47. if (F1.rows() <= 0 || F2.rows() <= 0) {
  48. throw "Component inside test cannot be done on empty component!";
  49. }
  50. Eigen::VectorXi I1(F1.rows()), I2(F2.rows());
  51. I1.setLinSpaced(F1.rows(), 0, F1.rows()-1);
  52. I2.setLinSpaced(F2.rows(), 0, F2.rows()-1);
  53. return igl::copyleft::cgal::component_inside_component(V1, F1, I1, V2, F2, I2);
  54. }
  55. #ifdef IGL_STATIC_LIBRARY
  56. // Explicit template specialization
  57. template bool igl::copyleft::cgal::component_inside_component<
  58. Eigen::Matrix<double, -1, -1, 0, -1, -1>,
  59. Eigen::Matrix< int, -1, -1, 0, -1, -1>,
  60. Eigen::Matrix< int, -1, -1, 0, -1, -1> > (
  61. Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&,
  62. Eigen::PlainObjectBase<Eigen::Matrix< int, -1, -1, 0, -1, -1> > const&,
  63. Eigen::PlainObjectBase<Eigen::Matrix< int, -1, -1, 0, -1, -1> > const&,
  64. Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&,
  65. Eigen::PlainObjectBase<Eigen::Matrix< int, -1, -1, 0, -1, -1> > const&,
  66. Eigen::PlainObjectBase<Eigen::Matrix< int, -1, -1, 0, -1, -1> > const&);
  67. template bool igl::copyleft::cgal::component_inside_component<
  68. Eigen::Matrix<double, -1, -1, 0, -1, -1>,
  69. Eigen::Matrix< int, -1, -1, 0, -1, -1> > (
  70. Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&,
  71. Eigen::PlainObjectBase<Eigen::Matrix< int, -1, -1, 0, -1, -1> > const&,
  72. Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&,
  73. Eigen::PlainObjectBase<Eigen::Matrix< int, -1, -1, 0, -1, -1> > const&);
  74. #endif