CGAL 求三维体数据的交并差(三维布尔运算)
本示例使用 boost_1_68_0, CGAL-5.1.2
特别提醒: 目前CGAL5以上版本可以用头文件模式使用, 编译出来的东西运行仅仅依赖libgmp 和libmpfr , 以前编译出来的会依赖一堆boost和cgal 的dll,部署容易出错.
CGAL首先是模板库开发, 要先定义一堆模板对象:
#pragma once// Construction kernel
#include "CGAL/Exact_predicates_exact_constructions_kernel.h"
#include "CGAL/Exact_predicates_inexact_constructions_kernel.h"// Polygon
#include "CGAL/Nef_polyhedron_2.h"
#include "CGAL/Polygon_2.h"
#include "CGAL/Polygon_with_holes_2.h"// Polyhedron
#include "CGAL/convex_hull_3.h"
#include "CGAL/Polyhedron_3.h"
#include "CGAL/Polyhedron_incremental_builder_3.h"
#include "CGAL/Nef_polyhedron_3.h"
#include "CGAL/IO/Polyhedron_iostream.h"
#include "CGAL/IO/Nef_polyhedron_iostream_3.h"// Utils
#include "CGAL/exceptions.h"
#include "CGAL/assertions.h"
#include "CGAL/assertions_behaviour.h"
#include "CGAL/utils.h"
#include "CGAL/Real_timer.h"
#include "CGAL/bounding_box.h"// Straight skeleton
#include "CGAL/Straight_skeleton_builder_2.h"
#include "CGAL/Polygon_offset_builder_2.h"
#include "CGAL/compute_outer_frame_margin.h"
#include "CGAL/create_straight_skeleton_2.h"
#include "CGAL/create_straight_skeleton_from_polygon_with_holes_2.h"// Surface mesh
#include "CGAL/Surface_mesh.h"
#include "CGAL/Surface_mesh_default_triangulation_3.h"
#include "CGAL/Complex_2_in_triangulation_3.h"
#include "CGAL/Side_of_triangle_mesh.h"
#include "CGAL/boost/graph/graph_traits_Surface_mesh.h"
#include "CGAL/make_surface_mesh.h"
#include "CGAL/Surface_mesh_default_criteria_3.h"
#include "CGAL/Implicit_surface_3.h"// Polygon mesh processing
#include "CGAL/Polygon_mesh_processing/bbox.h"
#include "CGAL/Polygon_mesh_processing/self_intersections.h"
#include "CGAL/Polygon_mesh_processing/stitch_borders.h"
#include "CGAL/Polygon_mesh_processing/orientation.h"// Delaunay triangulation
#include "CGAL/Constrained_Delaunay_triangulation_2.h"
#include "CGAL/Triangulation_face_base_with_info_2.h"
#include "CGAL/Delaunay_mesher_2.h"
#include "CGAL/Delaunay_mesh_face_base_2.h"
#include "CGAL/Delaunay_mesh_size_criteria_2.h"// AABB tree for cutting plane
//#include "CGAL/AABB_intersections.h"
#include "CGAL/AABB_tree.h"
#include "CGAL/AABB_traits.h"
#include "CGAL/boost/graph/graph_traits_Polyhedron_3.h"
#include "CGAL/AABB_halfedge_graph_segment_primitive.h"
#include "CGAL/AABB_face_graph_triangle_primitive.h"// Poisson for Point Cloud
//#include "CGAL/trace.h"
#include "CGAL/Surface_mesh_default_triangulation_3.h"
#include "CGAL/make_surface_mesh.h"
#include "CGAL/Implicit_surface_3.h"
#include "CGAL/Poisson_reconstruction_function.h"
#include "CGAL/Point_with_normal_3.h"
#include "CGAL/property_map.h"
#include "CGAL/compute_average_spacing.h"// IO
#include "CGAL/IO/Complex_2_in_triangulation_3_file_writer.h"
#include "CGAL/IO/facets_in_complex_2_to_triangle_mesh.h"
#include "CGAL/IO/output_surface_facets_to_polyhedron.h"//#ifdef CGAL_EIGEN3_ENABLED
//#include "CGAL/Eigen_solver_traits.h"
//#endif//#include "Base3D/UGPolySet.h"#include "CGAL/GMP/Gmpq_type.h"
namespace GeoStar
{namespace Kernel{namespace CGALData{// 基本要素typedef CGAL::Color CGAL_Color;typedef CGAL::Bbox_2 CGAL_Bbox2;typedef CGAL::Bbox_3 CGAL_Bbox3;// Kernel2结构typedef CGAL::Gmpq NT2;typedef CGAL::Extended_cartesian<NT2> CGAL_Kernel2;typedef CGAL::Point_2<CGAL_Kernel2> CGAL_Point2;typedef CGAL::Line_2<CGAL_Kernel2> CGAL_Line2;// 二维多边形结构typedef CGAL::Polygon_2<CGAL_Kernel2> CGAL_Polygon;typedef CGAL::Polygon_with_holes_2<CGAL_Kernel2> CGAL_Polygon_with_holes;// 二维矩阵typedef CGAL_Kernel2::Aff_transformation_2 CGAL_Aff_transformation2;// Kernel3结构typedef CGAL::Exact_predicates_exact_constructions_kernel CGAL_Exact_Kernel3;typedef CGAL::Exact_predicates_inexact_constructions_kernel CGAL_Inexact_Kernel3;typedef CGAL_Exact_Kernel3 CGAL_Kernel3;typedef CGAL::Simple_cartesian<double> CGAL_Simple_Kernel;typedef CGAL::Epick CGAL_Epick_Kernel;// 三维矩阵typedef CGAL_Exact_Kernel3::Aff_transformation_3 CGAL_Exact_transformation3;typedef CGAL_Inexact_Kernel3::Aff_transformation_3 CGAL_Inexact_transformation3;typedef CGAL_Exact_transformation3 CGAL_transformation3;// 三维多面体typedef CGAL::Polyhedron_3<CGAL_Exact_Kernel3> CGAL_Exact_Polyhedron;typedef CGAL::Polyhedron_3<CGAL_Inexact_Kernel3> CGAL_Inexact_Polyhedron;typedef CGAL_Exact_Polyhedron CGAL_Polyhedron;// Boolean operations work only with exact kerneltypedef CGAL::Nef_polyhedron_2<CGAL_Kernel2> CGAL_Nef_polyhedron2;typedef CGAL::Nef_polyhedron_3<CGAL_Exact_Kernel3> CGAL_Nef_polyhedron3;// 三维基本类型typedef CGAL::Point_3<CGAL_Exact_Kernel3> CGAL_Exact_Point3;typedef CGAL::Point_3<CGAL_Inexact_Kernel3> CGAL_Inexact_Point3;typedef CGAL_Exact_Point3 CGAL_Point3;typedef CGAL::Line_3<CGAL_Exact_Kernel3> CGAL_Exact_Line3;typedef CGAL::Line_3<CGAL_Inexact_Kernel3> CGAL_Inexact_Line3;typedef CGAL_Exact_Line3 CGAL_Line3;typedef CGAL::Segment_3<CGAL_Exact_Kernel3> CGAL_Exact_Segment3;typedef CGAL::Segment_3<CGAL_Inexact_Kernel3> CGAL_Inexact_Segment3;typedef CGAL_Exact_Segment3 CGAL_Segment3;typedef CGAL::Vector_3<CGAL_Exact_Kernel3> CGAL_Exact_Vector3;typedef CGAL::Vector_3<CGAL_Inexact_Kernel3> CGAL_Inexact_Vector3;typedef CGAL_Exact_Vector3 CGAL_Vector3;typedef CGAL::Plane_3<CGAL_Exact_Kernel3> CGAL_Exact_Plane3;typedef CGAL::Plane_3<CGAL_Inexact_Kernel3> CGAL_Inexact_Plane3;typedef CGAL_Exact_Plane3 CGAL_Plane3;typedef CGAL::Direction_3<CGAL_Exact_Kernel3> CGAL_Exact_Direction_3;typedef CGAL::Direction_3<CGAL_Inexact_Kernel3> CGAL_Inexact_Direction_3;typedef CGAL_Exact_Direction_3 CGAL_Direction_3;// AABB Treetypedef CGAL::AABB_face_graph_triangle_primitive<CGAL_Exact_Polyhedron> CGAL_Exact_AABB_Primetive;typedef CGAL::AABB_face_graph_triangle_primitive<CGAL_Inexact_Polyhedron> CGAL_Inexact_AABB_Primetive;typedef CGAL::AABB_traits<CGAL_Exact_Kernel3, CGAL_Exact_AABB_Primetive> CGAL_Exact_AABB_Traits;typedef CGAL::AABB_traits<CGAL_Inexact_Kernel3, CGAL_Inexact_AABB_Primetive> CGAL_Inexact_AABB_Traits;typedef CGAL::AABB_tree<CGAL_Exact_AABB_Traits> CGAL_Exact_AABB_Tree;typedef CGAL::AABB_tree<CGAL_Inexact_AABB_Traits> CGAL_Inexact_AABB_Tree;typedef CGAL_Exact_AABB_Tree CGAL_AABB_Tree;// Surface Meshtypedef CGAL::Surface_mesh<CGAL_Exact_Point3> CGAL_Exact_Surface_Mesh;typedef CGAL::Surface_mesh<CGAL_Inexact_Point3> CGAL_Inexact_Surface_Mesh;typedef CGAL_Exact_Surface_Mesh CGAL_Surface_Mesh;typedef CGAL_Point2 * Point2_iterator;typedef std::pair<Point2_iterator, Point2_iterator> Point2_range;typedef std::list<Point2_range> CGAL_Path2;typedef CGAL_Path2* Path2_iterator;typedef std::vector<Path2_iterator> CGAL_Polyline2;typedef CGAL_Point3 * Point3_iterator;typedef std::pair<Point3_iterator, Point3_iterator> Point3_range;typedef std::list<Point3_range> CGAL_Path3;typedef CGAL_Path3* Path3_iterator;typedef std::vector<Path3_iterator> CGAL_Polyline3;}}
}
调用文件如下:
#include "stdafx.h"#include <iostream>
#include "cgaldefine.h"#pragma comment(lib,"libgmp-10.lib")
#pragma comment(lib,"libmpfr-4.lib")
//#include <CGAL/Simple_cartesian.h>
//typedef CGAL::Simple_cartesian<double> Kernel;
//typedef Kernel::Point_2 Point_2;
//typedef Kernel::Segment_2 Segment_2;
//
//
//int testpoint()
//{
// //!笛卡尔坐标系双精度浮点类型的点和线段
// Point_2 p(1, 1), q(10, 10);
// std::cout << "p = " << p << std::endl;
// std::cout << "q = " << q.x() << " " << q.y() << std::endl;
// std::cout << "sqdist(p,q) = "
// << CGAL::squared_distance(p, q) << std::endl;
//
// Segment_2 s(p, q);
// Point_2 m(5, 9);
//
// std::cout << "m = " << m << std::endl;
// std::cout << "sqdist(Segment_2(p,q), m) = "
// << CGAL::squared_distance(s, m) << std::endl;
// std::cout << "p, q, and m ";
// //!方位
// switch (CGAL::orientation(p, q, m)) {
//
//
//
// case CGAL::COLLINEAR:
// std::cout << "are collinear\n";
// break;
// case CGAL::LEFT_TURN:
// std::cout << "make a left turn\n";
// break;
// case CGAL::RIGHT_TURN:
// std::cout << "make a right turn\n";
// break;
// }
// std::cout << " midpoint(p,q) = " << CGAL::midpoint(p, q) << std::endl;
// system("pause");
// return 0;
//}//#include <CGAL/Exact_integer.h>
//#include <CGAL/Homogeneous.h>
//#include <CGAL/Nef_polyhedron_3.h>
//typedef CGAL::Homogeneous<CGAL::Exact_integer> Kernel;
//typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron;
//
//int main()
//{
// Nef_polyhedron N0(Nef_polyhedron::EMPTY);
// Nef_polyhedron N1(Nef_polyhedron::COMPLETE);
// CGAL_assertion(N0 == N1.complement());
// CGAL_assertion(N0 != N1);
//
//}//
//#include <CGAL/Exact_integer.h>
//#include <CGAL/Extended_homogeneous.h>
//#include <CGAL/Nef_polyhedron_3.h>
//typedef CGAL::Exact_integer NT;
//typedef CGAL::Extended_homogeneous<NT> Kernel;
//typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron;
//typedef Nef_polyhedron::Plane_3 Plane_3;
//typedef Kernel::Plane_3 Plane_3;
//int main() {
// Nef_polyhedron N1(Plane_3(2, 5, 7, 11), Nef_polyhedron::INCLUDED);
// Nef_polyhedron N2(Plane_3(2, 5, 7, 11), Nef_polyhedron::EXCLUDED);
// CGAL_assertion(N1 >= N2);
// CGAL_assertion(N2 <= N1);
// CGAL_assertion(N1 != N2);
// CGAL_assertion(N1 > N2);
// CGAL_assertion(N2 < N1);
// N2 = N2.closure();
// CGAL_assertion(N1 == N2);
// CGAL_assertion(N1 >= N2);
// CGAL_assertion(N1 <= N2);
// return 0;
//}//#include <CGAL/Exact_integer.h>
//#include <CGAL/Homogeneous.h>
//
//#include <CGAL/Nef_polyhedron_3.h>
//#include <CGAL/IO/Nef_polyhedron_iostream_3.h>
//typedef CGAL::Exact_integer NT;
//typedef CGAL::Homogeneous<NT> Kernel;
//typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron;
//int main() {
// Nef_polyhedron N;
// std::cin >> N;
// CGAL_assertion((N - N.boundary()) == N.interior());
// CGAL_assertion(N.closure() == N.complement().interior().complement());
// CGAL_assertion(N.regularization() == N.interior().closure());
// N.intersection(N);
//
// return 0;
//}
#define CGAL_TYPE GeoStar::Kernel::CGALData typedef CGAL_TYPE::CGAL_Point2 Gs_Point2;
typedef CGAL_TYPE::CGAL_Point3 Gs_Point3;
typedef CGAL_TYPE::CGAL_Bbox2 Gs_Box2;
typedef CGAL_TYPE::CGAL_Bbox3 Gs_Box3;
typedef CGAL_TYPE::CGAL_Line2 Gs_Line2;
typedef CGAL_TYPE::CGAL_Line3 Gs_Line3;
typedef CGAL_TYPE::CGAL_Path2 Gs_Path2;
typedef CGAL_TYPE::CGAL_Polyline3 Gs_Polyline2;
typedef CGAL_TYPE::CGAL_Path3 Gs_Path3;
typedef CGAL_TYPE::CGAL_Polyline3 Gs_Polyline3;typedef CGAL_TYPE::CGAL_Segment3 Gs_Segment3;
typedef CGAL_TYPE::CGAL_Polygon Gs_Polygon;
typedef CGAL_TYPE::CGAL_Polygon_with_holes Gs_Polygon_With_Holes;
typedef CGAL_TYPE::CGAL_Exact_Polyhedron Gs_Polyhedron2;
typedef CGAL_TYPE::CGAL_Nef_polyhedron2 Gs_Nef_Polyhedron2;
typedef CGAL_TYPE::CGAL_Polyhedron Gs_Polyhedron3;
typedef CGAL_TYPE::CGAL_Nef_polyhedron3 Gs_Nef_Polyhedron3;
typedef CGAL_TYPE::CGAL_Plane3 Gs_Plane3;
typedef CGAL_TYPE::CGAL_Direction_3 Gs_Direction_3;
typedef CGAL_TYPE::CGAL_AABB_Tree Gs_AABB_Tree;
typedef CGAL_TYPE::CGAL_Surface_Mesh Gs_Surface_Mesh;
//CGAL::convert_nef_polyhedron_to_polygon_meshvoid fill_cube_1(Gs_Polyhedron3& poly)
{std::string input ="OFF\n\
8 12 0\n\
-1 -1 -1\n\
-1 1 -1\n\
1 1 -1\n\
1 -1 -1\n\
-1 -1 1\n\
-1 1 1\n\
1 1 1\n\
1 -1 1\n\
3 0 1 3\n\
3 3 1 2\n\
3 0 4 1\n\
3 1 4 5\n\
3 3 2 7\n\
3 7 2 6\n\
3 4 0 3\n\
3 7 4 3\n\
3 6 4 7\n\
3 6 5 4\n\
3 1 5 6\n\
3 2 1 6";std::stringstream ss;ss << input;ss >> poly;
}
void fill_cube_2(Gs_Polyhedron3& poly)
{std::string input ="OFF\n\
8 12 0\n\
-0.5 -0.5 -0.5\n\
-0.5 0.5 -0.5\n\
0.5 0.5 -0.5\n\
0.5 -0.5 -0.5\n\
-0.5 -0.5 0.5\n\
-0.5 0.5 0.5\n\
0.5 0.5 0.5\n\
0.5 -0.5 0.5\n\
3 0 1 3\n\
3 3 1 2\n\
3 0 4 1\n\
3 1 4 5\n\
3 3 2 7\n\
3 7 2 6\n\
3 4 0 3\n\
3 7 4 3\n\
3 6 4 7\n\
3 6 5 4\n\
3 1 5 6\n\
3 2 1 6";std::stringstream ss;ss << input;ss >> poly;
}
int main() {//构造两个多面体Gs_Polyhedron3 cube1, cube2;fill_cube_1(cube1);fill_cube_2(cube2);Gs_Nef_Polyhedron3 nef1(cube1);Gs_Nef_Polyhedron3 nef2(cube2);//交auto t = nef1.intersection(nef2);//并nef1.join(nef2);//对称差nef1.symmetric_difference(nef2);//差nef1.difference(nef2);//凸包nef1.boundary();//nef1.simplify();nef1.is_simple();return 0;
}
vs工程资源:
https://download.csdn.net/download/chijingjing/21455609
CGAL 求三维体数据的交并差(三维布尔运算)相关推荐
- MATLAB生成三维体数据
MATLAB生成三维体数据 一.三维体数据的生成 二.多二维矩阵生成三维体数据 三.多二维图像生成三维体数据 四.DICOM序列生成三维体数据 五.其他 by HPC_ZY 之前写了医学影像三维重建的 ...
- matlab标量数据,可视化标量三维体数据的方法
显示 MRI 数据的方法 标量数据的示例包括磁共振成像 (MRI) 数据.这种数据通常包含在一个三维体(例如人体)内采集的多个切片平面.MATLAB 包括一个 MRI 数据集,其中包含人类头部的 27 ...
- 三维体数据分割算法及实现
三维体数据分割算法及实现 本文基于分裂合并分割算法,提出了两种新的分割算法:基于八叉树的分裂合并算法和基于自适应包围盒的分裂合并算法.下面将对这两种算法进行描述. 1 分裂合并法分析 区域生长法的原理 ...
- Matlab:可视化标量三维体数据的方法
Matlab:可视化标量三维体数据的方法 什么是标量三维体数据? 显示 MRI 数据的方法 更改数据格式 显示 MRI 数据的图像 显示二维等高线切片 显示三维等高线切片 将等值面应用于 MRI 数据 ...
- C# 集合交、并、差、去重,对象集合交并差
关键词:C# List 集合 交集.并集.差集.去重, 对象集合. 对象.引用类型.交并差.List<T> 有时候看官网文档是最高效的学习方式! 一.简单集合 Intersect 交集, ...
- 计算机语言平均数怎么算,使用python怎么求三个数的平均值
使用python怎么求三个数的平均值 发布时间:2021-04-27 17:31:39 来源:亿速云 阅读:64 作者:Leah 本篇文章给大家分享的是有关使用python怎么求三个数的平均值,小编觉 ...
- kaggle实战—泰坦尼克(三、数据重构)
kaggle实战-泰坦尼克(一.数据分析) kaggle实战-泰坦尼克(二.数据清洗及特征处理) kaggle实战-泰坦尼克(三.数据重构) kaggle实战-泰坦尼克(四.数据可视化) kaggle ...
- python数字组合算法_python - 简单算法题 - 求三位数组合
求三位数组合 lst = [3, 6, 2, 7] 这四个数字能组成多少个互不相同且无重复数字的三位数?比如362算一个,326算一个,请逐个输出他们 思路分析 从4个数里面取3个数,且不重复,然后进 ...
- Bailian2932 期末考试第三题——最大最小数之差【文本+进制】
2932:期末考试第三题--最大最小数之差 总时间限制: 1000ms 内存限制: 65536kB 描述 输入一串长度不超过20的字符串,提取出其中可以表示十六进制数的数字和字母(数字0到9,及字母a ...
最新文章
- “偷懒”上热搜!南京大三学生自制宿舍关灯神器火了,网友:希望量产
- 听说这是写毕业论文的你?
- 计算机二级执行程序,计算机二级VFP程序文件的建立与执行
- Zynq器件XADC模块介绍
- Nginx配置免费SSL证书
- C语言再学习 -- linux 压缩与解压缩含义
- java mac pos_pos终端mac国密(sm4)算法(java实现)
- eclipse java main方法传参数
- shell脚本连接、读写、操作mysql数据库实例
- 文件怎么更新_安装累积更新丢文件似乎已成为惯例 KB4556799同样出现文件丢失问题...
- CV学习笔记-数字图像概述
- 30天敏捷生活(7):生成行动计划
- 4. 正则表达式(4)
- HTML5 webSQL查看表结构
- 键盘表和ASCII码表
- PLC仿真搭建问题与解答
- Acwing 187. 导弹防御系统
- requests关于Exceeded 30 redirects
- python 录音vad_语音活性检测器py-webrtcvad安装使用
- DAY 4 | 自学前端第四天