参照网上的教程安装CGAL后,可以成功用cmake编译生成一个.sln工程文件,但直接在Visual Studio中不能直接运行,需要配置一些库,具体操作如下:
以下操作适合win10 64bits笔记本, Visual Studio中选择“Debug x64”
鼠标右键项目名称“Project3”,点击最下方“属性”:
点击C/C++,“常规”,编辑“附加包含目录”,添加:
include: (C:\boost_1_61_0)
include: \include (C:\CGAL-4.11\include)
include: \auxiliary\gmp\include (C:\CGAL-4.11\auxiliary\gmp\include)
include: \include\Qt (C:\Qt\Qt5.6.0\5.6\msvc2015_64\include)
点击“链接器”, “常规”,编辑“链接库依赖项”:
- library: \lib (C:\Qt\Qt5.6.0\5.6\msvc2015_64\lib)
- library: \lib (C:\boost_1_61_0\lib64-msvc-14.0)
- library: \auxiliary\gmp\lib (C:\CGAL-4.11\auxiliary\gmp\lib)
点击“链接器”,“输入”,分别编辑“附加依赖项”和“忽略特定默认库”:
添加“libgmp-10.lib;libmpfr-4.lib” 到附加依赖项中。
添加 “gmp-vc100-mt-gd.lib;mpfr-vc100-mt-gd.lib”到忽略特定默认库中。
如果程序中还用到了Qt,还需要添加:
“qtmaind.lib”到附加依赖项中。
点击VC++目录,分别编辑“包含目录”,“库目录”,“源目录”
- 包含目录:
C:\CGAL-4.11\build\include (//C:\CGAL-4.11\build用cmake运行输出文件名,可自定义)
C:\boost_1_61_0
C:\CGAL-4.11\auxiliary\gmp\include
C:\CGAL-4.11\include - 库目录:
C:\boost_1_61_0\stage\lib
C:\CGAL-4.11\auxiliary\gmp\lib
C:\CGAL-4.11\build\lib - 源目录:
C:\CGAL-4.11\src
测试,下面是利用CGAL库中interpolation函数的代码,在Visual Studio中编译运行:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Interpolation_traits_2.h>
#include <CGAL/natural_neighbor_coordinates_2.h>
#include <CGAL/interpolation_functions.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Delaunay_triangulation;
typedef CGAL::Interpolation_traits_2<K> Traits;
typedef K::FT Coord_type;
typedef K::Point_2 Point;
int main()
{
Delaunay_triangulation T;
std::map<Point, Coord_type, K::Less_xy_2> function_values;
typedef CGAL::Data_access< std::map<Point, Coord_type, K::Less_xy_2 > >
Value_access;
Coord_type a(0.25), bx(1.3), by(-0.7);
for (int y = 0; y<3; y++) {
for (int x = 0; x<3; x++) {
K::Point_2 p(x, y);
T.insert(p);
function_values.insert(std::make_pair(p, a + bx* x + by*y));
}
}
//coordinate computation
K::Point_2 p(1.3, 0.34);
std::vector< std::pair< Point, Coord_type > > coords;
Coord_type norm =
CGAL::natural_neighbor_coordinates_2
(T, p, std::back_inserter(coords)).second;
Coord_type res = CGAL::linear_interpolation(coords.begin(), coords.end(),
norm,
Value_access(function_values));
std::cout << "Tested interpolation on " << p << " interpolation: "
<< res << " exact: " << a + bx* p.x() + by* p.y() << std::endl;
std::cout << "done" << std::endl;
system("pause");
return 0;
}
运行结果如下: