cgal demo

[遍历Delaunay的顶点、边和面(C)]

#include<vector>
#include<algorithm>
#include<CGAL/point_generators_2.h>
#include<CGAL/algorithm.h>
#include<CGAL/random_selection.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include<CGAL/Delaunay_triangulation_2.h>

#define CGAL_USE_BASIC_VIEWER
#include <CGAL/draw_triangulation_2.h>


using namespace CGAL;

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point;
typedef Creator_uniform_2<double, Point> Creator;
typedef std::vector<Point> Vector;
typedef CGAL::Delaunay_triangulation_2<Kernel> Delaunay;
typedef Delaunay::Vertex_iterator Vertex_iterator;
typedef Delaunay::Vertex_handle Vertex_handle;
typedef Delaunay::Edge_iterator Edge_iterator;
typedef Delaunay::Face_iterator Face_iterator;


int main() {
	Vector points;
	points.reserve(10);

	Random_points_in_disc_2<Point, Creator> g(150.0);
	CGAL::cpp11::copy_n(g, 10, std::back_inserter(points));

	Delaunay dt;

	dt.insert(points.begin(), points.end());

	std::cout << "Vertices are:" << std::endl;
	for (Vertex_iterator vc = dt.vertices_begin(); vc != dt.vertices_end(); vc++) {
		Point p = vc->point();
		std::cout << "(" << p.x() << "," << p.y() << ")" << std::endl;
	}

	std::cout << "Edges are:" << std::endl;
	for (Edge_iterator eg = dt.edges_begin(); eg != dt.edges_end(); eg++) {
		for (int i = 0; i < 2; i++) {
			Vertex_handle f_v1 = eg->first->vertex(dt.cw(eg->second));
			Vertex_handle f_v2 = eg->first->vertex(dt.ccw(eg->second));
			Point p1 = f_v1->point();
			Point p2 = f_v2->point();
			std::cout << "(" << p1.x() << "," << p1.y() << ")" << "(" << p2.x() << "," << p2.y() << ")"<< std::endl;
		}
		
	}

	std::cout << "Faces are:" << std::endl;
	for (Face_iterator fa = dt.faces_begin(); fa != dt.faces_end(); fa++) {
		for (int i = 0; i < 3; i++) {
			Point p = fa->vertex(i)->point();
			std::cout << "(" << p.x() << "," << p.y() << ")";
		}
		std::cout<<std::endl;
	}

    
	CGAL::draw(dt);



	return EXIT_SUCCESS;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lst0426

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值