CGAL将非manifold nef_polyhedron_3转换为三角网格
CGAL convert non-manifold Nef_polyhedron_3 to triangle mesh
在我的应用程序中,我有一个三角网格数据结构,我想用cgal进行布尔操作,并将结果转换为三角形网格。它可以正常工作,但是当结果是非manifold时,仅与nef_polyhedron_3一起使用。问题是我无法将其转换回三角形网格。
在以下代码中,我有一个立方体和一个棱镜,并且棱镜的边缘之一位于立方体的脸上,因此交叉路口将是非manifold。我可以使用nef_polyhedron_3进行操作,但是在操作后,我无法将其转换回三角形网格。
#include <CGAL/Exact_integer.h>
#include <CGAL/Homogeneous.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Polyhedron_incremental_builder_3.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Nef_polyhedron_3.h>
#include <CGAL/IO/Nef_polyhedron_iostream_3.h>
#include <CGAL/boost/graph/convert_nef_polyhedron_to_polygon_mesh.h>
#include <iostream>
#include <sstream>
#include <fstream>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point_3;
typedef CGAL::Surface_mesh<Point_3> Surface_mesh;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron_3;
typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron_3;
typedef Polyhedron_3::HalfedgeDS HalfedgeDS;
template <typename T>
void fill_cube (T& result)
{
std::string input =
"OFFn
8 12 0n
-0.5 -0.5 -0.5n
0.5 -0.5 -0.5n
0.5 -0.5 0.5n
-0.5 -0.5 0.5n
-0.5 0.5 -0.5n
0.5 0.5 -0.5n
0.5 0.5 0.5n
-0.5 0.5 0.5n
3 0 1 2n
3 0 2 3n
3 1 5 6n
3 1 6 2n
3 5 4 7n
3 5 7 6n
3 4 0 3n
3 4 3 7n
3 0 4 5n
3 0 5 1n
3 3 2 6n
3 3 6 7n";
std::stringstream ss;
ss << input;
ss >> result;
}
template <typename T>
void fill_prism (T& result)
{
std::string input =
"OFFn
6 8 0n
0.5 0 -0.5n
-0.25 0.433013 -0.5n
-0.25 -0.433013 -0.5n
0.5 0 0.5n
-0.25 0.433013 0.5n
-0.25 -0.433013 0.5n
3 2 1 0n
3 3 4 5n
3 0 1 4n
3 0 4 3n
3 1 2 5n
3 1 5 4n
3 2 0 3n
3 2 3 5n";
std::stringstream ss;
ss << input;
ss >> result;
}
int main()
{
{ // try with mesh processing
Surface_mesh cube;
Surface_mesh prism;
fill_cube (cube);
fill_prism (prism);
Surface_mesh result;
// will return false
bool success = CGAL::Polygon_mesh_processing::corefine_and_compute_difference (cube, prism, result);
}
{ // try with nef polyhedron
Polyhedron_3 cube;
Polyhedron_3 prism;
fill_cube (cube);
fill_prism (prism);
Nef_polyhedron_3 nefCube (cube);
Nef_polyhedron_3 nefPrism (prism);
Nef_polyhedron_3 result = nefCube - nefPrism;
Surface_mesh resultMesh;
// throws exception because is_polygon_soup_a_polygon_mesh(polygons) is false
CGAL::convert_nef_polyhedron_to_polygon_mesh (result, resultMesh, true);
}
system ("pause");
}
您是否知道如何将nef_polyhedron_3转换为三角网格?
在输出中,您具有非manifold边缘(Prism的一个边缘与立方体的脸相切)。因此,输出不是有效的表面网格,这就是为什么PMP方法未返回输出并且NEF也无法转换为多边形网格的原因。
我想我可以编写一个convert_nef_polyhedron_to_polygon_soup()
,它会给您一组三角形,而orient_polygon_soup()
可以复制所有非曼尼弗边缘,并且您将获得一个自相隔的三角形网格。
相关文章:
- 防止主数据类型C++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 努力将整数转换为链表。不知道我在这里做错了什么
- HEX值到wchar_t字符(UTF-8)的转换
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将 Qvector<uint8_t> 转换为 QString
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中使用nlohmann从类到json的转换
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 复制列表初始化的隐式转换的等级是多少
- 正在将指针转换为范围
- 如何防止 c++ 在从浮点型转换为双精度型(不适用于 IO)时添加额外的小数?
- 如何将三角孔贴片转换为曲面网格
- CGAL将非manifold nef_polyhedron_3转换为三角网格
- 三角矩阵转换和自动并行化
- 将正弦波或三角波转换为锯齿波