C++ cgal中的三角剖分面

C++ cgal中的三角剖分面,c++,computational-geometry,cgal,C++,Computational Geometry,Cgal,我试图理解CGAL中的三角剖分是如何工作的,我想编辑多边形三角剖分的面。该计划是: #include <CGAL/Point_2.h> #include <CGAL/Triangulation_2.h> #include <CGAL/Triangulation_euclidean_traits_2.h> #include <vector> typedef CGAL::Cartesian<double>

我试图理解CGAL中的三角剖分是如何工作的,我想编辑多边形三角剖分的面。该计划是:

#include <CGAL/Point_2.h>
#include <CGAL/Triangulation_2.h>
#include <CGAL/Triangulation_euclidean_traits_2.h>
#include <vector>
typedef CGAL::Cartesian<double>                              TutorialR;

typedef CGAL::Point_2<TutorialR>                             Point;
typedef CGAL::Vector_2<TutorialR>                            Vector;
typedef CGAL::Segment_2<TutorialR>                           Segment;
typedef CGAL::Triangle_2<TutorialR>                          Triangle;
typedef CGAL::Circle_2<TutorialR>                            Circle;
typedef CGAL::Bbox_2                                         Bbox;
typedef CGAL::Aff_transformation_2<TutorialR>                Transformation;

typedef CGAL::Polygon_traits_2<TutorialR>                    Polygon_traits;
typedef std::list< Point >                                   Polygon_Container;
typedef CGAL::Polygon_2< Polygon_traits, Polygon_Container > Polygon;

typedef CGAL::Triangulation_euclidean_traits_2<TutorialR>    EucliTraits;
typedef CGAL::Triangulation_vertex_base_2<EucliTraits>       TrianVbase;
typedef CGAL::Triangulation_face_base_2<EucliTraits>         TrianFbase;
typedef CGAL::Triangulation_default_data_structure_2<
                  EucliTraits, TrianVbase, TrianFbase>       TrianDs;
typedef CGAL::Triangulation_2<EucliTraits, TrianDs>          Triangulation;
typedef Triangulation::Face_iterator Face_iterator;
typedef Triangulation::Face Face;
typedef Face::Face_handle Face_handle;

int main()
{
  const int numPoints1 = 4;

  static Point points1[numPoints1] = { 
    Point(1, 0.3),
    Point(0.0, -0.9),
    Point(-1, 0)
    };

  Point point2(0.0, 0.0);
  Point point3(-1,1);

  std::vector<Point> points4(3); 
  points4[0] = Point(1, 0.9);
  points4[1] = Point(1.4, -0.3);
  points4[2] = Point(0.6, 0);

  Triangulation tr;                           // create an empty triangulation

  tr.insert(points1, points1+numPoints1);       // insert array of Point-s
  tr.insert(point2);                            // insert interior Point
  tr.insert(point3);                            // insert exterior Point
  tr.insert(points4.begin(),points4.end());     // insert vector of Point-s

 // std::cout << tr;                            

 // short hand type definitions

 Face_iterator it = tr.faces_begin(),       
 beyond = tr.faces_end();                   
 Face face;
 Face_handle neighbor;

 while(it != beyond) {
 face = *it;                                //get face
 ++it;                                      //advance the iterator
 int count = 0;                             //initialize counter
 for (int i=0; i<3;++i) {                   //for index 0,1,2
     neighbor = face.neighbor(i);           //get neighbor
     if (tr.is_infinite(neighbor)) {        //test its infinity
         ++count;
     }
 }

 std::cout << tr.triangle(face) << std::endl
            << "has " << count << " infinite neighbor(s)" <<std::endl;

 }
}
#包括
#包括
#包括
#包括
typedef CGAL::笛卡尔教程;
typedef CGAL::Point_2 Point;
typedef CGAL::Vector_2 Vector;
typedef CGAL::段_2段;
typedef CGAL::Triangle_2 Triangle;
typedef CGAL::Circle_2 Circle;
typedef CGAL::Bbox_2 Bbox;
typedef CGAL::Aff_变换_2变换;
typedef CGAL::多边形特征2多边形特征;
typedef std::listPolygon_容器;
typedef CGAL::Polygon_2Polygon;
typedef CGAL::三角剖分_欧几里德特征_2欧几里德特征;
typedef CGAL::三角剖分\顶点\底面\ 2三角底面;
typedef CGAL::三角测量\面\基\ 2三角基;
typedef CGAL::三角剖分\默认\数据\结构\ 2<
EucliTraits,TrianVbase,TrianVbase>TrianDs;
typedef CGAL::三角剖分_2三角剖分;
typedef三角剖分::面\迭代器面\迭代器;
typedef三角测量::面;
typedef Face::Face_handle Face_handle;
int main()
{
常量int numPoints1=4;
静态点1[numPoints1]={
第(1,0.3)点,
点(0.0,-0.9),
点(-1,0)
};
第2点(0.0,0.0);
第3点(-1,1);
std::向量点4(3);
点4[0]=点(1,0.9);
点4[1]=点(1.4,-0.3);
点4[2]=点(0.6,0);
三角剖分tr;//创建一个空三角剖分
tr.insert(points1,points1+numPoints1);//插入点-s的数组
tr.insert(point2);//插入内部点
tr.insert(point3);//插入外部点
tr.insert(points4.begin(),points4.end());//插入点-s的向量

//std::cout三角形函数需要一个
Face\u句柄作为参数。我还稍微简化了typedef

#包括
#包括
#包括
typedef CGAL::精确谓词\u不精确结构\u内核;
typedef CGAL::Point_2 Point;
typedef CGAL::三角剖分_2三角剖分;
typedef三角剖分::面\迭代器面\迭代器;
typedef三角测量::面\手柄面\手柄;
int main()
{
常量int numPoints1=4;
静态点1[numPoints1]={
第(1,0.3)点,
点(0.0,-0.9),
点(-1,0)
};
第2点(0.0,0.0);
第3点(-1,1);
std::向量点4(3);
点4[0]=点(1,0.9);
点4[1]=点(1.4,-0.3);
点4[2]=点(0.6,0);
三角剖分tr;//创建一个空三角剖分
tr.insert(points1,points1+numPoints1);//插入点-s的数组
tr.insert(point2);//插入内部点
tr.insert(point3);//插入外部点
tr.insert(points4.begin(),points4.end());//插入点-s的向量
//速记类型定义
Face_迭代器it=tr.faces_begin(),
beyond=tr.faces_end();
面\手柄面;
面对邻居;
而(它!=超越){
face=it;//获取face
++it;//推进迭代器
int count=0;//初始化计数器
for(int i=0;ineighbor(i);//获取邻居
如果(tr.is_infinite(neighbor)){//测试它的无限性
++计数;
}
}

std::你能接受这个答案吗?这些就是我们在官方CGAL文档中所期望的例子:feelsbadman: