CGAL

From SurfLab

Jump to: navigation, search

Contents

CGAL - Computational Geometry Algorithms Library

Visit the CGAL Home Page for the documentation and their underlying design philosophy.

Setting up CGAL

If you wish to install CGAL on your personal machine, refer to the CGAL installation guide. CGAL is already set up in the SurfLab research space for use on the linux machines in CSE313 (lin313-xx.cise.ufl.edu, where xx is the machine number), and that's the setup against which you will be graded. The steps below assume that you are on one of these machines, although it should also work on the CISE Solaris machines.

Set the environment variables

In each shell you wish to use to compile and/or execute your program, you need to set up environment variables by typing the following on the command line.

     $ source /cise/research/SurfLab/public/bin/setup_cgal_env.tcsh
Alternatively, you can type the above line into your ~/.tcshrc to have the environment automatically set when you start your command line.

Create a makefile

You need a makefile for each CGAL program. This can be copied and modified from a previous program or generated automatically by typing the following on the command line

     $ /cise/research/SurfLab/public/bin/create_cgal_makefile -d makefile
If the command is executed in a directory containing source code, then the auto-generated makefile incorporates the compilation of any .cpp files. Unfortunately, it doesn't set the header files as pre-requisites, so it is important to make the edits mentioned below. On the other hand, if the directory contains no source code, then the auto-generated makefile contains a section that looks like
     all:
     clean:
which needs to be filled out manually. Say your source code consists of the header files main.h and helper.h and the C++ files main.cpp and helper.cpp. To compile them into a single executable hw1, change the above section as follows
     all: hw1$(EXE_EXT)
     code$(OBJ_EXT):   main.h helper.h main.cpp
     helper$(OBJ_EXT): main.h helper.h helper.cpp
     hw1$(EXE_EXT):    main$(OBJ_EXT) helper$(OBJ_EXT)
     clean:
             -rm code$(OBJ_EXT) helper$(OBJ_EXT) hw1$(EXE_EXT)
If you additionally want support for OpenGL, you may do so by appending appropriate OpenGL flags to the definition of LDFLAGS as follows
     LDFLAGS = \
               $(LONG_NAME_PROBLEM_LDFLAGS) \
               $(CGAL_LDFLAGS) \
               -lGL -lGLU -lglut -lXi -lXmu -lXext -lX11
Note that in a makefile, indentation (like that in the line after "clean:") must use hard tabs instead of spaces.
Now you can simply run make on the command line to compile your code.

Using CGAL

The CGAL documentation and a document on the use of STL in CGAL are available in both HTML and PDF forms here. We are using CGAL for the half-edge data structure. You will not be using the HalfedgeDS class directly, but the Polyhedron_3 class built on top of it.

Sample: Download the files here into a single directory and compile and run as follows.

    $ make
    $ ./prog

prog loads cube.off and prints a list of vertices and half-edges. The example is already OpenGL-ready, but does not actually use any of it.

Feel free to reuse and modify this code - especially PolygonMesh.h - in your projects.

Personal tools