CGAL-由多面体Polyhedron_3输出obj文件

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

综述

多面体(四面体)输出obj

实现

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <iostream>
#include <string>
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::Point_iterator                   Point_iterator;
typedef Polyhedron::Halfedge_around_facet_circulator Halfedge_facet_circulator;
using namespace std;
int main() {
    Point_3 p( 0.0, 2, 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);
    for (Point_iterator k = P.points_begin(); k !=P.points_end(); ++k) {
        cout <<"v " << *k<< 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 << CGAL::circulator_size(j) << ' ';面片边数
        cout << "f ";
        do {
            cout << 1+distance(P.vertices_begin(), j->vertex()) <<" ";

        } while ( ++j != i->facet_begin());
        cout << endl;
    }
    return 0;
}

猜你喜欢

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