CGAL将非流形Nef_polyhedron_3转换为三角形网格

史密斯

在我的应用程序中,我有一个三角形网格数据结构,我想用CGAL进行布尔运算,并将结果转换回三角形网格。它可以正常工作,但是当结果为非流形时,则仅适用于Nef_polyhedron_3。问题是我无法将其转换回三角形网格。

在下面的代码中,我有一个立方体和一个棱镜,并且棱镜的边缘之一位于立方体的面上,因此交点将是非流形的。我可以使用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 =
"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 2\n\
3 0 2 3\n\
3 1 5 6\n\
3 1 6 2\n\
3 5 4 7\n\
3 5 7 6\n\
3 4 0 3\n\
3 4 3 7\n\
3 0 4 5\n\
3 0 5 1\n\
3 3 2 6\n\
3 3 6 7\n";
    std::stringstream ss;
    ss << input;
    ss >> result;
}

template <typename T>
void fill_prism (T& result)
{
    std::string input =
"OFF\n\
6 8 0\n\
0.5 0 -0.5\n\
-0.25 0.433013 -0.5\n\
-0.25 -0.433013 -0.5\n\
0.5 0 0.5\n\
-0.25 0.433013 0.5\n\
-0.25 -0.433013 0.5\n\
3 2 1 0\n\
3 3 4 5\n\
3 0 1 4\n\
3 0 4 3\n\
3 1 2 5\n\
3 1 5 4\n\
3 2 0 3\n\
3 2 3 5\n";
    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转换为三角形网格?

ori

在输出中,您具有非流形边缘(棱镜的一个边缘与立方体的一个面相切)。因此,输出不是有效的曲面网格,这就是PMP方法不返回输出且nef也不能转换为多边形网格的原因。

我想我可以编写一个convert_nef_polyhedron_to_polygon_soup()可以给您一组三角形并orient_polygon_soup()能够复制所有非流形边缘的方法,并且您会得到一个自相交的三角形网格。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章