You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CGAL中是否有从edge_is_constrained_map转vertex_is_constrained_map的内置功能?

CGAL中edge_is_constrained_map转vertex_is_constrained_map的实现

CGAL目前没有提供直接完成这种转换的内置函数,但你可以通过手动遍历边集快速实现该功能,逻辑很直观:

  • 遍历所有标记为受约束的边
  • 将每条受约束边的两个端点顶点标记为受约束状态

以下是基于CGAL三角剖分的示例代码(假设你使用的是Constrained_triangulation_2类):

#include <CGAL/Constrained_triangulation_2.h>
#include <map>

// 假设已根据你的需求定义好三角剖分类型
typedef CGAL::Constrained_triangulation_2<...> CT;
typedef CT::Edge Edge;
typedef CT::Vertex_handle Vertex_handle;

void edge_constrained_to_vertex_constrained(const CT& ct,
                                            const std::map<Edge, bool>& edge_is_constrained_map,
                                            std::map<Vertex_handle, bool>& vertex_is_constrained_map) {
    // 清空顶点映射容器
    vertex_is_constrained_map.clear();
    
    // 遍历所有受约束边,标记对应顶点
    for (const auto& entry : edge_is_constrained_map) {
        if (entry.second) {
            Vertex_handle v1 = entry.first.first->vertex(entry.first.second);
            Vertex_handle v2 = entry.first.first->vertex(entry.first.third);
            vertex_is_constrained_map[v1] = true;
            vertex_is_constrained_map[v2] = true;
        }
    }
    
    // 可选:为未被标记的有限顶点设置默认非约束状态
    for (auto vh : ct.finite_vertex_handles()) {
        if (!vertex_is_constrained_map.count(vh)) {
            vertex_is_constrained_map[vh] = false;
        }
    }
}

如果你的应用场景不是三角剖分,核心逻辑依然通用:遍历所有受约束边,标记其关联的顶点即可。

内容的提问来源于stack exchange,提问作者Fer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 16:01:00