c++ - 网格化算法搞砸了 Triangulation_vertex_base_with_id_2
问题描述
我正在尝试应用于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() {}
这意味着这_id
是默认初始化的:
解释
默认初始化在三种情况下执行:[...]
- 当构造函数初始值设定项列表中未提及基类或非静态数据成员并且调用该构造函数时。
然后阅读下一段:
默认初始化的效果是:
- 如果 T 是非 POD(C++11 前)类类型,则考虑构造函数并对其进行针对空参数列表的重载决议。调用选择的构造函数(默认构造函数之一)为新对象提供初始值;
- 如果 T 是数组类型,则数组的每个元素都是默认初始化的;
- 否则,什么都不做:具有自动存储持续时间的对象(及其子对象)被初始化为不确定的值。
这里的子对象_id
if 是 type int
,因此它不是类或数组。这就是它没有被初始化的原因。该值将是内存中存在的任何垃圾。
推荐阅读
- java - JPQL 查询中 DTO 构造函数的问题
- css - 应用于两个相等 DIV 之一的 rotate() 不能完美对齐背景图像
- android - Aapt 添加库资源
- powershell - 当您无法访问 -Extension 时使用 Select-Object 是否合适?
- python - while循环中try和if语句的问题
- plone - 从 Plone 4.3 迁移到 5.1 后不再访问历史视图
- google-cloud-platform - AccessDeniedException: 403 要计费的项目与已关闭的计费帐户相关联
- unicode - 为什么有些字符串看起来一样,但在检查字符串等价时被认为是不相同的?
- bash - 用于 jq 查询的 Bash 变量替换始终返回 null
- parsing - 带有 DFS 的 AST 的退出条件