作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想了解 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;
}
}
编译给我一个 tr.triangle(face) 的转换错误,但我不明白为什么。有人可以帮助我吗?
最佳答案
三角形函数需要一个 Face_handle
作为参数。我还稍微简化了 typedef。
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_2.h>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Point_2<Kernel> Point;
typedef CGAL::Triangulation_2<Kernel> Triangulation;
typedef Triangulation::Face_iterator Face_iterator;
typedef Triangulation::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
// short hand type definitions
Face_iterator it = tr.faces_begin(),
beyond = tr.faces_end();
Face_handle 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;
}
}
关于c++ - cgal中的三角剖分面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17816685/
我是一名优秀的程序员,十分优秀!