C++ 从CGAL'检索顶点;s-Delaunay约束三角剖分

C++ 从CGAL'检索顶点;s-Delaunay约束三角剖分,c++,geometry,computational-geometry,cgal,C++,Geometry,Computational Geometry,Cgal,我有一个2D点列表,它描述了一个简单的多边形。由于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));

我有一个2D点列表,它描述了一个简单的多边形。由于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;
        }

    }
Polygon_2polygon;
//从矢量创建多边形
对于(int j=0;j<(*itVectorPoint2D).size();j++){
polygon.push_back(点((*itVectorPoint2D[j].x,(*itVectorPoint2D[j].y));
}
//将多边形插入到受约束的三角剖分中
CDT-CDT;
插入_多边形(cdt,多边形);
//标记由多边形限定的域内的面
标记域(cdt);
对于(CDT::Finite_faces_iterator fit=CDT.Finite_faces_begin();fit!=CDT.Finite_faces_end();++fit)
{
if(fit->info().在_域()中){

std::cout vertex(0))以下内容适用于CGAL 4.2。请注意,使用CGAL 4.3时,将有一个专用函数以更集成的方式完成此工作,就像为
Delaunay_三角剖分_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;
}
#包括
#包括
#包括
#包括
#包括
typedef CGAL::精确谓词不精确结构内核K;
typedef CGAL::三角剖分(顶点、底面和信息)Vb;
typedef CGAL::约束的_三角剖分_面_底_2 Fb;
typedef CGAL::三角测量数据结构TDS;
typedef CGAL::精确谓词标记Itag;
typedef CGAL::约束的Delaunay三角剖分CDT;
typedef-CDT::Point-Point;
typedef CGAL::space_sort_traits_adapter_2 Search_traits;
模板
无效插入带有\u信息的\u(CDT&CDT、先输入者、后输入者)
{
std::向量指数;
std::向量点;
std::ptrdiff_t index=0;
for(输入计算器it=first;it!=last;++it){
点。将_向后推(*it);
index.push_back(index++);
}
CGAL::spatical_sort(index.begin()、index.end()、Search_traits(&(points[0])、cdt.geom_traits());
CDT::顶点句柄v\u提示;
CDT::Face_句柄提示;
for(typename std::vector::const_迭代器)
它=index.begin(),end=index.end();
它!=结束;++它){
v_hint=cdt.insert(点[*it],提示);
if(v_hint!=CDT::Vertex_handle()){
v_hint->info()=*它;
提示=v_提示->面();
}
}
}
int main()
{
标准::向量<点>点;
点。向后推(点(0,0));
点。向后推(点(1,0));
点。向后推(点(0,1));
点。向后推(点(14,4));
点。向后推(点(2,2));
点。向后推(点(-4,0));
CDT-CDT;
插入带有_信息的_(cdt,points.begin(),points.end());
CGAL_断言(cdt.number_of_顶点()=6);
//检查信息设置是否正确。
有限顶点迭代器vit;
对于(vit=cdt.finite_顶点_begin();vit!=cdt.finite_顶点_end();++vit)
如果(点[vit->info()]!=vit->point()){

std::cerr以下内容适用于CGAL 4.2。请注意,使用CGAL 4.3时,将有一个专用函数以更集成的方式完成此工作,就像为
Delaunay\u triangulation\u 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;
}
#包括
#包括
#包括
#包括
#包括
typedef CGAL::精确谓词不精确结构内核K;
typedef CGAL::三角剖分(顶点、底面和信息)Vb;
typedef CGAL::约束的_三角剖分_面_底_2 Fb;
typedef CGAL::三角测量数据结构TDS;
typedef CGAL::精确谓词标记Itag;
typedef CGAL::约束的Delaunay三角剖分CDT;
typedef-CDT::Point-Point;
typedef CGAL::space_sort_traits_adapter_2 Search_traits;
模板
无效插入带有\u信息的\u(CDT&CDT、先输入者、后输入者)
{
std::向量指数;
std::向量点;
std::ptrdiff_t index=0;
for(输入计算器it=first;it!=last;++it){
点。将_向后推(*it);
index.push_back(index++);
}
CGAL::spatical_sort(index.begin()、index.end()、Search_traits(&(points[0])、cdt.geom_traits());
CDT::顶点句柄v\u提示;
CDT::Face_句柄提示;
for(typename std::vector::const_迭代器)
它=index.begin(),end=index.end();
它!=结束;++它){
v_hint=cdt.insert(点[*it],提示);
if(v_hint!=CDT::Vertex_handle()){
v_hint->info()=*它;
提示=v_提示->面();
}
}
}
int main()
{
标准::向量<点>点;
点。向后推(点(0,0));
点。向后推(点(1,0));
点。向后推(点(0,1));
点。向后推(点(14,4));
点。向后推(点(2,2));
点。向后推(点(-4,0));
CDT-CDT;
插入带有_信息的_(cdt,points.begin(),points.end());
CGAL_断言(cdt.number_of_顶点()=6);
//检查信息设置是否正确。
有限顶点迭代器vit;
对于(vit=cdt.finite_顶点_begin();vit!=cdt.finite_顶点_end();++vit)
如果(点[vit->info()]!=vit->point()){

你需要索引来匹配插入顺序吗?或者如果索引与三角剖分中顶点的顺序匹配,你可以吗?@Slorio:我想检索我在第一个循环中使用的j,所以是输入顺序。你需要索引来匹配插入顺序吗?或者如果索引与ver的顺序匹配,你可以吗三角剖分中的细节?@slorio:我想检索我在第一个循环中使用的j,所以输入顺序是正确的。如果我理解得好,vit->info()返回j。因为我是CGAL的初学者,所以我不懂这行:CGAL::spatial_sort(index.begin(),index.end(),Search_traits(&(points[0]),cdt.geom_traits());这是干什么用的?非常感谢!为了加快在三角剖分中插入点的速度,点沿着希尔伯特曲线进行排序,以保证两个连续点彼此不远。排序是在索引上完成的。这是一个较晚的问题。但是,我没有看到一个关于如何在直观上像在非连续点上这样做的示例Aiden Delaunay三角剖分。有办法吗?看看我是否理解得很好,vit->info()返回j。因为我是CGAL的初学者,所以我不理解这行:CGAL::spatial_sort(index.begin(),in