【发布时间】:2018-02-15 14:33:21
【问题描述】:
使用CGAL,我可以获得OFF 格式的多面体网格。例如,下面的程序构建两个四面体,计算它们的交集,并在OFF 文件中返回结果。 OFF 输出提供顶点坐标和顶点索引给出的面。
但我想将顶点和面作为 C++ 变量(例如,double 用于顶点的向量和int 用于面的向量)。有可能吗,怎么做?
当然,我可以从 OFF 文件中提取我想要的内容,但可能有更好的方法。
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Nef_polyhedron_3.h>
#include <CGAL/Surface_mesh.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 Exact_kernel;
typedef CGAL::Polyhedron_3<Exact_kernel> Polyhedron;
typedef CGAL::Surface_mesh<Exact_kernel::Point_3> Surface_mesh;
typedef CGAL::Nef_polyhedron_3<Exact_kernel> Nef_polyhedron;
typedef Exact_kernel::Point_3 Point_3;
int main() {
double phi = (1+sqrt(5))/2;
double a = 1/sqrt(3);
double b = a/phi;
double c = a*phi;
Point_3 p1( 0, b, c);
Point_3 q1( b, -c, 0);
Point_3 r1( a, a, -a);
Point_3 s1( -c, 0, -b);
Polyhedron P1;
P1.make_tetrahedron( p1, q1, r1, s1);
Point_3 p2( a, -a, -a);
Point_3 q2( a, a, a);
Point_3 r2( -a, -a, a);
Point_3 s2( -a, a, -a);
Polyhedron P2;
P2.make_tetrahedron( p2, q2, r2, s2);
Nef_polyhedron nef1(P1);
Nef_polyhedron nef2(P2);
/* compute the intersection */
Nef_polyhedron nef = nef1*nef2;
Surface_mesh smesh;
CGAL::convert_nef_polyhedron_to_polygon_mesh(nef, smesh);
std::ofstream outfile;
outfile.open("output.off");
outfile << smesh;
outfile.close();
}
【问题讨论】:
标签: c++ computational-geometry cgal