insert_into_cdt.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "insert_into_cdt.h"
  9. #include <CGAL/Point_3.h>
  10. #include <CGAL/Segment_3.h>
  11. #include <CGAL/Triangle_3.h>
  12. template <typename Kernel>
  13. IGL_INLINE void igl::copyleft::cgal::insert_into_cdt(
  14. const CGAL::Object & obj,
  15. const CGAL::Plane_3<Kernel> & P,
  16. CGAL::Constrained_triangulation_plus_2<
  17. CGAL::Constrained_Delaunay_triangulation_2<
  18. Kernel,
  19. CGAL::Triangulation_data_structure_2<
  20. CGAL::Triangulation_vertex_base_2<Kernel>,
  21. CGAL::Constrained_triangulation_face_base_2< Kernel>
  22. >,
  23. CGAL::Exact_intersections_tag
  24. >
  25. >
  26. & cdt)
  27. {
  28. typedef CGAL::Point_3<Kernel> Point_3;
  29. typedef CGAL::Segment_3<Kernel> Segment_3;
  30. typedef CGAL::Triangle_3<Kernel> Triangle_3;
  31. if(const Segment_3 *iseg = CGAL::object_cast<Segment_3 >(&obj))
  32. {
  33. // Add segment constraint
  34. cdt.insert_constraint( P.to_2d(iseg->vertex(0)),P.to_2d(iseg->vertex(1)));
  35. }else if(const Point_3 *ipoint = CGAL::object_cast<Point_3 >(&obj))
  36. {
  37. // Add point
  38. cdt.insert(P.to_2d(*ipoint));
  39. } else if(const Triangle_3 *itri = CGAL::object_cast<Triangle_3 >(&obj))
  40. {
  41. // Add 3 segment constraints
  42. cdt.insert_constraint( P.to_2d(itri->vertex(0)),P.to_2d(itri->vertex(1)));
  43. cdt.insert_constraint( P.to_2d(itri->vertex(1)),P.to_2d(itri->vertex(2)));
  44. cdt.insert_constraint( P.to_2d(itri->vertex(2)),P.to_2d(itri->vertex(0)));
  45. } else if(const std::vector<Point_3 > *polyp =
  46. CGAL::object_cast< std::vector<Point_3 > >(&obj))
  47. {
  48. const std::vector<Point_3 > & poly = *polyp;
  49. const size_t m = poly.size();
  50. assert(m>=2);
  51. for(size_t p = 0;p<m;p++)
  52. {
  53. const size_t np = (p+1)%m;
  54. cdt.insert_constraint(P.to_2d(poly[p]),P.to_2d(poly[np]));
  55. }
  56. }else {
  57. throw std::runtime_error("Unknown intersection object!");
  58. }
  59. }
  60. #ifdef IGL_STATIC_LIBRARY
  61. // Explicit template instantiation
  62. #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
  63. template void igl::copyleft::cgal::insert_into_cdt<CGAL::Epick>(CGAL::Object const&, CGAL::Plane_3<CGAL::Epick> const&, CGAL::Constrained_triangulation_plus_2<CGAL::Constrained_Delaunay_triangulation_2<CGAL::Epick, CGAL::Triangulation_data_structure_2<CGAL::Triangulation_vertex_base_2<CGAL::Epick, CGAL::Triangulation_ds_vertex_base_2<void> >, CGAL::Constrained_triangulation_face_base_2<CGAL::Epick, CGAL::Triangulation_face_base_2<CGAL::Epick, CGAL::Triangulation_ds_face_base_2<void> > > >, CGAL::Exact_intersections_tag> >&);
  64. template void igl::copyleft::cgal::insert_into_cdt<CGAL::Epeck>(CGAL::Object const&, CGAL::Plane_3<CGAL::Epeck> const&, CGAL::Constrained_triangulation_plus_2<CGAL::Constrained_Delaunay_triangulation_2<CGAL::Epeck, CGAL::Triangulation_data_structure_2<CGAL::Triangulation_vertex_base_2<CGAL::Epeck, CGAL::Triangulation_ds_vertex_base_2<void> >, CGAL::Constrained_triangulation_face_base_2<CGAL::Epeck, CGAL::Triangulation_face_base_2<CGAL::Epeck, CGAL::Triangulation_ds_face_base_2<void> > > >, CGAL::Exact_intersections_tag> >&);
  65. #endif