如何在 CGAL 中将三角测量对象(Constrained_Delaunay_triangulation_2)保存到文件(vtk、vtu、msh 等)

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

基于8.3 Example: a Constrained Delaunay Triangulation创建了简单的程序。只是想将它导出为一些常见的网格文件格式,如 vtk、msh 等,以便能够在 GMesh 或 ParaView 中打开它。为此,我发现最直接的方法是使用 write_VTU。在示例代码的开头和结尾,我添加了下一个:

#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();
...

结果出现这样的编译时错误:

[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

我对 write_vtu 或更一般的用法有什么问题:如何将网格对象(受约束)导出到文件(msh、vtk、vtu 等)中。

UPD:示例 8.4 给出了同样的错误。

如文档所述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

请注意,有一个 Python 界面,pygalmesh(由我编写),让您可以轻松地做到这一点:

import numpy as np
import pygalmesh

points = np.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]])
constraints = [[0, 1], [1, 2], [2, 3], [3, 0]]

mesh = pygalmesh.generate_2d(
    points,
    constraints,
    max_edge_size=1.0e-1,
    num_lloyd_steps=10,
)

# save in whatever format is supported by meshio
# https://github.com/nschloe/meshio
mesh.write("out.vtk")