diff --git a/Constrained_triangulation_3/examples/Constrained_triangulation_3/remesh_constrained_Delaunay_triangulation_3.cpp b/Constrained_triangulation_3/examples/Constrained_triangulation_3/remesh_constrained_Delaunay_triangulation_3.cpp index 490a284fb48..956ed10fdf6 100644 --- a/Constrained_triangulation_3/examples/Constrained_triangulation_3/remesh_constrained_Delaunay_triangulation_3.cpp +++ b/Constrained_triangulation_3/examples/Constrained_triangulation_3/remesh_constrained_Delaunay_triangulation_3.cpp @@ -11,11 +11,10 @@ #include using K = CGAL::Exact_predicates_inexact_constructions_kernel; -using Vb = CGAL::Constrained_Delaunay_triangulation_vertex_base_3>; -using Cb = CGAL::Constrained_Delaunay_triangulation_cell_base_3>; +using Vb = CGAL::Constrained_Delaunay_triangulation_vertex_base_3; +using Cb = CGAL::Constrained_Delaunay_triangulation_cell_base_3; using Tds = CGAL::Triangulation_data_structure_3; using Tr = CGAL::Triangulation_3; -using CDt = CGAL::Constrained_Delaunay_triangulation_3; int main(int argc, char* argv[]) { diff --git a/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_3.h b/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_3.h index a40c78469f1..1bb3988f2a1 100644 --- a/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_3.h +++ b/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_3.h @@ -26,8 +26,8 @@ #include #include -#include #include +#include #include #include #include @@ -74,6 +74,7 @@ #ifndef DOXYGEN_RUNNING +#if 0 namespace CGAL { /*! @@ -170,6 +171,7 @@ namespace CGAL { }; } // end namespace CGAL +#endif // 0 namespace CGAL { @@ -524,70 +526,6 @@ concept Range_of_polygon_3 = std::ranges::common_range && Polygon_3, Kernel>; #endif // concepts -template > -class Constrained_Delaunay_triangulation_cell_base_3 - : public Base_with_time_stamp -{ - using Base = Base_with_time_stamp; - Constrained_Delaunay_triangulation_cell_data_3 cdt_3_data_; -public: - // To get correct cell type in TDS - template < class TDS3 > - struct Rebind_TDS { - typedef typename Cb::template Rebind_TDS::Other Cb3; - typedef Constrained_Delaunay_triangulation_cell_base_3 Other; - }; - - // Constructor - using Base::Base; - - Constrained_Delaunay_triangulation_cell_data_3& cdt_3_data() { - return cdt_3_data_; - } - - const Constrained_Delaunay_triangulation_cell_data_3& cdt_3_data() const { - return cdt_3_data_; - } - - static std::string io_signature() { - return Get_io_signature()() + "+(" + Get_io_signature()() - + ")[4]"; - } - - friend std::ostream& - operator<<(std::ostream& os, - const Constrained_Delaunay_triangulation_cell_base_3& c) - { - os << static_cast(c); - for( unsigned li = 0; li < 4; ++li ) { - if(IO::is_ascii(os)) { - os << " " << c.cdt_3_data().face_id[li]; - } else { - CGAL::write(os, c.cdt_3_data().face_id[li]); - } - } - return os; - } - friend std::istream& - operator>>(std::istream& is, - Constrained_Delaunay_triangulation_cell_base_3& c) - { - is >> static_cast(c); - if(!is) return is; - for( int li = 0; li < 4; ++li ) { - int i; - if(IO::is_ascii(is)) { - is >> i; - } else { - CGAL::read(is, i); - } - if(!is) return is; - c.face_id[li] = i; - } - return is; - } -}; - template struct Output_rep, With_point_and_info_tag> : public Output_rep> diff --git a/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_cell_base_3.h b/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_cell_base_3.h index 2ea46918955..78a8a967c0d 100644 --- a/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_cell_base_3.h +++ b/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_cell_base_3.h @@ -21,6 +21,7 @@ #ifndef CGAL_CONSTRAINED_DELAUNAY_TRIANGULATION_CELL_BASE_3_H #define CGAL_CONSTRAINED_DELAUNAY_TRIANGULATION_CELL_BASE_3_H +#include #include namespace CGAL { @@ -43,9 +44,93 @@ namespace CGAL { * * \sa `CGAL::Constrained_Delaunay_triangulation_vertex_base_3` */ -template < typename Gt, typename Cb = Triangulation_cell_base_3 > -class Constrained_Delaunay_triangulation_cell_base_3 : public Cb { +template > +class Constrained_Delaunay_triangulation_cell_base_3 + : public Base_with_time_stamp +{ + using Base = Base_with_time_stamp; + Constrained_Delaunay_triangulation_cell_data_3 cdt_3_data_; + + mutable bool sliver_cache_validity_ = false; + CDT_3_face_index subdomain_index_ = -1; + double sliver_value_ = 0.; public: + // To get correct cell type in TDS + template < class TDS3 > + struct Rebind_TDS { + typedef typename Cb::template Rebind_TDS::Other Cb3; + typedef Constrained_Delaunay_triangulation_cell_base_3 Other; + }; + + // Constructors inherited from the base class + using Base::Base; + + Constrained_Delaunay_triangulation_cell_data_3& cdt_3_data() { + return cdt_3_data_; + } + + const Constrained_Delaunay_triangulation_cell_data_3& cdt_3_data() const { + return cdt_3_data_; + } + + // model of SimplicialMeshCellBase_3 + using Surface_patch_index = CDT_3_face_index; + using Subdomain_index = CDT_3_face_index; + bool is_facet_on_surface(int i) const { return cdt_3_data().is_facet_constrained(i); } + Surface_patch_index surface_patch_index(int i) const { return cdt_3_data().face_constraint_index(i) + 1; } + void set_surface_patch_index(int i, Surface_patch_index index) { cdt_3_data().face_id[unsigned(i)] = index - 1; } + Subdomain_index subdomain_index() const { return subdomain_index_; } + void set_subdomain_index(Subdomain_index i) { subdomain_index_ = i; } + + // model of RemeshingCellBase_3 + void set_sliver_value(double value) { + sliver_cache_validity_ = true; + sliver_value_ = value; + } + double sliver_value() const { + CGAL_assertion(is_cache_valid()); + return sliver_value_; + } + bool is_cache_valid() const { return sliver_cache_validity_; } + void reset_cache_validity() const { sliver_cache_validity_ = false; } + + static std::string io_signature() { + return Get_io_signature()() + "+(" + Get_io_signature()() + + ")[4]"; + } + + friend std::ostream& + operator<<(std::ostream& os, + const Constrained_Delaunay_triangulation_cell_base_3& c) + { + os << static_cast(c); + for( unsigned li = 0; li < 4; ++li ) { + if(IO::is_ascii(os)) { + os << " " << c.cdt_3_data().face_id[li]; + } else { + CGAL::write(os, c.cdt_3_data().face_id[li]); + } + } + return os; + } + friend std::istream& + operator>>(std::istream& is, + Constrained_Delaunay_triangulation_cell_base_3& c) + { + is >> static_cast(c); + if(!is) return is; + for( int li = 0; li < 4; ++li ) { + int i; + if(IO::is_ascii(is)) { + is >> i; + } else { + CGAL::read(is, i); + } + if(!is) return is; + c.face_id[li] = i; + } + return is; + } }; } // namespace CGAL diff --git a/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_vertex_base_3.h b/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_vertex_base_3.h index c700e5e9408..70a28e29683 100644 --- a/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_vertex_base_3.h +++ b/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_vertex_base_3.h @@ -48,6 +48,12 @@ template < typename Gt, typename Vb = Triangulation_vertex_base_3 > class Constrained_Delaunay_triangulation_vertex_base_3 : public Base_with_time_stamp { Constrained_Delaunay_triangulation_vertex_data_3 cdt_3_data_; + bool cache_validity_ = false; + CDT_3_face_index index_ = 0; + int dim_ = -1; + std::size_t number_of_incident_facets_ = 0; + std::size_t number_of_components_ = 0; + public: // To get correct vertex type in TDS template struct Rebind_TDS @@ -56,16 +62,54 @@ public: using Other = Constrained_Delaunay_triangulation_vertex_base_3; }; + // constructors, inherited from the base class using Base = Base_with_time_stamp; using Base::Base; - Constrained_Delaunay_triangulation_vertex_data_3& cdt_3_data() { - return cdt_3_data_; + // model of SimplicialMeshVertexBase_3 + using Index = CDT_3_face_index; + int in_dimension() const { return dim_; } + void set_dimension(int d) { dim_ = d; } + Index index() const { return index_; } + void set_index(Index i) { index_ = i; } + bool is_c2t3_cache_valid() const { return cache_validity_; } + void invalidate_c2t3_cache() { cache_validity_ = false; } + void set_c2t3_cache(std::size_t i, std::size_t j) + { + number_of_incident_facets_ = i; + number_of_components_ = j; + cache_validity_ = true; + } + std::size_t cached_number_of_incident_facets() const { return number_of_incident_facets_; } + std::size_t cached_number_of_components() const { return number_of_components_; } + + void sync() { + switch(cdt_3_data().vertex_type()) { + case CDT_3_vertex_type::FREE: + set_dimension(3); + set_index(0); + break; + case CDT_3_vertex_type::CORNER: + set_dimension(0); + set_index(0); + break; + case CDT_3_vertex_type::STEINER_ON_EDGE: + set_dimension(1); + set_index(0); + break; + case CDT_3_vertex_type::STEINER_IN_FACE: + set_dimension(2); + set_index(cdt_3_data().face_index()); + break; + default: + CGAL_error(); + break; + } } - const Constrained_Delaunay_triangulation_vertex_data_3& cdt_3_data() const { - return cdt_3_data_; - } + // model of ConstrainedDelaunayTriangulationVertexBase_3 + Constrained_Delaunay_triangulation_vertex_data_3& cdt_3_data() { return cdt_3_data_; } + const Constrained_Delaunay_triangulation_vertex_data_3& cdt_3_data() const { return cdt_3_data_; } static std::string io_signature() { return Get_io_signature()(); diff --git a/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_vertex_data_3.h b/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_vertex_data_3.h index 30bdde4b4f1..ac37e0738a8 100644 --- a/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_vertex_data_3.h +++ b/Constrained_triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_vertex_data_3.h @@ -25,6 +25,8 @@ #include +#include + namespace CGAL { #ifdef DOXYGEN_RUNNING @@ -53,6 +55,7 @@ enum class CDT_3_vertex_marker { struct Constrained_Delaunay_triangulation_vertex_data_3 { protected: + // TODO: check and improve the compactness of this class CDT_3_vertex_type m_vertex_type = CDT_3_vertex_type::FREE; std::bitset(CDT_3_vertex_marker::nb_of_markers)> mark{}; union U { diff --git a/Constrained_triangulation_3/include/CGAL/make_constrained_Delaunay_triangulation_3.h b/Constrained_triangulation_3/include/CGAL/make_constrained_Delaunay_triangulation_3.h index a0ab8fdce5d..6044e06f910 100644 --- a/Constrained_triangulation_3/include/CGAL/make_constrained_Delaunay_triangulation_3.h +++ b/Constrained_triangulation_3/include/CGAL/make_constrained_Delaunay_triangulation_3.h @@ -86,7 +86,32 @@ Triangulation_3 make_constrained_Delaunay_triangulation_3(const PolygonMesh& mesh, const NamedParams& np = parameters::default_values()) { Constrained_Delaunay_triangulation_3 cdt(mesh, np); - return std::move(cdt).triangulation(); + Triangulation_3 tr = std::move(cdt).triangulation(); + + for(auto vh : tr.all_vertex_handles()) { + vh->sync(); + } + + for(auto ch : tr.all_cell_handles()) { + ch->set_subdomain_index(1); + } + + std::stack stack; + stack.push(tr.infinite_cell()); + while(!stack.empty()) { + auto ch = stack.top(); + stack.pop(); + ch->set_subdomain_index(0); + for(int i = 0; i < 4; ++i) { + if(ch->is_facet_on_surface(i)) continue; + auto n = ch->neighbor(i); + if(n->subdomain_index() == 1) { + stack.push(n); + } + } + } + + return tr; } } // end namespace CGAL