component_inside_component.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. template <typename DerivedV, typename DerivedF, typename DerivedI>
  20. IGL_INLINE bool igl::cgal::component_inside_component(
  21. const Eigen::PlainObjectBase<DerivedV>& V1,
  22. const Eigen::PlainObjectBase<DerivedF>& F1,
  23. const Eigen::PlainObjectBase<DerivedI>& I1,
  24. const Eigen::PlainObjectBase<DerivedV>& V2,
  25. const Eigen::PlainObjectBase<DerivedF>& F2,
  26. const Eigen::PlainObjectBase<DerivedI>& I2) {
  27. if (F1.rows() <= 0 || I1.rows() <= 0 || F2.rows() <= 0 || I2.rows() <= 0) {
  28. throw "Component inside test cannot be done on empty component!";
  29. }
  30. const Eigen::Vector3i& f = F1.row(I1(0, 0));
  31. const Eigen::Matrix<typename DerivedV::Scalar, 1, 3> query(
  32. (V1(f[0],0) + V1(f[1],0) + V1(f[2],0))/3.0,
  33. (V1(f[0],1) + V1(f[1],1) + V1(f[2],1))/3.0,
  34. (V1(f[0],2) + V1(f[1],2) + V1(f[2],2))/3.0);
  35. Eigen::VectorXi inside;
  36. igl::cgal::points_inside_component(V2, F2, I2, query, inside);
  37. assert(inside.size() == 1);
  38. return inside[0];
  39. }
  40. template<typename DerivedV, typename DerivedF>
  41. IGL_INLINE bool igl::cgal::component_inside_component(
  42. const Eigen::PlainObjectBase<DerivedV>& V1,
  43. const Eigen::PlainObjectBase<DerivedF>& F1,
  44. const Eigen::PlainObjectBase<DerivedV>& V2,
  45. const Eigen::PlainObjectBase<DerivedF>& F2) {
  46. if (F1.rows() <= 0 || F2.rows() <= 0) {
  47. throw "Component inside test cannot be done on empty component!";
  48. }
  49. Eigen::VectorXi I1(F1.rows()), I2(F2.rows());
  50. I1.setLinSpaced(F1.rows(), 0, F1.rows()-1);
  51. I2.setLinSpaced(F2.rows(), 0, F2.rows()-1);
  52. return igl::cgal::component_inside_component(V1, F1, I1, V2, F2, I2);
  53. }
  54. #ifdef IGL_STATIC_LIBRARY
  55. // Explicit template specialization
  56. template bool igl::cgal::component_inside_component<
  57. Eigen::Matrix<double, -1, -1, 0, -1, -1>,
  58. Eigen::Matrix<int, -1, -1, 0, -1, -1>,
  59. Eigen::Matrix<int, -1, -1, 0, -1, -1>,
  60. Eigen::Matrix<double, -1, -1, 0, -1, -1>,
  61. Eigen::Matrix<int, -1, -1, 0, -1, -1>,
  62. Eigen::Matrix<int, -1, -1, 0, -1, -1> >(
  63. Eigen::Matrix<double, -1, -1, 0, -1, -1>& const,
  64. Eigen::Matrix<int, -1, -1, 0, -1, -1>& const,
  65. Eigen::Matrix<int, -1, -1, 0, -1, -1>& const,
  66. Eigen::Matrix<double, -1, -1, 0, -1, -1>& const,
  67. Eigen::Matrix<int, -1, -1, 0, -1, -1>& const,
  68. Eigen::Matrix<int, -1, -1, 0, -1, -1>& const);
  69. template bool igl::cgal::component_inside_component<
  70. Eigen::Matrix<double, -1, -1, 0, -1, -1>,
  71. Eigen::Matrix<int, -1, -1, 0, -1, -1>,
  72. Eigen::Matrix<double, -1, -1, 0, -1, -1>,
  73. Eigen::Matrix<int, -1, -1, 0, -1, -1> >(
  74. Eigen::Matrix<double, -1, -1, 0, -1, -1>& const,
  75. Eigen::Matrix<int, -1, -1, 0, -1, -1>& const,
  76. Eigen::Matrix<double, -1, -1, 0, -1, -1>& const,
  77. Eigen::Matrix<int, -1, -1, 0, -1, -1>& const);
  78. #endif