mirror of https://github.com/CGAL/cgal
merge from branch b6aout to main trunc
This commit is contained in:
parent
dc6dd31582
commit
1d41d99cf3
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
example:
|
||||
Illustrates features of the triangulation package.
|
||||
It has no graphical IO and does not depend on any other library.
|
||||
|
||||
|
||||
voronoi:
|
||||
Illustrate the use of a Delaunay triangulation and
|
||||
takes the dual of the triangulation.
|
||||
|
||||
points:
|
||||
Illustrates how to input user defined points and a user provided traits
|
||||
class in a Triangulation
|
||||
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
#! /bin/sh
|
||||
|
||||
# This is a script for the CGAL test suite. Such a script must obey
|
||||
# the following rules:
|
||||
#
|
||||
# - the name of the script is cgal_test
|
||||
# - for every target two one line messages are written to the file 'error.txt'
|
||||
# the first one indicates if the compilation was successful
|
||||
# the second one indicates if the execution was successful
|
||||
# if one of the two was not successful, the line should start with 'ERROR:'
|
||||
# - running the script should not require any user interaction
|
||||
# - the script should clean up object files and executables
|
||||
|
||||
ERRORFILE=error.txt
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# compile_and_run <target>
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
compile_and_run()
|
||||
{
|
||||
echo "Compiling $1 ... "
|
||||
if eval 'make CGAL_MAKEFILE=$CGAL_MAKEFILE \
|
||||
TESTSUITE_CXXFLAGS="$TESTSUITE_CXXFLAGS" \
|
||||
TESTSUITE_LDFLAGS="$TESTSUITE_LDFLAGS" $1' ; then
|
||||
echo " compilation of $1 succeeded" >> $ERRORFILE
|
||||
else
|
||||
echo " ERROR: compilation of $1 failed" >> $ERRORFILE
|
||||
fi
|
||||
|
||||
if [ -f $1 ] ; then
|
||||
OUTPUTFILE=ProgramOutput.$1.$PLATFORM
|
||||
rm -f $OUTPUTFILE
|
||||
COMMAND="./$1"
|
||||
if [ -f $1.cmd ] ; then
|
||||
COMMAND="$COMMAND `cat $1.cmd`"
|
||||
fi
|
||||
if [ -f $1.cin ] ; then
|
||||
COMMAND="echo `cat $1.cin` | $COMMAND"
|
||||
fi
|
||||
echo "Executing $1 ... $COMMAND"
|
||||
echo
|
||||
if eval 2>&1 $COMMAND > $OUTPUTFILE ; then
|
||||
echo " execution of $1 succeeded" >> $ERRORFILE
|
||||
else
|
||||
echo " ERROR: execution of $1 failed" >> $ERRORFILE
|
||||
fi
|
||||
else
|
||||
echo " ERROR: could not execute $1" >> $ERRORFILE
|
||||
fi
|
||||
|
||||
eval "2>&1 make CGAL_MAKEFILE=$CGAL_MAKEFILE clean > /dev/null "
|
||||
}
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# remove the previous error file
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
rm -f $ERRORFILE
|
||||
touch $ERRORFILE
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# compile and run the tests
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
if [ $# -ne 0 ] ; then
|
||||
for file in $* ; do
|
||||
compile_and_run $file
|
||||
done
|
||||
else
|
||||
compile_and_run example
|
||||
compile_and_run points
|
||||
compile_and_run voronoi
|
||||
fi
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
6
|
||||
0.528 -0.3245 1 0.891 -0.0825 1
|
||||
-0.748 -0.451 1 -0.022 -0.4895 1
|
||||
0.5115 0.055 1 -0.55 -0.0715 1
|
||||
-0.682 0.374 1 -0.165 0.363 1
|
||||
0.737 0.4125 1 -0.264 0.1485 1
|
||||
-0.4345 0.913 1 -0.0605 0.55 1
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
6
|
||||
0.528 -0.3245 1 0.891 -0.0825 1
|
||||
-0.748 -0.451 1 -0.022 -0.4895 1
|
||||
0.5115 0.055 1 -0.55 -0.0715 1
|
||||
-0.682 0.374 1 -0.165 0.363 1
|
||||
0.737 0.4125 1 -0.264 0.1485 1
|
||||
-0.4345 0.913 1 -0.0605 0.55 1
|
||||
|
|
@ -0,0 +1,247 @@
|
|||
|
||||
#include <CGAL/basic.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
#include <strstream.h>
|
||||
#include <iterator.h>
|
||||
|
||||
// Define shorter names to please linker (g++/egcs)
|
||||
#define Cartesian C
|
||||
#define Homogeneous H
|
||||
|
||||
//#include <CGAL/Gmpz.h>
|
||||
#include <CGAL/Cartesian.h>
|
||||
//#include <CGAL/Homogeneous.h>
|
||||
|
||||
|
||||
#include <CGAL/Triangulation_euclidean_traits_2.h>
|
||||
#include <CGAL/Triangulation_2.h>
|
||||
#include <CGAL/Delaunay_triangulation_2.h>
|
||||
|
||||
class Options {
|
||||
public:
|
||||
Options()
|
||||
: file_input(false)
|
||||
|
||||
{}
|
||||
|
||||
char program[100];
|
||||
char fname[100];
|
||||
bool file_input;
|
||||
};
|
||||
|
||||
|
||||
|
||||
void usage(char* program)
|
||||
{
|
||||
cerr << "\nNAME\n "
|
||||
<< program << " - Triangulation of a point set\n\n";
|
||||
cerr << "SYNOPSIS\n "
|
||||
<< program << " [-file fname]\n";
|
||||
|
||||
cerr << "\nDESCRIPTION\n"
|
||||
<< " Triangulates a point set that comes from a file or stdin.\n";
|
||||
cerr << "\nOPTIONS\n"
|
||||
<< " All options can be abbreviated by their first character\n\n";
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
parse(int argc, char* argv[], Options &opt)
|
||||
{
|
||||
strcpy(opt.program, argv[0]);
|
||||
--argc;
|
||||
argv++;
|
||||
|
||||
while ((argc > 0) && (argv[0][0] == '-')){
|
||||
if ((!strcmp(argv[0], "-f")) || (!strcmp(argv[0], "-file"))) {
|
||||
strcpy(opt.fname, argv[1]);
|
||||
opt.file_input = true;
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
}
|
||||
else if ((!strcmp(argv[0], "-?")) ||
|
||||
(!strcmp(argv[0], "-h")) ||
|
||||
(!strcmp(argv[0], "-help"))) {
|
||||
usage(opt.program);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
cerr << "Unrecognized option " << argv[0] << endl;
|
||||
usage(opt.program);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(argc > 0){
|
||||
cerr << "Unrecognized option " << argv[0] << endl;
|
||||
usage(opt.program);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
typedef double coord_type;
|
||||
//typedef leda_integer coord_type;
|
||||
//typedef CGAL::Gmpz coord_type;
|
||||
//typedef CGAL::Fixed coord_type;
|
||||
|
||||
typedef CGAL::Cartesian<coord_type> Rpst;
|
||||
//typedef CGAL::Homogeneous<coord_type> Rpst;
|
||||
|
||||
typedef CGAL::Triangulation_euclidean_traits_2<Rpst> Gt;
|
||||
typedef CGAL::Triangulation_vertex_base_2<Gt> Vb;
|
||||
typedef CGAL::Triangulation_face_base_2<Gt> Fb;
|
||||
typedef CGAL::Triangulation_default_data_structure_2<Gt,Vb,Fb> Tds;
|
||||
typedef CGAL::Triangulation_2<Gt,Tds> Triangulation;
|
||||
//typedef CGAL::Delaunay_triangulation_2<Gt,Tds> Delaunay_triangulation_2;
|
||||
|
||||
typedef Gt::Point Point;
|
||||
typedef Triangulation::Face Face;
|
||||
typedef Triangulation::Vertex Vertex;
|
||||
typedef Triangulation::Face_handle Face_handle;
|
||||
typedef Triangulation::Vertex_handle Vertex_handle;
|
||||
|
||||
typedef Triangulation::Face_circulator Face_circulator;
|
||||
typedef Triangulation::Vertex_circulator Vertex_circulator;
|
||||
|
||||
typedef Triangulation::Locate_type Locate_type;
|
||||
|
||||
typedef Triangulation::Face_iterator Face_iterator;
|
||||
typedef Triangulation::Vertex_iterator Vertex_iterator;
|
||||
typedef Triangulation::Edge_iterator Edge_iterator;
|
||||
typedef Triangulation::Line_face_circulator Line_face_circulator;
|
||||
|
||||
|
||||
|
||||
void input_from_file(Triangulation &T,
|
||||
const Options& opt)
|
||||
{
|
||||
if(! opt.file_input){
|
||||
return;
|
||||
}
|
||||
|
||||
ifstream is(opt.fname);
|
||||
CGAL::set_ascii_mode(is);
|
||||
|
||||
int n;
|
||||
is >> n;
|
||||
cout << "Reading " << n << " points" << endl;
|
||||
|
||||
istream_iterator<Point, ptrdiff_t> begin(is);
|
||||
istream_iterator<Point, ptrdiff_t> end;
|
||||
T.insert(begin, end);
|
||||
}
|
||||
|
||||
void input_from_range(Triangulation &T)
|
||||
{
|
||||
std::list<Point> L;
|
||||
L.push_front(Point(0,0));
|
||||
L.push_front(Point(1,0));
|
||||
L.push_front(Point(1,1));
|
||||
|
||||
int n =T.insert(L.begin(), L.end());
|
||||
cout << n << " points inserted from a list." << endl;
|
||||
|
||||
std::vector<Point> V(3);
|
||||
V[0] = Point(0, 0);
|
||||
V[1] = Point(0.4, 0.4);
|
||||
V[2] = Point(0.3, 0.3);
|
||||
|
||||
n = T.insert(V.begin(), V.end());
|
||||
cout << n << " points inserted from a vector." << endl;
|
||||
}
|
||||
|
||||
|
||||
void faces_along_line(Triangulation &T)
|
||||
{
|
||||
Point p(0.2, 0.6), q(0.7, 0.4);
|
||||
|
||||
cin >> p >> q;
|
||||
Face_handle f = T.locate(p);
|
||||
Line_face_circulator lfc = T.line_walk(p, q, f),
|
||||
done(lfc);
|
||||
if(lfc == (CGAL_NULL_TYPE) NULL){
|
||||
cout << "Line does not intersect convex hull" << endl;
|
||||
} else {
|
||||
int count = 0;
|
||||
do{
|
||||
if(! T.is_infinite(lfc)){
|
||||
count++;
|
||||
}
|
||||
}while(++lfc != done);
|
||||
cout << "The line intersects " << count << " finite faces" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void convex_hull(Triangulation &T)
|
||||
{
|
||||
Point p, q;
|
||||
|
||||
Vertex_circulator chc = T.infinite_vertex()->incident_vertices(),
|
||||
done(chc);
|
||||
if(chc == (CGAL_NULL_TYPE)NULL) {
|
||||
cout << "convex hull is empty" << endl;
|
||||
} else {
|
||||
p = chc->point();
|
||||
do {
|
||||
--chc;
|
||||
q = chc->point();
|
||||
p = q;
|
||||
} while(chc != done);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void fileIO(Triangulation &T,
|
||||
const Options& opt)
|
||||
{
|
||||
cout << "The triangulation will be written to a file and read again\n";
|
||||
{
|
||||
ofstream out("tr");
|
||||
CGAL::set_ascii_mode(out);
|
||||
out << T << endl;
|
||||
}
|
||||
Triangulation T2;
|
||||
|
||||
ifstream in("tr");
|
||||
CGAL::set_ascii_mode(in);
|
||||
in >> T2;
|
||||
assert( T2.is_valid() );
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
Options opt;
|
||||
parse(argc, argv, opt);
|
||||
|
||||
Triangulation T;
|
||||
|
||||
input_from_range(T);
|
||||
input_from_file(T, opt);
|
||||
|
||||
std::list<Point> L;
|
||||
L.push_front(Point(0,0));
|
||||
L.push_front(Point(1,0));
|
||||
L.push_front(Point(1,1));
|
||||
|
||||
int n = T.insert(L.begin(), L.end());
|
||||
cout << n << " points inserted from a list." << endl;
|
||||
|
||||
|
||||
T.insert(Point(0,0));
|
||||
T.is_valid();
|
||||
|
||||
faces_along_line(T);
|
||||
|
||||
convex_hull(T);
|
||||
|
||||
fileIO(T, opt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
0.743 0.34 0.523 0.234
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
-file data/replay
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
# This is the makefile for compiling a CGAL application.
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# include platform specific settings
|
||||
#---------------------------------------------------------------------#
|
||||
# Choose the right include file from the <cgalroot>/make directory.
|
||||
|
||||
include $(CGAL_MAKEFILE)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# compiler flags
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
|
||||
CXXFLAGS = -I../../include\
|
||||
$(CGAL_CXXFLAGS)\
|
||||
$(LONG_NAME_PROBLEM_CXXFLAGS)
|
||||
# -B$(UTIL)/Binutils/SunOS/bin/
|
||||
# $(LONG_NAME_PROBLEM_CXXFLAGS)
|
||||
# \
|
||||
# -g
|
||||
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# linker flags
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
LDFLAGS = \
|
||||
$(TESTSUITE_LDFLAGS) \
|
||||
$(LONG_NAME_PROBLEM_LDFLAGS) \
|
||||
$(CGAL_LDFLAGS)
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# target entries
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
# QUANTIFY = quantify
|
||||
|
||||
all: points example voronoi
|
||||
|
||||
points: points.o
|
||||
$(CGAL_CXX) -o points points.o $(LDFLAGS)
|
||||
|
||||
example: example.o
|
||||
$(CGAL_CXX) -o example example.o $(LDFLAGS)
|
||||
|
||||
voronoi: voronoi.o
|
||||
$(CGAL_CXX) -o voronoi voronoi.o $(LDFLAGS)
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *~ *.o core tr
|
||||
|
||||
realclean: clean
|
||||
rm -rf points example voronoi Program* Compiler* Error* error.txt
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# suffix rules
|
||||
#---------------------------------------------------------------------#
|
||||
|
||||
.C.o:
|
||||
$(CGAL_CXX) $(CXXFLAGS) -c $<
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
|
||||
#include <assert.h>
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
#include <CGAL/basic.h>
|
||||
#include <CGAL/predicates_on_pointsC2.h> // for the orientation
|
||||
|
||||
#include "points.h"
|
||||
|
||||
#include <CGAL/Triangulation_2.h>
|
||||
#include <CGAL/Delaunay_triangulation_2.h>
|
||||
|
||||
|
||||
typedef Euclidean_2 Gt;
|
||||
typedef CGAL::Triangulation_vertex_base_2<Gt> Vb;
|
||||
typedef CGAL::Triangulation_face_base_2<Gt> Fb;
|
||||
typedef CGAL::Triangulation_default_data_structure_2<Gt,Vb,Fb> Tds;
|
||||
typedef CGAL::Triangulation_2<Gt,Tds> Triangulation;
|
||||
typedef CGAL::Delaunay_triangulation_2<Gt,Tds> Delaunay_triangulation;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
Triangulation T;
|
||||
|
||||
PVector V;
|
||||
|
||||
ifstream data(argv[1]);
|
||||
|
||||
if(data.bad()){
|
||||
cout << "Problem with file " << argv[1] << endl;
|
||||
}
|
||||
data >> V;
|
||||
|
||||
cout << V.size() << endl;
|
||||
|
||||
int count = 0;
|
||||
cout << "Start insertion" << endl;
|
||||
for(int i = 0; i<V.size();i++){
|
||||
|
||||
T.insert(V[i]);
|
||||
|
||||
if(++count == 100){
|
||||
cout << ".";
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
cout << endl << "done" << endl;
|
||||
T.is_valid();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
data/replay
|
||||
|
|
@ -0,0 +1,347 @@
|
|||
|
||||
class PVector;
|
||||
class segment;
|
||||
class triangle;
|
||||
class dir;
|
||||
class ray;
|
||||
|
||||
|
||||
class point{
|
||||
public:
|
||||
friend PVector;
|
||||
point()
|
||||
: _x(0), _y(0)
|
||||
{}
|
||||
|
||||
point(const point& p)
|
||||
: _x(p._x), _y(p._y)
|
||||
{}
|
||||
|
||||
point(double x, double y)
|
||||
: _x(x), _y(y)
|
||||
{}
|
||||
|
||||
double x() const
|
||||
{
|
||||
return _x;
|
||||
}
|
||||
|
||||
double y() const
|
||||
{
|
||||
return _y;
|
||||
}
|
||||
|
||||
bool operator==(const point& p) const
|
||||
{
|
||||
return x() == p.x() && y() == p.y();
|
||||
}
|
||||
|
||||
bool operator!=(const point& p) const
|
||||
{
|
||||
return x() != p.x() || y() != p.y();
|
||||
}
|
||||
|
||||
private:
|
||||
double _x, _y;
|
||||
};
|
||||
|
||||
|
||||
|
||||
ostream& operator<<(ostream& os, const point& p)
|
||||
{
|
||||
os << "(" << p.x() << ", " << p.y() << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class dir
|
||||
{
|
||||
protected:
|
||||
double _x, _y;
|
||||
public:
|
||||
dir() {}
|
||||
dir(double x, double y) : _x(x), _y(y) {}
|
||||
dir(const point* p, const point* q)
|
||||
: _x( q->x()-p->x() ), _y( q->y()-p->y() ) {}
|
||||
|
||||
double x() const { return _x; }
|
||||
double y() const { return _y; }
|
||||
|
||||
dir perpendicular() const { return dir(y(),-x()); }
|
||||
};
|
||||
|
||||
|
||||
ostream& operator<< (ostream& os, const dir& d)
|
||||
{
|
||||
os << "(" << d.x() << ", " << d.y() << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class segment{
|
||||
public:
|
||||
segment(point* s, point* t)
|
||||
: _s(s), _t(t)
|
||||
{}
|
||||
|
||||
segment()
|
||||
: _s(0), _t(0)
|
||||
{}
|
||||
|
||||
segment(const segment& s)
|
||||
: _s(s._s), _t(s._t)
|
||||
{}
|
||||
|
||||
point* source() const
|
||||
{
|
||||
return _s;
|
||||
}
|
||||
|
||||
point* target() const
|
||||
{
|
||||
return _t;
|
||||
}
|
||||
|
||||
bool operator==(const segment& s) const
|
||||
{
|
||||
return *source() == *s.source() && *target() == *s.target();
|
||||
}
|
||||
|
||||
bool operator!=(const segment& s) const
|
||||
{
|
||||
return *source() != *s.source() || *target() != *s.target();
|
||||
}
|
||||
|
||||
dir direction() const
|
||||
{
|
||||
return dir(source(),target());
|
||||
}
|
||||
|
||||
private:
|
||||
point *_s, *_t;
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os, const segment& s)
|
||||
{
|
||||
os << "(" << *(s.source()) << ", " << *(s.target()) << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class triangle{
|
||||
public:
|
||||
triangle(point* p, point* q, point* r)
|
||||
: _p(p), _q(q), _r(r)
|
||||
{}
|
||||
|
||||
triangle()
|
||||
: _p(0), _q(0), _r(0)
|
||||
{}
|
||||
|
||||
triangle(const triangle& t)
|
||||
: _p(t._p), _q(t._q), _r(t._r)
|
||||
{}
|
||||
|
||||
point* vertex(int i) const
|
||||
{
|
||||
switch(i){
|
||||
case 0:
|
||||
return _p;
|
||||
case 1:
|
||||
return _q;
|
||||
}
|
||||
return _r;
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const triangle& t) const
|
||||
{
|
||||
return vertex(0) == t.vertex(0) && vertex(1) == t.vertex(1) && vertex(2) == t.vertex(2) ;
|
||||
}
|
||||
|
||||
bool operator!=(const triangle& t) const
|
||||
{
|
||||
return vertex(0) != t.vertex(0) || vertex(1) != t.vertex(1) || vertex(2) != t.vertex(2) ;
|
||||
}
|
||||
|
||||
private:
|
||||
point *_p, *_q, *_r;
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os, const triangle& t)
|
||||
{
|
||||
os << "(" << t.vertex(0) << ", " << t.vertex(1) << ", " << t.vertex(2) << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
class ray
|
||||
{
|
||||
friend ostream& operator<< (ostream&, const ray&);
|
||||
|
||||
protected:
|
||||
point _p;
|
||||
dir _d;
|
||||
public:
|
||||
ray() {}
|
||||
ray(const point& p, const dir& d) : _p(p), _d(d) {}
|
||||
|
||||
point p() const { return _p; }
|
||||
dir d() const { return _d; }
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream& os, const ray& r)
|
||||
{
|
||||
os << r.p() << "+" << r.d();
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class PVector {
|
||||
public:
|
||||
PVector()
|
||||
: V(NULL), _size(0)
|
||||
{}
|
||||
|
||||
~PVector()
|
||||
{
|
||||
if(V == NULL){
|
||||
delete []V;
|
||||
}
|
||||
}
|
||||
|
||||
int size()
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
point* operator[](int i) const
|
||||
{
|
||||
return V+i;
|
||||
}
|
||||
|
||||
void reserve(int n)
|
||||
{
|
||||
if(V == NULL){
|
||||
delete []V;
|
||||
}
|
||||
V = new point[n];
|
||||
_size = n;
|
||||
}
|
||||
|
||||
void read(istream& is)
|
||||
{
|
||||
int n;
|
||||
is >> n;
|
||||
|
||||
reserve(n);
|
||||
double x,y;
|
||||
point* ptr = V;
|
||||
for(;n>0;n--){
|
||||
is >> x >> y;
|
||||
ptr->_x = x;
|
||||
ptr->_y = y;
|
||||
++ptr;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
point* V;
|
||||
int _size;
|
||||
};
|
||||
|
||||
istream& operator>>(istream& is, PVector &pv)
|
||||
{
|
||||
pv.read(is);
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/basic_constructionsC2.h>
|
||||
#include <CGAL/predicates_on_pointsC2.h>
|
||||
|
||||
|
||||
|
||||
class Euclidean_2 {
|
||||
public:
|
||||
typedef point* Point;
|
||||
typedef segment Segment;
|
||||
typedef triangle Triangle;
|
||||
typedef dir Direction;
|
||||
typedef ray Ray;
|
||||
|
||||
|
||||
bool compare(const Point &p, const Point &q) const
|
||||
{
|
||||
return (p == q);
|
||||
}
|
||||
|
||||
CGAL::Comparison_result compare_x(const Point &p, const Point &q) const
|
||||
{
|
||||
return CGAL::compare(p->x(), q->x());
|
||||
}
|
||||
|
||||
CGAL::Comparison_result compare_y(const Point &p, const Point &q) const
|
||||
{
|
||||
return CGAL::compare(p->y(), q->y());
|
||||
}
|
||||
|
||||
CGAL::Orientation orientation(const Point &p,
|
||||
const Point &q,
|
||||
const Point &r) const
|
||||
{
|
||||
if(*p==*q || *p == *r || *q == *r){
|
||||
cout << "coll" << endl;
|
||||
return CGAL::COLLINEAR;
|
||||
}
|
||||
return CGAL::orientationC2(p->x(), p->y(), q->x(), q->y(), r->x(), r->y());
|
||||
}
|
||||
|
||||
|
||||
CGAL::Orientation extremal(const Point &p,
|
||||
const Point &q,
|
||||
const Point &r) const
|
||||
{
|
||||
if(*p==*q || *p == *r || *q == *r){
|
||||
cout << "coll" << endl;
|
||||
return CGAL::COLLINEAR;
|
||||
}
|
||||
return CGAL::orientationC2(p->x(), p->y(), q->x(), q->y(), r->x(), r->y());
|
||||
}
|
||||
|
||||
point circumcenter(const point& p, const point& q, const point& r)
|
||||
{
|
||||
double px( p.x());
|
||||
double py( p.y());
|
||||
double qx( q.x());
|
||||
double qy( q.y());
|
||||
double rx( r.x());
|
||||
double ry( r.y());
|
||||
|
||||
double px_qx( px - qx);
|
||||
double py_qy( py - qy);
|
||||
double qx_rx( qx - rx);
|
||||
double qy_ry( qy - ry);
|
||||
double rx_px( rx - px);
|
||||
double ry_py( ry - py);
|
||||
|
||||
double px2_py2( px*px + py*py);
|
||||
double qx2_qy2( qx*qx + qy*qy);
|
||||
double rx2_ry2( rx*rx + ry*ry);
|
||||
|
||||
double num_x( px2_py2*qy_ry + qx2_qy2*ry_py + rx2_ry2*py_qy);
|
||||
double num_y( px2_py2*qx_rx + qx2_qy2*rx_px + rx2_ry2*px_qx);
|
||||
|
||||
double den_x( ( px*qy_ry + qx*ry_py + rx*py_qy) * 2.0);
|
||||
double den_y( ( py*qx_rx + qy*rx_px + ry*px_qx) * 2.0);
|
||||
|
||||
return point(num_x/den_x, num_y/den_y);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
#include <CGAL/basic.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
#include <strstream.h>
|
||||
#include <iterator.h>
|
||||
|
||||
// Define shorter names to please linker (g++/egcs)
|
||||
#define Cartesian Cart
|
||||
|
||||
#include <CGAL/Cartesian.h>
|
||||
|
||||
#include <CGAL/squared_distance_2.h> // to avoid a g++ problem
|
||||
#include <CGAL/Point_2.h>
|
||||
#include <CGAL/predicates_on_points_2.h>
|
||||
#include <CGAL/Triangle_2.h>
|
||||
#include <CGAL/Segment_2.h>
|
||||
|
||||
#include <CGAL/Triangulation_euclidean_traits_2.h>
|
||||
#include <CGAL/Delaunay_triangulation_2.h>
|
||||
|
||||
class Options {
|
||||
public:
|
||||
Options()
|
||||
: file_input(false)
|
||||
|
||||
{}
|
||||
|
||||
char program[100];
|
||||
char fname[100];
|
||||
bool file_input;
|
||||
};
|
||||
|
||||
|
||||
|
||||
void usage(char* program)
|
||||
{
|
||||
cerr << "\nNAME\n "
|
||||
<< program << " - Triangulation of a point set\n\n";
|
||||
cerr << "SYNOPSIS\n "
|
||||
<< program << " [-file fname]\n";
|
||||
|
||||
cerr << "\nDESCRIPTION\n"
|
||||
<< " Triangulates a point set that comes from a file or stdin.\n";
|
||||
cerr << "\nOPTIONS\n"
|
||||
<< " All options can be abbreviated by their first character\n\n";
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
parse(int argc, char* argv[], Options &opt)
|
||||
{
|
||||
strcpy(opt.program, argv[0]);
|
||||
--argc;
|
||||
argv++;
|
||||
|
||||
while ((argc > 0) && (argv[0][0] == '-')){
|
||||
if ((!strcmp(argv[0], "-f")) || (!strcmp(argv[0], "-file"))) {
|
||||
strcpy(opt.fname, argv[1]);
|
||||
opt.file_input = true;
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
}
|
||||
else if ((!strcmp(argv[0], "-?")) ||
|
||||
(!strcmp(argv[0], "-h")) ||
|
||||
(!strcmp(argv[0], "-help"))) {
|
||||
usage(opt.program);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
cerr << "Unrecognized option " << argv[0] << endl;
|
||||
usage(opt.program);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(argc > 0){
|
||||
cerr << "Unrecognized option " << argv[0] << endl;
|
||||
usage(opt.program);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//typedef leda_integer coord_type;
|
||||
typedef double coord_type;
|
||||
//typedef CGAL::Fixed coord_type;
|
||||
|
||||
typedef CGAL::Cartesian<coord_type> Rpst;
|
||||
//typedef CGAL::Homogeneous<coord_type> Rpst;
|
||||
|
||||
typedef CGAL::Point_2<Rpst> Point;
|
||||
typedef CGAL::Segment_2<Rpst> Segment;
|
||||
typedef CGAL::Ray_2<Rpst> Ray;
|
||||
typedef CGAL::Line_2<Rpst> Line;
|
||||
typedef CGAL::Triangle_2<Rpst> Triangle;
|
||||
|
||||
typedef CGAL::Triangulation_euclidean_traits_2<Rpst> Gt;
|
||||
typedef CGAL::Triangulation_vertex_base_2<Gt> Vb;
|
||||
typedef CGAL::Triangulation_face_base_2<Gt> Fb;
|
||||
typedef CGAL::Triangulation_default_data_structure_2<Gt,Vb,Fb> Tds;
|
||||
typedef CGAL::Delaunay_triangulation_2<Gt,Tds> Triangulation;
|
||||
|
||||
typedef Triangulation::Face Face;
|
||||
typedef Triangulation::Vertex Vertex;
|
||||
typedef Triangulation::Face_handle Face_handle;
|
||||
typedef Triangulation::Vertex_handle Vertex_handle;
|
||||
|
||||
typedef Triangulation::Face_circulator Face_circulator;
|
||||
typedef Triangulation::Vertex_circulator Vertex_circulator;
|
||||
|
||||
typedef Triangulation::Locate_type Locate_type;
|
||||
|
||||
typedef Triangulation::Face_iterator Face_iterator;
|
||||
typedef Triangulation::Vertex_iterator Vertex_iterator;
|
||||
typedef Triangulation::Edge_iterator Edge_iterator;
|
||||
typedef Triangulation::Line_face_circulator Line_face_circulator;
|
||||
|
||||
|
||||
|
||||
|
||||
void input_from_file(Triangulation &T,
|
||||
const Options& opt)
|
||||
{
|
||||
if(! opt.file_input){
|
||||
return;
|
||||
}
|
||||
|
||||
ifstream is(opt.fname);
|
||||
CGAL::set_ascii_mode(is);
|
||||
|
||||
int n;
|
||||
is >> n;
|
||||
cout << "Reading " << n << " points" << endl;
|
||||
|
||||
istream_iterator<Point, ptrdiff_t> begin(is);
|
||||
istream_iterator<Point, ptrdiff_t> end;
|
||||
T.insert(begin, end);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
Options opt;
|
||||
parse(argc, argv, opt);
|
||||
|
||||
Triangulation T;
|
||||
|
||||
input_from_file(T, opt);
|
||||
|
||||
cout << "Vertices :" << endl << "=============" << endl;
|
||||
Face_iterator fit, fbegin=T.faces_begin(), fend=T.faces_end();
|
||||
for (fit=fbegin; fit != fend; ++fit)
|
||||
cout << T.dual(fit) << endl;
|
||||
|
||||
cout << "Segment :" << endl << "=============" << endl;
|
||||
{
|
||||
Edge_iterator eit, ebegin=T.edges_begin(), eend=T.edges_end();
|
||||
for (eit=ebegin; eit != eend; ++eit)
|
||||
{
|
||||
CGAL::Object o = T.dual(eit);
|
||||
Triangulation::Segment s;
|
||||
if (CGAL::assign(s,o)) cout << s << endl;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Rays :" << endl << "=============" << endl;
|
||||
{
|
||||
Edge_iterator eit, ebegin=T.edges_begin(), eend=T.edges_end();
|
||||
for (eit=ebegin; eit != eend; ++eit)
|
||||
{
|
||||
CGAL::Object o = T.dual(eit);
|
||||
Triangulation::Ray r;
|
||||
if (CGAL::assign(r,o)) cout << r << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
-file data/replay
|
||||
Loading…
Reference in New Issue