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

Posted

技术标签:

【中文标题】如何在 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 【发布时间】:2022-01-19 19:45:58 【问题描述】:

基于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

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

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

【问题讨论】:

【参考方案1】:

如文档中的here 所述,三角剖分的面类型必须是DelaunayMeshFaceBase_2 的模型。例如,您可以使用Delaunay_mesh_face_base_2,如this example。

【讨论】:

【参考方案2】:

请注意,有一个 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")  

【讨论】:

谢谢,python 我认为应该促进学习过程而不是 c++。

以上是关于如何在 CGAL 中将三角测量对象(Constrained_Delaunay_triangulation_2)保存到文件(vtk、vtu、msh 等)的主要内容,如果未能解决你的问题,请参考以下文章

[CGAL]带岛多边形三角化

网格到网格交叉点

轻量级 Delaunay 三角函数库(用于 C++)[关闭]

CGAL 中的 Delaunay_triangulation_2 不保持输入顶点的顺序

4个视图中的6个点的三角测量

三角测量在3D空间的任意平面上的点集