CGAL自带的例子是通过CMAKE组织的编译,先通过cmake-gui生成vs的sln,在进行编译。本文介绍通过Qt的pro组织的代码工程配置。
重点参考版本和环境搭配:
1、VS2015 update 3
2、CGAL-5.5.2 + boost 1.71(看cmake最少要求1.66,太新了1.82也能可能遇到编译不过问题)
D:\Program Files\CMake\share\cmake-3.23\Modules\FindBoost.cmake
3、以及通过CGAL官网下载的编译好的X64-VC14的库,包括CGAL-5.5.2-win64-auxiliary-libraries-gmp-mpfr.zip。
4、cmake-3.23
提示:如果版本不一定一致,通过编译错误,尝试替换boost版本;如果遇到enable_if_t编译错误,那可能是没有开启C++ 14,或者编译器支持不够(VS2015需要选用update 3的版本)。
QT -= gui CONFIG += c++14 console CONFIG -= app_bundle DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp #QMAKE_CXXFLAGS += -std=c++14 INCLUDEPATH += D:/CGAL/CGAL-5.5.2/include DEPENDPATH += D:/CGAL/CGAL-5.5.2/include INCLUDEPATH += D:/boost/boost_1_71_0 DEPENDPATH += D:/boost/boost_1_71_0 win32: LIBS += -LD:/CGAL/CGAL-5.5.2/auxiliary/gmp/lib/ -llibgmp-10 INCLUDEPATH += D:/CGAL/CGAL-5.5.2/auxiliary/gmp/include DEPENDPATH += D:/CGAL/CGAL-5.5.2/auxiliary/gmp/include
#include <QCoreApplication>
#include <iostream>
#include <CGAL/Exact_integer.h>
#include <CGAL/Homogeneous.h>
#include <CGAL/Nef_polyhedron_S2.h>
#include <CGAL/Nef_S2/Sphere_circle.h>
#include <QDebug>
typedef CGAL::Exact_integer RT;
typedef CGAL::Homogeneous<RT> Kernel;
typedef CGAL::Nef_polyhedron_S2<Kernel> Nef_polyhedron;
typedef Nef_polyhedron::Sphere_circle Sphere_circle;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// std::cout << "__cplusplus:" << __cplusplus << std::endl;
Nef_polyhedron N1(Sphere_circle(1,0,0));
Nef_polyhedron N2(Sphere_circle(0,1,0), Nef_polyhedron::EXCLUDED);
const Nef_polyhedron N3 = N1 * N2;
const Nef_polyhedron::Sphere_map &m = N3.sphere_map();
Nef_polyhedron::Const_decorator D(&m);
qDebug() << D.number_of_svertices();
qDebug() << D.number_of_sedges();
qDebug() << D.number_of_sloops();
qDebug() << D.number_of_sfaces();
return a.exec();
}