From 5b6b521ca89bd37b5c5bd67aef07a659dcef58f7 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 15 Mar 2022 17:45:41 +0100 Subject: [PATCH] Deal with write_VTU() --- Mesh_2/doc/Mesh_2/CGAL/IO/write_VTU.h | 23 +++++++++++ Mesh_2/include/CGAL/IO/write_VTU.h | 56 +++++++++++++++++---------- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/Mesh_2/doc/Mesh_2/CGAL/IO/write_VTU.h b/Mesh_2/doc/Mesh_2/CGAL/IO/write_VTU.h index 9b2b778c32e..e42e5c784d5 100644 --- a/Mesh_2/doc/Mesh_2/CGAL/IO/write_VTU.h +++ b/Mesh_2/doc/Mesh_2/CGAL/IO/write_VTU.h @@ -17,4 +17,27 @@ template void write_VTU(std::ostream& os, const CDT& tr, IO::Mode mode = IO::BINARY); + + +//!\ingroup PkgMesh2IO +//! \brief writes the faces of a domain and its constrained edges embedded in +//! a 2D constrained Delaunay triangulation using the `PolyData` XML +//! format. + //! The faces output are those for which `get(ipm, f)` returns + //! `true` where `f`is a `CDT::Face_handle`, +//! the edges are those for which `ConstrainedTriangulationFaceBase_2::is_constrained()` returns `true`. +//! \tparam CDT a `Constrained_Delaunay_triangulation_2` with face type model of `DelaunayMeshFaceBase_2`. +//! +//! \param os the stream used for writing. +//! \param tr the triangulated domain to be written. +//! \param mode decides if the data should be written in binary (`BINARY`) +//! or in \ascii (`ASCII`). +//! +template +void write_VTU(std::ostream& os, + const CDT& tr, + InDomainPmap ipm, + IO::Mode mode = IO::BINARY); + + } } diff --git a/Mesh_2/include/CGAL/IO/write_VTU.h b/Mesh_2/include/CGAL/IO/write_VTU.h index de6a0a313bd..56edc191afe 100644 --- a/Mesh_2/include/CGAL/IO/write_VTU.h +++ b/Mesh_2/include/CGAL/IO/write_VTU.h @@ -35,10 +35,11 @@ namespace internal { // writes the cells tags before binary data is appended -template + template void write_cells_tag_2(std::ostream& os, const CDT & tr, + InDomainPmap in_domain, std::size_t number_of_triangles, std::map & V, bool binary, @@ -74,12 +75,12 @@ write_cells_tag_2(std::ostream& os, end = tr.finite_faces_end(); fit != end; ++fit) { - if(fit->is_in_domain()) - { - os << V[fit->vertex(0)] << " "; - os << V[fit->vertex(2)] << " "; - os << V[fit->vertex(1)] << " "; - } + if(get(in_domain, fit)) + { + os << V[fit->vertex(0)] << " "; + os << V[fit->vertex(2)] << " "; + os << V[fit->vertex(1)] << " "; + } } for(typename CDT::Constrained_edges_iterator cei = tr.constrained_edges_begin(), @@ -114,7 +115,7 @@ write_cells_tag_2(std::ostream& os, fit != tr.finite_faces_end() ; ++fit ) { - if(fit->is_in_domain()) + if(get(in_domain, fit)) { cells_offset += 3; os << cells_offset << " "; @@ -149,7 +150,7 @@ write_cells_tag_2(std::ostream& os, fit != tr.finite_faces_end() ; ++fit ) { - if(fit->is_in_domain()) + if(get(in_domain, fit)) { os << "5 "; } @@ -166,10 +167,11 @@ write_cells_tag_2(std::ostream& os, } // writes the cells appended data at the end of the .vtu file -template + template void write_cells_2(std::ostream& os, const CDT & tr, + InDomainPmap in_domain, std::size_t number_of_triangles, std::map & V) { @@ -185,7 +187,7 @@ write_cells_2(std::ostream& os, end = tr.finite_faces_end(); fit != end; ++fit) { - if(fit->is_in_domain()) + if(get(in_domain, fit)) { off += 3; offsets.push_back(off); @@ -324,11 +326,12 @@ write_attributes_2(std::ostream& os, write_vector(os,att); } -template +template void write_VTU_with_attributes(std::ostream& os, - const CDT& tr, - std::vector*> >& attributes, - Mode mode = BINARY) + const CDT& tr, + InDomainPmap in_domain, + std::vector*> >& attributes, + Mode mode = BINARY) { typedef typename CDT::Vertex_handle Vertex_handle; std::map V; @@ -355,14 +358,14 @@ void write_VTU_with_attributes(std::ostream& os, end = tr.finite_faces_end(); fit != end; ++fit) { - if(fit->is_in_domain()) ++number_of_triangles; + if(get(in_domain, fit)) ++number_of_triangles; } os << " \n"; std::size_t offset = 0; const bool binary = (mode == BINARY); write_cdt_points_tag(os,tr,V,binary,offset); - write_cells_tag_2(os,tr,number_of_triangles, V,binary,offset); + write_cells_tag_2(os,tr, in_domain, number_of_triangles, V,binary,offset); if(attributes.empty()) os << " \n"; else @@ -377,7 +380,7 @@ void write_VTU_with_attributes(std::ostream& os, if (binary) { os << "\n_"; write_cdt_points(os,tr,V); // write points before cells to fill the std::map V - write_cells_2(os,tr, number_of_triangles, V); + write_cells_2(os, tr, in_domain, number_of_triangles, V); for(std::size_t i = 0; i< attributes.size(); ++i) write_attributes_2(os, *attributes[i].second); } @@ -386,15 +389,26 @@ void write_VTU_with_attributes(std::ostream& os, } // namespace internal -template +template +void write_VTU(std::ostream& os, + const CDT& tr, + InDomainPmap ipm, + Mode mode = BINARY) +{ + std::vector*> > dummy_atts; + internal::write_VTU_with_attributes(os, tr, ipm, dummy_atts, mode); +} + +template void write_VTU(std::ostream& os, const CDT& tr, Mode mode = BINARY) { - std::vector*> > dummy_atts; - internal::write_VTU_with_attributes(os, tr, dummy_atts, mode); + internal::In_domain in_domain; + write_VTU(os, tr, in_domain, mode); } + } // namespace IO #ifndef CGAL_NO_DEPRECATED_CODE