gpt4 book ai didi

c++ - 网格划分算法搞砸了 Triangulation_vertex_base_with_id_2

转载 作者:行者123 更新时间:2023-11-28 01:19:59 25 4
gpt4 key购买 nike

我正在尝试将 Delaunay_mesher_2::refine_mesh 应用于一组编号的顶点(即顶点类是 Triangulation_vertex_base_with_id_2)。我希望在此过程中创建的任何顶点都应具有 id()==0。然而事实并非如此。相反,ID 具有各种正/负值。

我尝试使用 Triangulation_vertex_base_with_info_2,但结果是一样的。

我的代码或多或少是这样工作的:

using K = CGAL::Exact_predicates_inexact_constructions_kernel;
using Vb = CGAL::Triangulation_vertex_base_with_id_2<K>;
using Fb = CGAL::Delaunay_mesh_face_base_2<K>;
using Tds = CGAL::Triangulation_data_structure_2<Vb, Fb>;
using CDT_Tag = CGAL::Exact_intersections_tag;
using CDT = CGAL::Constrained_Delaunay_triangulation_2<K, Tds, CDT_Tag>;
using Criteria = CGAL::Delaunay_mesh_size_criteria_2<CDT>;
CDT cdt;
CGAL::Delaunay_mesher_2<CDT, Criteria> mesher(cdt, Criteria(0.125, 0.5));
... // Add some points and constraints.
static const CDT::Point INFINITE_POINT = { 1e100, 1e100 };
std::vector<CDT::Point> seeds = { INFINITE_POINT };
mesher.set_seeds(seeds.begin(), seeds.end());
mesher.refine_mesh();

for (auto vertices_iter = cdt.finite_vertices_begin();
vertices_iter != cdt.finite_vertices_end();
++vertices_iter) {
// do something with vertices_iter->id().
}

最佳答案

CGAL::Triangulation_vertex_base_with_id_2<K> 的默认构造函数不初始化 id成员:

template < typename GT,
typename Vb = Triangulation_vertex_base_2<GT> >
class Triangulation_vertex_base_with_id_2
: public Vb
{
int _id;

public:

// [...]

Triangulation_vertex_base_with_id_2()
: Vb() {}

这意味着_iddefault-initialized :

Explanation

Default initialization is performed in three situations: [...]

  1. when a base class or a non-static data member is not mentioned in a constructor initializer list and that constructor is called.

然后阅读下一段:

The effects of default initialization are:

  • if T is a non-POD (until C++11) class type, the constructors are considered and subjected to overload resolution against the empty argument list. The constructor selected (which is one of the default constructors) is called to provide the initial value for the new object;
  • if T is an array type, every element of the array is default-initialized;
  • otherwise, nothing is done: the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.

这里是子对象 _id如果类型 int ,因此它不是类或数组。这就是它没有被初始化的原因。该值将是内存中的任何垃圾。

关于c++ - 网格划分算法搞砸了 Triangulation_vertex_base_with_id_2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56891435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com