submesh_aabb_tree.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Alec Jacobson
  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 "submesh_aabb_tree.h"
  9. #include <stdexcept>
  10. template<
  11. typename DerivedV,
  12. typename DerivedF,
  13. typename DerivedI,
  14. typename Kernel>
  15. IGL_INLINE void igl::copyleft::cgal::submesh_aabb_tree(
  16. const Eigen::PlainObjectBase<DerivedV>& V,
  17. const Eigen::PlainObjectBase<DerivedF>& F,
  18. const Eigen::PlainObjectBase<DerivedI>& I,
  19. CGAL::AABB_tree<
  20. CGAL::AABB_traits<
  21. Kernel,
  22. CGAL::AABB_triangle_primitive<
  23. Kernel, typename std::vector<
  24. typename Kernel::Triangle_3 >::iterator > > > & tree,
  25. std::vector<typename Kernel::Triangle_3 > & triangles,
  26. std::vector<bool> & in_I)
  27. {
  28. in_I.resize(F.rows(), false);
  29. const size_t num_faces = I.rows();
  30. for (size_t i=0; i<num_faces; i++)
  31. {
  32. const Eigen::Vector3i f = F.row(I(i, 0));
  33. in_I[I(i,0)] = true;
  34. triangles.emplace_back(
  35. typename Kernel::Point_3(V(f[0], 0), V(f[0], 1), V(f[0], 2)),
  36. typename Kernel::Point_3(V(f[1], 0), V(f[1], 1), V(f[1], 2)),
  37. typename Kernel::Point_3(V(f[2], 0), V(f[2], 1), V(f[2], 2)));
  38. #ifndef NDEBUG
  39. if (triangles.back().is_degenerate())
  40. {
  41. throw std::runtime_error(
  42. "Input facet components contains degenerated triangles");
  43. }
  44. #endif
  45. }
  46. tree.insert(triangles.begin(), triangles.end());
  47. tree.accelerate_distance_queries();
  48. }
  49. #ifdef IGL_STATIC_LIBRARY
  50. // Explicit template instanciation
  51. template void igl::copyleft::cgal::submesh_aabb_tree<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, CGAL::Epeck>(Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, CGAL::AABB_tree<CGAL::AABB_traits<CGAL::Epeck, CGAL::AABB_triangle_primitive<CGAL::Epeck, std::vector<CGAL::Epeck::Triangle_3, std::allocator<CGAL::Epeck::Triangle_3> >::iterator, CGAL::Boolean_tag<false> > > >&, std::vector<CGAL::Epeck::Triangle_3, std::allocator<CGAL::Epeck::Triangle_3> >&, std::vector<bool, std::allocator<bool> >&);
  52. #endif