CGAL 快速构建三维凸包
快速 构建 三维 凸包
2023-09-14 09:15:11 时间
一、三维凸包
和二维凸包类似,给定一堆三维空间中的点,包含它们的最小凸多面体称为这些点的凸包。
二、代码实现
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/convex_hull_3.h>
#include <CGAL/Surface_mesh.h> // .ply格式
#include <vector>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K> Polyhedron_3;
typedef K::Point_3 Point_3;
typedef CGAL::Surface_mesh<Point_3> Surface_mesh;
int main(int argc, char* argv[])
{
std::string inFile("E://data//bunny.txt");
std::string outFile = "cgal//out.ply";
std::ifstream in(inFile);
std::vector<Point_3> points;
Point_3 p;
while (in >> p)
{
points.push_back(p);
}
// define polyhedron to hold convex hull
Polyhedron_3 poly;
// compute convex hull of non-collinear points
CGAL::convex_hull_3(points.begin(), points.end(), poly);
std::cout << "The convex hull contains " << poly.size_of_vertices() << " vertices" << std::endl;
Surface_mesh sm;
CGAL::convex_hull_3(points.begin(), points.end(), sm);
std::cout << "The convex hull contains " << num_vertices(sm) << " vertices" << std::endl;
// ---------------------------结果保存成.ply------------------------------
std::ofstream f(outFile, std::ios_base::binary);
CGAL::IO::set_binary_mode(f);
CGAL::IO::write_PLY(f, sm);
f.close();
return 0;
}
三、结果展示
四、结论
快速构建算法确实很快,比PCL里的算法快了将近10倍!!!!
相关文章
- L18 如何快速查找文档获得帮助
- 快速搭建Springboot项目的两种方式!!
- 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-人机界面如何快速调整大量控件的位置
- 如何快速把ps序列图层建立帧动画?
- 如何快速、低成本构建一套稳定、高效、可靠的互联网主播直播/商业直播(推流/分发/播放)方案
- 快速反编绎jar war包
- Atitit 前后端交互模式 目录 1.1. Ajax1 1.2. Fetch api1 1.3. 服务端脚本模式(简单快速)1 1.4. 浏览器注入对象、函数1 1.5. 浏览器插件模式
- 【万字】熬夜修行Android Studio技巧到出神入化,快速涨薪【建议收藏】
- 如何支撑企业快速构建数字孪生体
- LCP 40. 心算挑战-快速排序+贪心算法
- 6132. 使数组中所有元素都等于零-快速排序法
- 如何在IDEA中自定义模板、快速生成完整的代码?
- 为什么在域环境下不能进行快速用户切换?
- 华为云之RDS云数据库的管理使用与快速入门