代码改变世界

CGAL环境配置

2011-12-20 16:47  John's blog  阅读(2370)  评论(0编辑  收藏  举报

一、 CGAL简介

Official: The goal of the CGAL Open Source Project is to provide easy access to efficient and reliable geometric algorithms in the form of a C++ library. CGAL is used in various areas needing geometric computation, such as: computer graphics, scientific visualization, computer aided design and modeling, geographic information systems, molecular biology, medical imaging, robotics and motion planning, mesh generation, numerical methods... More on the projects using CGAL web page.

The Computational Geometry Algorithms Library (CGAL), offers data structures and algorithms like triangulations (2D constrained triangulations and Delaunay triangulations in 2D and 3D, periodic triangulations in 3D), Voronoi diagrams (for 2D and 3D points, 2D additively weighted Voronoi diagrams, and segment Voronoi diagrams),polygons (Boolean operations, offsets, straight skeleton), polyhedra (Boolean operations), arrangements of curves and their applications (2D and 3D envelopes, Minkowski sums), mesh generation (2D Delaunay mesh generation and 3D surface and volume mesh generation, skin surfaces), geometry processing (surface mesh simplification, subdivision and parameterization, as well as estimation of local differential properties, and approximation of ridges and umbilics), alpha shapes, convex hull algorithms (in 2D, 3D and dD), search structures (kd trees for nearest neighbor search, and range and segment trees), interpolation (natural neighbor interpolation and placement of streamlines), shape analysis, fitting, and distances (smallest enclosing sphere of points or spheres, smallest enclosing ellipsoid of points, principal component analysis), and kinetic data structures.

All these data structures and algorithms operate on geometric objects like points and segments, and perform geometric tests on them. These objects and predicates are regrouped in CGAL Kernels.

Finally, the Support Library offers geometric object generators and spatial sorting functions, as well as a matrix search framework and a solver for linear and quadratic programs. It further offers interfaces to third party software such as the GUI libraries Qt, Geomview, and the boost Graph Library. (http://www.cgal.org/)

Package Overview: (http://www.cgal.org/Manual/latest/doc_html/cgal_manual/packages.html)

二、 CGAL环境配置

在安装CGAL前,必须认真阅读官方文档中的安装手册(http://www.cgal.org/Manual/latest/doc_html/installation_manual/Chapter_installation_manual.html)。其中对CGAL所依赖的第三方库,以及整个安装和配置过程都有详细的解释。对于Windows用户,建议直接下载官方的安装包(Installer),其在安装的过程中会自动下载CGAL所依赖的一些库文件。另外,用户需要下载最新的boost库。与VTK类似,CGAL同样采用了CMake进行环境配置,但是要更为简便一些,这里就其中关键的几步说明一下。

第一步-准备安装环境

下载:

CMake (http://www.cmake.org/cmake/resources/software.html)

boost (http://sourceforge.net/projects/boost/files/boost/)

CGAL (http://www.cgal.org/download.html)

RS (http://vegas.loria.fr/rs/)(单变元多项式方程求解,视需要下载)

首先需要安装 boost。由于 boost本身大多数功能是不需要编译的(Header-only lib),因此,在下载了boost之后,直接将其解压缩到安装目录(比如C:\Program Files(x86)\)即可。但是,由于CGAL在编译中需要boost_thread库,因此需要利用boost自带的编译工具bjam对其进行编译。流程为:

使用管理员身份打开控制台界面。进入boost所在的目录,运行bootstrap.bat,生成bjam。然后使用如下命令编译:

bjam stage --toolset=msvc-10.0 --with=thread --stagedir="c:\Program Files(x86)\boost_1_44_0\lib" link=static runtime-link=shared runtime-link=static threading=multi debug release

(其中的参数说明请参照http://www.cnblogs.com/wondering/archive/2009/05/21/boost_setup.html)。

最终的库文件被生成在boost目录中的lib文件夹下。

另外,如果网速允许,还可以利用boost的安装程序自动下载预编译文件(http://www.boostpro.com/download/),这就免除了上述的编译过程。

最后,设置boost的环境变量BOOST_ROOT和Boost_LIBRARYDIR(如不设置,在CMake配置的过程中也可以修改)。设置的方法为:在控制面板\系统和安全\系统中的高级系统设置中添加如下路径:BOOST_ROOT = C:\Program Files (x86)\boost_1_44_0\和Boost_LIBRARYDIR = C:\Program Files (x86)\boost_1_44_0\lib。

第二步-生成项目文件

对于Windows用户:采用CMake的gui界面对CGAL的Source,和Output路径进行设置,然后Configure。经过检查后,CMake会用红色区域来提示需要定义的编译选项。CGAL的编译选项较少,一般来说选择默认即可。如果不编译CGAL自带的示例,那么可以不编译Qt和demos和examples。另外,CORE是CGAL的核心所依赖的对实数进行处理的库,而GMP和MPFI是多倍精度计算(Multi precision)的支持库,均建议勾选。LEDA则是对上述三个库的一种可选的替代方案,默认不选。其余,OpenNL在CGAL中已经包含;RS用于对曲面的计算,视需要而定。ZLIB用于压缩,用在CGAL的一个示例中,可不选。最后,我选择的第三方库有CGAL_Core, GMP, MPFI, RS。由于imageIO 已在VTK中包含,因此没有选择。

第三步-编译项目

CMake会将上一步配置的CGAL版本的项目文件生成在Output的目录(默认为bin)中。直接对其进行编译(启动工程为CGAL,编译项目为ALL_BUILD),生成的所有的库文件都存放在bin目录下的lib文件夹中。另外,也可以编译项目Install,其会在c:\Program Files(x86)下生成一个CGAL的文件夹,其中包含了所需的头文件和库文件。

第四步-用户开发环境设置

在工程的属性->C/C++->General中,添加以下目录:

$(CGAL_DIR)\include;

$(CGAL_DIR)\auxiliary\gmp\include;

$(CGAL_DIR)\auxiliary\taucs\include;

$(CGAL_DIR)\auxiliary\librs_3.1.0\include;

$(BOOST_ROOT);

在工程的属性->Linker->General->Additional Library Directories中添加:

$(BOOST_ROOT)\lib;

$(CGAL_DIR)\bin\lib;

$(CGAL_DIR)\auxiliary\gmp\lib;

$(CGAL_DIR)\auxiliary\librs_3.1.0\i686_WINDOWS\lib;

$(CGAL_DIR)\auxiliary\taucs\lib;

其中CGAL_DIR为环境变量中CGAL的安装路径,BOOST_ROOT为环境变量中boost的安装路径。