CGAL 二维Delaunay三角剖分

一、概述

  类Delaunay_triangulation_2<Traits,Tds>用来表示平面上一组数据点的Delaunay三角剖分。Delaunay三角剖分满足以下空圆性质(也称为Delaunay性质):三角剖分的任何面的围合圆内部不包含任何数据点。对于没有四个共圆点子集的点集,Delaunay三角剖分是唯一的,它与点集的Voronoi图是对偶的。类Delaunay_triangulation_2<Traits,Tds>源自类Triangulation_2<Traits,Tds>。类Delaunay_triangulation_2<Traits,Tds>继承由基本类Triangulation_2<Traits,Tds>定义的类型。traits类提供的其他类型被定义为表示双重Voronoi图。类Delaunay_triangulation_2<Traits,Tds>覆盖在三角剖分中插入、移动或移除点的成员函数,以维护Delaunay属性。它还有一个成员函数(Vertex_handle Delaunay_triangulation_2::nearest_vertex(const Point& p))来进行最近邻查询,还有一个成员函数来构造双Voronoi图的元素(顶点和边)。

二、代码实现

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>   // 内核
#include <CGAL/Projection_traits_xy_3.h>   // xy投影面
#include <CGAL/Delaunay_triangulation_2.h> // Delaunay三角剖分

#include <fstream>
// 保存成.ply
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/graph_traits_Delaunay_triangulation_2.h>


typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Projection_traits_xy_3<K>  Gt;
typedef CGAL::Delaunay_triangulation_2<Gt> Delaunay;
typedef K::Point_3   Point;
using Mesh = CGAL::Surface_mesh<Point>;

int main()
{
    
    
	std::ifstream in("terrain.cin");
	std::istream_iterator<Point> begin(in);
	std::istream_iterator<Point> end;

	Delaunay dt(begin, end);
	std::cout << dt.number_of_vertices() << std::endl;

	// 保存成.ply
	Mesh dsm_mesh;
	CGAL::copy_face_graph(dt, dsm_mesh);
	std::ofstream dsm_ofile("terrain.ply", std::ios_base::binary);
	CGAL::IO::set_binary_mode(dsm_ofile);
	CGAL::IO::write_PLY(dsm_ofile, dsm_mesh);
	dsm_ofile.close();

	return 0;
}

三、结果展示

在这里插入图片描述

四、测试数据

1 2 3 1
4 5 6 1
1 2 3 1
7 8 9 1
3 5 6 1
7 8 3 1
9 6 7 1
5 6 3 1
4 3 8 1
5 5 8 1
7 4 2 1

猜你喜欢

转载自blog.csdn.net/qq_36686437/article/details/130294485