CGAL-顶点遍历的方式总结以Polyhedron为例

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/OOFFrankDura/article/details/81738443

综述

发现cgal中很多结构的组织、遍历方式的语法都是相似的。以Polyhedron顶点遍历器为例.依次类推,对于face,edge都是如此。

方法

导入

typedef CGAL::Polyhedron_3<Kernel>                   Polyhedron;
typedef Polyhedron::Vertex_iterator        Vertex_iterator;

第一种方法

 CGAL::set_ascii_mode( std::cout);
    for ( Vertex_iterator v = P.vertices_begin(); v != P.vertices_end(); ++v)
        std::cout << v->point() << std::endl;

第二种方法

std::copy( P.points_begin(), P.points_end(), 
std::ostream_iterator<Point_3>(std::cout,"\n"));

给出一个完整的example

#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::Facet_iterator                   Facet_iterator;
typedef Polyhedron::Halfedge_around_facet_circulator Halfedge_facet_circulator;
typedef Polyhedron::Vertex_iterator        Vertex_iterator;

using namespace std;
int main() {
    Point_3 p( 0.0, 0.0, 0.0);
    Point_3 q( 1.0, 0.0, 0.0);
    Point_3 r( 0.0, 1.0, 0.0);
    Point_3 s( 0.0, 0.0, 1.0);
    Polyhedron P;
    P.make_tetrahedron( p, q, r, s);
    // Write polyhedron in Object File Format (OFF).
    CGAL::set_ascii_mode( cout);
    for ( Vertex_iterator v = P.vertices_begin(); v != P.vertices_end(); ++v)
        cout <<"v "<< v->point() << endl;

    for (  Facet_iterator i = P.facets_begin(); i != P.facets_end(); ++i) {
        Halfedge_facet_circulator j = i->facet_begin();
        // Facets in polyhedral surfaces are at least triangles.
        CGAL_assertion( CGAL::circulator_size(j) >= 3);
        cout << "f" << ' ';
        do {
            cout <<distance(P.vertices_begin(), j->vertex())+1 <<" ";
        } while ( ++j != i->facet_begin());
        cout << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/OOFFrankDura/article/details/81738443