CGAL - 在Delaunay Triangulation之后检索三角面顶点索引

  • 目前在使用cgal构建二维delaunay网,当我从Face_handle访问顶点时发现除了x和y坐标之外,每个点都有更多的关联数据,无法访问三角面的三个顶点对应全局的索引。
    因此,我想知道是否可以检索每个点的索引,以便我可以在另一个向量中访问我自己的点结构,经过苦苦寻找,在stackoverflow上找到了解决方案,特此记录一下,采用以下代码可实现目的:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <vector>

typedef CGAL::Exact_predicates_inexact_constructions_kernel            Kernel;
typedef CGAL::Triangulation_vertex_base_with_info_2<unsigned int, Kernel> Vb;
typedef CGAL::Triangulation_data_structure_2<Vb>                       Tds;
typedef CGAL::Delaunay_triangulation_2<Kernel, Tds>                    Delaunay;
typedef Kernel::Point_2                                                Point;

int main() {
  std::vector< std::pair<Point,unsigned> > points;
  points.push_back( std::make_pair( Point(1,1), 0 ) );
  points.push_back( std::make_pair( Point(1,2), 1 ) );
  points.push_back( std::make_pair( Point(1,3), 2 ) );
  points.push_back( std::make_pair( Point(2,1), 3 ) );
  points.push_back( std::make_pair( Point(2,2), 4 ) );
  points.push_back( std::make_pair( Point(2,3), 5 ) );

  Delaunay triangulation;
  triangulation.insert(points.begin(),points.end());

  for(Delaunay::Finite_faces_iterator fit = triangulation.finite_faces_begin();
      fit != triangulation.finite_faces_end(); ++fit) {

    Delaunay::Face_handle face = fit;
    unsigned int Vid1 =face->vertex(0)->info();
    unsigned int Vid2 =face->vertex(1)->info();
    unsigned int Vid3 =face->vertex(2)->info();
    std::cout << "Triangle:\t" << triangulation.triangle(face) << std::endl;
    std::cout << "Vertex 0:\t" << triangulation.triangle(face)[0] << std::endl;
    std::cout << "Vertex 0:\t" << face->vertex(0)->info() << std::endl;
  }
}

原文地址:https://stackoverflow.com/questions/19850354/cgal-retrieve-vertex-index-after-delaunay-triangulation

补充:
其他使用方法也可参考官网实例:https://doc.cgal.org/latest/Triangulation_2/index.html#title40

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值