【问题标题】:Retrieve vertices from CGAL's Delaunay Constrained Triangulation从 CGAL 的 Delaunay 约束三角剖分中检索顶点
【发布时间】:2013-07-16 15:07:32
【问题描述】:

我有一个二维点列表,它描述了一个简单的多边形。由于 CGAL,我计算了 Delaunay 约束。

    Polygon_2 polygon;
    //Create a polygon from a vector
    for(int j=0; j < (*itVectorPoint2D).size(); j++) {
        polygon.push_back(Point((*itVectorPoint2D)[j].x,(*itVectorPoint2D)[j].y));
    }

    //Insert the polygon into a constrained triangulation
    CDT cdt;
    insert_polygon(cdt,polygon);
    //Mark facets that are inside the domain bounded by the polygon
    mark_domains(cdt);

    for (CDT::Finite_faces_iterator fit=cdt.finite_faces_begin(); fit!=cdt.finite_faces_end();++fit)
    {
        if (fit->info().in_domain()) {
            std::cout << (*(fit->vertex(0))) << ";" << (*(fit->vertex(1))) << ";" << (*(fit->vertex(2))) << std::endl;
        }

    }

我的问题是我想从初始向量中检索具有索引三元组的每个三角形。例如,对于由 0 定义的正方形:(0,0) 1:(1,0) 2:(1,1) 和 3:(0,1),我要检索 (0强>、12)和(023) .我可以检索当前顶点的坐标并将它们与向量中的每个点进行比较,但我认为它(而且效率低下,可能是问题的根源?)。

有办法吗?

【问题讨论】:

  • 您是否需要索引来匹配插入顺序,或者如果索引与三角剖分中顶点的顺序匹配,您是否可以?
  • @sloriot : 我想检索我在第一个循环中使用的 j,所以是输入顺序。

标签: c++ geometry computational-geometry cgal


【解决方案1】:

以下内容适用于 CGAL 4.2。请注意,在 CGAL 4.3 中,将有一个专用函数以更集成的方式完成这项工作,就像 hereDelaunay_triangulation_2 类所做的那样。

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <CGAL/Spatial_sort_traits_adapter_2.h>
#include <vector>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;

typedef CGAL::Triangulation_vertex_base_with_info_2<unsigned, K> Vb;
typedef CGAL::Constrained_triangulation_face_base_2<K>           Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb>              TDS;
typedef CGAL::Exact_predicates_tag                               Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, Itag> CDT;
typedef CDT::Point          Point;
typedef CGAL::Spatial_sort_traits_adapter_2<K,Point*> Search_traits;

template <class InputIterator>
void insert_with_info(CDT& cdt, InputIterator first,InputIterator last)
{
  std::vector<std::ptrdiff_t> indices;
  std::vector<Point> points;
  std::ptrdiff_t index=0;

  for (InputIterator it=first;it!=last;++it){
    points.push_back( *it);
    indices.push_back(index++);
  }

  CGAL::spatial_sort(indices.begin(),indices.end(),Search_traits(&(points[0]),cdt.geom_traits()));

  CDT::Vertex_handle v_hint;
  CDT::Face_handle hint;
  for (typename std::vector<std::ptrdiff_t>::const_iterator
    it = indices.begin(), end = indices.end();
    it != end; ++it){
    v_hint = cdt.insert(points[*it], hint);
    if (v_hint!=CDT::Vertex_handle()){
      v_hint->info()=*it;
      hint=v_hint->face();
    }
  }
}

int main()
{
  std::vector< Point > points;
  points.push_back( Point(0,0) );
  points.push_back( Point(1,0) );
  points.push_back( Point(0,1) );
  points.push_back( Point(14,4) );
  points.push_back( Point(2,2) );
  points.push_back( Point(-4,0) );


  CDT cdt;
  insert_with_info(cdt, points.begin(), points.end());

  CGAL_assertion( cdt.number_of_vertices() == 6 );

  // check that the info was correctly set.
  CDT::Finite_vertices_iterator vit;
  for (vit = cdt.finite_vertices_begin(); vit != cdt.finite_vertices_end(); ++vit)
    if( points[ vit->info() ] != vit->point() ){
      std::cerr << "Error different info" << std::endl;
      exit(EXIT_FAILURE);
    }
  std::cout << "OK" << std::endl;
}

【讨论】:

  • 如果我理解得很好,vit->info() 返回 j。因为我是 CGAL 的初学者,所以我不明白这行:CGAL::spatial_sort(indices.begin(),indices.end(),Search_traits(&(points[0]),cdt.geom_traits())) ;它有什么用?非常感谢!
  • 为了加快三角剖分中点的插入速度,点沿希尔伯特曲线排序,保证两个连续点彼此相距不远。排序是在索引上完成的。
  • 这是一个迟到的问题。但是,我没有看到像无约束的德劳内三角剖分那样直观地执行此操作的示例。有办法吗?
猜你喜欢
  • 2013-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-23
  • 1970-01-01
  • 1970-01-01
  • 2020-05-06
  • 2020-08-05
相关资源
最近更新 更多