Manual C Gap
Manual C Gap
Separate Build
1 Introduction 1
2 Compiler/Linker installation 3
3 Using CGAP 7
4 Demos 13
5 Reference Pages 15
i
ii
Chapter 1
Introduction
In this user and reference manual a small introduction to the CGAP library is given.
For people who are not accustomed with Conformal Geometric Algebra, it is recommended to get accustomed
to it by reading the GA-tutorial of Leo Dorst and Daniël Fontijne1.
In this user manual several demos and examples of the CGAP library will be given. The complete code of the
examples can be found in the directory CGAP/examples, the demos can be found in CGAP/demo.
1
2
Chapter 2
Compiler/Linker installation
The demos were tested in a Microsoft Visual Studio 2005 (MSVC8) environment and in the Dev-C++ editor
(mingw, gcc compiler). The Dev-C++ project files can be found in the folder /CGAP/demo/CGAP. The Visual
Studio solutions can be found in the individual folders in /CGAP/demo/CGAP/MSVC8.
The applications have been tested in a Windows 2000, XP and Vista environment. Since FLTK was used for the
GUI part of the project, the code is also assumed to work on Linux machines.
Compiler
There are two ways to add the CGAP-package library: by adding /CGAP/include to the compiler include
directories or by adding all files to your project directly.
Compiler options:
• disable warnings
1 In the include directives of compiler and linker we use several constants: $CGAL ROOT equals /CGAL-3.2 in the CGAL-package.
The latest version of CGAL can be downloaded from http://www.cgal.org. $FLTK is an additional library that can be downloaded from
http://www.fltk.org. For this version the release fltk-2.0.x-r5187 was used and the corresponding fluid-GUI-editor was used to
build the viewer.
3
Linker
Linker libraries:
The CGAL-lib:
• $CGAL ROOT/lib/msvc7/CGAL.lib (for Microsoft Visual Studio and the MinGW C++-compiler; when
you use another compiler, see the CGAL user manual for more instructions)
• $FLTK/lib/libfltk.a
• $FLTK/lib/libfltk gl.a
• $FLTK/lib/libfltk png.a
• $FLTK/lib/libfltk images.a
• $FLTK/lib/libfltk jpeg.a
• $FLTK/lib/fltkd.lib
• $FLTK/lib/fltkdlld.lib
In the options of some linkers the default library Libc.lib has to be excluded, because otherwise the linker will
complain about several functions that occur twice in the code. In some other cases the files libcd, msvcrt
and msvcprt have to be excluded. (depending on debugging settings)
• libgdi32.a
• libwsock32.a
• libole32.a
• libuuid.a
• libcomctl32.a
• libopengl32.a
Makefile The files gaigenhl.cpp, gaigenhl.h, and cxga element.h of the GAIGEN-library should not be put as a
rule in the makefile. Otherwise this will result in some compiler errors. When using a C++ GUI-editor: disable
the building of those files.
2 Remark: fltk should be correctly installed on your computer
3 Remark: these libraries should be included AFTER the fltk-libraries (and not before, otherwise the linker will complain).
4
2.1 Bug fixing in CGAL
5
6
Chapter 3
Using CGAP
To discuss all basic components of an application based on CGA types, we give the code of simple program.
// Simple addition
GA_Type_2 a = 1;
GA_Type_2 b = 1;
GA_Type_2 result = a + b;
a.print(); cout << "plus\n"; b.print();
cout << "equals"; result.print(""); cout << "\n\n";
7
Specification of the number type
The first important choice in a CGAP program is the use of a CGA type (GA Type). Basically a GAIGEN based
CGA-type can be used.
#include <algebrasGAIGEN/c2ga_element/c2ga_element.h>
typedef c2ga_element GA_Type_2;
Simple additions
As we see in the code, several calculations can be made with CGA-elements.
Construction of CGA-elements
There are two ways to construct CGA-elements:
Operators
Which operators are available depends on the CGA type. When GAIGEN is used, the geometric product is
available as the *-operator, the addition as the +-operator, the outer product as ˆ-operator. The inner product
does not have an operator, but should be called by the hip-function.
3.2.1 Primitives
// File: /CGAP/examples/CGAP/Primitives_Example_3d.cpp
#include <iostream>
using namespace std;
// Define 3D-kernel
#define C3GA_KERNEL
#include <CGAL/CGAP/GA_Kernel.h>
// Use GA_Type_3 as GA type and float as field number type
typedef CGAL::C3GA<GA_Type_3, float> FK_3;
class K3 : public FK_3 {};
// Define types
typedef K3::Point Point;
typedef K3::Segment Segment;
8
typedef K3::Line Line;
typedef K3::Plane Plane;
typedef K3::Vector Vector;
typedef K3::Ray Ray;
typedef K3::Triangle Triangle;
typedef K3::Tetrahedron Tetrahedron;
// VECTOR EXAMPLES
// Contruct the (positionless) vector with direction pt1->pt2
Vector v1(pt1,pt2);
// Calculate the result vector pt1-pt2
Vector v2 = pt1 - pt2;
// Initialize as Null vector
Vector v3(CGAL::NULL_VECTOR);
// Add the vector to a point
Point pt4 = pt3 + v1;
// SEGMENT EXAMPLES
// Construct the segment pt1-pt3
Segment seg(pt1, pt3);
// Extract start and endpoint
Point p = seg.startPoint(), q=seg.endPoint();
// LINE EXAMPLES
// Construct the line through pt1 and pt2
Line ln1(pt1, pt2);
// Construct the line through the segment seg
Line ln2(seg);
// RAY EXAMPLES
// Construct a ray originating at pt1 and directing to pt2
Ray r1(pt1, pt2);
// Construct a ray originating at pt2 and directing in direction of ln1
9
Ray r2(pt2, ln1);
// Construct a ray originating at pt2 and directing in direction of vector v1
Ray r3(pt4, v1);
// PLANE EXAMPLES
// Construction from 3 points
Plane pl1(pt1,pt2,pt3);
// Construction from a line and a point
Plane pl2(ln2, pt2);
return 0;
}
3.2.2 Operations
// File: /CGAP/examples/CGAP/Operations_Example_3d.cpp
#include <iostream>
using namespace std;
// Define 3D-kernel
#define C3GA_KERNEL
#include <CGAL/CGAP/GA_Kernel.h>
// Use GA_Type_3 as GA type and float as field number type
typedef CGAL::C3GA<GA_Type_3, float> FK_3;
class K3 : public FK_3 {};
// Define types
typedef K3::Point Point;
typedef K3::Segment Segment;
typedef K3::Line Line;
typedef K3::Plane Plane;
typedef K3::Vector Vector;
typedef K3::Ray Ray;
typedef K3::Triangle Triangle;
typedef K3::Tetrahedron Tetrahedron;
10
pt4(-5.3, 5.4, 0.3), pt5(8.2,-3.4,-4.3), pt6(1.2,3.2,-4.7);
Plane pl1(pt1, pt2, pt3);
// Calculate the centre of the circle through pt1, pt2 and pt3
Point centre = K3().construct_circumcenter_3_object()(pt1, pt2, pt3);
return 0;
}
For further examples of use of the kernel we refer to the chapter about the demos. In the reference manual, the
individual predicate function objects will be discussed.
11
12
Chapter 4
Demos
• A Delaunay viewer application that shows the use of CGAP for 2D and 3D graphics. It illustrates
chapter 6 of the master thesis.
• A Voronoi viewer application that shows the use of CGAP in combination with flags for 2D and 3D
graphics. This application is discussed in chapter 7 of the thesis.
• A Voronoi file application that works with CGAP in combination with flags for nD. Due to the limitations
of GAIGEN yields 2 ≤ n ≤ 5. It reads an input file with points and outputs the result to a specified output
file.
All three demo applications can work with point input files. An example input file has the following format:
4 2
1.0 2.5
2.5 1.0
3.5 3.6
1.0 6.0
At the first line the number of points n (here: 2) and the dimension d (here: 4) are specified. At the succeeding
lines, the n points should be present. The different coordinates of the points are separated by spaces. The . is
used as a decimal separator.
13
14
Chapter 5
Reference Pages
The following pages give an overview on the functionality provided in the kernel.
15
5.1 Global Functions
See Also
CGAL::orientation 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page ??
16
Point 3<Kernel> s)
17
Function Object Class CGAL::CompareX 2
18
See Also
19
See Also
CGAL::PlaneGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page ??
See Also
CGAL::RayGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page ??
See Also
CGAL::TetrahedronGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .page ??
20
See Also
CGAL::TriangleGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page ??
See Also
CGAL::TriangleGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page ??
Bounded side Coplanar side of bounded circle 3( Point 3 p, Point 3 q, Point 3 r, Point 3 t)
21
Function Object Class CGAL::SideOfOrientedCircle 2
#include <../../include/CGAL/CGAP/LineGA.h>
Definition
The class Linear algebraHd<RT> serves as the default traits class for the LA parameter of
CGAL::Homogeneous d<RT,LA>. It implements linear algebra for Euclidean ring number types RT.
LinearAlgebraTraits d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page ??
22
Requirements
To make a ring number type RT work with this class it has to provide a division operator/ with remainder.
Operations
23