mirror of https://github.com/CGAL/cgal
Deal with write_VTU()
This commit is contained in:
parent
e7c0c9d57e
commit
5b6b521ca8
|
|
@ -17,4 +17,27 @@ template <class CDT>
|
||||||
void write_VTU(std::ostream& os,
|
void write_VTU(std::ostream& os,
|
||||||
const CDT& tr,
|
const CDT& tr,
|
||||||
IO::Mode mode = IO::BINARY);
|
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 <class CDT, typename InDomainPmap>
|
||||||
|
void write_VTU(std::ostream& os,
|
||||||
|
const CDT& tr,
|
||||||
|
InDomainPmap ipm,
|
||||||
|
IO::Mode mode = IO::BINARY);
|
||||||
|
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,11 @@ namespace internal {
|
||||||
|
|
||||||
// writes the cells tags before binary data is appended
|
// writes the cells tags before binary data is appended
|
||||||
|
|
||||||
template <class CDT>
|
template <class CDT, class InDomainPmap>
|
||||||
void
|
void
|
||||||
write_cells_tag_2(std::ostream& os,
|
write_cells_tag_2(std::ostream& os,
|
||||||
const CDT & tr,
|
const CDT & tr,
|
||||||
|
InDomainPmap in_domain,
|
||||||
std::size_t number_of_triangles,
|
std::size_t number_of_triangles,
|
||||||
std::map<typename CDT::Vertex_handle, std::size_t> & V,
|
std::map<typename CDT::Vertex_handle, std::size_t> & V,
|
||||||
bool binary,
|
bool binary,
|
||||||
|
|
@ -74,12 +75,12 @@ write_cells_tag_2(std::ostream& os,
|
||||||
end = tr.finite_faces_end();
|
end = tr.finite_faces_end();
|
||||||
fit != end; ++fit)
|
fit != end; ++fit)
|
||||||
{
|
{
|
||||||
if(fit->is_in_domain())
|
if(get(in_domain, fit))
|
||||||
{
|
{
|
||||||
os << V[fit->vertex(0)] << " ";
|
os << V[fit->vertex(0)] << " ";
|
||||||
os << V[fit->vertex(2)] << " ";
|
os << V[fit->vertex(2)] << " ";
|
||||||
os << V[fit->vertex(1)] << " ";
|
os << V[fit->vertex(1)] << " ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(typename CDT::Constrained_edges_iterator
|
for(typename CDT::Constrained_edges_iterator
|
||||||
cei = tr.constrained_edges_begin(),
|
cei = tr.constrained_edges_begin(),
|
||||||
|
|
@ -114,7 +115,7 @@ write_cells_tag_2(std::ostream& os,
|
||||||
fit != tr.finite_faces_end() ;
|
fit != tr.finite_faces_end() ;
|
||||||
++fit )
|
++fit )
|
||||||
{
|
{
|
||||||
if(fit->is_in_domain())
|
if(get(in_domain, fit))
|
||||||
{
|
{
|
||||||
cells_offset += 3;
|
cells_offset += 3;
|
||||||
os << cells_offset << " ";
|
os << cells_offset << " ";
|
||||||
|
|
@ -149,7 +150,7 @@ write_cells_tag_2(std::ostream& os,
|
||||||
fit != tr.finite_faces_end() ;
|
fit != tr.finite_faces_end() ;
|
||||||
++fit )
|
++fit )
|
||||||
{
|
{
|
||||||
if(fit->is_in_domain())
|
if(get(in_domain, fit))
|
||||||
{
|
{
|
||||||
os << "5 ";
|
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
|
// writes the cells appended data at the end of the .vtu file
|
||||||
template <class CDT>
|
template <class CDT, class InDomainPmap>
|
||||||
void
|
void
|
||||||
write_cells_2(std::ostream& os,
|
write_cells_2(std::ostream& os,
|
||||||
const CDT & tr,
|
const CDT & tr,
|
||||||
|
InDomainPmap in_domain,
|
||||||
std::size_t number_of_triangles,
|
std::size_t number_of_triangles,
|
||||||
std::map<typename CDT::Vertex_handle, std::size_t> & V)
|
std::map<typename CDT::Vertex_handle, std::size_t> & V)
|
||||||
{
|
{
|
||||||
|
|
@ -185,7 +187,7 @@ write_cells_2(std::ostream& os,
|
||||||
end = tr.finite_faces_end();
|
end = tr.finite_faces_end();
|
||||||
fit != end; ++fit)
|
fit != end; ++fit)
|
||||||
{
|
{
|
||||||
if(fit->is_in_domain())
|
if(get(in_domain, fit))
|
||||||
{
|
{
|
||||||
off += 3;
|
off += 3;
|
||||||
offsets.push_back(off);
|
offsets.push_back(off);
|
||||||
|
|
@ -324,11 +326,12 @@ write_attributes_2(std::ostream& os,
|
||||||
write_vector(os,att);
|
write_vector(os,att);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class CDT>
|
template <class CDT, class InDomainPmap>
|
||||||
void write_VTU_with_attributes(std::ostream& os,
|
void write_VTU_with_attributes(std::ostream& os,
|
||||||
const CDT& tr,
|
const CDT& tr,
|
||||||
std::vector<std::pair<const char*, const std::vector<double>*> >& attributes,
|
InDomainPmap in_domain,
|
||||||
Mode mode = BINARY)
|
std::vector<std::pair<const char*, const std::vector<double>*> >& attributes,
|
||||||
|
Mode mode = BINARY)
|
||||||
{
|
{
|
||||||
typedef typename CDT::Vertex_handle Vertex_handle;
|
typedef typename CDT::Vertex_handle Vertex_handle;
|
||||||
std::map<Vertex_handle, std::size_t> V;
|
std::map<Vertex_handle, std::size_t> V;
|
||||||
|
|
@ -355,14 +358,14 @@ void write_VTU_with_attributes(std::ostream& os,
|
||||||
end = tr.finite_faces_end();
|
end = tr.finite_faces_end();
|
||||||
fit != end; ++fit)
|
fit != end; ++fit)
|
||||||
{
|
{
|
||||||
if(fit->is_in_domain()) ++number_of_triangles;
|
if(get(in_domain, fit)) ++number_of_triangles;
|
||||||
}
|
}
|
||||||
os << " <Piece NumberOfPoints=\"" << tr.number_of_vertices()
|
os << " <Piece NumberOfPoints=\"" << tr.number_of_vertices()
|
||||||
<< "\" NumberOfCells=\"" << number_of_triangles + std::distance(tr.constrained_edges_begin(), tr.constrained_edges_end()) << "\">\n";
|
<< "\" NumberOfCells=\"" << number_of_triangles + std::distance(tr.constrained_edges_begin(), tr.constrained_edges_end()) << "\">\n";
|
||||||
std::size_t offset = 0;
|
std::size_t offset = 0;
|
||||||
const bool binary = (mode == BINARY);
|
const bool binary = (mode == BINARY);
|
||||||
write_cdt_points_tag(os,tr,V,binary,offset);
|
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())
|
if(attributes.empty())
|
||||||
os << " <CellData >\n";
|
os << " <CellData >\n";
|
||||||
else
|
else
|
||||||
|
|
@ -377,7 +380,7 @@ void write_VTU_with_attributes(std::ostream& os,
|
||||||
if (binary) {
|
if (binary) {
|
||||||
os << "<AppendedData encoding=\"raw\">\n_";
|
os << "<AppendedData encoding=\"raw\">\n_";
|
||||||
write_cdt_points(os,tr,V); // write points before cells to fill the std::map V
|
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)
|
for(std::size_t i = 0; i< attributes.size(); ++i)
|
||||||
write_attributes_2(os, *attributes[i].second);
|
write_attributes_2(os, *attributes[i].second);
|
||||||
}
|
}
|
||||||
|
|
@ -386,15 +389,26 @@ void write_VTU_with_attributes(std::ostream& os,
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
template <class CDT>
|
template <class CDT, class InDomainPmap>
|
||||||
|
void write_VTU(std::ostream& os,
|
||||||
|
const CDT& tr,
|
||||||
|
InDomainPmap ipm,
|
||||||
|
Mode mode = BINARY)
|
||||||
|
{
|
||||||
|
std::vector<std::pair<const char*, const std::vector<double>*> > dummy_atts;
|
||||||
|
internal::write_VTU_with_attributes(os, tr, ipm, dummy_atts, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class CDT, class InDomainPmap>
|
||||||
void write_VTU(std::ostream& os,
|
void write_VTU(std::ostream& os,
|
||||||
const CDT& tr,
|
const CDT& tr,
|
||||||
Mode mode = BINARY)
|
Mode mode = BINARY)
|
||||||
{
|
{
|
||||||
std::vector<std::pair<const char*, const std::vector<double>*> > dummy_atts;
|
internal::In_domain<CDT> in_domain;
|
||||||
internal::write_VTU_with_attributes(os, tr, dummy_atts, mode);
|
write_VTU(os, tr, in_domain, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace IO
|
} // namespace IO
|
||||||
|
|
||||||
#ifndef CGAL_NO_DEPRECATED_CODE
|
#ifndef CGAL_NO_DEPRECATED_CODE
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue