Search code examples
c++iomeshcgal

How to save triangulation object(Constrained_Delaunay_triangulation_2) to file(vtk, vtu, msh etc) in CGAL


Created simple program based on 8.3 Example: a Constrained Delaunay Triangulation. And just wanna to export it to some common mesh file format like vtk, msh etc, to be able open it in GMesh or ParaView. To do so I found that most straightforward way is to use write_VTU. And at the beginning and at the end of example code I added next:

#include <CGAL/IO/write_VTU.h>
#include <fstream>
...
//example 8.3
...
std::ofstream mesh_file("mesh.VTU");
CGAL::write_vtu(mesh_file, cdt);
mesh_file.close();
...

As a result getting such compile time error:

[build] In file included from /home/oleg/Документи/riversim/source/../include/RiverSim.hpp:5,
[build]                  from /home/oleg/Документи/riversim/source/main.cpp:1:
[build] /usr/local/include/CGAL/IO/write_VTU.h: In instantiation of ‘void CGAL::IO::internal::write_VTU_with_attributes(std::ostream&, const CDT&, std::vector<std::pair<const char*, const std::vector<double>*> >&, CGAL::IO::Mode) [with CDT = CGAL::Constrained_Delaunay_triangulation_2<CGAL::Epick, CGAL::Default, CGAL::Exact_predicates_tag>; std::ostream = std::basic_ostream<char>]’:
[build] /usr/local/include/CGAL/IO/write_VTU.h:395:38:   required from ‘void CGAL::IO::write_VTU(std::ostream&, const CDT&, CGAL::IO::Mode) [with CDT = CGAL::Constrained_Delaunay_triangulation_2<CGAL::Epick, CGAL::Default, CGAL::Exact_predicates_tag>; std::ostream = std::basic_ostream<char>]’
[build] /usr/local/include/CGAL/IO/write_VTU.h:406:16:   required from ‘void CGAL::write_vtu(std::ostream&, const CDT&, CGAL::IO::Mode) [with CDT = CGAL::Constrained_Delaunay_triangulation_2<CGAL::Epick, CGAL::Default, CGAL::Exact_predicates_tag>; std::ostream = std::basic_ostream<char>]’
[build] /home/oleg/Документи/riversim/source/../include/RiverSim.hpp:44:47:   required from here
[build] /usr/local/include/CGAL/IO/write_VTU.h:358:13: error: ‘class CGAL::Constrained_triangulation_face_base_2<CGAL::Epick, CGAL::Triangulation_face_base_2<CGAL::Epick, CGAL::Triangulation_ds_face_base_2<CGAL::Triangulation_data_structure_2<CGAL::Triangulation_vertex_base_2<CGAL::Epick, CGAL::Triangulation_ds_vertex_base_2<void> >, CGAL::Constrained_triangulation_face_base_2<CGAL::Epick, CGAL::Triangulation_face_base_2<CGAL::Epick, CGAL::Triangulation_ds_face_base_2<void> > > > > > >’ has no member named ‘is_in_domain’
[build]   358 |     if(fit->is_in_domain()) ++number_of_triangles;
[build]       |        ~~~~~^~~~~~~~~~~~
[build] make[2]: *** [source/CMakeFiles/river.dir/build.make:63: source/CMakeFiles/river.dir/main.cpp.o] Помилка 1
[build] make[1]: *** [CMakeFiles/Makefile2:96: source/CMakeFiles/river.dir/all] Помилка 2
[build] make: *** [Makefile:84: all] Помилка 2
[build] Build finished with exit code 2

What is wrong with my ussage of write_vtu or more generally: How to export mesh object(constrained) into the file(msh, vtk, vtu etc).

UPD: Example 8.4 gives same error.


Solution

  • As documented here the face type of the triangulation must be a model of DelaunayMeshFaceBase_2. You can for example use Delaunay_mesh_face_base_2 like in this example.