我使用了一个从网上下载的源码来进行测试,当使用简单的off数据的时候可以获得布尔运算的结果。但是当我把off文件换成较为复杂的不规则模型,比如说骆驼这种的数据的时候并不能获得布尔运算的结果。输出得到的数据依旧是我输入进去的第一个off文件。
下面这个是我所采用的源码。
#include <iostream>
#include <fstream>
#include <time.h>
#include <string.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Nef_polyhedron_3.h>
#include <CGAL/Polyhedron_incremental_builder_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron;
typedef Polyhedron::HalfedgeDS HalfedgeDS;
using namespace std;
int main()
{
Polyhedron mesh1, mesh2, result;
ifstream fin1("C:\\Users\\hm\\Desktop\\TestMesh\\torus.off", ios::in);
fin1 >> mesh1;
fin1.close();
ifstream fin2("C:\\Users\\hm\\Desktop\\TestMesh\\cube.off", ios::in);
fin2 >> mesh2;
fin2.close();
Nef_polyhedron nef1(mesh1);
Nef_polyhedron nef2(mesh2);
Nef_polyhedron out;
clock_t start, finish;
start = clock();
out= nef1 - nef2;
finish = clock();
if (out.is_simple()) {
out.convert_to_polyhedron(result);
std::ofstream fout("d:\\CGAL_TEST6.off", ios::out);
fout << result;
fout.close();
}
else {
std::cerr << "N1 is not a 2-manifold." << std::endl;
return -1;
}
std::cout << "duration: " << finish - start << std::endl;
system("pause");
return 0;
}