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