首页 > 解决方案 > CGAL::Polyhedron_3 使用 make_tetrahedron() 生成不需要的重复顶点,如何解决?

问题描述

我试图使用CGAL::Polyhedron_3数据结构创建体积网格,但在进行一些测试时,我注意到该make_tetrahedron函数复制了多面体中已经存在的顶点。

示例:共享一个共同面的两个四面体

这是我试过的代码:

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <iostream>

typedef CGAL::Simple_cartesian<double>     Kernel;
typedef Kernel::Point_3                    Point_3;
typedef CGAL::Polyhedron_3<Kernel>         Polyhedron;
typedef Polyhedron::Vertex_iterator        Vertex_iterator;

int main(void) {
    // common points
    Point_3 p( 1.0, 0.0, 0.0 );
    Point_3 q( 0.0, 1.0, 0.0 );
    Point_3 s( 0.0, 0.0, 0.0 );

    // the other two
    Point_3 r( 0.0, 0.0, 1.0 );
    Point_3 d( 0.0, 0.0,-1.0 );

    Polyhedron P;
    P.make_tetrahedron( p, q, r, s );
    P.make_tetrahedron( p, q, s, d );

    CGAL::IO::set_ascii_mode( std::cout );
    
    // printing out the vertices
    for ( Vertex_iterator v = P.vertices_begin(); v != P.vertices_end(); ++v )
        std::cout << v->point() << std::endl;

    return 0;
}

这是我希望看到的输出:

1 0 0
0 1 0
0 0 1
0 0 0
0 0 -1

但这就是我得到的:
1 0 0
0 1 0
0 0 1
0 0 0
1 0 0
0 1 0
0 0 0
0 0 -1

现在,问题是:是否可以在使用该函数
时仅将一个点存储为顶点一次?CGAL::Polyhedron_3make_tetrahedron

标签: c++cgalpolyhedratetrahedra

解决方案


您不能将非流形特征存储在多面体中,您需要类似线性单元复合体的东西。看这里


推荐阅读