projected_cdt.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "projected_cdt.h"
  9. #include "insert_into_cdt.h"
  10. #include "assign_scalar.h"
  11. #include "../../list_to_matrix.h"
  12. template <typename Kernel, typename Index>
  13. IGL_INLINE void igl::copyleft::cgal::projected_cdt(
  14. const std::vector<CGAL::Object> & objects,
  15. const CGAL::Plane_3<Kernel> & P,
  16. std::vector<CGAL::Point_3<Kernel> >& vertices,
  17. std::vector<std::vector<Index> >& faces)
  18. {
  19. typedef CGAL::Point_3<Kernel> Point_3;
  20. typedef CGAL::Segment_3<Kernel> Segment_3;
  21. typedef CGAL::Triangle_3<Kernel> Triangle_3;
  22. typedef CGAL::Plane_3<Kernel> Plane_3;
  23. typedef CGAL::Triangulation_vertex_base_2<Kernel> TVB_2;
  24. typedef CGAL::Constrained_triangulation_face_base_2<Kernel> CTFB_2;
  25. typedef CGAL::Triangulation_data_structure_2<TVB_2,CTFB_2> TDS_2;
  26. typedef CGAL::Exact_intersections_tag Itag;
  27. typedef CGAL::Constrained_Delaunay_triangulation_2<Kernel,TDS_2,Itag> CDT_2;
  28. typedef CGAL::Constrained_triangulation_plus_2<CDT_2> CDT_plus_2;
  29. CDT_plus_2 cdt;
  30. for(const auto & obj : objects) insert_into_cdt(obj,P,cdt);
  31. // Read off vertices of the cdt, remembering index
  32. std::map<typename CDT_plus_2::Vertex_handle,Index> v2i;
  33. size_t count=0;
  34. for (
  35. auto itr = cdt.finite_vertices_begin();
  36. itr != cdt.finite_vertices_end();
  37. itr++)
  38. {
  39. vertices.push_back(P.to_3d(itr->point()));
  40. v2i[itr] = count;
  41. count++;
  42. }
  43. // Read off faces and store index triples
  44. for (
  45. auto itr = cdt.finite_faces_begin();
  46. itr != cdt.finite_faces_end();
  47. itr++)
  48. {
  49. faces.push_back(
  50. { v2i[itr->vertex(0)], v2i[itr->vertex(1)], v2i[itr->vertex(2)] });
  51. }
  52. }
  53. template < typename Kernel, typename DerivedV, typename DerivedF>
  54. IGL_INLINE void igl::copyleft::cgal::projected_cdt(
  55. const std::vector<CGAL::Object> & objects,
  56. const CGAL::Plane_3<Kernel> & P,
  57. Eigen::PlainObjectBase<DerivedV> & V,
  58. Eigen::PlainObjectBase<DerivedF> & F)
  59. {
  60. std::vector<CGAL::Point_3<Kernel> > vertices;
  61. std::vector<std::vector<typename DerivedF::Scalar> > faces;
  62. projected_cdt(objects,P,vertices,faces);
  63. V.resize(vertices.size(),3);
  64. for(int v = 0;v<vertices.size();v++)
  65. {
  66. for(int d = 0;d<3;d++)
  67. {
  68. assign_scalar(vertices[v][d], V(v,d));
  69. }
  70. }
  71. list_to_matrix(faces,F);
  72. }
  73. #ifdef IGL_STATIC_LIBRARY
  74. // Explicit template specialization
  75. // generated by autoexplicit.sh
  76. template void igl::copyleft::cgal::projected_cdt<CGAL::Epick, long>(std::vector<CGAL::Object, std::allocator<CGAL::Object> > const&, CGAL::Plane_3<CGAL::Epick> const&, std::vector<CGAL::Point_3<CGAL::Epick>, std::allocator<CGAL::Point_3<CGAL::Epick> > >&, std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > >&);
  77. // generated by autoexplicit.sh
  78. template void igl::copyleft::cgal::projected_cdt<CGAL::Epeck, long>(std::vector<CGAL::Object, std::allocator<CGAL::Object> > const&, CGAL::Plane_3<CGAL::Epeck> const&, std::vector<CGAL::Point_3<CGAL::Epeck>, std::allocator<CGAL::Point_3<CGAL::Epeck> > >&, std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > >&);
  79. #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
  80. #endif