Initial revision

This commit is contained in:
Sylvain Pion 2001-03-14 16:55:14 +00:00
parent 8b2981c20c
commit b8d8bbe97b
81 changed files with 11712 additions and 0 deletions

View File

@ -0,0 +1 @@
0.1 BETA version of the new CGAL - Delaunay triangulation based point set

View File

@ -0,0 +1,38 @@
include $(CGAL_MAKEFILE)
CC = $(CGAL_CXX) $(CGAL_WINDOW_LIBPATH)
CGALCFLAGS = $(CGAL_CXXFLAGS)
CGDL = $(CGAL_GEOWIN_LDFLAGS)
geowin_pset_2d_tb$(EXE_EXT) : geowin_pset_2d_tb$(OBJ_EXT)
$(CC) $(EXE_OPT)geowin_pset_2d_tb geowin_pset_2d_tb$(OBJ_EXT) $(CGDL)
geowin_k_nearest_neighbors_tb$(EXE_EXT) : geowin_k_nearest_neighbors_tb$(OBJ_EXT)
$(CC) $(EXE_OPT)geowin_k_nearest_neighbors_tb geowin_k_nearest_neighbors_tb$(OBJ_EXT) $(CGDL)
clean :
rm -f tt *~ *.o *.obj *.exe
rm -f geowin_k_nearest_neighbors_tb geowin_pset_2d_tb
all: geowin_k_nearest_neighbors_tb geowin_pset_2d_tb
cleano :
rm -f *~ *.o
#---------------------------------------------------------------------#
# suffix rules
#---------------------------------------------------------------------#
.C$(OBJ_EXT):
$(CGAL_CXX) $(CGALCFLAGS) -c $<
.c$(OBJ_EXT):
$(CGAL_CXX) $(CGALCFLAGS) -c $<

View File

@ -0,0 +1,89 @@
#include <CGAL/geowin_support.h>
#include <CGAL/Triangulation_short_names_2.h>
#include <CGAL/Triangulation_euclidean_traits_2.h>
#include <CGAL/Point_set_2_tb.h>
typedef CGAL::Cartesian<double> REP;
typedef CGAL::Triangulation_euclidean_traits_2<REP> 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::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge Edge;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge_iterator Edge_iterator;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex_handle Vertex_handle;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex Vertex;
CGAL::Point_set_2_tb<TRAITS,Gt,Tds> PST;
int k;
class construct_pointset : public geowin_update<std::list<CGAL::Point_2<REP> >,std::list<CGAL::Segment_2<REP> > >
{
public:
void update(const std::list<CGAL::Point_2<REP> >& Lin, std::list<CGAL::Segment_2<REP> >& Lout)
{
PST.init(Lin.begin(),Lin.end());
Lout.clear();
PST.segments(std::back_inserter(Lout));
}
};
class nearest_neighbors : public geowin_update<std::list<CGAL::Point_2<REP> >, std::list<CGAL::Circle_2<REP> > >
{
public:
void update(const std::list<CGAL::Point_2<REP> >& Lin, std::list<CGAL::Circle_2<REP> >& Lout)
{
Lout.clear();
std::list<CGAL::Point_2<REP> >::const_iterator it = Lin.begin();
std::list<Vertex_handle> output;
std::list<Vertex_handle>::const_iterator pit;
for (; it != Lin.end(); it++){
PST.nearest_neighbors(*it, k, std::back_inserter(output));
}
for (pit=output.begin(); pit != output.end(); pit++){
Lout.push_back(CGALCircle(PST.pos(*pit),2.0));
}
}
};
int main()
{
geowin_init_default_type((std::list<CGAL::Point_2<REP> >*)0, leda_string("CGALPointlist"));
std::cout << "Find the k nearest neighbors of every point in scene 2.\n";
std::cout << "k:"; std::cin >> k;
GeoWin gw;
std::list<CGAL::Point_2<REP> > Lp;
geo_scene sc1 = gw.new_scene(Lp);
std::list<CGAL::Point_2<REP> > Lother;
geo_scene sc2 = gw.new_scene(Lother);
gw.set_color(sc2,leda_blue);
construct_pointset CP;
geo_scene sc3 = gw.new_scene(CP, sc1, leda_string("2d point set"));
gw.set_color(sc3,leda_blue);
nearest_neighbors NN;
geo_scene sc4 = gw.new_scene(NN, sc2, leda_string("k nearest neighbors"));
gw.set_fill_color(sc4,leda_red);
gw.set_color(sc4,leda_red);
gw.set_point_style(sc4,leda_circle_point);
gw.set_line_width(sc4,4);
gw.set_all_visible(true);
gw.add_dependence(sc1,sc4);
gw.edit(sc1);
return 0;
}

View File

@ -0,0 +1,119 @@
#include <CGAL/geowin_support.h>
#include <CGAL/Triangulation_short_names_2.h>
#include <CGAL/Triangulation_euclidean_traits_2.h>
#include <CGAL/Point_set_2_tb.h>
typedef CGAL::Cartesian<double> REP;
typedef CGAL::Triangulation_euclidean_traits_2<REP> 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::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge Edge;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge_iterator Edge_iterator;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex_handle Vertex_handle;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex Vertex;
CGAL::Point_set_2_tb<TRAITS,Gt,Tds> PST;
class construct_pointset : public geowin_update<std::list<CGALPoint>, std::list<CGALSegment> >
{
public:
void update(const std::list<CGALPoint>& Lin, std::list<CGALSegment>& Lout)
{
PST.init(Lin.begin(),Lin.end());
Lout.clear();
PST.segments(std::back_inserter(Lout));
}
};
class circle_range_search : public geowin_update<std::list<CGALCircle>, std::list<CGALCircle> >
{
void update(const std::list<CGALCircle>& Lin, std::list<CGALCircle>& Lout)
{
Lout.clear();
std::list<CGALCircle>::const_iterator it = Lin.begin();
std::list<Vertex_handle> output;
std::list<Vertex_handle>::const_iterator pit;
for (; it != Lin.end(); it++){
PST.range_search(*it, std::back_inserter(output));
}
for (pit=output.begin(); pit != output.end(); pit++){
Lout.push_back(CGALCircle(PST.pos(*pit),2.0));
}
}
};
class triangle_range_search : public geowin_update<std::list<CGALTriangle>, std::list<CGALCircle> >
{
public:
void update(const std::list<CGALTriangle>& Lin, std::list<CGALCircle>& Lout)
{
Lout.clear();
std::list<CGALTriangle>::const_iterator it = Lin.begin();
std::list<Vertex_handle> output;
std::list<Vertex_handle>::const_iterator pit;
for (; it != Lin.end(); it++){
PST.range_search((*it).vertex(0),(*it).vertex(1),(*it).vertex(2), std::back_inserter(output));
}
for (pit=output.begin(); pit != output.end(); pit++){
Lout.push_back(CGALCircle(PST.pos(*pit),1.0));
}
}
};
int main()
{
geowin_init_default_type((CGALPointlist*)0, leda_string("CGALPointlist"));
geowin_init_default_type((CGALCirclelist*)0, leda_string("CGALCirclelist"));
geowin_init_default_type((CGALTrianglelist*)0, leda_string("CGALTrianglelist"));
GeoWin gw;
std::list<CGALPoint> Lp;
geo_scene sc1 = gw.new_scene(Lp);
std::list<CGALCircle> Lc;
geo_scene sc_circ = gw.new_scene(Lc);
gw.set_color(sc_circ, leda_blue);
gw.set_fill_color(sc_circ, leda_invisible);
std::list<CGALTriangle> Lt;
geo_scene sc_triang = gw.new_scene(Lt);
gw.set_color(sc_triang, leda_blue2);
gw.set_line_width(sc_triang,3);
gw.set_active_line_width(sc_triang,3);
gw.set_fill_color(sc_triang, leda_invisible);
construct_pointset CP;
gw.new_scene(CP, sc1, leda_string("2d point set"));
circle_range_search CRS;
geo_scene sc3 = gw.new_scene(CRS, sc_circ, leda_string("circular range search"));
gw.set_color(sc3,leda_red);
gw.set_point_style(sc3, leda_circle_point);
gw.set_line_width(sc3,4);
triangle_range_search TRS;
geo_scene sc4 = gw.new_scene(TRS, sc_triang, leda_string("triangular range search"));
gw.set_color(sc4,leda_green);
gw.set_point_style(sc4, leda_circle_point);
gw.set_line_width(sc4,4);
gw.set_all_visible(true);
gw.add_dependence(sc1,sc3);
gw.add_dependence(sc1,sc4);
gw.edit(sc1);
return 1;
}

View File

@ -0,0 +1,39 @@
include $(CGAL_MAKEFILE)
CC = $(CGAL_CXX) $(CGAL_WINDOW_LIBPATH)
CGALCFLAGS = $(CGAL_CXXFLAGS)
CGDL = $(CGAL_WINDOW_LDFLAGS)
ps_test1_tb$(EXE_EXT) : ps_test1_tb$(OBJ_EXT)
$(CC) $(EXE_OPT)ps_test1_tb ps_test1_tb$(OBJ_EXT) $(CGDL)
ps_test1_cgal_tb$(EXE_EXT) : ps_test1_cgal_tb$(OBJ_EXT)
$(CC) $(EXE_OPT)ps_test1_cgal_tb ps_test1_cgal_tb$(OBJ_EXT) $(CGDL)
nearest_neighbor_tb$(EXE_EXT) : nearest_neighbor_tb$(OBJ_EXT)
$(CC) $(EXE_OPT)nearest_neighbor_tb nearest_neighbor_tb$(OBJ_EXT) $(CGDL)
range_search_tb$(EXE_EXT) : range_search_tb$(OBJ_EXT)
$(CC) $(EXE_OPT)range_search_tb range_search_tb$(OBJ_EXT) $(CGDL)
clean :
rm -f tt *~ *.o *.obj *.exe core
rm -f nearest_neighbor_tb ps_test1_cgal_tb ps_test1_tb range_search_tb
all: nearest_neighbor_tb ps_test1_cgal_tb ps_test1_tb range_search_tb
cleano :
rm -f *~ *.o
#---------------------------------------------------------------------#
# suffix rules
#---------------------------------------------------------------------#
.C$(OBJ_EXT):
$(CGAL_CXX) $(CGALCFLAGS) $(OBJ_OPT) $<

View File

@ -0,0 +1,102 @@
#include <CGAL/config.h>
#include <list>
#include <LEDA/window.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Triangulation_short_names_2.h>
#include <CGAL/Triangulation_euclidean_traits_2.h>
#include <CGAL/Point_set_2_tb.h>
#include <CGAL/IO/Window_stream.h>
typedef CGAL::Cartesian<double> REP;
typedef CGAL::Triangulation_euclidean_traits_2<REP> 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::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge Edge;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge_iterator Edge_iterator;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex_handle Vertex_handle;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex Vertex;
leda_segment get_seg(const CGAL::Segment_2<REP>& s)
{
CGAL::Point_2<REP> ps=s.source();
CGAL::Point_2<REP> pt=s.target();
leda_point p1(ps.x(),ps.y()), p2(pt.x(),pt.y());
return leda_segment(p1, p2);
}
void output(leda_window& W, const CGAL::Point_set_2_tb<TRAITS,Gt,Tds>& PSet)
{
W.clear();
Edge e;
Edge_iterator eit = PSet.finite_edges_begin();
for(;eit != PSet.finite_edges_end(); eit++) {
e = *eit;
CGAL::Segment_2<REP> s= PSet.seg(e);
W << get_seg(s);
}
}
int main()
{
CGAL::Point_set_2_tb<TRAITS,Gt,Tds> PSet;
leda_window W(600,500, leda_string("Finding nearest neighbors"));
CGAL::cgalize( W);
W.init(-500,500,-400);
W.display(100,100);
CGAL::Point_2<REP> actual;
int i;
for (i=0; i<25; i++){
W >> actual;
PSet.insert(actual);
output(W,PSet);
}
// nearest neighbor ...
for (i=0; i<5; i++){
W >> actual;
Vertex_handle v = PSet.nearest_neighbor(actual);
CGAL::Segment_2<REP> my_seg(actual,PSet.pos(v));
W << CGAL::RED << PSet.pos(v) << CGAL::BLACK;
W << CGAL::BLUE << my_seg << CGAL::BLACK;
}
// k nearest neighbors ...
std::list<Vertex_handle> L;
std::list<Vertex_handle>::const_iterator it;
for (i=0; i<5; i++){
L.clear();
W >> actual;
PSet.nearest_neighbors(actual,5, std::back_inserter(L));
std::cout << "actual point: " << actual << "\n";
W.clear();
output(W,PSet);
W << CGAL::RED << actual << CGAL::BLACK;
for (it=L.begin();it != L.end(); it++){
W << CGAL::GREEN << PSet.pos(*it) << CGAL::BLACK;
std::cout << PSet.pos(*it) << "\n";
}
std::cout << "\n";
}
W.read_mouse();
return 1;
}

View File

@ -0,0 +1,135 @@
#include <CGAL/config.h>
#include <list>
#include <LEDA/window.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Triangulation_short_names_2.h>
#include <CGAL/Triangulation_euclidean_traits_2.h>
#include <CGAL/Point_set_2_tb.h>
#include <CGAL/IO/Window_stream.h>
#include <CGAL/leda_rational.h>
#include <LEDA/rat_point.h>
//typedef CGAL::Cartesian<double> REP;
typedef CGAL::Cartesian<leda_rational> REP;
typedef CGAL::Triangulation_euclidean_traits_2<REP> 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::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge Edge;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge_iterator Edge_iterator;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex_handle Vertex_handle;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex Vertex;
leda_segment get_seg(const CGAL::Segment_2<REP>& s)
{
CGAL::Point_2<REP> ps=s.source();
CGAL::Point_2<REP> pt=s.target();
leda_rat_point p1(ps.x(),ps.y()), p2(pt.x(),pt.y());
return leda_segment(p1.to_float(), p2.to_float());
}
void output(leda_window& W, const CGAL::Point_set_2_tb<TRAITS,Gt,Tds>& PSet)
{
W.clear();
Edge e;
Edge_iterator eit = PSet.finite_edges_begin();
for(;eit != PSet.finite_edges_end(); eit++) {
e = *eit;
CGAL::Segment_2<REP> s= PSet.seg(e);
W << get_seg(s);
}
}
int main()
{
int i;
CGAL::Point_set_2_tb<TRAITS,Gt,Tds> PSR_rat;
leda_window W(600,500);
CGAL::cgalize( W);
W.init(-500,500,-400);
W.display(100,100);
output(W,PSR_rat);
for (i=0; i<25; i++) {
CGAL::Point_2<REP> pnew;
W >> pnew;
PSR_rat.insert(pnew);
output(W,PSR_rat);
}
for (i=0; i<2; i++) {
CGAL::Point_2<REP> pnew;
W >> pnew;
Vertex_handle v = PSR_rat.nearest_neighbor(pnew);
PSR_rat.del(v);
output(W,PSR_rat);
}
std::cout << "circular range search !\n";
CGAL::Circle_2<REP> rc;
W >> rc;
std::list<Vertex_handle> LV;
std::list<Vertex_handle>::const_iterator vit;
PSR_rat.range_search(rc,std::back_inserter(LV));
W.set_color(leda_red);
for(vit=LV.begin(); vit!=LV.end(); vit++){
W << PSR_rat.pos(*vit);
}
W.set_color(leda_black);
std::cout << LV.size() << "\n";
std::cout << "triangular range search !\n";
CGAL::Point_2<REP> pt1,pt2,pt3,pt4;
W >> pt1;
W >> pt2;
W >> pt3;
std::list<Vertex_handle> outlist;
PSR_rat.range_search(pt1,pt2,pt3,std::back_inserter(outlist));
W.set_color(leda_green);
for(vit=outlist.begin(); vit!=outlist.end(); vit++){
W << PSR_rat.pos(*vit);
}
W.set_color(leda_black);
std::cout << outlist.size() << "\n";
outlist.clear();
std::cout << "rectangular range search !\n";
W >> pt1; W >> pt3;
pt2 = CGAL::Point_2<REP>(pt3.x(),pt1.y());
pt4 = CGAL::Point_2<REP>(pt1.x(),pt3.y());
PSR_rat.range_search(pt1,pt2,pt3,pt4,std::back_inserter(outlist));
W.set_color(leda_yellow);
for(vit=outlist.begin(); vit!=outlist.end(); vit++){
W << PSR_rat.pos(*vit);
}
W.set_color(leda_black);
std::cout << outlist.size() << "\n";
W.read_mouse();
return 1;
}

View File

@ -0,0 +1,123 @@
#include <CGAL/config.h>
#include <list>
#include <LEDA/window.h>
#include <LEDA/rat_window.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Triangulation_short_names_2.h>
#include <CGAL/Triangulation_euclidean_leda_traits_2.h>
#include <CGAL/point_set_leda_traits_2.h>
#include <CGAL/Point_set_2_tb.h>
#include <CGAL/IO/Window_stream.h>
#include <LEDA/point.h>
//typedef CGAL::Triangulation_euclidean_leda_rat_traits_2 Gt;
typedef CGAL::Triangulation_euclidean_leda_float_traits_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::point_set_leda_rat_traits_2 TRAITS;
typedef CGAL::point_set_leda_float_traits_2 TRAITS;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge Edge;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge_iterator Edge_iterator;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex_handle Vertex_handle;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex Vertex;
typedef Gt::Segment_2 Segment;
typedef Gt::Point_2 Point;
//typedef leda_rat_circle Circle;
typedef leda_circle Circle;
void output(leda_window& W, const CGAL::Point_set_2_tb<TRAITS,Gt,Tds>& PSet)
{
W.clear();
Edge e;
Edge_iterator eit = PSet.finite_edges_begin();
for(;eit != PSet.finite_edges_end(); eit++) {
e = *eit;
Segment s= PSet.seg(e);
W << s.to_float();
}
}
int main()
{
int i;
CGAL::Point_set_2_tb<TRAITS,Gt,Tds> PSR_rat;
leda_window W(500,400);
W.init(-500,500,-400);
W.display();
for (i=0; i<30; i++) {
Point pnew;
W >> pnew;
PSR_rat.insert(pnew);
output(W,PSR_rat);
}
for (i=0; i<3; i++) {
Point pnew;
W >> pnew;
Vertex_handle v = PSR_rat.nearest_neighbor(pnew);
PSR_rat.del(v);
output(W,PSR_rat);
}
Circle rc;
W >> rc; W << rc;
#if (__LEDA__ >= 400)
W.set_point_style(leda_disc_point);
#endif
std::list<Vertex_handle> LV;
std::list<Vertex_handle>::const_iterator vit;
PSR_rat.range_search(rc,std::back_inserter(LV));
W.set_color(leda_red);
for(vit=LV.begin(); vit!=LV.end(); vit++){
W << PSR_rat.pos(*vit);
}
W.set_color(leda_black);
std::cout << "circular range_search - found " << LV.size() << " vertices!\n";
std::cout << "range search for triangle !\n";
Point pt1,pt2,pt3,pt4;
W >> pt1; W << pt1;
W >> pt2; W << pt2;
W >> pt3; W << pt3;
LV.clear();
PSR_rat.range_search(pt1,pt2,pt3,std::back_inserter(LV));
std::list<Vertex_handle>::const_iterator it;
W.set_color(leda_green);
for (it=LV.begin();it != LV.end(); it++)
W << PSR_rat.pos(*it);
std::cout << "triangular range_search - found " << LV.size() << " vertices!\n";
LV.clear();
W >> pt1; W << pt1;
W >> pt3; W << pt3;
pt2 = Point(pt3.xcoord(),pt1.ycoord());
pt4 = Point(pt1.xcoord(),pt3.ycoord());
W.set_color(leda_orange);
PSR_rat.range_search(pt1,pt2,pt3,pt4,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
W << PSR_rat.pos(*it);
std::cout << "rectangular range_search - found " << LV.size() << " vertices!\n";
W.read_mouse();
return 0;
}

View File

@ -0,0 +1,113 @@
#include <CGAL/config.h>
#include <list>
#include <LEDA/window.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Triangulation_short_names_2.h>
#include <CGAL/Triangulation_euclidean_traits_2.h>
#include <CGAL/Point_set_2_tb.h>
#include <CGAL/IO/Window_stream.h>
typedef CGAL::Cartesian<double> REP;
typedef CGAL::Triangulation_euclidean_traits_2<REP> 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::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge Edge;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge_iterator Edge_iterator;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex_handle Vertex_handle;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex Vertex;
leda_segment get_seg(const CGAL::Segment_2<REP>& s)
{
CGAL::Point_2<REP> ps=s.source();
CGAL::Point_2<REP> pt=s.target();
leda_point p1(ps.x(),ps.y()), p2(pt.x(),pt.y());
return leda_segment(p1, p2);
}
void output(leda_window& W, const CGAL::Point_set_2_tb<TRAITS,Gt,Tds>& PSet)
{
W.clear();
Edge e;
Edge_iterator eit = PSet.finite_edges_begin();
for(;eit != PSet.finite_edges_end(); eit++) {
e = *eit;
CGAL::Segment_2<REP> s= PSet.seg(e);
W << get_seg(s);
}
}
int main()
{
int i;
CGAL::Point_set_2_tb<TRAITS,Gt,Tds> PSet;
CGAL::Point_2<REP> pnew;
leda_window W(600,500,leda_string("Range searches"));
CGAL::cgalize( W);
W.init(-500,500,-400);
W.display(100,100);
for (i=0; i<30; i++) {
W >> pnew;
PSet.insert(pnew);
output(W,PSet);
}
for (i=0; i<5; i++) {
W >> pnew;
Vertex_handle v = PSet.nearest_neighbor(pnew);
std::cout << "delete!\n"; std::cout.flush();
PSet.del(v);
output(W,PSet);
}
std::cout << "range search for circle !\n";
CGAL::Circle_2<REP> rc;
W >> rc;
std::list<Vertex_handle> LV;
PSet.range_search(rc,std::back_inserter(LV));
std::list<Vertex_handle>::const_iterator it;
for (it=LV.begin();it != LV.end(); it++)
W << CGAL::GREEN << PSet.pos(*it) << CGAL::BLACK;
std::cout << "range search for triangle !\n";
CGAL::Point_2<REP> pt1,pt2,pt3,pt4;
W >> pt1;
W >> pt2;
W >> pt3;
LV.clear();
PSet.range_search(pt1,pt2,pt3,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
W << CGAL::BLUE << PSet.pos(*it) << CGAL::BLACK;
LV.clear();
std::cout << "range search for iso rectangle !\n";
W >> pt1; // lower left
W >> pt3; // upper right
pt2 = CGAL::Point_2<REP>(pt3.x(),pt1.y());
pt4 = CGAL::Point_2<REP>(pt1.x(),pt3.y());
PSet.range_search(pt1,pt2,pt3,pt4,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
W << CGAL::RED << PSet.pos(*it) << CGAL::BLACK;
W.read_mouse();
return 1;
}

View File

@ -0,0 +1,2 @@
2d Point set data type - CGAL triangulation based version

View File

@ -0,0 +1,52 @@
include $(CGAL_MAKEFILE)
#---------------------------------------------------------------------#
# compiler flags
#---------------------------------------------------------------------#
CXXFLAGS = \
$(CGAL_CXXFLAGS)
#---------------------------------------------------------------------#
# linker flags
#---------------------------------------------------------------------#
LIBPATH = \
$(TESTSUITE_LIBPATH) \
$(CGAL_LIBPATH)
LDFLAGS = \
$(TESTSUITE_LDFLAGS) \
$(CGAL_LDFLAGS)
#---------------------------------------------------------------------#
# target entries
#---------------------------------------------------------------------#
all: \
range_search_tr \
range_search_tr_leda \
nearest_nb1_tr
range_search_tr$(EXE_EXT) : range_search_tr$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)range_search_tr range_search_tr$(OBJ_EXT) $(LDFLAGS)
range_search_tr_leda$(EXE_EXT) : range_search_tr_leda$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)range_search_tr_leda range_search_tr_leda$(OBJ_EXT) $(LDFLAGS)
nearest_nb1_tr$(EXE_EXT) : nearest_nb1_tr$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)nearest_nb1_tr nearest_nb1_tr$(OBJ_EXT) $(LDFLAGS)
clean:
rm -f range_search_tr nearest_nb1_tr range_search_tr_leda *$(OBJ_EXT) *.obj *.exe core
#---------------------------------------------------------------------#
# suffix rules
#---------------------------------------------------------------------#
.C$(OBJ_EXT):
$(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $<

View File

@ -0,0 +1,115 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <vector>
#include <CGAL/Cartesian.h>
#include <CGAL/Triangulation_short_names_2.h>
#include <CGAL/Triangulation_euclidean_traits_2.h>
#include <CGAL/Point_set_2_tb.h>
#include <CGAL/leda_rational.h>
using namespace CGAL;
using namespace std;
typedef Cartesian<leda_rational> REP;
typedef CGAL::Triangulation_euclidean_traits_2<REP> 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 point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge Edge;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge_iterator Edge_iterator;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex_handle Vertex_handle;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex Vertex;
Point_set_2_tb<TRAITS,Gt,Tds> PSet;
Point_2<REP> ar1[5];
int check1(std::list<Vertex_handle> L)
{
cout << "check 1!\n";
if (L.size() != 5) return 1;
std::list<Vertex_handle>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar1[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int main()
{
std::list<Point_2<REP> > Lr;
int w1,w2;
Point_2<REP> p1(12,14,1);
Point_2<REP> p2(-12,14,1);
Point_2<REP> p3(2,11,1);
Point_2<REP> p4(5,6,1);
Point_2<REP> p5(67,38,10);
Point_2<REP> p6(11,20,1);
Point_2<REP> p7(-5,6,1);
Point_2<REP> p8(12,0,1);
Point_2<REP> p9(4,31,1);
Point_2<REP> p10(-10,-10,1);
Lr.push_back(p1); Lr.push_back(p2); Lr.push_back(p3);
Lr.push_back(p4); Lr.push_back(p5); Lr.push_back(p6);
Lr.push_back(p7); Lr.push_back(p8); Lr.push_back(p9);
Lr.push_back(p10);
PSet.init(Lr.begin(),Lr.end());
// init
ar1[0]=p4; ar1[1]=p5; ar1[2]=p3; ar1[3]=p7; ar1[4]=p8;
Point_2<REP> actual(30,45,10);
// nearest neighbor ...
Vertex_handle v = PSet.nearest_neighbor(actual);
cout << "Nearest neighbor:" << PSet.pos(v) << "\n";
if (PSet.pos(v) == p4) w1=0; else w1=1;
// k nearest neighbors ...
std::list<Vertex_handle> L;
std::list<Vertex_handle>::const_iterator it;
PSet.nearest_neighbors(actual,5,back_inserter(L));
cout << "actual point: " << actual << "\n";
for (it=L.begin();it != L.end(); it++)
cout << PSet.pos(*it) << "\n";
w2=check1(L);
if (w1==0 && w2==0) return 0;
else return 1;
}
#endif

View File

@ -0,0 +1,169 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA) || (__LEDA__ < 400)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <vector>
#include <CGAL/Cartesian.h>
#include <CGAL/Triangulation_short_names_2.h>
#include <CGAL/Triangulation_euclidean_traits_2.h>
#include <CGAL/Point_set_2_tb.h>
#include <CGAL/leda_rational.h>
using namespace CGAL;
using namespace std;
typedef Cartesian<leda_rational> REP;
typedef CGAL::Triangulation_euclidean_traits_2<REP> 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 point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge Edge;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge_iterator Edge_iterator;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex_handle Vertex_handle;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex Vertex;
Point_set_2_tb<TRAITS,Gt,Tds> PSet;
Point_2<REP> ar1[6];
Point_2<REP> ar2[3];
Point_2<REP> ar3[3];
int check1(std::list<Vertex_handle> L)
{
cout << "check 1!\n";
if (L.size() != 6) return 1;
std::list<Vertex_handle>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar1[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int check2(std::list<Vertex_handle> L)
{
cout << "check 2!\n";
if (L.size() != 3) return 1;
std::list<Vertex_handle>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar2[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int check3(std::list<Vertex_handle> L)
{
cout << "check 3!\n";
if (L.size() != 3) return 1;
std::list<Vertex_handle>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar3[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int main()
{
Point_2<REP> pnew(120,62,10);
int w1,w2,w3;
std::list<Point_2<REP> > Lr;
Point_2<REP> p1(12,14,1);
Point_2<REP> p2(-12,14,1);
Point_2<REP> p3(2,11,1);
Point_2<REP> p4(5,6,1);
Point_2<REP> p5(67,38,10);
Point_2<REP> p6(11,20,1);
Point_2<REP> p7(-5,6,1);
Point_2<REP> p8(12,0,1);
Point_2<REP> p9(4,31,1);
Point_2<REP> p10(-10,-10,1);
// init
ar1[0]=p1; ar1[1]=p6; ar1[2]=p3; ar1[3]=p4; ar1[4]=p5; ar1[5]=pnew;
ar2[0]=p2; ar2[1]=p3; ar2[2]=p1;
ar3[0]=p7; ar3[1]=p10; ar3[2]=p3;
Lr.push_back(p1); Lr.push_back(p2); Lr.push_back(p3);
Lr.push_back(p4); Lr.push_back(p5); Lr.push_back(p6);
Lr.push_back(p7); Lr.push_back(p8); Lr.push_back(p9);
Lr.push_back(p10);
PSet.init(Lr.begin(),Lr.end());
cout << "insert!\n"; cout.flush();
PSet.insert(pnew);
cout << "range search for circle !\n";
Circle_2<REP> rc(p5,p6);
std::list<Vertex_handle> LV;
PSet.range_search(rc,back_inserter(LV));
std::list<Vertex_handle>::const_iterator it;
for (it=LV.begin();it != LV.end(); it++)
cout << PSet.pos(*it) << "\n";
w1 = check1(LV);
cout << "range search for triangle !\n";
LV.clear();
PSet.range_search(p1,p2,p3,back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
cout << PSet.pos(*it) << "\n";
w2 = check2(LV);
LV.clear();
cout << "range search for iso rectangle !\n";
Point_2<REP> pt1=p10; // lower left
Point_2<REP> pt3=p3; // upper right
Point_2<REP> pt2 = Point_2<REP>(pt3.x(),pt1.y());
Point_2<REP> pt4 = Point_2<REP>(pt1.x(),pt3.y());
PSet.range_search(pt1,pt2,pt3,pt4,back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
cout << PSet.pos(*it) << "\n";
w3 = check3(LV);
if (w1==0 && w2==0 && w3==0) return 0;
else return 1;
}
#endif

View File

@ -0,0 +1,174 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA) || (__LEDA__ < 400)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <vector>
#include <CGAL/Cartesian.h>
#include <CGAL/Triangulation_short_names_2.h>
#include <CGAL/Triangulation_euclidean_leda_traits_2.h>
#include <CGAL/point_set_leda_traits_2.h>
#include <CGAL/Point_set_2_tb.h>
#include <CGAL/leda_rational.h>
using namespace CGAL;
using namespace std;
//typedef CGAL::Triangulation_euclidean_leda_rat_traits_2 Gt;
typedef CGAL::Triangulation_euclidean_leda_float_traits_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::point_set_leda_rat_traits_2 TRAITS;
typedef CGAL::point_set_leda_float_traits_2 TRAITS;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge Edge;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Edge_iterator Edge_iterator;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex_handle Vertex_handle;
typedef CGAL::Point_set_2_tb<TRAITS,Gt,Tds>::Vertex Vertex;
typedef Gt::Segment_2 Segment;
typedef Gt::Point_2 Point;
//typedef leda_rat_circle Circle;
typedef leda_circle Circle;
Point_set_2_tb<TRAITS,Gt,Tds> PSet;
Point ar1[6];
Point ar2[3];
Point ar3[3];
int check1(std::list<Vertex_handle> L)
{
cout << "check 1!\n";
if (L.size() != 6) return 1;
std::list<Vertex_handle>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar1[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int check2(std::list<Vertex_handle> L)
{
cout << "check 2!\n";
if (L.size() != 3) return 1;
std::list<Vertex_handle>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar2[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int check3(std::list<Vertex_handle> L)
{
cout << "check 3!\n";
if (L.size() != 3) return 1;
std::list<Vertex_handle>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar3[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int main()
{
Point pnew(120,62,10);
int w1,w2,w3;
std::list<Point> Lr;
Point p1(12,14,1);
Point p2(-12,14,1);
Point p3(2,11,1);
Point p4(5,6,1);
Point p5(67,38,10);
Point p6(11,20,1);
Point p7(-5,6,1);
Point p8(12,0,1);
Point p9(4,31,1);
Point p10(-10,-10,1);
// init
ar1[0]=p1; ar1[1]=p6; ar1[2]=p3; ar1[3]=p4; ar1[4]=p5; ar1[5]=pnew;
ar2[0]=p2; ar2[1]=p3; ar2[2]=p1;
ar3[0]=p7; ar3[1]=p10; ar3[2]=p3;
Lr.push_back(p1); Lr.push_back(p2); Lr.push_back(p3);
Lr.push_back(p4); Lr.push_back(p5); Lr.push_back(p6);
Lr.push_back(p7); Lr.push_back(p8); Lr.push_back(p9);
Lr.push_back(p10);
PSet.init(Lr.begin(),Lr.end());
cout << "insert!\n"; cout.flush();
PSet.insert(pnew);
cout << "range search for circle !\n";
Circle rc(p5,p6);
std::list<Vertex_handle> LV;
PSet.range_search(rc,back_inserter(LV));
std::list<Vertex_handle>::const_iterator it;
for (it=LV.begin();it != LV.end(); it++)
cout << PSet.pos(*it) << "\n";
w1 = check1(LV);
cout << "range search for triangle !\n";
LV.clear();
PSet.range_search(p1,p2,p3,back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
cout << PSet.pos(*it) << "\n";
w2 = check2(LV);
LV.clear();
cout << "range search for iso rectangle !\n";
Point pt1=p10; // lower left
Point pt3=p3; // upper right
Point pt2 = Point(pt3.xcoord(),pt1.ycoord());
Point pt4 = Point(pt1.xcoord(),pt3.ycoord());
PSet.range_search(pt1,pt2,pt3,pt4,back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
cout << PSet.pos(*it) << "\n";
w3 = check3(LV);
if (w1==0 && w2==0 && w3==0) return 0;
else return 1;
}
#endif

View File

@ -0,0 +1,640 @@
// ======================================================================
//
// Copyright (c) 1999 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------
//
// release :
// release_date : 2000, December 15
//
// file : include/CGAL/Point_set_2_tb.h
// package : Point_set_2_tb (0.1)
// maintainer : Matthias Baesken <baesken@informatik.uni-trier.de>
// revision : 0.1
// revision_date : 15 December 2000
// author(s) : Matthias Baesken
//
// coordinator : Matthias Baesken, Trier (<baesken@informatik.uni-trier.de>)
// ======================================================================
#ifndef CGAL_POINT_SET_2_TB_H
#define CGAL_POINT_SET_2_TB_H
#include <CGAL/basic.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <list>
#include <queue>
#if defined(USE_LEDA_CONTAINERS)
#include <LEDA/map.h>
#endif
#if !defined(USE_LEDA_CONTAINERS)
#include <map>
#include <stack>
#else
#include <LEDA/p_queue.h>
#endif
#include <cmath>
#include <CGAL/point_set_traits_2.h>
CGAL_BEGIN_NAMESPACE
#if !defined(USE_LEDA_CONTAINERS)
// compare function objects for the priority queues used in nearest neighbor search
template<class VP, class NT>
class compare_vertices {
public:
std::map<VP,NT,std::less<VP> > *pmap;
compare_vertices(std::map<VP,NT,std::less<VP> > *p){ pmap=p; }
bool operator()(VP e1, VP e2)
// get the priorities from the map and return result of comparison ...
{ NT& v1 = (*pmap)[e1];
NT& v2 = (*pmap)[e2];
return (v1 > v2);
}
};
#endif
template<class Str, class Gt, class Tds>
class Point_set_2_tb : public Delaunay_triangulation_2<Gt,Tds>
{
public:
typedef Gt Geom_traits;
typedef typename Geom_traits::Point_2 Point;
typedef typename Geom_traits::Ray_2 Ray;
typedef typename Geom_traits::Line_2 Line;
typedef Triangulation_2<Gt,Tds> Triangulation;
typedef typename Triangulation::Locate_type Locate_type;
typedef typename Triangulation::Face_handle Face_handle;
typedef typename Triangulation::Vertex_handle Vertex_handle;
typedef typename Triangulation::Edge Edge;
typedef typename Triangulation::Vertex Vertex;
typedef typename Triangulation::Face Face;
typedef typename Triangulation::Edge_circulator Edge_circulator;
typedef typename Triangulation::Finite_edges_iterator Finite_edges_iterator;
typedef typename Triangulation::Vertex_iterator Vertex_iterator;
typedef typename Triangulation::Edge_iterator Edge_iterator;
typedef typename Str::FT Numb_type;
typedef typename Str::Circle Circle;
typedef typename Str::Segment Segment;
//functionality on these types...
typedef typename Str::Compare_xy_2 Comparepoints;
typedef typename Str::Compare_dist_2 Comparedist;
typedef typename Str::Orientation Orientation_2;
typedef typename Str::Side_of_oriented_circle_2 Sideofcircle;
typedef typename Str::Side_of_halfspace_2 Sideofhalfspace;
typedef typename Str::Segment_has_on_2 Segmentcontains;
typedef typename Str::Squared_distance Sqrdist;
typedef typename Str::Squared_distance_to_line Linesqrdist;
typedef typename Str::Circle_bounded_side_2 Circleptori;
typedef typename Str::Circle_center_2 Circlecenter;
//constructors...
typedef typename Str::Construct_circle_2 Createcircle_3p;
typedef typename Str::Construct_segment_2 Createsegment_2p;
typedef typename Str::Construct_line_2 Createline_2p;
Str traits;
Comparepoints tr_comparepoints;
Comparedist tr_comparedist;
Orientation_2 tr_orientation;
Sideofcircle tr_so_circle;
Sideofhalfspace tr_so_hp;
Segmentcontains tr_seg_contains;
Sqrdist tr_sqrdist;
Linesqrdist tr_linesqrdist;
Circleptori tr_circleptori;
Circlecenter tr_circlecenter;
//constructors...
Createcircle_3p tr_createcircle_3p;
Createsegment_2p tr_createsegment_2p;
Createline_2p tr_createline_2p;
Point_set_2_tb()
{
init_vertex_marks();
}
Point_set_2_tb(const std::list<Point>& S)
{
init_vertex_marks();
init(S);
}
template<class InputIterator>
Point_set_2_tb(InputIterator first, InputIterator last)
{
init_vertex_marks();
init(first,last);
}
~Point_set_2_tb() {}
void init(const std::list<Point>& L0)
{
clear();
insert(L0.begin(), L0.end());
init_vertex_marks();
}
template<class InputIterator>
void init(InputIterator first, InputIterator last)
{
clear();
insert(first,last);
init_vertex_marks();
}
std::list<Point> points() const
{ std::list <Point> L;
Vertex_iterator vit = finite_vertices_begin();
for(;vit != finite_vertices_end(); vit++) {
Vertex v = *vit;
L.push_back(v.point());
}
return L;
}
template<class OutputIterator>
OutputIterator points(OutputIterator out)
{
Vertex_iterator vit = finite_vertices_begin();
for (; vit != finite_vertices_end(); vit++) { *out= (*vit).point(); out++; }
return out;
}
template<class OutputIterator>
OutputIterator segments(OutputIterator out)
{
Edge_iterator eit = finite_edges_begin();
for (; eit != finite_edges_end(); eit++) {
*out= segment(eit);
out++;
}
return out;
}
template<class OutputIterator>
OutputIterator vertices(OutputIterator res)
// return vertex handles ...
{
Vertex_iterator vit = finite_vertices_begin();
for (; vit != finite_vertices_end(); vit++) { *res= (*vit).handle(); res++; }
return res;
}
template<class OutputIterator>
OutputIterator edges(OutputIterator out)
{
Edge_iterator eit = finite_edges_begin();
for (; eit != finite_edges_end(); eit++) {
*out = *eit;
}
return out;
}
// -----------------------------------------------------
// d_face_cycle_succ and d_face_cycle_pred removed ...
// -----------------------------------------------------
bool empty() { return number_of_vertices() == 0; }
bool is_empty() { return number_of_vertices() == 0; }
// -------------------------------------------------------------------------
// locate removed; use the locate - operations inherited from triangulation
// -------------------------------------------------------------------------
// Vertex -> Vertex_handle ...
Vertex_handle lookup(Point p) const
{
if (number_of_vertices() == 0) return NULL;
// locate ...
Locate_type lt;
int li;
Face_handle fh = locate(p,lt,li);
if (lt == VERTEX){
Face f = *fh;
return f.vertex(li);
}
else return NULL;
}
void del(Vertex_handle v)
{
remove(v);
}
void del(Point p)
{ Vertex_handle v = lookup(p);
if ( v != NULL ) del(v);
}
Vertex_handle nearest_neighbor(Point p)
{
if (number_of_vertices() == 0) return NULL;
return nearest_vertex(p);
}
Vertex_handle nearest_neighbor(Vertex_handle v) const
{
if (number_of_vertices() <= 1) return NULL;
Point p = v->point();
Vertex_circulator vc = incident_vertices(v);
Vertex_circulator start =vc;
Vertex_handle min_v = (*vc).handle();
if (is_infinite(min_v)){
vc++;
min_v = (*vc).handle();
}
Vertex_handle act;
// go through the vertices ...
do {
act = vc->handle();
if (! is_infinite(act)) {
if ( tr_comparedist(p,act->point(), min_v->point()) == SMALLER ) min_v = act;
}
vc++;
} while (vc != start);
return min_v;
}
template<class OutputIterator>
OutputIterator nearest_neighbors(Point p, int k, OutputIterator res)
{
int n = number_of_vertices();
if ( k <= 0 ) return res;
if ( n <= k ) { // return all finite vertices ...
return vertices(res);
}
// insert p, if nesessary
Vertex_handle vh = lookup(p);
bool old_node = true;
// we have to add a new vertex ...
if (vh == NULL){
vh = insert(p);
old_node = false;
k++;
}
std::list<Vertex_handle> res_list;
nearest_neighbors(vh, k, res_list);
if ( !old_node )
{
res_list.pop_front();
remove(vh);
}
std::list<Vertex_handle>::const_iterator it = res_list.begin();
for (; it != res_list.end(); it++) { *res= *it; res++; }
return res;
}
template<class OutputIterator>
OutputIterator nearest_neighbors(Vertex_handle v, int k,OutputIterator res)
{
int n = number_of_vertices();
if ( k <= 0 ) return res;
if ( n <= k ) { // return all (finite) vertices ...
return vertices(res);
}
std::list<Vertex_handle> res_list;
nearest_neighbors(v, k, res_list);
}
void nearest_neighbors(Vertex_handle v, int k, std::list<Vertex_handle>& res)
{
int n = number_of_vertices();
if ( k <= 0 ) return;
if ( n <= k ) { vertices(std::back_inserter(res)); return; }
Point p = v->point();
// "unmark" the vertices ...
init_dfs();
#if defined(USE_LEDA_CONTAINERS)
leda_p_queue<Numb_type,Vertex*> PQ;
#else
std::map<Vertex*,Numb_type, std::less<Vertex*> > priority_number; // here we save the priorities ...
compare_vertices<Vertex*,Numb_type> comp(& priority_number); // comparison object ...
priority_queue<Vertex*, std::vector<Vertex*>, CGAL::compare_vertices<Vertex*,Numb_type> > PQ(comp);
#endif
#if defined(USE_LEDA_CONTAINERS)
PQ.insert(0,v.ptr());
#else
priority_number[v.ptr()] = 0;
PQ.push(v.ptr());
#endif
mark_vertex(v);
while ( k > 0 )
{
#if defined(USE_LEDA_CONTAINERS)
pq_item it = PQ.find_min();
Vertex* w = PQ.inf(it);
PQ.del_item(it);
#else
// find minimum from PQ ...
Vertex* w = PQ.top(); PQ.pop();
priority_number.erase(w); // and clean entry in priority map
#endif
res.push_back(w->handle()); k--;
// get the incident vertices of w ...
Vertex_circulator vc = incident_vertices(w->handle());
Vertex_circulator start =vc;
Vertex* act;
do {
act = &(*vc);
if ( (!is_marked(act)) && (! is_infinite(act->handle())) )
{
#if defined(USE_LEDA_CONTAINERS)
PQ.insert(tr_sqrdist(p,act->point()), act);
#else
priority_number[act] = tr_sqrdist(p,act->point());
PQ.push(act);
#endif
mark_vertex(act->handle());
}
vc++;
} while (vc != start);
}
}
// dfs
// for marking nodes in search procedures
int cur_mark;
#if defined(USE_LEDA_CONTAINERS)
leda_map<Vertex*,int> mark;
#else
std::map<Vertex*,int, std::less<Vertex*> > mark;
typedef typename std::map<Vertex*,int, std::less<Vertex*> >::iterator map_iterator;
#endif
void init_vertex_marks()
{
cur_mark = 0;
#if defined(USE_LEDA_CONTAINERS)
mark.clear();
#else
mark.erase(mark.begin(), mark.end());
#endif
}
void init_dfs()
{
cur_mark++;
if (cur_mark == MAXINT) init_vertex_marks();
}
void mark_vertex(Vertex_handle vh)
// mark vh as visited ...
{
Vertex* v = vh.ptr();
mark[v] = cur_mark;
}
bool is_marked(Vertex_handle vh)
{
Vertex* v = vh.ptr();
#if defined(USE_LEDA_CONTAINERS)
if (! mark.defined(v)) return false;
#else
map_iterator mit = mark.find(v);
if (mit == mark.end()) return false;
#endif
return (mark[v] == cur_mark);
}
void dfs(Vertex_handle v,const Circle& C, std::list<Vertex_handle>& L)
{
L.push_back(v);
mark_vertex(v);
// get incident vertices of v ...
Vertex_circulator vc = incident_vertices(v);
Vertex_circulator start =vc;
Vertex_handle act;
// go through the vertices ...
do {
act = vc->handle();
if (! is_infinite(act)) {
if (!is_marked(act) && ! (tr_circleptori(C,act->point())==ON_UNBOUNDED_SIDE) )
dfs(act,C,L);
}
vc++;
} while (vc != start);
}
template<class OutputIterator>
OutputIterator range_search(const Circle& C, OutputIterator res)
{
if (number_of_vertices() == 0) return res;
if (number_of_vertices() == 1)
{
// get the one vertex ...
Vertex_iterator vit = finite_vertices_begin();
Vertex v = (*vit);
Point p = v.point();
if (! (tr_circleptori(C, p) == ON_UNBOUNDED_SIDE)){
*res= v.handle(); res++;
}
return res;
}
// normal case ...
Point p = tr_circlecenter(C);
Vertex_handle v = lookup(p);
bool new_v = false;
if ( v == NULL )
{
new_v = true;
v = insert(p);
}
init_dfs();
std::list<Vertex_handle> L;
dfs(v,C,L);
if (new_v)
{ L.pop_front(); //first one was inserted in range_search ...
remove(v);
}
std::list<Vertex_handle>::const_iterator iter = L.begin();
for(;iter != L.end() ;iter++){ *res= *iter; res++; }
return res;
}
template<class OutputIterator>
OutputIterator range_search(const Point& a, const Point& b, const Point& c,OutputIterator res)
{ int orient = (int)(tr_orientation(a,b,c));
Circle C = tr_createcircle_3p(a,b,c);
std::list<Vertex_handle> L;
range_search(C,std::back_inserter(L));
std::list<Vertex_handle>::const_iterator it = L.begin();
for(;it != L.end();it++)
{ Point p = (*it)->point();
if ( ((int)(tr_orientation(a,b,p))) == - orient ||
((int)(tr_orientation(b,c,p))) == - orient ||
((int)(tr_orientation(c,a,p))) == - orient ) { }
else { *res = *it; res++; }
}
return res;
}
template<class OutputIterator>
OutputIterator range_search(const Point& a1, const Point& b1, const Point& c1,const Point&
d1,OutputIterator res)
// a1 lower left, b1 lower right , c1 upper right
{
//Point b(c.xcoord(),a.ycoord());
//Point d(a.xcoord(),c.ycoord());
Point a=a1,b=b1,c=c1,d=d1;
if (tr_orientation(a,b,c) == RIGHTTURN)
{ Point tmp = b;
b = d;
d = tmp;
}
Circle C = tr_createcircle_3p(a,b,c);
std::list<Vertex_handle> L;
range_search(C,std::back_inserter(L));
std::list<Vertex_handle>::const_iterator it = L.begin();
for(;it != L.end();it++)
{ Point p = (*it)->point();
if ( tr_orientation(a,b,p) == RIGHTTURN || tr_orientation(b,c,p) == RIGHTTURN ||
tr_orientation(c,d,p) == RIGHTTURN || tr_orientation(d,a,p) == RIGHTTURN ) { }
else { *res = *it; res++; }
}
return res;
}
// minimum spanning tree removed ...
//template<class OutputIterator>
//OutputIterator minimum_spanning_tree(OutputIterator result) const
bool IS_NON_DIAGRAM_DART(Edge e) const
{
Face_handle f1 = e.first;
Face_handle f2 = f1->neighbor(e.second);
int i = e.second;
// flip test
Point a = f1->vertex(cw(i))->point();
Point b = f1->vertex(i)->point();
Point c = f1->vertex(ccw(i))->point();
Point d = f1->mirror_vertex(i)->point();
if ((tr_orientation(a,b,c)==LEFTTURN) && (tr_orientation(b,c,d)==LEFTTURN) &&
(tr_orientation(c,d,a)==LEFTTURN) && (tr_orientation(d,a,c)==LEFTTURN) &&
(tr_so_circle(a,b,c,d)==ON_ORIENTED_BOUNDARY) )
return true;
return false;
}
bool is_non_diagram_edge(Edge e) const
{
return IS_NON_DIAGRAM_DART(e);
}
Edge get_cur_dart() const { return cur_dart; }
void set_cur_dart(Edge e) { cur_dart = e; }
void set_hull_dart(Edge e) { hull_dart = e; }
Point pos(Vertex_handle v) const
{ return v->point(); }
Point pos_source(Edge e) const
{ return segment(e).source(); }
Point pos_target(Edge e) const
{ return segment(e).target(); }
Segment seg(Edge e) const
{ return segment(e); }
};
CGAL_END_NAMESPACE
#endif

View File

@ -0,0 +1,555 @@
// ======================================================================
//
// Copyright (c) 1999 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------
//
// release :
// release_date : 2000, December 15
//
// file : include/CGAL/Triangulation_euclidean_leda_traits_2.h
// package : Point_set_2_tb (0.1)
// maintainer : Matthias Baesken <baesken@informatik.uni-trier.de>
// revision : 0.1
// revision_date : 15 December 2000
// author(s) : Matthias Baesken
//
// coordinator : Matthias Baesken, Trier (<baesken@informatik.uni-trier.de>)
// ======================================================================
// LEDA traits classes for CGAL Delaunay triangulation
#ifndef CGAL_TRIANGULATION_EUCLIDEAN_LEDA_TRAITS_2_H
#define CGAL_TRIANGULATION_EUCLIDEAN_LEDA_TRAITS_2_H
// float kernel
#include <LEDA/point.h>
#include <LEDA/segment.h>
#include <LEDA/triangle.h>
#include <LEDA/circle.h>
#include <LEDA/line.h>
#include <LEDA/ray.h>
#include <LEDA/vector.h>
// rat kernel
#include <LEDA/rat_point.h>
#include <LEDA/rat_segment.h>
#include <LEDA/rat_triangle.h>
#include <LEDA/rat_circle.h>
#include <LEDA/rat_line.h>
#include <LEDA/rat_ray.h>
#include <LEDA/rat_vector.h>
#include <CGAL/assertions.h>
#include <CGAL/distance_predicates_2.h>
#include <CGAL/triangulation_assertions.h>
#include <CGAL/Triangulation_short_names_2.h>
//#define LEDA_TRIANG_DEBUG
template<class I>
class leda_distance {
public:
typedef leda_point Point;
leda_distance(const I* = NULL) {}
leda_distance(const Point& p0,const I* = NULL)
{ p[0]=p0; }
leda_distance(const Point& p0, const Point& p1,const I* = NULL)
{ p[0]=p0; p[1]=p1; }
leda_distance(const Point& p0, const Point& p1, const Point& p2,const I* = NULL)
{ p[0]=p0; p[1]=p1; p[2]=p2; }
void set_point(int i, const Point& q)
{
CGAL_precondition( ((unsigned int) i) < 3 );
p[i] = q;
}
Point get_point(int i) const
{
CGAL_precondition( ((unsigned int) i) < 3 );
return p[i];
}
CGAL::Comparison_result compare() const
{
return (CGAL::Comparison_result) (::cmp_distances(p[0], p[1], p[0], p[2]));
}
private:
Point p[3];
};
template<class I>
class leda_rat_distance {
public:
typedef leda_rat_point Point;
leda_rat_distance(const I* = NULL) {}
leda_rat_distance(const Point& p0,const I* = NULL)
{ p[0]=p0; }
leda_rat_distance(const Point& p0, const Point& p1,const I* = NULL)
{ p[0]=p0; p[1]=p1; }
leda_rat_distance(const Point& p0, const Point& p1, const Point& p2,const I* = NULL)
{ p[0]=p0; p[1]=p1; p[2]=p2; }
void set_point(int i, const Point& q)
{
CGAL_precondition( ((unsigned int) i) < 3 );
p[i] = q;
}
Point get_point(int i) const
{
CGAL_precondition( ((unsigned int) i) < 3 );
return p[i];
}
CGAL::Comparison_result compare() const
{
return (CGAL::Comparison_result) (::cmp_distances(p[0], p[1], p[0], p[2]));
}
private:
Point p[3];
};
CGAL_BEGIN_NAMESPACE
// rational kernel ...
class Leda_rat_compare_x_2 {
public:
Comparison_result operator()(const leda_rat_point &p, const leda_rat_point &q) const
{
return (CGAL::Comparison_result)(leda_rat_point::cmp_x(p, q));
}
};
class Leda_rat_compare_y_2 {
public:
Comparison_result operator()(const leda_rat_point &p, const leda_rat_point &q) const
{
return (CGAL::Comparison_result)(leda_rat_point::cmp_y(p, q));
}
};
class Leda_rat_orientation_2 {
public:
Orientation operator()(const leda_rat_point &p,const leda_rat_point &q, const leda_rat_point &r) const
{
return (CGAL::Orientation)(::orientation(p, q, r));
}
};
class Leda_rat_side_of_oriented_circle_2 {
public:
Oriented_side operator()(const leda_rat_point &p,const leda_rat_point &q,
const leda_rat_point &r,
const leda_rat_point &s) const
{
return (CGAL::Oriented_side)(::side_of_circle(p, q, r, s));
}
};
class Leda_rat_construct_circumcenter_2 {
public:
leda_rat_point operator()(const leda_rat_point &p, const leda_rat_point &q, const leda_rat_point &r) const
{
leda_rat_circle C(p,q,r);
return C.center();
}
};
class Leda_rat_construct_bisector_2 {
public:
leda_rat_line operator()(const leda_rat_point &p1, leda_rat_point& p2) const
{
return leda_rat_line(::p_bisector(p1,p2));
}
};
class Leda_rat_construct_midpoint {
public:
leda_rat_point operator()(const leda_rat_point &p, const leda_rat_point &q) const
{
return ::midpoint(p,q);
}
};
class Leda_rat_construct_segment_2 {
public:
leda_rat_segment operator()(const leda_rat_point &p, const leda_rat_point &q) const
{
return leda_rat_segment(p,q);
}
};
class Leda_rat_construct_triangle_2 {
public:
leda_rat_triangle operator()(const leda_rat_point &p, const leda_rat_point &q, const leda_rat_point &r) const
{
return leda_rat_triangle(p,q,r);
}
};
class Leda_rat_less_distance_to_point_2 {
leda_rat_point _p;
public:
Leda_rat_less_distance_to_point_2( const leda_rat_point& p) : _p(p) {}
bool operator()( const leda_rat_point& p1, const leda_rat_point& p2) const
{
int c = ::cmp_distances(_p,p1,_p,p2);
if (c==-1) return true; else return false;
}
};
class Leda_rat_construct_direction_of_line_2 {
public:
leda_rat_vector operator()( const leda_rat_line& l)
{ return (l.point2() - l.point1()); }
};
class Leda_rat_construct_ray_2 {
public:
leda_rat_ray operator()(const leda_rat_point& p, const leda_rat_vector& d)
{ return leda_rat_ray(p, p+d); }
};
// float kernel ...
class Leda_float_compare_x_2 {
public:
Comparison_result operator()(const leda_point &p, const leda_point &q) const
{
#if defined LEDA_TRIANG_DEBUG
std::cout << "compare_x_2!\n"; std::cout.flush();
#endif
return (CGAL::Comparison_result)(leda_point::cmp_x(p, q));
}
};
class Leda_float_compare_y_2 {
public:
Comparison_result operator()(const leda_point &p, const leda_point &q) const
{
#if defined LEDA_TRIANG_DEBUG
std::cout << "compare_y_2!\n"; std::cout.flush();
#endif
return (CGAL::Comparison_result)(leda_point::cmp_y(p, q));
}
};
class Leda_float_orientation_2 {
public:
Orientation operator()(const leda_point &p,const leda_point &q, const leda_point &r) const
{
#if defined LEDA_TRIANG_DEBUG
std::cout << "orientation_2!\n"; std::cout.flush();
#endif
return (CGAL::Orientation)(::orientation(p, q, r));
}
};
class Leda_float_side_of_oriented_circle_2 {
public:
Oriented_side operator()(const leda_point &p,const leda_point &q,
const leda_point &r,
const leda_point &s) const
{
#if defined LEDA_TRIANG_DEBUG
std::cout << "side_of_oriented_circle_2!\n"; std::cout.flush();
if (::collinear(p, q, r)) { std::cout << " circle is degenerate!\n"; std::cout.flush(); }
#endif
return (CGAL::Oriented_side)(::side_of_circle(p, q, r, s));
}
};
class Leda_float_construct_circumcenter_2 {
public:
leda_point operator()(const leda_point &p, const leda_point &q, const leda_point &r) const
{
#if defined LEDA_TRIANG_DEBUG
std::cout << "construct_circumcenter_2!\n"; std::cout.flush();
#endif
if (::collinear(p,q,r)){
std::cout << "collinear!\n"; std::cout.flush();
return leda_point();
}
else {
leda_circle C(p,q,r);
return C.center();
}
}
};
class Leda_float_construct_bisector_2 {
public:
leda_line operator()(const leda_point& p1, const leda_point& p2 ) const
{
#if defined LEDA_TRIANG_DEBUG
std::cout << "construct_bisector_2!\n"; std::cout.flush();
#endif
return leda_line(::p_bisector(p1,p2));
}
};
class Leda_float_construct_midpoint {
public:
leda_point operator()(const leda_point &p, const leda_point &q) const
{
#if defined LEDA_TRIANG_DEBUG
std::cout << "construct_midpoint!\n"; std::cout.flush();
#endif
return ::midpoint(p,q);
}
};
class Leda_float_construct_segment_2 {
public:
leda_segment operator()(const leda_point &p, const leda_point &q) const
{
#if defined LEDA_TRIANG_DEBUG
std::cout << "construct_segment_2!\n"; std::cout.flush();
#endif
return leda_segment(p,q);
}
};
class Leda_float_construct_triangle_2 {
public:
leda_triangle operator()(const leda_point &p, const leda_point &q, const leda_point &r) const
{
#if defined LEDA_TRIANG_DEBUG
std::cout << "construct_triangle_2!\n"; std::cout.flush();
#endif
return leda_triangle(p,q,r);
}
};
class Leda_float_less_distance_to_point_2 {
leda_point _p;
public:
Leda_float_less_distance_to_point_2( const leda_point& p) : _p(p) {}
bool operator()( const leda_point& p1, const leda_point& p2) const
{
#if defined LEDA_TRIANG_DEBUG
std::cout << "less_distance_to_point_2!\n"; std::cout.flush();
#endif
int c = ::cmp_distances(_p,p1,_p,p2);
if (c==-1) return true; else return false;
}
};
class Leda_float_construct_direction_of_line_2 {
public:
leda_vector operator()( const leda_line& l)
{
#if defined LEDA_TRIANG_DEBUG
std::cout << "construct_direction_of_line_2!\n"; std::cout.flush();
#endif
return (l.point2() - l.point1());
}
};
class Leda_float_construct_ray_2 {
public:
leda_ray operator()(const leda_point& p, const leda_vector& d)
{
#if defined LEDA_TRIANG_DEBUG
std::cout << "construct_ray_2!\n"; std::cout.flush();
#endif
return leda_ray(p,d);
}
};
class Triangulation_euclidean_leda_rat_traits_2 {
public:
typedef leda_rational Rep;
typedef leda_rat_point Point_2;
typedef leda_rat_segment Segment_2;
typedef leda_rat_triangle Triangle_2;
typedef leda_rat_circle Circle_2;
typedef leda_rat_line Line_2;
typedef leda_rat_ray Ray_2;
typedef leda_rat_vector Direction_2;
typedef leda_rat_distance<Triangulation_euclidean_leda_rat_traits_2> Distance;
// new
typedef Leda_rat_compare_x_2 Compare_x_2;
typedef Leda_rat_compare_y_2 Compare_y_2;
typedef Leda_rat_orientation_2 Orientation_2;
typedef Leda_rat_side_of_oriented_circle_2 Side_of_oriented_circle_2;
typedef Leda_rat_construct_circumcenter_2 Construct_circumcenter_2;
typedef Leda_rat_construct_bisector_2 Construct_bisector_2;
typedef Leda_rat_construct_segment_2 Construct_segment_2;
typedef Leda_rat_construct_triangle_2 Construct_triangle_2;
typedef Leda_rat_construct_midpoint Construct_midpoint;
typedef Leda_rat_less_distance_to_point_2 Less_distance_to_point_2;
typedef Leda_rat_construct_direction_of_line_2 Construct_direction_of_line_2;
typedef Leda_rat_construct_ray_2 Construct_ray_2;
Triangulation_euclidean_leda_rat_traits_2() {}
Triangulation_euclidean_leda_rat_traits_2(const Triangulation_euclidean_leda_rat_traits_2 &) {}
Triangulation_euclidean_leda_rat_traits_2 &operator=
(const Triangulation_euclidean_leda_rat_traits_2 &)
{return *this;}
Compare_x_2
compare_x_2_object() const
{ return Compare_x_2();}
Compare_y_2
compare_y_2_object() const
{ return Compare_y_2();}
Orientation_2
orientation_2_object() const
{ return Orientation_2();}
Side_of_oriented_circle_2
side_of_oriented_circle_2_object() const
{return Side_of_oriented_circle_2();}
Construct_circumcenter_2
construct_circumcenter_2_object() const
{ return Construct_circumcenter_2();}
Construct_bisector_2
construct_bisector_2_object() const
{return Construct_bisector_2();}
Construct_midpoint
construct_midpoint_object() const
{return Construct_midpoint();}
Construct_segment_2
construct_segment_2_object() const
{return Construct_segment_2(); }
Construct_triangle_2
construct_triangle_2_object() const
{return Construct_triangle_2(); }
Less_distance_to_point_2
less_distance_to_point_2_object(const Point_2& p) const
{return Less_distance_to_point_2(p);}
Construct_direction_of_line_2
construct_direction_of_line_2_object() const
{ return Construct_direction_of_line_2(); }
Construct_ray_2
construct_ray_2_object() const
{ return Construct_ray_2(); }
};
class Triangulation_euclidean_leda_float_traits_2 {
public:
typedef double Rep;
typedef leda_point Point_2;
typedef leda_segment Segment_2;
typedef leda_triangle Triangle_2;
typedef leda_circle Circle_2;
typedef leda_line Line_2;
typedef leda_ray Ray_2;
typedef leda_vector Direction_2;
typedef leda_distance<Triangulation_euclidean_leda_float_traits_2> Distance;
// new
typedef Leda_float_compare_x_2 Compare_x_2;
typedef Leda_float_compare_y_2 Compare_y_2;
typedef Leda_float_orientation_2 Orientation_2;
typedef Leda_float_side_of_oriented_circle_2 Side_of_oriented_circle_2;
typedef Leda_float_construct_circumcenter_2 Construct_circumcenter_2;
typedef Leda_float_construct_bisector_2 Construct_bisector_2;
typedef Leda_float_construct_segment_2 Construct_segment_2;
typedef Leda_float_construct_triangle_2 Construct_triangle_2;
typedef Leda_float_construct_midpoint Construct_midpoint;
typedef Leda_float_less_distance_to_point_2 Less_distance_to_point_2;
typedef Leda_float_construct_direction_of_line_2 Construct_direction_of_line_2;
typedef Leda_float_construct_ray_2 Construct_ray_2;
Triangulation_euclidean_leda_float_traits_2() {}
Triangulation_euclidean_leda_float_traits_2(const Triangulation_euclidean_leda_float_traits_2 &) {}
Triangulation_euclidean_leda_float_traits_2 &operator=
(const Triangulation_euclidean_leda_float_traits_2 &)
{return *this;}
Compare_x_2
compare_x_2_object() const
{ return Compare_x_2();}
Compare_y_2
compare_y_2_object() const
{ return Compare_y_2();}
Orientation_2
orientation_2_object() const
{ return Orientation_2();}
Side_of_oriented_circle_2
side_of_oriented_circle_2_object() const
{return Side_of_oriented_circle_2();}
Construct_circumcenter_2
construct_circumcenter_2_object() const
{ return Construct_circumcenter_2();}
Construct_bisector_2
construct_bisector_2_object() const
{return Construct_bisector_2();}
Construct_midpoint
construct_midpoint_object() const
{return Construct_midpoint();}
Construct_segment_2
construct_segment_2_object() const
{return Construct_segment_2(); }
Construct_triangle_2
construct_triangle_2_object() const
{return Construct_triangle_2(); }
Less_distance_to_point_2
less_distance_to_point_2_object(const Point_2& p) const
{return Less_distance_to_point_2(p);}
Construct_direction_of_line_2
construct_direction_of_line_2_object() const
{ return Construct_direction_of_line_2(); }
Construct_ray_2
construct_ray_2_object() const
{ return Construct_ray_2(); }
};
CGAL_END_NAMESPACE
#endif // CGAL_TRIANGULATION_EUCLIDEAN_TRAITS_2_H

View File

@ -0,0 +1 @@
Matthias Baesken <baesken@informatik.uni-trier.de>

View File

@ -0,0 +1,2 @@
0.1 (15 December 2000)
maintainer: Matthias Baesken <baesken@informatik.uni-trier.de>

View File

@ -0,0 +1,62 @@
1.2.4 - HTML Manual changes
1.2.3 - added some \ccHtmlNoLinksFrom in the documentation to prevent linking of Vertex/Line
in the HTML Manual version
1.2.2 - some manual changes
1.2.1 - small changes to Point_set_2.h to please MSVC
- LEDA check added to program files
1.2 - manual split (into user - and reference manual)
- Point_set_2.h reorganized
1.1.8 - no more usage of LEDA/rat_window.h
(is not available on LEDA 3.7.1)
1.1.6 - demo makefile changed
- a typename added for g++ in Point_set_2.h to please g++ -pedantic
1.1.5 - changed demo makefile
- renaming of traits in manual
- additions in testsuite
1.1.4 - 2x std::std removed from Point_set_2.h
1.1.3 - demos changed (no using any more, some other small changes)
- cerr -> std::cerr in Point_set_2.h
1.1.2 - test and examples makefile changed for BC
1.1.1 - function save_state and inclusion of fstream-headers
removed
1.1 - Pointset_2 -> Point_set_2
- Traits classes changed
- lots of changes in the manual
1.0.9 - makefiles changed
1.0.8 - removed some endl without the std:: prefix
1.0.7 - GeoWin demos changed
- some demo - Makefiles changed
- lookup crash on empty pointset fixed
1.0.6 - demos changed; some typename stuff in
pointset_cgaltraits_2.h changed for MSVC
1.0.5 - changes in Pointset_2.h for compatibility with older LEDA versions
1.0.4 - small change in Pointset_2.h
1.0.3 - some demos were changed
1.0.2 - changes in Makefiles
- added inclusion of CGAL/config.h at the beginning of programs
- small change for better VC - compatibility
1.0.1 - some demo programs changed
- 2 errors in the file headers fixed
1.0 First released version of the Pointset_2 for CGAL

View File

@ -0,0 +1,38 @@
include $(CGAL_MAKEFILE)
CC = $(CGAL_CXX) $(CGAL_WINDOW_LIBPATH)
CGALCFLAGS = $(CGAL_CXXFLAGS)
CGDL = $(CGAL_GEOWIN_LDFLAGS)
geowin_pset_2d$(EXE_EXT) : geowin_pset_2d$(OBJ_EXT)
$(CC) $(EXE_OPT)geowin_pset_2d geowin_pset_2d$(OBJ_EXT) $(CGDL)
geowin_k_nearest_neighbors$(EXE_EXT) : geowin_k_nearest_neighbors$(OBJ_EXT)
$(CC) $(EXE_OPT)geowin_k_nearest_neighbors geowin_k_nearest_neighbors$(OBJ_EXT) $(CGDL)
clean :
rm -f tt *~ *.o *.obj *.exe
rm -f geowin_k_nearest_neighbors geowin_pset_2d
all: geowin_k_nearest_neighbors geowin_pset_2d
cleano :
rm -f *~ *.o
#---------------------------------------------------------------------#
# suffix rules
#---------------------------------------------------------------------#
.C$(OBJ_EXT):
$(CGAL_CXX) $(CGALCFLAGS) -c $<
.c$(OBJ_EXT):
$(CGAL_CXX) $(CGALCFLAGS) -c $<

View File

@ -0,0 +1,111 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA) || (__LEDA__ < 400)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA 4.0 or higher installed!\n";
std::cout << "A LEDA version >= 4.0 is required !\n";
return 0;
}
#else
#include <CGAL/geowin_support.h>
#include <CGAL/Point_set_2.h>
typedef CGAL::Cartesian<double> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
CGAL::Point_set_2<TRAITS> PST;
int k;
class construct_pointset : public geowin_update<std::list<CGAL::Point_2<REP> >,std::list<CGAL::Segment_2<REP> > >
{
public:
void update(const std::list<CGAL::Point_2<REP> >& Lin, std::list<CGAL::Segment_2<REP> >& Lout)
{
PST.init(Lin.begin(),Lin.end());
Lout.clear();
PST.segments(std::back_inserter(Lout));
}
};
class mst : public geowin_update<std::list<CGAL::Point_2<REP> >, std::list<CGAL::Segment_2<REP> > >
{
public:
void update(const std::list<CGAL::Point_2<REP> >& Lin, std::list<CGAL::Segment_2<REP> >& Lout)
{
Lout.clear();
std::list<Edge> output;
std::list<Edge>::const_iterator pit;
PST.minimum_spanning_tree( std::back_inserter(output));
for (pit=output.begin(); pit != output.end(); pit++){
Lout.push_back(CGALSegment(PST.seg(*pit)));
}
}
};
class nearest_neighbors : public geowin_update<std::list<CGAL::Point_2<REP> >, std::list<CGAL::Circle_2<REP> > >
{
public:
void update(const std::list<CGAL::Point_2<REP> >& Lin, std::list<CGAL::Circle_2<REP> >& Lout)
{
Lout.clear();
std::list<CGAL::Point_2<REP> >::const_iterator it = Lin.begin();
std::list<Vertex> output;
std::list<Vertex>::const_iterator pit;
for (; it != Lin.end(); it++){
PST.nearest_neighbors(*it, k, std::back_inserter(output));
}
for (pit=output.begin(); pit != output.end(); pit++){
Lout.push_back(CGALCircle(PST.pos(*pit),2.0));
}
}
};
int main()
{
geowin_init_default_type((std::list<CGAL::Point_2<REP> >*)0, leda_string("CGALPointlist"));
std::cout << "Find the k nearest neighbors of every point in scene 2.\n";
std::cout << "k:"; std::cin >> k;
GeoWin gw;
std::list<CGAL::Point_2<REP> > Lp;
geo_scene sc1 = gw.new_scene(Lp);
std::list<CGAL::Point_2<REP> > Lother;
geo_scene sc2 = gw.new_scene(Lother);
gw.set_color(sc2,leda_blue);
construct_pointset CP;
geo_scene sc3 = gw.new_scene(CP, sc1, leda_string("2d point set"));
gw.set_color(sc3,leda_blue);
nearest_neighbors NN;
geo_scene sc4 = gw.new_scene(NN, sc2, leda_string("k nearest neighbors"));
gw.set_fill_color(sc4,leda_red);
gw.set_color(sc4,leda_red);
gw.set_point_style(sc4,leda_circle_point);
gw.set_line_width(sc4,4);
mst MS;
geo_scene sc5 = gw.new_scene(MS, sc1, leda_string("Minimum spanning tree"));
gw.set_line_width(sc5,2);
gw.set_all_visible(true);
gw.add_dependence(sc1,sc4);
gw.edit(sc1);
return 0;
}
#endif

View File

@ -0,0 +1,120 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA) || (__LEDA__ < 400)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA 4.0 or higher installed!\n";
std::cout << "A LEDA version >= 4.0 is required !\n";
return 0;
}
#else
#include <CGAL/geowin_support.h>
#include <CGAL/Point_set_2.h>
typedef CGAL::Cartesian<double> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
CGAL::Point_set_2<TRAITS> PST;
class construct_pointset : public geowin_update<std::list<CGALPoint>, std::list<CGALSegment> >
{
public:
void update(const std::list<CGALPoint>& Lin, std::list<CGALSegment>& Lout)
{
PST.init(Lin.begin(),Lin.end());
Lout.clear();
PST.segments(std::back_inserter(Lout));
}
};
class circle_range_search : public geowin_update<std::list<CGALCircle>, std::list<CGALCircle> >
{
void update(const std::list<CGALCircle>& Lin, std::list<CGALCircle>& Lout)
{
Lout.clear();
std::list<CGALCircle>::const_iterator it = Lin.begin();
std::list<Vertex> output;
std::list<Vertex>::const_iterator pit;
for (; it != Lin.end(); it++){
PST.range_search(*it, std::back_inserter(output));
}
for (pit=output.begin(); pit != output.end(); pit++){
Lout.push_back(CGALCircle(PST.pos(*pit),2.0));
}
}
};
class triangle_range_search : public geowin_update<std::list<CGALTriangle>, std::list<CGALCircle> >
{
public:
void update(const std::list<CGALTriangle>& Lin, std::list<CGALCircle>& Lout)
{
Lout.clear();
std::list<CGALTriangle>::const_iterator it = Lin.begin();
std::list<Vertex> output;
std::list<Vertex>::const_iterator pit;
for (; it != Lin.end(); it++){
PST.range_search((*it).vertex(0),(*it).vertex(1),(*it).vertex(2), std::back_inserter(output));
}
for (pit=output.begin(); pit != output.end(); pit++){
Lout.push_back(CGALCircle(PST.pos(*pit),1.0));
}
}
};
int main()
{
geowin_init_default_type((CGALPointlist*)0, leda_string("CGALPointlist"));
geowin_init_default_type((CGALCirclelist*)0, leda_string("CGALCirclelist"));
geowin_init_default_type((CGALTrianglelist*)0, leda_string("CGALTrianglelist"));
GeoWin gw;
std::list<CGALPoint> Lp;
geo_scene sc1 = gw.new_scene(Lp);
std::list<CGALCircle> Lc;
geo_scene sc_circ = gw.new_scene(Lc);
gw.set_color(sc_circ, leda_blue);
gw.set_fill_color(sc_circ, leda_invisible);
std::list<CGALTriangle> Lt;
geo_scene sc_triang = gw.new_scene(Lt);
gw.set_color(sc_triang, leda_blue2);
gw.set_line_width(sc_triang,3);
gw.set_active_line_width(sc_triang,3);
gw.set_fill_color(sc_triang, leda_invisible);
construct_pointset CP;
gw.new_scene(CP, sc1, leda_string("2d point set"));
circle_range_search CRS;
geo_scene sc3 = gw.new_scene(CRS, sc_circ, leda_string("circular range search"));
gw.set_color(sc3,leda_red);
gw.set_point_style(sc3, leda_circle_point);
gw.set_line_width(sc3,4);
triangle_range_search TRS;
geo_scene sc4 = gw.new_scene(TRS, sc_triang, leda_string("triangular range search"));
gw.set_color(sc4,leda_green);
gw.set_point_style(sc4, leda_circle_point);
gw.set_line_width(sc4,4);
gw.set_all_visible(true);
gw.add_dependence(sc1,sc3);
gw.add_dependence(sc1,sc4);
gw.edit(sc1);
return 0;
}
#endif

View File

@ -0,0 +1,53 @@
include $(CGAL_MAKEFILE)
CC = $(CGAL_CXX) $(CGAL_WINDOW_LIBPATH)
CGALCFLAGS = $(CGAL_CXXFLAGS)
CGDL = $(CGAL_WINDOW_LDFLAGS)
ps_test1$(EXE_EXT) : ps_test1$(OBJ_EXT)
$(CC) $(EXE_OPT)ps_test1 ps_test1$(OBJ_EXT) $(CGDL)
voronoi$(EXE_EXT) : voronoi$(OBJ_EXT)
$(CC) $(EXE_OPT)voronoi voronoi$(OBJ_EXT) $(CGDL)
rtest$(EXE_EXT) : rtest$(OBJ_EXT)
$(CC) $(EXE_OPT)rtest rtest$(OBJ_EXT) $(CGDL)
ps_test1_cgal$(EXE_EXT) : ps_test1_cgal$(OBJ_EXT)
$(CC) $(EXE_OPT)ps_test1_cgal ps_test1_cgal$(OBJ_EXT) $(CGDL)
nearest_neighbor$(EXE_EXT) : nearest_neighbor$(OBJ_EXT)
$(CC) $(EXE_OPT)nearest_neighbor nearest_neighbor$(OBJ_EXT) $(CGDL)
locate_test$(EXE_EXT) : locate_test$(OBJ_EXT)
$(CC) $(EXE_OPT)locate_test locate_test$(OBJ_EXT) $(CGDL)
range_search$(EXE_EXT) : range_search$(OBJ_EXT)
$(CC) $(EXE_OPT)range_search range_search$(OBJ_EXT) $(CGDL)
range_search_hm$(EXE_EXT) : range_search_hm$(OBJ_EXT)
$(CC) $(EXE_OPT)range_search_hm range_search_hm$(OBJ_EXT) $(CGDL)
locate_test_hm$(EXE_EXT) : locate_test_hm$(OBJ_EXT)
$(CC) $(EXE_OPT)locate_test_hm locate_test_hm$(OBJ_EXT) $(CGDL)
clean :
rm -f tt *~ *.o *.obj *.exe core
rm -f voronoi ps_test1 ps_test1_cgal nearest_neighbor locate_test range_search range_search_hm locate_test_hm
all: ps_test1_cgal nearest_neighbor locate_test range_search range_search_hm locate_test_hm
cleano :
rm -f *~ *.o
#---------------------------------------------------------------------#
# suffix rules
#---------------------------------------------------------------------#
.C$(OBJ_EXT):
$(CGAL_CXX) $(CGALCFLAGS) $(OBJ_OPT) $<

View File

@ -0,0 +1,14 @@
Various demonstration programs for the 2d Pointset.
All use the LEDA window class for visualization.
GeoWin:
In this folder are 2 demos using the GeoWin library.
geowin_pset_2d: range searches on the Pointset_2
geowin_k_nearest_neighbors: nearest neighbors, minimum spanning tree
- note that for optimising compilation you have to add on some platforms
the flag -fno_default_inline

View File

@ -0,0 +1,80 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <LEDA/window.h>
#include <CGAL/Point_set_2.h>
#include <CGAL/leda_rational.h>
#include <CGAL/IO/Window_stream.h>
typedef CGAL::Cartesian<leda_rational> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
leda_segment get_seg(const CGAL::Segment_2<REP>& s)
{
CGAL::Point_2<REP> ps=s.source();
CGAL::Point_2<REP> pt=s.target();
leda_rat_point p1(ps.x(),ps.y()), p2(pt.x(),pt.y());
return leda_segment(p1.to_point(),p2.to_point());
}
void output(leda_window& W, const CGAL::Point_set_2<TRAITS>& PSet)
{
W.clear();
leda_edge e;
forall_edges(e,PSet) {
CGAL::Segment_2<REP> s= PSet.seg(e);
W << get_seg(s);
}
}
int main()
{
int i;
CGAL::Point_set_2<TRAITS> PSet;
CGAL::Point_2<REP> actual;
leda_window W(600,500,leda_string("Input vertices of the Delaunay Triangulation!"));
CGAL::cgalize( W);
W.init(-500,500,-400);
W.display(100,100);
// read in 20 points ...
for (i=0; i<20; i++){
W >> actual;
PSet.insert(actual);
output(W,PSet);
}
W.set_frame_label(leda_string("Locate!"));
// locate ...
for (i=0; i<10; i++){
W >> actual;
Edge e = PSet.locate(actual);
CGAL::Segment_2<REP> my_seg = PSet.seg(e);
W << CGAL::BLUE << my_seg << CGAL::BLACK;
}
W.read_mouse();
return 0;
}
#endif

View File

@ -0,0 +1,80 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <LEDA/window.h>
#include <CGAL/Point_set_2.h>
#include <CGAL/leda_integer.h>
#include <CGAL/IO/Window_stream.h>
typedef CGAL::Homogeneous<leda_integer> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
leda_segment get_seg(const CGAL::Segment_2<REP>& s)
{
CGAL::Point_2<REP> ps=s.source();
CGAL::Point_2<REP> pt=s.target();
leda_rat_point p1(ps.hx()/ps.hw(),ps.hy()/ps.hw());
leda_rat_point p2(pt.hx()/ps.hw(),pt.hy()/ps.hw());
return leda_segment(p1.to_point(),p2.to_point());
}
void output(leda_window& W, const CGAL::Point_set_2<TRAITS>& PSet)
{
W.clear();
leda_edge e;
forall_edges(e,PSet) {
CGAL::Segment_2<REP> s = PSet.seg(e);
W << get_seg(s);
}
}
int main()
{
int i;
CGAL::Point_set_2<TRAITS> PSet;
CGAL::Point_2<REP> actual;
leda_window W(600,500,leda_string("Input vertices of the Delaunay Triangulation!"));
CGAL::cgalize( W);
W.init(-500,500,-400);
W.display(100,100);
// read in 20 points ...
for (i=0; i<20; i++){
W >> actual;
PSet.insert(actual);
output(W,PSet);
}
// locate ...
for (i=0; i<5; i++){
W >> actual;
Edge e = PSet.locate(actual);
CGAL::Segment_2<REP> my_seg = PSet.seg(e);
W << CGAL::BLUE << my_seg << CGAL::BLACK;
}
W.read_mouse();
return 0;
}
#endif

View File

@ -0,0 +1,100 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <LEDA/window.h>
#include <CGAL/Point_set_2.h>
#include <CGAL/leda_rational.h>
#include <CGAL/IO/Window_stream.h>
typedef CGAL::Cartesian<leda_rational> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
leda_segment get_seg(const CGAL::Segment_2<REP>& s)
{
CGAL::Point_2<REP> ps=s.source();
CGAL::Point_2<REP> pt=s.target();
leda_rat_point p1(ps.x(),ps.y()), p2(pt.x(),pt.y());
return leda_segment(p1.to_point(),p2.to_point());
}
void output(leda_window& W, const CGAL::Point_set_2<TRAITS>& PSet)
{
W.clear();
leda_edge e;
forall_edges(e,PSet) {
CGAL::Segment_2<REP> s= PSet.seg(e);
W << get_seg(s);
}
}
int main()
{
CGAL::Point_set_2<TRAITS> PSet;
leda_window W(600,500, leda_string("Finding nearest neighbors"));
CGAL::cgalize( W);
W.init(-500,500,-400);
W.display(100,100);
CGAL::Point_2<REP> actual;
int i;
for (i=0; i<25; i++){
W >> actual;
PSet.insert(actual);
output(W,PSet);
}
// nearest neighbor ...
for (i=0; i<5; i++){
W >> actual;
Vertex v = PSet.nearest_neighbor(actual);
CGAL::Segment_2<REP> my_seg(actual,PSet.pos(v));
W << CGAL::RED << PSet.pos(v) << CGAL::BLACK;
W << CGAL::BLUE << my_seg << CGAL::BLACK;
}
// k nearest neighbors ...
std::list<Vertex> L;
std::list<Vertex>::const_iterator it;
for (i=0; i<5; i++){
L.clear();
W >> actual;
PSet.nearest_neighbors(actual,5, std::back_inserter(L));
std::cout << "actual point: " << actual << "\n";
W.clear();
output(W,PSet);
W << CGAL::RED << actual << CGAL::BLACK;
for (it=L.begin();it != L.end(); it++){
W << CGAL::GREEN << PSet.pos(*it) << CGAL::BLACK;
std::cout << PSet.pos(*it) << "\n";
}
std::cout << "\n";
}
W.read_mouse();
return 0;
}
#endif

View File

@ -0,0 +1,111 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA) || (__LEDA__ < 400)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA 4.0 or higher installed!\n";
std::cout << "A LEDA version >= 4.0 is required !\n";
return 0;
}
#else
// Pointset demo using LEDA lists as containers;
// LEDA 4.0 or higher should be used
#include <CGAL/config.h>
#include <list>
#include <LEDA/window.h>
#include <LEDA/rat_window.h>
#include <CGAL/Point_set_2.h>
typedef CGAL::point_set_leda_rat_traits_2 TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
void output(leda_window& W, const CGAL::Point_set_2<TRAITS>& PSR_rat)
{
W.clear();
leda_edge e;
forall_edges(e,PSR_rat) W << leda_segment(PSR_rat.seg(e).to_segment());
}
int main()
{
int i;
CGAL::Point_set_2<TRAITS> PSR_rat;
leda_window W(500,400);
W.init(-500,500,-400);
W.display();
for (i=0; i<30; i++) {
leda_rat_point pnew;
W >> pnew;
PSR_rat.insert(pnew);
output(W,PSR_rat);
}
for (i=0; i<3; i++) {
leda_rat_point pnew;
W >> pnew;
Vertex v = PSR_rat.nearest_neighbor(pnew);
PSR_rat.del(v);
output(W,PSR_rat);
}
leda_rat_circle rc;
W >> rc; W << rc;
#if (__LEDA__ >= 400)
W.set_point_style(leda_disc_point);
#endif
leda_list<Vertex> LV = PSR_rat.range_search(rc);
Vertex v;
W.set_color(leda_red);
forall(v,LV) W << PSR_rat.pos(v);
std::cout << "circular range_search - found " << LV.size() << " vertices!\n";
std::cout << "range search for triangle !\n";
leda_rat_point pt1,pt2,pt3,pt4;
W >> pt1; W << pt1;
W >> pt2; W << pt2;
W >> pt3; W << pt3;
LV.clear();
PSR_rat.range_search(pt1,pt2,pt3,std::back_inserter(LV));
leda_list<Vertex>::iterator it;
W.set_color(leda_green);
for (it=LV.begin();it != LV.end(); it++)
W << PSR_rat.pos(*it);
std::cout << "triangular range_search - found " << LV.size() << " vertices!\n";
LV.clear();
W >> pt1; W << pt1;
W >> pt3; W << pt3;
pt2 = leda_rat_point(pt3.xcoord(),pt1.ycoord());
pt4 = leda_rat_point(pt1.xcoord(),pt3.ycoord());
W.set_color(leda_orange);
PSR_rat.range_search(pt1,pt2,pt3,pt4,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
W << PSR_rat.pos(*it);
std::cout << "rectangular range_search - found " << LV.size() << " vertices!\n";
leda_list<Edge> El = PSR_rat.minimum_spanning_tree();
std::cout << "\nMST: " << El.size() << " vertices\n";
W.read_mouse();
return 0;
}
#endif

View File

@ -0,0 +1,131 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <LEDA/window.h>
#include <CGAL/Point_set_2.h>
#include <CGAL/IO/Window_stream.h>
typedef CGAL::Cartesian<double> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
leda_segment get_seg(const CGAL::Segment_2<REP>& s)
{
CGAL::Point_2<REP> ps=s.source();
CGAL::Point_2<REP> pt=s.target();
leda_point p1(ps.x(),ps.y()), p2(pt.x(),pt.y());
return leda_segment(p1,p2);
}
void output(leda_window& W, const CGAL::Point_set_2<TRAITS>& PSR_rat)
{
W.clear();
leda_edge e;
forall_edges(e,PSR_rat) {
CGAL::Segment_2<REP> s= PSR_rat.seg(e);
W << get_seg(s);
}
}
int main()
{
int i;
CGAL::Point_set_2<TRAITS> PSR_rat;
leda_window W(600,500);
CGAL::cgalize( W);
W.init(-500,500,-400);
W.display(100,100);
output(W,PSR_rat);
for (i=0; i<25; i++) {
CGAL::Point_2<REP> pnew;
W >> pnew;
PSR_rat.insert(pnew);
output(W,PSR_rat);
}
for (i=0; i<2; i++) {
CGAL::Point_2<REP> pnew;
W >> pnew;
Vertex v = PSR_rat.nearest_neighbor(pnew);
PSR_rat.del(v);
output(W,PSR_rat);
}
std::cout << "circular range search !\n";
CGAL::Circle_2<REP> rc;
W >> rc;
std::list<Vertex> LV;
std::list<Vertex>::const_iterator vit;
PSR_rat.range_search(rc,std::back_inserter(LV));
W.set_color(leda_red);
for(vit=LV.begin(); vit!=LV.end(); vit++){
W << PSR_rat.pos(*vit);
}
W.set_color(leda_black);
std::cout << LV.size() << "\n";
std::cout << "triangular range search !\n";
CGAL::Point_2<REP> pt1,pt2,pt3,pt4;
W >> pt1;
W >> pt2;
W >> pt3;
std::list<Vertex> outlist;
PSR_rat.range_search(pt1,pt2,pt3,std::back_inserter(outlist));
W.set_color(leda_green);
for(vit=outlist.begin(); vit!=outlist.end(); vit++){
W << PSR_rat.pos(*vit);
}
W.set_color(leda_black);
std::cout << outlist.size() << "\n";
outlist.clear();
std::cout << "rectangular range search !\n";
W >> pt1; W >> pt3;
pt2 = CGAL::Point_2<REP>(pt3.x(),pt1.y());
pt4 = CGAL::Point_2<REP>(pt1.x(),pt3.y());
PSR_rat.range_search(pt1,pt2,pt3,pt4,std::back_inserter(outlist));
W.set_color(leda_yellow);
for(vit=outlist.begin(); vit!=outlist.end(); vit++){
W << PSR_rat.pos(*vit);
}
W.set_color(leda_black);
std::cout << outlist.size() << "\n";
leda_list<Edge> El = PSR_rat.minimum_spanning_tree();
std::cout << "MST:\n" << El.size() << " vertices\n";
W.read_mouse();
return 0;
}
#endif

View File

@ -0,0 +1,115 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <LEDA/window.h>
#include <CGAL/Point_set_2.h>
#include <CGAL/leda_rational.h>
#include <CGAL/IO/Window_stream.h>
typedef CGAL::Cartesian<leda_rational> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
leda_segment get_seg(const CGAL::Segment_2<REP>& s)
{
CGAL::Point_2<REP> ps=s.source();
CGAL::Point_2<REP> pt=s.target();
leda_rat_point p1(ps.x(),ps.y()), p2(pt.x(),pt.y());
return leda_segment(p1.to_point(),p2.to_point());
}
void output(leda_window& W, const CGAL::Point_set_2<TRAITS>& PSet)
{
W.clear();
leda_edge e;
forall_edges(e,PSet) {
CGAL::Segment_2<REP> s= PSet.seg(e);
W << get_seg(s);
}
}
int main()
{
int i;
CGAL::Point_set_2<TRAITS> PSet;
CGAL::Point_2<REP> pnew;
leda_window W(600,500,leda_string("Range searches"));
CGAL::cgalize( W);
W.init(-500,500,-400);
W.display(100,100);
for (i=0; i<30; i++) {
W >> pnew;
PSet.insert(pnew);
output(W,PSet);
}
for (i=0; i<5; i++) {
W >> pnew;
Vertex v = PSet.nearest_neighbor(pnew);
std::cout << "delete!\n"; std::cout.flush();
PSet.del(v);
output(W,PSet);
}
std::cout << "range search for circle !\n";
CGAL::Circle_2<REP> rc;
W >> rc;
std::list<Vertex> LV;
PSet.range_search(rc,std::back_inserter(LV));
std::list<Vertex>::const_iterator it;
for (it=LV.begin();it != LV.end(); it++)
W << CGAL::GREEN << PSet.pos(*it) << CGAL::BLACK;
std::cout << "range search for triangle !\n";
CGAL::Point_2<REP> pt1,pt2,pt3,pt4;
W >> pt1;
W >> pt2;
W >> pt3;
LV.clear();
PSet.range_search(pt1,pt2,pt3,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
W << CGAL::BLUE << PSet.pos(*it) << CGAL::BLACK;
LV.clear();
std::cout << "range search for iso rectangle !\n";
W >> pt1; // lower left
W >> pt3; // upper right
pt2 = CGAL::Point_2<REP>(pt3.x(),pt1.y());
pt4 = CGAL::Point_2<REP>(pt1.x(),pt3.y());
PSet.range_search(pt1,pt2,pt3,pt4,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
W << CGAL::RED << PSet.pos(*it) << CGAL::BLACK;
leda_list<Edge> El = PSet.minimum_spanning_tree();
Edge eakt;
std::cout << "minimum spanning tree !\n";
forall(eakt,El) W << CGAL::VIOLET << PSet.seg(eakt);
W.read_mouse();
return 0;
}
#endif

View File

@ -0,0 +1,115 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <LEDA/window.h>
#include <CGAL/Point_set_2.h>
#include <CGAL/leda_integer.h>
#include <CGAL/IO/Window_stream.h>
typedef CGAL::Homogeneous<leda_integer> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
leda_segment get_seg(const CGAL::Segment_2<REP>& s)
{
CGAL::Point_2<REP> ps=s.source();
CGAL::Point_2<REP> pt=s.target();
leda_rat_point p1(ps.hx()/ps.hw(),ps.hy()/ps.hw());
leda_rat_point p2(pt.hx()/ps.hw(),pt.hy()/ps.hw());
return leda_segment(p1.to_point(),p2.to_point());
}
void output(leda_window& W, const CGAL::Point_set_2<TRAITS>& PSet)
{
W.clear();
leda_edge e;
forall_edges(e,PSet) {
CGAL::Segment_2<REP> s = PSet.seg(e);
W << get_seg(s);
}
}
int main()
{
int i;
CGAL::Point_set_2<TRAITS> PSet;
CGAL::Point_2<REP> pnew;
leda_window W(600,500,leda_string("Range searches"));
CGAL::cgalize( W);
W.init(-500,500,-400);
W.display(100,100);
for (i=0; i<35; i++) {
W >> pnew;
PSet.insert(pnew);
output(W,PSet);
}
for (i=0; i<5; i++) {
W >> pnew;
Vertex v = PSet.nearest_neighbor(pnew);
std::cout << "delete!\n"; std::cout.flush();
PSet.del(v);
output(W,PSet);
}
std::cout << "circular range search !\n";
CGAL::Circle_2<REP> rc;
W >> rc;
std::list<Vertex> LV;
PSet.range_search(rc,std::back_inserter(LV));
std::list<Vertex>::const_iterator it;
for (it=LV.begin();it != LV.end(); it++)
W << CGAL::GREEN << PSet.pos(*it) << CGAL::BLACK;
std::cout << "range search for triangle !\n";
CGAL::Point_2<REP> pt1,pt2,pt3,pt4;
W >> pt1; W >> pt2; W >> pt3;
LV.clear();
PSet.range_search(pt1,pt2,pt3,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
W << CGAL::BLUE << PSet.pos(*it) << CGAL::BLACK;
LV.clear();
std:: cout << "rectangular range search!\n";
W >> pt1; W >> pt3;
pt2 = CGAL::Point_2<REP>(pt3.hx()/pt3.hw(),pt1.hy()/pt3.hw());
pt4 = CGAL::Point_2<REP>(pt1.hx()/pt3.hw(),pt3.hy()/pt3.hw());
PSet.range_search(pt1,pt2,pt3,pt4,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
W << CGAL::RED << PSet.pos(*it) << CGAL::BLACK;
std::list<Edge> El;
PSet.minimum_spanning_tree(std::back_inserter(El));
std::list<Edge>::const_iterator eit;
std::cout << "minimum spanning tree !\n";
for(eit=El.begin();eit!=El.end();eit++)
W << CGAL::VIOLET << PSet.seg(*eit);
W.read_mouse();
return 0;
}
#endif

View File

@ -0,0 +1,84 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <vector>
#include <CGAL/Point_set_2.h>
typedef CGAL::Cartesian<double> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
int main()
{
CGAL::Point_set_2<TRAITS> PSet;
CGAL::Point_2<REP> pnew;
std::list<CGAL::Point_2<REP> > Lr;
CGAL::Point_2<REP> p1(12,14);
CGAL::Point_2<REP> p2(-12,14);
CGAL::Point_2<REP> p3(2,11);
CGAL::Point_2<REP> p4(5,6);
CGAL::Point_2<REP> p5(6.7,3.8);
CGAL::Point_2<REP> p6(11,20);
CGAL::Point_2<REP> p7(-5,6);
CGAL::Point_2<REP> p8(12,0);
CGAL::Point_2<REP> p9(4,31);
CGAL::Point_2<REP> p10(-10,-10);
Lr.push_back(p1); Lr.push_back(p2); Lr.push_back(p3);
Lr.push_back(p4); Lr.push_back(p5); Lr.push_back(p6);
Lr.push_back(p7); Lr.push_back(p8); Lr.push_back(p9);
Lr.push_back(p10);
PSet.init(Lr.begin(),Lr.end());
pnew= CGAL::Point_2<REP>(12,6.2);
std::cout << "insert!\n";
PSet.insert(pnew);
std::cout << "range search for circle !\n";
CGAL::Circle_2<REP> rc(p5,p6);
std::list<Vertex> LV;
PSet.range_search(rc,std::back_inserter(LV));
std::list<Vertex>::const_iterator it;
for (it=LV.begin();it != LV.end(); it++)
std::cout << PSet.pos(*it) << "\n";
std::cout << "range search for triangle !\n";
LV.clear();
PSet.range_search(p1,p2,p3,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
std::cout << PSet.pos(*it) << "\n";
LV.clear();
std::cout << "range search for iso rectangle !\n";
CGAL::Point_2<REP> pt1=p10; // lower left
CGAL::Point_2<REP> pt3=p3; // upper right
CGAL::Point_2<REP> pt2 = CGAL::Point_2<REP>(pt3.x(),pt1.y());
CGAL::Point_2<REP> pt4 = CGAL::Point_2<REP>(pt1.x(),pt3.y());
PSet.range_search(pt1,pt2,pt3,pt4,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
std::cout << PSet.pos(*it) << "\n";
return 0;
}
#endif

View File

@ -0,0 +1 @@
2d Point set data type

View File

@ -0,0 +1,374 @@
% +------------------------------------------------------------------------+
% | CGAL User Manual: Point_set_2.tex
% +------------------------------------------------------------------------+
\ccParDims
\chapter{Point Set in 2D}
\label{chapterPoint_set_2}
\ccChapterAuthor{Matthias B\"asken}
%---------------------------------------------
% Introduction
%---------------------------------------------
\section{Introduction}
Geometric Queries are fundamental to many applications in computational
geometry. The task is to maintain a dynamic set of geometric objects
in such a way that certain queries can be performed efficiently.
Typical examples of queries are:
find out whether a given object is contained in the set,
find all objects of the set lying in a given area (e.g. rectangle),
find the object closest to a given point or
find the pair of objects in the set lying closest to each other.
Furthermore, the set should be dynamic in the sense that deletions and
insertions of objects can be performed efficiently.
In computational geometry literature one can find many different data structures for
maintaining sets of geometric objects. Most of them are data structures
that have been developed to support a single very special kind of query
operation.
Examples are Voronoi diagrams for answering nearest neighbor
searches, range trees for orthogonal range queries, partition trees
for more general range queries, hierarchical triangulations for point
location and segment trees for intersection queries \dots.
In many applications, different types of queries have to be
performed on the same set of objects. A naive approach to this
problem would use a collection of the above mentioned data structures to
represent the set of objects and delegate every query operation to
the corresponding structure.
However, this is completely impractical since it uses too much
memory and requires the maintenance of all these data structures in the presence of
update operations.
Data structures that are non-optimal in theory seem to perform quite well in
practice for many of these queries.
For example, the Delaunay diagram turns out to be a very powerful
data structure for storing dynamic sets of points under range and nearest
neighbor queries. A first implementation and computational
study of using Delaunay diagrams for geometric queries is described by
Mehlhorn and N\"aher in ~\cite{LEDAbook}.
In this section we present a generic variant of a two dimensional point set
data type supporting various geometric queries.
The \ccc{CGAL::Point\_set\_2} class in this section is a planar embedded bidirected
graph representing the {\em Delaunay Triangulation} of its vertex set.
The \ccc{CGAL::Point\_set\_2} class depends on a template parameter standing for a
geometric traits class. This traits class has to provide the needed classes of
geometric objects and geometric predicates on these objects.
\section{Examples}
\subsection{Range search operations}
The following example program demonstrates the various range search operations
of the two dimensional point set.
First we construct a two dimensional point set $PSet$ and initialize it with a few points.
After the $init$ - call $PSet$ is the point set of the points $p1$, ..., $p9$ .
Then we perform circular, triangular and isorectangular range search operations on the
point set.
The traits class used in the example is the standard traits class for \cgal\ kernel
objects.
\ccHtmlLinksOff
{\bf rs\_test.C :}
\begin{verbatim}
#include <CGAL/config.h>
#include <list>
#include <vector>
#include <CGAL/Point_set_2.h>
typedef CGAL::Cartesian<double> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
int main()
{
CGAL::Point_set_2<TRAITS> PSet;
CGAL::Point_2<REP> pnew;
std::list<CGAL::Point_2<REP> > Lr;
CGAL::Point_2<REP> p1(12,14);
CGAL::Point_2<REP> p2(-12,14);
CGAL::Point_2<REP> p3(2,11);
CGAL::Point_2<REP> p4(5,6);
CGAL::Point_2<REP> p5(6.7,3.8);
CGAL::Point_2<REP> p6(11,20);
CGAL::Point_2<REP> p7(-5,6);
CGAL::Point_2<REP> p8(12,0);
CGAL::Point_2<REP> p9(4,31);
CGAL::Point_2<REP> p10(-10,-10);
Lr.push_back(p1); Lr.push_back(p2); Lr.push_back(p3);
Lr.push_back(p4); Lr.push_back(p5); Lr.push_back(p6);
Lr.push_back(p7); Lr.push_back(p8); Lr.push_back(p9);
Lr.push_back(p10);
PSet.init(Lr.begin(),Lr.end());
pnew= CGAL::Point_2<REP>(12,6.2);
std::cout << "insert!\n";
PSet.insert(pnew);
std::cout << "range search for circle !\n";
CGAL::Circle_2<REP> rc(p5,p6);
std::list<Vertex> LV;
PSet.range_search(rc,std::back_inserter(LV));
std::list<Vertex>::const_iterator it;
for (it=LV.begin();it != LV.end(); it++)
std::cout << PSet.pos(*it) << "\n";
std::cout << "range search for triangle !\n";
LV.clear();
PSet.range_search(p1,p2,p3,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
std::cout << PSet.pos(*it) << "\n";
LV.clear();
std::cout << "range search for iso rectangle !\n";
CGAL::Point_2<REP> pt1=p10; // lower left
CGAL::Point_2<REP> pt3=p3; // upper right
CGAL::Point_2<REP> pt2 = CGAL::Point_2<REP>(pt3.x(),pt1.y());
CGAL::Point_2<REP> pt4 = CGAL::Point_2<REP>(pt1.x(),pt3.y());
PSet.range_search(pt1,pt2,pt3,pt4,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
std::cout << PSet.pos(*it) << "\n";
return 0;
}
\end{verbatim}
\ccHtmlLinksOn
\subsection{Minimum spanning tree and k nearest neighbor search operation}
The next example program demonstrates the $k$ nearest neighbors operation
and the computation of the minimum spanning tree.
This demonstration program uses the $GeoWin$ library for visualization.
\ccHtmlLinksOff
{\bf geowin\_k\_nearest\_neighbors.C :}
\begin{verbatim}
#include <CGAL/geowin_support.h>
#include <CGAL/Point_set_2.h>
typedef CGAL::Cartesian<double> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
CGAL::Point_set_2<TRAITS> PST;
int k;
class construct_pointset : public geowin_update<std::list<CGAL::Point_2<REP> >,
std::list<CGAL::Segment_2<REP> > >
{
public:
void update(const std::list<CGAL::Point_2<REP> >& Lin,
std::list<CGAL::Segment_2<REP> >& Lout)
{
PST.init(Lin.begin(),Lin.end());
Lout.clear();
PST.segments(std::back_inserter(Lout));
}
};
class mst : public geowin_update<std::list<CGAL::Point_2<REP> >,
std::list<CGAL::Segment_2<REP> > >
{
public:
void update(const std::list<CGAL::Point_2<REP> >& Lin,
std::list<CGAL::Segment_2<REP> >& Lout)
{
Lout.clear();
std::list<Edge> output;
std::list<Edge>::const_iterator pit;
PST.minimum_spanning_tree( std::back_inserter(output));
for (pit=output.begin(); pit != output.end(); pit++){
Lout.push_back(CGALSegment(PST.seg(*pit)));
}
}
};
class nearest_neighbors : public geowin_update<std::list<CGAL::Point_2<REP> >,
std::list<CGAL::Circle_2<REP> > >
{
public:
void update(const std::list<CGAL::Point_2<REP> >& Lin,
std::list<CGAL::Circle_2<REP> >& Lout)
{
Lout.clear();
std::list<CGAL::Point_2<REP> >::const_iterator it = Lin.begin();
std::list<Vertex> output;
std::list<Vertex>::const_iterator pit;
for (; it != Lin.end(); it++){
PST.nearest_neighbors(*it, k, std::back_inserter(output));
}
for (pit=output.begin(); pit != output.end(); pit++){
Lout.push_back(CGALCircle(PST.pos(*pit),2.0));
}
}
};
int main()
{
geowin_init_default_type((std::list<CGAL::Point_2<REP> >*)0,
leda_string("CGALPointlist"));
std::cout << "Find the k nearest neighbors of every point in scene 2.\n";
std::cout << "k:"; std::cin >> k;
GeoWin gw;
std::list<CGAL::Point_2<REP> > Lp;
geo_scene sc1 = gw.new_scene(Lp);
std::list<CGAL::Point_2<REP> > Lother;
geo_scene sc2 = gw.new_scene(Lother);
gw.set_color(sc2,leda_blue);
construct_pointset CP;
geo_scene sc3 = gw.new_scene(CP, sc1, leda_string("2d point set"));
gw.set_color(sc3,leda_blue);
nearest_neighbors NN;
geo_scene sc4 = gw.new_scene(NN, sc2, leda_string("k nearest neighbors"));
gw.set_fill_color(sc4,leda_red);
gw.set_color(sc4,leda_red);
gw.set_point_style(sc4,leda_circle_point);
gw.set_line_width(sc4,4);
mst MS;
geo_scene sc5 = gw.new_scene(MS, sc1, leda_string("Minimum spanning tree"));
gw.set_line_width(sc5,2);
gw.set_all_visible(true);
gw.add_dependence(sc1,sc4);
gw.edit(sc1);
return 0;
}
\end{verbatim}
\ccHtmlLinksOn
\subsection{Using the LEDA kernel}
We provide also traits classes for the \leda\ floating point and rational kernels. The next short
example demonstrates the usage of the two dimensional point set with the rational \leda\ kernel.
\ccHtmlLinksOff
\begin{verbatim}
#include <CGAL/config.h>
#include <list>
#include <LEDA/rat_window.h>
#include <CGAL/Point_set_2.h>
typedef CGAL::point_set_leda_rat_traits_2 TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
void output(leda_window& W, const CGAL::Point_set_2<TRAITS>& PSR_rat)
{
W.clear();
leda_edge e;
forall_edges(e,PSR_rat) W << leda_segment(PSR_rat.seg(e).to_segment());
}
int main()
{
int i;
CGAL::Point_set_2<TRAITS> PSR_rat;
leda_window W(500,400);
W.init(-500,500,-400);
W.display();
// insert operation
for (i=0; i<30; i++) {
leda_rat_point pnew;
W >> pnew;
PSR_rat.insert(pnew);
output(W,PSR_rat);
}
// delete operation
for (i=0; i<3; i++) {
leda_rat_point pnew;
W >> pnew;
Vertex v = PSR_rat.nearest_neighbor(pnew);
PSR_rat.del(v);
output(W,PSR_rat);
}
W.set_point_style(leda_disc_point);
leda_rat_circle rc;
W >> rc; W << rc;
leda_list<Vertex> LV;
// circular range search
PSR_rat.range_search(rc, std::back_inserter(LV));
Vertex v;
W.set_color(leda_red);
forall(v,LV) W << PSR_rat.pos(v);
leda_rat_point pt1,pt2,pt3,pt4;
W >> pt1; W << pt1;
W >> pt2; W << pt2;
W >> pt3; W << pt3;
LV.clear();
// triangular range search
PSR_rat.range_search(pt1,pt2,pt3,std::back_inserter(LV));
leda_list<Vertex>::iterator it;
W.set_color(leda_green);
for (it=LV.begin();it != LV.end(); it++)
W << PSR_rat.pos(*it);
LV.clear();
W >> pt1; W << pt1;
W >> pt3; W << pt3;
pt2 = leda_rat_point(pt3.xcoord(),pt1.ycoord());
pt4 = leda_rat_point(pt1.xcoord(),pt3.ycoord());
W.set_color(leda_orange);
// iso rectangular range search
PSR_rat.range_search(pt1,pt2,pt3,pt4,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
W << PSR_rat.pos(*it);
W.read_mouse();
return 1;
}
\end{verbatim}
\ccHtmlLinksOn

View File

@ -0,0 +1,290 @@
% +----------------------------------------------------------+
%---------------------------------------------
% Point_set_2 data type
%---------------------------------------------
\begin{ccRefClass}{Point_set_2<Traits>}
\ccDefinition
\ccInclude{CGAL/Point_set_2.h}
An instance $T$ of data type \ccRefName\ is a planar embedded bidirected
graph representing the {\em Delaunay Triangulation} of its vertex set.
The position of a vertex $v$ is given by $T.pos(v)$ and we use
$S = \{ T.pos(v) \mid v \in T \}$ to denote the underlying point set.
Each face of $T$ (except for the outer face) is a triangle whose
circumscribing circle does not contain any point of $S$ in its interior.
For every edge $e$, the sequence
\[e, T.face\_cycle\_succ(e), T.face\_cycle\_succ(T.face\_cycle\_succ(e)),\ldots\]
traces the boundary of the face to the left of $e$.
The edges of the outer face of $T$ form the convex hull of $S$; the trace of
the convex hull is clockwise.
The subgraph obtained from $T$ by removing all diagonals of
co-circular quadrilaterals is called the {\em Delaunay Diagram}
of $S$.
The class \ccRefName\ provides operations for inserting and deleting points,
point location, nearest neighbor searches, and navigation in both
the triangulation and the diagram.
Note that the \ccRefName\ is derived from the \leda\ GRAPH class
(Parameterized Graphs). That means that it provides all constant
graph operations (like $reversal$, $all\_edges$, ...).
See the \leda\ user manual or \leda\ book ~\cite{LEDAbook} for more details.
Be aware that the nearest neighbor queries for a point (not for a node) and
the range search queries for circles, triangles, and rectangles are non-const
operations and modify the underlying graph. The set of nodes and edges is
not changed; however, it is not guaranteed that the underlying Delaunay
triangulation is unchanged.
The \ccRefName\ class of \cgal\ depends on a template parameter standing for a
geometric traits class. This traits class has to provide the geometric objects needed
in \ccRefName\ and geometric predicates on these objects.
\ccCreationVariable{T}
\ccHtmlLinksOff
\ccTypes
\ccThree{typedef Traits::Point Point;}{the point type}{}
\ccThreeToTwo
\ccTypedef{typedef Traits::Point Point;}{the point type}{}
\ccTypedef{typedef Traits::Segment Segment;}{the segment type}
\ccTypedef{typedef Traits::Circle Circle;}{the circle type}
\ccTypedef{typedef Traits::Line Line;}{the line type}
\ccTypedef{typedef Traits::FT Numb_type;}{the field type of the representation class}
\ccNestedType{Vertex}{the vertex type.}
\ccNestedType{Edge}{the edge type.}
\ccHtmlLinksOn
\ccCreation
\ccConstructor{Point_set_2();}
{creates an empty \ccRefName\ .}
\ccConstructor{Point_set_2(const std::list<Point>& S);}
{creates a \ccRefName\ \ccVar\ of the points in $S$.
If $S$ contains multiple occurrences of points only the last
occurrence of each point is retained.}
\ccConstructor{template<class InputIterator>
Point_set_2d(InputIterator first, InputIterator last);}
{creates a \ccRefName\ \ccVar\ of the points in the range
[$first$,$last$).}
\ccOperations
\ccMethod{void init(const std::list<Point>& L);}
{ makes \ccVar\ a \ccRefName\ for the points in $L$.}
\ccMethod{template<class InputIterator>
void init(InputIterator first, InputIterator last);}
{ makes \ccVar\ a \ccRefName\ for the points in the range
[$first$,$last$).}
\ccMethod{template<class OutputIterator>
OutputIterator points(OutputIterator out);}
{ places all points of \ccVar as a sequence of objects of type
$Point$ in a container of value type of $out$,
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.}
\ccMethod{template<class OutputIterator>
OutputIterator segments(OutputIterator out);}
{ places all segments of \ccVar\ as a sequence of objects of type
$Segment$ in a container of value type of $out$,
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.}
\ccHtmlLinksOff
\ccMethod{template<class OutputIterator>
OutputIterator vertices(OutputIterator out);}
{ places all vertices of \ccVar\ as a sequence of objects of type
Vertex in a container of value type of $out$,
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.}
\ccHtmlLinksOn
\ccMethod{template<class OutputIterator>
OutputIterator edges(OutputIterator out);}
{ places all points of \ccVar\ as a sequence of objects of type
$Edge$ in a container of value type of $out$,
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.}
\ccMethod{Edge d_face_cycle_succ(Edge e);}
{ returns the face cycle successor of $e$ in the Delaunay diagram
of \ccVar . \ccPrecond $e$ belongs to the Delaunay diagram.}
\ccMethod{Edge d_face_cycle_pred(Edge e);}
{ returns the face cycle predecessor of $e$ in the Delaunay diagram
of \ccVar. \ccPrecond $e$ belongs to the Delaunay diagram.}
\ccMethod{bool is_empty();}
{ decides whether \ccVar\ is empty. }
\ccMethod{void clear();}
{ makes \ccVar\ empty. }
\ccMethod{Edge locate(Point p);}
{ returns an edge $e$ of \ccVar\ that contains $p$ or that
borders the face that contains $p$. In the former case,
a hull edge is returned if $p$ lies on the boundary of the convex hull.
In the latter case we have $T.orientation(e,p) > 0$ except if all points of
$T$ are collinear and
$p$ lies on the induced line. In this case $target(e)$ is visible from
$p$. The function returns $NULL$ if $T$ has no edge.}
\ccHtmlLinksOff
\ccMethod{Vertex lookup(Point p);}
{ if \ccVar\ contains a Vertex $v$ with $|pos(v)| = p$
the result is $v$ otherwise the result is $NULL$. }
\ccMethod{Vertex insert(Point p);}
{ inserts point $p$ into \ccVar\ and returns the corresponding vertex.
More precisely, if there is already a vertex $v$ in \ccVar\ positioned
at $p$ then $pos(v)$ is made identical to $p$ and if there is no
such node then a new node $v$ with $pos(v) = p$ is added to $T$.
In either case, $v$ is returned.}
\ccMethod{void del(Vertex v);}
{ removes the vertex $v$ from \ccVar. \ccPrecond v is a vertex in \ccVar.}
\ccMethod{void del(Point p);}
{ removes the vertex $v$ with position $p$ from \ccVar. If there is
no such vertex in \ccVar, the function returns without changing \ccVar. }
\ccMethod{Vertex nearest_neighbor(Point p);}
{ computes a vertex $v$ of \ccVar\ that is closest to $p$.
If \ccVar\ is empty, $NULL$ is returned.
This is a non-const operation.}
\ccMethod{Vertex nearest_neighbor(Vertex v);}
{ computes a vertex $w$ of \ccVar\ that is closest to $v$.
If $v$ is the only vertex in \ccVar\ , $NULL$ is returned.
\ccPrecond $v$ is a vertex in \ccVar.}
\ccMethod{template<class OutputIterator>
OutputIterator nearest_neighbors(Point p, int k, OutputIterator res);}
{ computes the $k$ nearest neighbors of $p$, and places them as a sequence of objects of type
Vertex in a container of value type of $res$
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence. }
\ccMethod{template<class OutputIterator>
OutputIterator nearest_neighbors(Vertex v, int k,OutputIterator res);}
{ computes the $k$ nearest neighbors of $v$, and places them as a sequence of objects of type
Vertex in a container of value type of $res$
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence. }
\ccMethod{template<class OutputIterator>
OutputIterator range_search(const Circle& C, OutputIterator res);}
{ computes all vertices contained in the closure of disk $C$.
\ccPrecond $C$ must be a proper circle (not a straight line).
The computed vertices will be placed as a sequence of objects in a container of value type
of $res$
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.
This is a non-const operation.}
\ccMethod{template<class OutputIterator>
OutputIterator range_search(const Point& a, const Point& b, const Point& c,OutputIterator res);}
{ computes all vertices contained in the closure of the triangle $(a,b,c)$.\\
\ccPrecond $a$, $b$, and $c$ must not be collinear.
The computed vertices will be placed as a sequence of objects in a container of value type
of $res$
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.
This is a non-const operation.}
\ccMethod{template<class OutputIterator>
OutputIterator range_search(const Point& a1, const Point& b1, const Point& c1,const Point&
d1,OutputIterator res);}
{ computes all vertices contained in the closure of the iso-rectangle $(a1,b1,c1,d1)$.\\
\ccPrecond $a1$ is the lower left point, $b1$ the lower right, $c1$ the upper
right and $d1$ the upper left point of the iso rectangle.
The computed vertices will be placed as a sequence of objects in a container of value type
of $res$
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.
This is a non-const operation.}
\ccMethod{template<class OutputIterator>
OutputIterator minimum_spanning_tree(OutputIterator result);}
{ places all edges of the minimum spanning tree of \ccVar\ as a sequence of objects of type
$Edge$ in a container of type corresponding to the type of $out$
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.}
\ccMethod{bool is_non_diagram_edge(Edge e);}
{ checks whether $e$ is a non-diagram edge. }
\ccMethod{Point pos(Vertex v);}
{ returns the position of $v$ in \ccVar.}
\ccMethod{Vertex source(Edge e);}
{ returns the source vertex of $e$.}
\ccMethod{Vertex target(Edge e);}
{ returns the target vertex of $e$.}
\ccMethod{Point pos_source(Edge e);}
{ returns the position of the source of $e$ in \ccVar.}
\ccMethod{Point pos_target(Edge e);}
{ returns the position of the target of $e$ in \ccVar.}
\ccMethod{Segment seg(Edge e);}
{ returns the line segment corresponding to edge $e$ starting
at $pos\_source(e)$.}
\ccMethod{Line supporting_line(Edge e);}
{ returns the supporting line of edge $e$.}
\ccMethod{int orientation(Edge e, Point p);}
{ returns $orientation(T.pos\_source(e),T.pos\_target(e),p)$.}
\ccMethod{Edge get_hull_edge();}
{ returns an edge of the outer face of \ccVar\ (i.e., an edge of the convex hull). }
\ccMethod{bool is_diagram_edge(Edge e);}
{returns true if $e$ is an edge of the Delaunay diagram, i.e., either
an edge on the convex hull or an edge where the incident triangles have
distinct circumcircles.}
\ccMethod{bool is_hull_edge(Edge e);}
{returns true if $e$ is an edge of the convex hull of \ccVar, i.e.,
an edge on the face cycle of the outer face. }
\ccHtmlLinksOn
\ccMethod{int dim();}
{returns $-1$ if \ccVar\ is empty, returns $0$ if \ccVar
consists of only one point,
returns $1$ if \ccVar\ consists of at least two points
and all points in \ccVar\
are collinear, and returns $2$ otherwise.}
\end{ccRefClass}

View File

@ -0,0 +1,114 @@
\begin{ccRefConcept} {Point_set_traits}
\subsection{Requirements for the Point\_set traits class}
A point set traits class has to provide some primitives that are used by the point set class.
The following catalog lists the involved primitives.
The types used in the traits class must have a copy constructor and an assignment operator.
\ccCreationVariable{ps_traits}
\ccTypes
\ccNestedType{FT}%
{The field type of the representation class of the point, segment, circle and line types.}
\ccNestedType{Point}%
{The point type on which the point set operates.}
\ccNestedType{Circle}%
{The circle type on which the point set operates.}
\ccHtmlLinksOff
\ccNestedType{Line}%
{The line type on which the point set operates.}
\ccHtmlLinksOn
\ccNestedType{Segment}%
{The segment type on which the point set operates.}
\ccNestedType{Compare_xy_2}%
{The primitive must provide
\ccc{int operator()(const Point& p1,const Point& p2) const}
and has to be derived from $leda\_cmp\_base<Point>$.
The operator has to compare the points $p1$ and $p2$ lexicographically in
$xy$ order. If $p1$ is smaller, the operator has to return -1, if $p1$
is larger, the operator has to return 1, 0 otherwise.
}
\ccNestedType{Compare_dist_2}%
{The primitive must provide
\ccc{Comparison_result operator()(const Point& p1,const Point& p2, const Point& p3) const}.
The operator has to compare the distances of points $p2$ and $p3$ to $p1$.
The operator returns \ccc{SMALLER}, if $p2$ is closer (to $p1$), \ccc{LARGER} if $p3$ is closer,
\ccc{EQUAL} otherwise.
}
\ccNestedType{Orientation}%
{The primitive must provide
\ccc{Orientation operator()(const Point& p1,const Point& p2,const Point& p3) const}.
This operator has to return \ccc{COLLINEAR} if the 3 points are collinear,
\ccc{LEFTTURN} if $p3$ lies on the left of the directed line through $p1$ and $p2$,
\ccc{RIGHTTURN} otherwise.
}
\ccNestedType{Side_of_oriented_circle_2}%
{The primitive must provide
\ccc{Oriented_side operator()(const Point& p1,const Point& p2,const Point& p3, const Point& p4) const}.
This operator has to return \ccc{ON_POSITIVE_SIDE} if $p4$ lies on the positive side of the circle through
the points $p1$,$p2$ and $p3$, \ccc{ON_NEGATIVE_SIDE} if $p4$ lies on the negative side of the circle,
\ccc{ON_ORIENTED_BOUNDARY} otherwise.
}
\ccNestedType{Side_of_halfspace_2}%
{The primitive must provide
\ccc{Orientation operator()(const Point& a,const Point& b, const Point& p3) const }.
This operator has to return \ccc{LEFTTURN} if $p3$ lies in the open halfspace $h$ orthogonal to vector
$b-a$ containing $b$ and having $a$ on its boundary, \ccc{COLLINEAR} if $p3$ is on the boundary of $h$ and
\ccc{RIGHTTURN} otherwise.
}
\ccNestedType{Segment_has_on_2}%
{The primitive must provide
\ccc{bool operator()(const Segment& seg, const Point& p) const }.
This operator has to return true if $seg$ contains $p$, false otherwise.}
\ccNestedType{Squared_distance}%
{The primitive must provide
\ccc{FT operator()(const Point& p1,const Point& p2) const}.
The operator has to return the squared distance from $p1$ to $p2$.}
\ccNestedType{Squared_distance_to_line}%
{The primitive must provide
\ccc{FT operator()(const Line& l,const Point& p) const}.
The operator has to return the squared distance from $l$ to $p$.}
\ccNestedType{Circle_bounded_side_2}%
{The primitive must provide
\ccc{Bounded_side operator()(const Circle& c, const Point& p) const}.
The operator has to return \ccc{ON_BOUNDED_SIDE} if $p$ lies on the bounded side of $c$,
\ccc{ON_UNBOUNDED_SIDE} if $p$ lies on the unbounded side of $c$, \ccc{ON_BOUNDARY} otherwise.}
\ccNestedType{Circle_center_2}%
{The primitive must provide
\ccc{Point operator()(const Circle& c) const}.
The operator has to return the center of $c$.}
\ccNestedType{Construct_circle_2}%
{This primitive constructs a circle. It must provide
\ccc{Circle operator()(const Point& p1,const Point& p2, const Point& p3) const }.
The points $p1$, $p2$ and $p3$ are on the boundary.}
\ccNestedType{Construct_segment_2}%
{This primitive constructs a segment. It must provide
\ccc{Segment operator()(const Point& p1,const Point& p2) const}.
Point $p1$ is the source of the segment, $p2$ the target.}
\ccNestedType{Construct_line_2}%
{This primitive constructs a line. It must provide
\ccc{Line operator()(const Point& p1,const Point& p2) const}.
The line is constructed through $p1$ and $p2$.}
\end{ccRefConcept}

View File

@ -0,0 +1,17 @@
@Book{LEDAbook,
author
=
"K. Mehlhorn and S. N\"aher",
title
=
"LEDA -- A platform for combnatorial and geometric computing",
publisher
=
"Cambridge University Press",
year
=
"1999",
}

View File

@ -0,0 +1,26 @@
% +------------------------------------------------------------------------+
% | CGAL Reference Manual: Point_set_2.tex
% +------------------------------------------------------------------------+
\ccParDims
\clearpage
\section{Reference pages for Point Set in 2D}
\section*{Summary}
The two dimensional point set is a class for geometric queries.
It supports circular, triangular and iso rectangular range searches,
nearest neighbor searches and the computation of the minimum spanning tree.
The point set is a dynamic data structure supporting the insertion and
deletion of points.
\subsection*{Concepts}
\ccc{Point_set_traits}\\
\subsection*{Classes}
\ccc{CGAL::Point_set_2}\\
\ccc{CGAL::point_set_traits_2}\\
\ccc{CGAL::point_set_leda_float_traits_2}\\
\ccc{CGAL::point_set_leda_rat_traits_2}\\

View File

@ -0,0 +1,15 @@
% +------------------------------------------------------------------------+
% | CGAL Reference Manual: main.tex
% +------------------------------------------------------------------------+
% | Point_set_2
% |
% +------------------------------------------------------------------------+
\input{Point_set_2_ref/intro}
\input{Point_set_2_ref/Point_set_2}
\input{Point_set_2_ref/Point_set_traits}
\input{Point_set_2_ref/point_set_traits_2}
\input{Point_set_2_ref/point_set_leda_float_traits_2}
\input{Point_set_2_ref/point_set_leda_rat_traits_2}
%% EOF %%

View File

@ -0,0 +1,35 @@
\begin{ccRefClass}{point_set_leda_float_traits_2}
\subsubsection{Traits classes for \leda\ 2D Points}
\ccInclude{CGAL/point_set_leda_traits_2.h}
The traits class \ccc{point_set_leda_float_traits_2} deals with \leda\ 2D float kernel objects.
\ccTypes
\ccThree{typedef ttttttttttttttttttttt}{tttttttttt}{}
\ccThreeToTwo
\ccTypedef{typedef double FT;}{}
\ccTypedef{typedef leda_point Point;}{}
\ccTypedef{typedef leda_segment Segment;}{}
\ccHtmlLinksOff
\ccTypedef{typedef leda_line Line;}{}
\ccHtmlLinksOn
\ccTypedef{typedef leda_circle Circle;}{}
\ccNestedType{Compare_xy_2}{}
\ccNestedType{Compare_dist_2}{}
\ccNestedType{Orientation}{}
\ccNestedType{Side_of_oriented_circle_2}{}
\ccNestedType{Side_of_halfspace_2}{}
\ccNestedType{Segment_has_on_2}{}
\ccNestedType{Squared_distance}{}
\ccNestedType{Squared_distance_to_line}{}
\ccNestedType{Circle_bounded_side_2}{}
\ccNestedType{Circle_center_2}{}
\ccNestedType{Construct_circle_2}{}
\ccNestedType{Construct_segment_2}{}
\ccNestedType{Construct_line_2}{}
\end{ccRefClass}

View File

@ -0,0 +1,35 @@
\begin{ccRefClass}{point_set_leda_rat_traits_2}
The traits class \ccc{point_set_leda_rat_traits_2} deals with \leda\ 2D rational kernel objects.
\ccTypes
\ccThree{typedef ttttttttttttttttttttttt}{tttttttttt}{}
\ccThreeToTwo
\ccTypedef{typedef leda_rational FT;}{}
\ccTypedef{typedef leda_rat_point Point;}{}
\ccTypedef{typedef leda_rat_segment Segment;}{}
\ccHtmlLinksOff
\ccTypedef{typedef leda_rat_line Line;}{}
\ccHtmlLinksOn
\ccTypedef{typedef leda_rat_circle Circle;}{}
\ccNestedType{Compare_xy_2}{}
\ccNestedType{Compare_dist_2}{}
\ccNestedType{Orientation}{}
\ccNestedType{Side_of_oriented_circle_2}{}
\ccNestedType{Side_of_halfspace_2}{}
\ccNestedType{Segment_has_on_2}{}
\ccNestedType{Squared_distance}{}
\ccNestedType{Squared_distance_to_line}{}
\ccNestedType{Circle_bounded_side_2}{}
\ccNestedType{Circle_center_2}{}
\ccNestedType{Construct_circle_2}{}
\ccNestedType{Construct_segment_2}{}
\ccNestedType{Construct_line_2}{}
\end{ccRefClass}
\ccParDims

View File

@ -0,0 +1,36 @@
\begin{ccRefClass}{point_set_traits_2<T>}
\subsubsection{Traits class for \cgal\ 2D kernel objects}
\ccInclude{CGAL/point_set_traits_2.h}
The traits class \ccRefName\ deals with \cgal\ 2D kernel objects.
\ccTypes
\ccThree{typedef ttttttttttttttttttttt}{tttttttttt}{}
\ccThreeToTwo
\ccTypedef{typedef T::FT FT;}{}
\ccTypedef{typedef Point_2<T> Point;}{}
\ccTypedef{typedef Segment_2<T> Segment;}{}
\ccHtmlLinksOff
\ccTypedef{typedef Line_2<T> Line;}{}
\ccHtmlLinksOn
\ccTypedef{typedef Circle_2<T> Circle;}{}
\ccNestedType{Compare_xy_2}{}
\ccNestedType{Compare_dist_2}{}
\ccNestedType{Orientation}{}
\ccNestedType{Side_of_oriented_circle_2}{}
\ccNestedType{Side_of_halfspace_2}{}
\ccNestedType{Segment_has_on_2}{}
\ccNestedType{Squared_distance}{}
\ccNestedType{Squared_distance_to_line}{}
\ccNestedType{Circle_bounded_side_2}{}
\ccNestedType{Circle_center_2}{}
\ccNestedType{Construct_circle_2}{}
\ccNestedType{Construct_segment_2}{}
\ccNestedType{Construct_line_2}{}
\end{ccRefClass}

View File

@ -0,0 +1,17 @@
@Book{LEDAbook,
author
=
"K. Mehlhorn and S. N\"aher",
title
=
"LEDA -- A platform for combnatorial and geometric computing",
publisher
=
"Cambridge University Press",
year
=
"1999",
}

View File

@ -0,0 +1,12 @@
% +------------------------------------------------------------------------+
% | CGAL Reference Manual: main.tex
% +------------------------------------------------------------------------+
% | Point_set_2
% |
% | 15.10.1999 Matthias Baesken
% +------------------------------------------------------------------------+
\input{Point_set_2}
\input{Point_set_2_ref/main}
%% EOF %%

View File

@ -0,0 +1,374 @@
% +------------------------------------------------------------------------+
% | CGAL User Manual: Point_set_2.tex
% +------------------------------------------------------------------------+
\ccParDims
\chapter{Point Set in 2D}
\label{chapterPoint_set_2}
\ccChapterAuthor{Matthias B\"asken}
%---------------------------------------------
% Introduction
%---------------------------------------------
\section{Introduction}
Geometric Queries are fundamental to many applications in computational
geometry. The task is to maintain a dynamic set of geometric objects
in such a way that certain queries can be performed efficiently.
Typical examples of queries are:
find out whether a given object is contained in the set,
find all objects of the set lying in a given area (e.g. rectangle),
find the object closest to a given point or
find the pair of objects in the set lying closest to each other.
Furthermore, the set should be dynamic in the sense that deletions and
insertions of objects can be performed efficiently.
In computational geometry literature one can find many different data structures for
maintaining sets of geometric objects. Most of them are data structures
that have been developed to support a single very special kind of query
operation.
Examples are Voronoi diagrams for answering nearest neighbor
searches, range trees for orthogonal range queries, partition trees
for more general range queries, hierarchical triangulations for point
location and segment trees for intersection queries \dots.
In many applications, different types of queries have to be
performed on the same set of objects. A naive approach to this
problem would use a collection of the above mentioned data structures to
represent the set of objects and delegate every query operation to
the corresponding structure.
However, this is completely impractical since it uses too much
memory and requires the maintenance of all these data structures in the presence of
update operations.
Data structures that are non-optimal in theory seem to perform quite well in
practice for many of these queries.
For example, the Delaunay diagram turns out to be a very powerful
data structure for storing dynamic sets of points under range and nearest
neighbor queries. A first implementation and computational
study of using Delaunay diagrams for geometric queries is described by
Mehlhorn and N\"aher in ~\cite{LEDAbook}.
In this section we present a generic variant of a two dimensional point set
data type supporting various geometric queries.
The \ccc{CGAL::Point\_set\_2} class in this section is a planar embedded bidirected
graph representing the {\em Delaunay Triangulation} of its vertex set.
The \ccc{CGAL::Point\_set\_2} class depends on a template parameter standing for a
geometric traits class. This traits class has to provide the needed classes of
geometric objects and geometric predicates on these objects.
\section{Examples}
\subsection{Range search operations}
The following example program demonstrates the various range search operations
of the two dimensional point set.
First we construct a two dimensional point set $PSet$ and initialize it with a few points.
After the $init$ - call $PSet$ is the point set of the points $p1$, ..., $p9$ .
Then we perform circular, triangular and isorectangular range search operations on the
point set.
The traits class used in the example is the standard traits class for \cgal\ kernel
objects.
\ccHtmlLinksOff
{\bf rs\_test.C :}
\begin{verbatim}
#include <CGAL/config.h>
#include <list>
#include <vector>
#include <CGAL/Point_set_2.h>
typedef CGAL::Cartesian<double> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
int main()
{
CGAL::Point_set_2<TRAITS> PSet;
CGAL::Point_2<REP> pnew;
std::list<CGAL::Point_2<REP> > Lr;
CGAL::Point_2<REP> p1(12,14);
CGAL::Point_2<REP> p2(-12,14);
CGAL::Point_2<REP> p3(2,11);
CGAL::Point_2<REP> p4(5,6);
CGAL::Point_2<REP> p5(6.7,3.8);
CGAL::Point_2<REP> p6(11,20);
CGAL::Point_2<REP> p7(-5,6);
CGAL::Point_2<REP> p8(12,0);
CGAL::Point_2<REP> p9(4,31);
CGAL::Point_2<REP> p10(-10,-10);
Lr.push_back(p1); Lr.push_back(p2); Lr.push_back(p3);
Lr.push_back(p4); Lr.push_back(p5); Lr.push_back(p6);
Lr.push_back(p7); Lr.push_back(p8); Lr.push_back(p9);
Lr.push_back(p10);
PSet.init(Lr.begin(),Lr.end());
pnew= CGAL::Point_2<REP>(12,6.2);
std::cout << "insert!\n";
PSet.insert(pnew);
std::cout << "range search for circle !\n";
CGAL::Circle_2<REP> rc(p5,p6);
std::list<Vertex> LV;
PSet.range_search(rc,std::back_inserter(LV));
std::list<Vertex>::const_iterator it;
for (it=LV.begin();it != LV.end(); it++)
std::cout << PSet.pos(*it) << "\n";
std::cout << "range search for triangle !\n";
LV.clear();
PSet.range_search(p1,p2,p3,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
std::cout << PSet.pos(*it) << "\n";
LV.clear();
std::cout << "range search for iso rectangle !\n";
CGAL::Point_2<REP> pt1=p10; // lower left
CGAL::Point_2<REP> pt3=p3; // upper right
CGAL::Point_2<REP> pt2 = CGAL::Point_2<REP>(pt3.x(),pt1.y());
CGAL::Point_2<REP> pt4 = CGAL::Point_2<REP>(pt1.x(),pt3.y());
PSet.range_search(pt1,pt2,pt3,pt4,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
std::cout << PSet.pos(*it) << "\n";
return 0;
}
\end{verbatim}
\ccHtmlLinksOn
\subsection{Minimum spanning tree and k nearest neighbor search operation}
The next example program demonstrates the $k$ nearest neighbors operation
and the computation of the minimum spanning tree.
This demonstration program uses the $GeoWin$ library for visualization.
\ccHtmlLinksOff
{\bf geowin\_k\_nearest\_neighbors.C :}
\begin{verbatim}
#include <CGAL/geowin_support.h>
#include <CGAL/Point_set_2.h>
typedef CGAL::Cartesian<double> REP;
typedef CGAL::point_set_traits_2<REP> TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
CGAL::Point_set_2<TRAITS> PST;
int k;
class construct_pointset : public geowin_update<std::list<CGAL::Point_2<REP> >,
std::list<CGAL::Segment_2<REP> > >
{
public:
void update(const std::list<CGAL::Point_2<REP> >& Lin,
std::list<CGAL::Segment_2<REP> >& Lout)
{
PST.init(Lin.begin(),Lin.end());
Lout.clear();
PST.segments(std::back_inserter(Lout));
}
};
class mst : public geowin_update<std::list<CGAL::Point_2<REP> >,
std::list<CGAL::Segment_2<REP> > >
{
public:
void update(const std::list<CGAL::Point_2<REP> >& Lin,
std::list<CGAL::Segment_2<REP> >& Lout)
{
Lout.clear();
std::list<Edge> output;
std::list<Edge>::const_iterator pit;
PST.minimum_spanning_tree( std::back_inserter(output));
for (pit=output.begin(); pit != output.end(); pit++){
Lout.push_back(CGALSegment(PST.seg(*pit)));
}
}
};
class nearest_neighbors : public geowin_update<std::list<CGAL::Point_2<REP> >,
std::list<CGAL::Circle_2<REP> > >
{
public:
void update(const std::list<CGAL::Point_2<REP> >& Lin,
std::list<CGAL::Circle_2<REP> >& Lout)
{
Lout.clear();
std::list<CGAL::Point_2<REP> >::const_iterator it = Lin.begin();
std::list<Vertex> output;
std::list<Vertex>::const_iterator pit;
for (; it != Lin.end(); it++){
PST.nearest_neighbors(*it, k, std::back_inserter(output));
}
for (pit=output.begin(); pit != output.end(); pit++){
Lout.push_back(CGALCircle(PST.pos(*pit),2.0));
}
}
};
int main()
{
geowin_init_default_type((std::list<CGAL::Point_2<REP> >*)0,
leda_string("CGALPointlist"));
std::cout << "Find the k nearest neighbors of every point in scene 2.\n";
std::cout << "k:"; std::cin >> k;
GeoWin gw;
std::list<CGAL::Point_2<REP> > Lp;
geo_scene sc1 = gw.new_scene(Lp);
std::list<CGAL::Point_2<REP> > Lother;
geo_scene sc2 = gw.new_scene(Lother);
gw.set_color(sc2,leda_blue);
construct_pointset CP;
geo_scene sc3 = gw.new_scene(CP, sc1, leda_string("2d point set"));
gw.set_color(sc3,leda_blue);
nearest_neighbors NN;
geo_scene sc4 = gw.new_scene(NN, sc2, leda_string("k nearest neighbors"));
gw.set_fill_color(sc4,leda_red);
gw.set_color(sc4,leda_red);
gw.set_point_style(sc4,leda_circle_point);
gw.set_line_width(sc4,4);
mst MS;
geo_scene sc5 = gw.new_scene(MS, sc1, leda_string("Minimum spanning tree"));
gw.set_line_width(sc5,2);
gw.set_all_visible(true);
gw.add_dependence(sc1,sc4);
gw.edit(sc1);
return 0;
}
\end{verbatim}
\ccHtmlLinksOn
\subsection{Using the LEDA kernel}
We provide also traits classes for the \leda\ floating point and rational kernels. The next short
example demonstrates the usage of the two dimensional point set with the rational \leda\ kernel.
\ccHtmlLinksOff
\begin{verbatim}
#include <CGAL/config.h>
#include <list>
#include <LEDA/rat_window.h>
#include <CGAL/Point_set_2.h>
typedef CGAL::point_set_leda_rat_traits_2 TRAITS;
typedef CGAL::Point_set_2<TRAITS>::Edge Edge;
typedef CGAL::Point_set_2<TRAITS>::Vertex Vertex;
void output(leda_window& W, const CGAL::Point_set_2<TRAITS>& PSR_rat)
{
W.clear();
leda_edge e;
forall_edges(e,PSR_rat) W << leda_segment(PSR_rat.seg(e).to_segment());
}
int main()
{
int i;
CGAL::Point_set_2<TRAITS> PSR_rat;
leda_window W(500,400);
W.init(-500,500,-400);
W.display();
// insert operation
for (i=0; i<30; i++) {
leda_rat_point pnew;
W >> pnew;
PSR_rat.insert(pnew);
output(W,PSR_rat);
}
// delete operation
for (i=0; i<3; i++) {
leda_rat_point pnew;
W >> pnew;
Vertex v = PSR_rat.nearest_neighbor(pnew);
PSR_rat.del(v);
output(W,PSR_rat);
}
W.set_point_style(leda_disc_point);
leda_rat_circle rc;
W >> rc; W << rc;
leda_list<Vertex> LV;
// circular range search
PSR_rat.range_search(rc, std::back_inserter(LV));
Vertex v;
W.set_color(leda_red);
forall(v,LV) W << PSR_rat.pos(v);
leda_rat_point pt1,pt2,pt3,pt4;
W >> pt1; W << pt1;
W >> pt2; W << pt2;
W >> pt3; W << pt3;
LV.clear();
// triangular range search
PSR_rat.range_search(pt1,pt2,pt3,std::back_inserter(LV));
leda_list<Vertex>::iterator it;
W.set_color(leda_green);
for (it=LV.begin();it != LV.end(); it++)
W << PSR_rat.pos(*it);
LV.clear();
W >> pt1; W << pt1;
W >> pt3; W << pt3;
pt2 = leda_rat_point(pt3.xcoord(),pt1.ycoord());
pt4 = leda_rat_point(pt1.xcoord(),pt3.ycoord());
W.set_color(leda_orange);
// iso rectangular range search
PSR_rat.range_search(pt1,pt2,pt3,pt4,std::back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
W << PSR_rat.pos(*it);
W.read_mouse();
return 1;
}
\end{verbatim}
\ccHtmlLinksOn

View File

@ -0,0 +1,290 @@
% +----------------------------------------------------------+
%---------------------------------------------
% Point_set_2 data type
%---------------------------------------------
\begin{ccRefClass}{Point_set_2<Traits>}
\ccDefinition
\ccInclude{CGAL/Point_set_2.h}
An instance $T$ of data type \ccRefName\ is a planar embedded bidirected
graph representing the {\em Delaunay Triangulation} of its vertex set.
The position of a vertex $v$ is given by $T.pos(v)$ and we use
$S = \{ T.pos(v) \mid v \in T \}$ to denote the underlying point set.
Each face of $T$ (except for the outer face) is a triangle whose
circumscribing circle does not contain any point of $S$ in its interior.
For every edge $e$, the sequence
\[e, T.face\_cycle\_succ(e), T.face\_cycle\_succ(T.face\_cycle\_succ(e)),\ldots\]
traces the boundary of the face to the left of $e$.
The edges of the outer face of $T$ form the convex hull of $S$; the trace of
the convex hull is clockwise.
The subgraph obtained from $T$ by removing all diagonals of
co-circular quadrilaterals is called the {\em Delaunay Diagram}
of $S$.
The class \ccRefName\ provides operations for inserting and deleting points,
point location, nearest neighbor searches, and navigation in both
the triangulation and the diagram.
Note that the \ccRefName\ is derived from the \leda\ GRAPH class
(Parameterized Graphs). That means that it provides all constant
graph operations (like $reversal$, $all\_edges$, ...).
See the \leda\ user manual or \leda\ book ~\cite{LEDAbook} for more details.
Be aware that the nearest neighbor queries for a point (not for a node) and
the range search queries for circles, triangles, and rectangles are non-const
operations and modify the underlying graph. The set of nodes and edges is
not changed; however, it is not guaranteed that the underlying Delaunay
triangulation is unchanged.
The \ccRefName\ class of \cgal\ depends on a template parameter standing for a
geometric traits class. This traits class has to provide the geometric objects needed
in \ccRefName\ and geometric predicates on these objects.
\ccCreationVariable{T}
\ccHtmlLinksOff
\ccTypes
\ccThree{typedef Traits::Point Point;}{the point type}{}
\ccThreeToTwo
\ccTypedef{typedef Traits::Point Point;}{the point type}{}
\ccTypedef{typedef Traits::Segment Segment;}{the segment type}
\ccTypedef{typedef Traits::Circle Circle;}{the circle type}
\ccTypedef{typedef Traits::Line Line;}{the line type}
\ccTypedef{typedef Traits::FT Numb_type;}{the field type of the representation class}
\ccNestedType{Vertex}{the vertex type.}
\ccNestedType{Edge}{the edge type.}
\ccHtmlLinksOn
\ccCreation
\ccConstructor{Point_set_2();}
{creates an empty \ccRefName\ .}
\ccConstructor{Point_set_2(const std::list<Point>& S);}
{creates a \ccRefName\ \ccVar\ of the points in $S$.
If $S$ contains multiple occurrences of points only the last
occurrence of each point is retained.}
\ccConstructor{template<class InputIterator>
Point_set_2d(InputIterator first, InputIterator last);}
{creates a \ccRefName\ \ccVar\ of the points in the range
[$first$,$last$).}
\ccOperations
\ccMethod{void init(const std::list<Point>& L);}
{ makes \ccVar\ a \ccRefName\ for the points in $L$.}
\ccMethod{template<class InputIterator>
void init(InputIterator first, InputIterator last);}
{ makes \ccVar\ a \ccRefName\ for the points in the range
[$first$,$last$).}
\ccMethod{template<class OutputIterator>
OutputIterator points(OutputIterator out);}
{ places all points of \ccVar as a sequence of objects of type
$Point$ in a container of value type of $out$,
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.}
\ccMethod{template<class OutputIterator>
OutputIterator segments(OutputIterator out);}
{ places all segments of \ccVar\ as a sequence of objects of type
$Segment$ in a container of value type of $out$,
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.}
\ccHtmlLinksOff
\ccMethod{template<class OutputIterator>
OutputIterator vertices(OutputIterator out);}
{ places all vertices of \ccVar\ as a sequence of objects of type
Vertex in a container of value type of $out$,
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.}
\ccHtmlLinksOn
\ccMethod{template<class OutputIterator>
OutputIterator edges(OutputIterator out);}
{ places all points of \ccVar\ as a sequence of objects of type
$Edge$ in a container of value type of $out$,
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.}
\ccMethod{Edge d_face_cycle_succ(Edge e);}
{ returns the face cycle successor of $e$ in the Delaunay diagram
of \ccVar . \ccPrecond $e$ belongs to the Delaunay diagram.}
\ccMethod{Edge d_face_cycle_pred(Edge e);}
{ returns the face cycle predecessor of $e$ in the Delaunay diagram
of \ccVar. \ccPrecond $e$ belongs to the Delaunay diagram.}
\ccMethod{bool is_empty();}
{ decides whether \ccVar\ is empty. }
\ccMethod{void clear();}
{ makes \ccVar\ empty. }
\ccMethod{Edge locate(Point p);}
{ returns an edge $e$ of \ccVar\ that contains $p$ or that
borders the face that contains $p$. In the former case,
a hull edge is returned if $p$ lies on the boundary of the convex hull.
In the latter case we have $T.orientation(e,p) > 0$ except if all points of
$T$ are collinear and
$p$ lies on the induced line. In this case $target(e)$ is visible from
$p$. The function returns $NULL$ if $T$ has no edge.}
\ccHtmlLinksOff
\ccMethod{Vertex lookup(Point p);}
{ if \ccVar\ contains a Vertex $v$ with $|pos(v)| = p$
the result is $v$ otherwise the result is $NULL$. }
\ccMethod{Vertex insert(Point p);}
{ inserts point $p$ into \ccVar\ and returns the corresponding vertex.
More precisely, if there is already a vertex $v$ in \ccVar\ positioned
at $p$ then $pos(v)$ is made identical to $p$ and if there is no
such node then a new node $v$ with $pos(v) = p$ is added to $T$.
In either case, $v$ is returned.}
\ccMethod{void del(Vertex v);}
{ removes the vertex $v$ from \ccVar. \ccPrecond v is a vertex in \ccVar.}
\ccMethod{void del(Point p);}
{ removes the vertex $v$ with position $p$ from \ccVar. If there is
no such vertex in \ccVar, the function returns without changing \ccVar. }
\ccMethod{Vertex nearest_neighbor(Point p);}
{ computes a vertex $v$ of \ccVar\ that is closest to $p$.
If \ccVar\ is empty, $NULL$ is returned.
This is a non-const operation.}
\ccMethod{Vertex nearest_neighbor(Vertex v);}
{ computes a vertex $w$ of \ccVar\ that is closest to $v$.
If $v$ is the only vertex in \ccVar\ , $NULL$ is returned.
\ccPrecond $v$ is a vertex in \ccVar.}
\ccMethod{template<class OutputIterator>
OutputIterator nearest_neighbors(Point p, int k, OutputIterator res);}
{ computes the $k$ nearest neighbors of $p$, and places them as a sequence of objects of type
Vertex in a container of value type of $res$
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence. }
\ccMethod{template<class OutputIterator>
OutputIterator nearest_neighbors(Vertex v, int k,OutputIterator res);}
{ computes the $k$ nearest neighbors of $v$, and places them as a sequence of objects of type
Vertex in a container of value type of $res$
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence. }
\ccMethod{template<class OutputIterator>
OutputIterator range_search(const Circle& C, OutputIterator res);}
{ computes all vertices contained in the closure of disk $C$.
\ccPrecond $C$ must be a proper circle (not a straight line).
The computed vertices will be placed as a sequence of objects in a container of value type
of $res$
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.
This is a non-const operation.}
\ccMethod{template<class OutputIterator>
OutputIterator range_search(const Point& a, const Point& b, const Point& c,OutputIterator res);}
{ computes all vertices contained in the closure of the triangle $(a,b,c)$.\\
\ccPrecond $a$, $b$, and $c$ must not be collinear.
The computed vertices will be placed as a sequence of objects in a container of value type
of $res$
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.
This is a non-const operation.}
\ccMethod{template<class OutputIterator>
OutputIterator range_search(const Point& a1, const Point& b1, const Point& c1,const Point&
d1,OutputIterator res);}
{ computes all vertices contained in the closure of the iso-rectangle $(a1,b1,c1,d1)$.\\
\ccPrecond $a1$ is the lower left point, $b1$ the lower right, $c1$ the upper
right and $d1$ the upper left point of the iso rectangle.
The computed vertices will be placed as a sequence of objects in a container of value type
of $res$
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.
This is a non-const operation.}
\ccMethod{template<class OutputIterator>
OutputIterator minimum_spanning_tree(OutputIterator result);}
{ places all edges of the minimum spanning tree of \ccVar\ as a sequence of objects of type
$Edge$ in a container of type corresponding to the type of $out$
which points to the first object in the sequence. The function
returns an output iterator pointing to the position beyond the end
of the sequence.}
\ccMethod{bool is_non_diagram_edge(Edge e);}
{ checks whether $e$ is a non-diagram edge. }
\ccMethod{Point pos(Vertex v);}
{ returns the position of $v$ in \ccVar.}
\ccMethod{Vertex source(Edge e);}
{ returns the source vertex of $e$.}
\ccMethod{Vertex target(Edge e);}
{ returns the target vertex of $e$.}
\ccMethod{Point pos_source(Edge e);}
{ returns the position of the source of $e$ in \ccVar.}
\ccMethod{Point pos_target(Edge e);}
{ returns the position of the target of $e$ in \ccVar.}
\ccMethod{Segment seg(Edge e);}
{ returns the line segment corresponding to edge $e$ starting
at $pos\_source(e)$.}
\ccMethod{Line supporting_line(Edge e);}
{ returns the supporting line of edge $e$.}
\ccMethod{int orientation(Edge e, Point p);}
{ returns $orientation(T.pos\_source(e),T.pos\_target(e),p)$.}
\ccMethod{Edge get_hull_edge();}
{ returns an edge of the outer face of \ccVar\ (i.e., an edge of the convex hull). }
\ccMethod{bool is_diagram_edge(Edge e);}
{returns true if $e$ is an edge of the Delaunay diagram, i.e., either
an edge on the convex hull or an edge where the incident triangles have
distinct circumcircles.}
\ccMethod{bool is_hull_edge(Edge e);}
{returns true if $e$ is an edge of the convex hull of \ccVar, i.e.,
an edge on the face cycle of the outer face. }
\ccHtmlLinksOn
\ccMethod{int dim();}
{returns $-1$ if \ccVar\ is empty, returns $0$ if \ccVar
consists of only one point,
returns $1$ if \ccVar\ consists of at least two points
and all points in \ccVar\
are collinear, and returns $2$ otherwise.}
\end{ccRefClass}

View File

@ -0,0 +1,114 @@
\begin{ccRefConcept} {Point_set_traits}
\subsection{Requirements for the Point\_set traits class}
A point set traits class has to provide some primitives that are used by the point set class.
The following catalog lists the involved primitives.
The types used in the traits class must have a copy constructor and an assignment operator.
\ccCreationVariable{ps_traits}
\ccTypes
\ccNestedType{FT}%
{The field type of the representation class of the point, segment, circle and line types.}
\ccNestedType{Point}%
{The point type on which the point set operates.}
\ccNestedType{Circle}%
{The circle type on which the point set operates.}
\ccHtmlLinksOff
\ccNestedType{Line}%
{The line type on which the point set operates.}
\ccHtmlLinksOn
\ccNestedType{Segment}%
{The segment type on which the point set operates.}
\ccNestedType{Compare_xy_2}%
{The primitive must provide
\ccc{int operator()(const Point& p1,const Point& p2) const}
and has to be derived from $leda\_cmp\_base<Point>$.
The operator has to compare the points $p1$ and $p2$ lexicographically in
$xy$ order. If $p1$ is smaller, the operator has to return -1, if $p1$
is larger, the operator has to return 1, 0 otherwise.
}
\ccNestedType{Compare_dist_2}%
{The primitive must provide
\ccc{Comparison_result operator()(const Point& p1,const Point& p2, const Point& p3) const}.
The operator has to compare the distances of points $p2$ and $p3$ to $p1$.
The operator returns \ccc{SMALLER}, if $p2$ is closer (to $p1$), \ccc{LARGER} if $p3$ is closer,
\ccc{EQUAL} otherwise.
}
\ccNestedType{Orientation}%
{The primitive must provide
\ccc{Orientation operator()(const Point& p1,const Point& p2,const Point& p3) const}.
This operator has to return \ccc{COLLINEAR} if the 3 points are collinear,
\ccc{LEFTTURN} if $p3$ lies on the left of the directed line through $p1$ and $p2$,
\ccc{RIGHTTURN} otherwise.
}
\ccNestedType{Side_of_oriented_circle_2}%
{The primitive must provide
\ccc{Oriented_side operator()(const Point& p1,const Point& p2,const Point& p3, const Point& p4) const}.
This operator has to return \ccc{ON_POSITIVE_SIDE} if $p4$ lies on the positive side of the circle through
the points $p1$,$p2$ and $p3$, \ccc{ON_NEGATIVE_SIDE} if $p4$ lies on the negative side of the circle,
\ccc{ON_ORIENTED_BOUNDARY} otherwise.
}
\ccNestedType{Side_of_halfspace_2}%
{The primitive must provide
\ccc{Orientation operator()(const Point& a,const Point& b, const Point& p3) const }.
This operator has to return \ccc{LEFTTURN} if $p3$ lies in the open halfspace $h$ orthogonal to vector
$b-a$ containing $b$ and having $a$ on its boundary, \ccc{COLLINEAR} if $p3$ is on the boundary of $h$ and
\ccc{RIGHTTURN} otherwise.
}
\ccNestedType{Segment_has_on_2}%
{The primitive must provide
\ccc{bool operator()(const Segment& seg, const Point& p) const }.
This operator has to return true if $seg$ contains $p$, false otherwise.}
\ccNestedType{Squared_distance}%
{The primitive must provide
\ccc{FT operator()(const Point& p1,const Point& p2) const}.
The operator has to return the squared distance from $p1$ to $p2$.}
\ccNestedType{Squared_distance_to_line}%
{The primitive must provide
\ccc{FT operator()(const Line& l,const Point& p) const}.
The operator has to return the squared distance from $l$ to $p$.}
\ccNestedType{Circle_bounded_side_2}%
{The primitive must provide
\ccc{Bounded_side operator()(const Circle& c, const Point& p) const}.
The operator has to return \ccc{ON_BOUNDED_SIDE} if $p$ lies on the bounded side of $c$,
\ccc{ON_UNBOUNDED_SIDE} if $p$ lies on the unbounded side of $c$, \ccc{ON_BOUNDARY} otherwise.}
\ccNestedType{Circle_center_2}%
{The primitive must provide
\ccc{Point operator()(const Circle& c) const}.
The operator has to return the center of $c$.}
\ccNestedType{Construct_circle_2}%
{This primitive constructs a circle. It must provide
\ccc{Circle operator()(const Point& p1,const Point& p2, const Point& p3) const }.
The points $p1$, $p2$ and $p3$ are on the boundary.}
\ccNestedType{Construct_segment_2}%
{This primitive constructs a segment. It must provide
\ccc{Segment operator()(const Point& p1,const Point& p2) const}.
Point $p1$ is the source of the segment, $p2$ the target.}
\ccNestedType{Construct_line_2}%
{This primitive constructs a line. It must provide
\ccc{Line operator()(const Point& p1,const Point& p2) const}.
The line is constructed through $p1$ and $p2$.}
\end{ccRefConcept}

View File

@ -0,0 +1,17 @@
@Book{LEDAbook,
author
=
"K. Mehlhorn and S. N\"aher",
title
=
"LEDA -- A platform for combnatorial and geometric computing",
publisher
=
"Cambridge University Press",
year
=
"1999",
}

View File

@ -0,0 +1,26 @@
% +------------------------------------------------------------------------+
% | CGAL Reference Manual: Point_set_2.tex
% +------------------------------------------------------------------------+
\ccParDims
\clearpage
\section{Reference pages for Point Set in 2D}
\section*{Summary}
The two dimensional point set is a class for geometric queries.
It supports circular, triangular and iso rectangular range searches,
nearest neighbor searches and the computation of the minimum spanning tree.
The point set is a dynamic data structure supporting the insertion and
deletion of points.
\subsection*{Concepts}
\ccc{Point_set_traits}\\
\subsection*{Classes}
\ccc{CGAL::Point_set_2}\\
\ccc{CGAL::point_set_traits_2}\\
\ccc{CGAL::point_set_leda_float_traits_2}\\
\ccc{CGAL::point_set_leda_rat_traits_2}\\

View File

@ -0,0 +1,15 @@
% +------------------------------------------------------------------------+
% | CGAL Reference Manual: main.tex
% +------------------------------------------------------------------------+
% | Point_set_2
% |
% +------------------------------------------------------------------------+
\input{Point_set_2_ref/intro}
\input{Point_set_2_ref/Point_set_2}
\input{Point_set_2_ref/Point_set_traits}
\input{Point_set_2_ref/point_set_traits_2}
\input{Point_set_2_ref/point_set_leda_float_traits_2}
\input{Point_set_2_ref/point_set_leda_rat_traits_2}
%% EOF %%

View File

@ -0,0 +1,35 @@
\begin{ccRefClass}{point_set_leda_float_traits_2}
\subsubsection{Traits classes for \leda\ 2D Points}
\ccInclude{CGAL/point_set_leda_traits_2.h}
The traits class \ccc{point_set_leda_float_traits_2} deals with \leda\ 2D float kernel objects.
\ccTypes
\ccThree{typedef ttttttttttttttttttttt}{tttttttttt}{}
\ccThreeToTwo
\ccTypedef{typedef double FT;}{}
\ccTypedef{typedef leda_point Point;}{}
\ccTypedef{typedef leda_segment Segment;}{}
\ccHtmlLinksOff
\ccTypedef{typedef leda_line Line;}{}
\ccHtmlLinksOn
\ccTypedef{typedef leda_circle Circle;}{}
\ccNestedType{Compare_xy_2}{}
\ccNestedType{Compare_dist_2}{}
\ccNestedType{Orientation}{}
\ccNestedType{Side_of_oriented_circle_2}{}
\ccNestedType{Side_of_halfspace_2}{}
\ccNestedType{Segment_has_on_2}{}
\ccNestedType{Squared_distance}{}
\ccNestedType{Squared_distance_to_line}{}
\ccNestedType{Circle_bounded_side_2}{}
\ccNestedType{Circle_center_2}{}
\ccNestedType{Construct_circle_2}{}
\ccNestedType{Construct_segment_2}{}
\ccNestedType{Construct_line_2}{}
\end{ccRefClass}

View File

@ -0,0 +1,35 @@
\begin{ccRefClass}{point_set_leda_rat_traits_2}
The traits class \ccc{point_set_leda_rat_traits_2} deals with \leda\ 2D rational kernel objects.
\ccTypes
\ccThree{typedef ttttttttttttttttttttttt}{tttttttttt}{}
\ccThreeToTwo
\ccTypedef{typedef leda_rational FT;}{}
\ccTypedef{typedef leda_rat_point Point;}{}
\ccTypedef{typedef leda_rat_segment Segment;}{}
\ccHtmlLinksOff
\ccTypedef{typedef leda_rat_line Line;}{}
\ccHtmlLinksOn
\ccTypedef{typedef leda_rat_circle Circle;}{}
\ccNestedType{Compare_xy_2}{}
\ccNestedType{Compare_dist_2}{}
\ccNestedType{Orientation}{}
\ccNestedType{Side_of_oriented_circle_2}{}
\ccNestedType{Side_of_halfspace_2}{}
\ccNestedType{Segment_has_on_2}{}
\ccNestedType{Squared_distance}{}
\ccNestedType{Squared_distance_to_line}{}
\ccNestedType{Circle_bounded_side_2}{}
\ccNestedType{Circle_center_2}{}
\ccNestedType{Construct_circle_2}{}
\ccNestedType{Construct_segment_2}{}
\ccNestedType{Construct_line_2}{}
\end{ccRefClass}
\ccParDims

View File

@ -0,0 +1,36 @@
\begin{ccRefClass}{point_set_traits_2<T>}
\subsubsection{Traits class for \cgal\ 2D kernel objects}
\ccInclude{CGAL/point_set_traits_2.h}
The traits class \ccRefName\ deals with \cgal\ 2D kernel objects.
\ccTypes
\ccThree{typedef ttttttttttttttttttttt}{tttttttttt}{}
\ccThreeToTwo
\ccTypedef{typedef T::FT FT;}{}
\ccTypedef{typedef Point_2<T> Point;}{}
\ccTypedef{typedef Segment_2<T> Segment;}{}
\ccHtmlLinksOff
\ccTypedef{typedef Line_2<T> Line;}{}
\ccHtmlLinksOn
\ccTypedef{typedef Circle_2<T> Circle;}{}
\ccNestedType{Compare_xy_2}{}
\ccNestedType{Compare_dist_2}{}
\ccNestedType{Orientation}{}
\ccNestedType{Side_of_oriented_circle_2}{}
\ccNestedType{Side_of_halfspace_2}{}
\ccNestedType{Segment_has_on_2}{}
\ccNestedType{Squared_distance}{}
\ccNestedType{Squared_distance_to_line}{}
\ccNestedType{Circle_bounded_side_2}{}
\ccNestedType{Circle_center_2}{}
\ccNestedType{Construct_circle_2}{}
\ccNestedType{Construct_segment_2}{}
\ccNestedType{Construct_line_2}{}
\end{ccRefClass}

View File

@ -0,0 +1,17 @@
@Book{LEDAbook,
author
=
"K. Mehlhorn and S. N\"aher",
title
=
"LEDA -- A platform for combnatorial and geometric computing",
publisher
=
"Cambridge University Press",
year
=
"1999",
}

View File

@ -0,0 +1,12 @@
% +------------------------------------------------------------------------+
% | CGAL Reference Manual: main.tex
% +------------------------------------------------------------------------+
% | Point_set_2
% |
% | 15.10.1999 Matthias Baesken
% +------------------------------------------------------------------------+
\input{Point_set_2}
\input{Point_set_2_ref/main}
%% EOF %%

View File

@ -0,0 +1,48 @@
include $(CGAL_MAKEFILE)
#---------------------------------------------------------------------#
# compiler flags
#---------------------------------------------------------------------#
CXXFLAGS = \
$(CGAL_CXXFLAGS)
#---------------------------------------------------------------------#
# linker flags
#---------------------------------------------------------------------#
LIBPATH = \
$(TESTSUITE_LIBPATH) \
$(CGAL_LIBPATH)
LDFLAGS = \
$(TESTSUITE_LDFLAGS) \
$(CGAL_LDFLAGS)
#---------------------------------------------------------------------#
# target entries
#---------------------------------------------------------------------#
all: \
range_search \
nearest_nb1
range_search$(EXE_EXT) : range_search$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)range_search range_search$(OBJ_EXT) $(LDFLAGS)
nearest_nb1$(EXE_EXT) : nearest_nb1$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)nearest_nb1 nearest_nb1$(OBJ_EXT) $(LDFLAGS)
clean:
rm -f range_search nearest_nb1 rs_test *.o *.obj *.exe core
#---------------------------------------------------------------------#
# suffix rules
#---------------------------------------------------------------------#
.C$(OBJ_EXT):
$(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $<

View File

@ -0,0 +1,121 @@
// ============================================================================
//
// Copyright (c) 1999 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------------
// release :
// release_date :
//
// file : examples/Point_set_2/nearest_nb1.C
// revision : 1.2.4
// revision_date : 14 September 2000
// author(s) : Kurt Mehlhorn, Stefan Naeher, Matthias Baesken
//
// coordinator : Matthias Baesken, Halle (<baesken@informatik.uni-trier.de>)
// ============================================================================
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <vector>
#include <CGAL/Point_set_2.h>
#include <CGAL/leda_rational.h>
using namespace CGAL;
using namespace std;
typedef Cartesian<leda_rational> REP;
typedef point_set_traits_2<REP> TRAITS;
typedef Point_set_2<TRAITS>::Edge Edge;
typedef Point_set_2<TRAITS>::Vertex Vertex;
Point_set_2<TRAITS> PSet;
Point_2<REP> ar1[5];
int check1(std::list<Vertex> L)
{
cout << "check 1!\n";
if (L.size() != 5) return 1;
std::list<Vertex>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar1[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int main()
{
std::list<Point_2<REP> > Lr;
int w1,w2;
Point_2<REP> p1(12,14,1);
Point_2<REP> p2(-12,14,1);
Point_2<REP> p3(2,11,1);
Point_2<REP> p4(5,6,1);
Point_2<REP> p5(67,38,10);
Point_2<REP> p6(11,20,1);
Point_2<REP> p7(-5,6,1);
Point_2<REP> p8(12,0,1);
Point_2<REP> p9(4,31,1);
Point_2<REP> p10(-10,-10,1);
Lr.push_back(p1); Lr.push_back(p2); Lr.push_back(p3);
Lr.push_back(p4); Lr.push_back(p5); Lr.push_back(p6);
Lr.push_back(p7); Lr.push_back(p8); Lr.push_back(p9);
Lr.push_back(p10);
PSet.init(Lr.begin(),Lr.end());
// init
ar1[0]=p4; ar1[1]=p5; ar1[2]=p3; ar1[3]=p7; ar1[4]=p8;
Point_2<REP> actual(30,45,10);
// nearest neighbor ...
Vertex v = PSet.nearest_neighbor(actual);
cout << "Nearest neighbor:" << PSet.pos(v) << "\n";
if (PSet.pos(v) == p4) w1=0; else w1=1;
// k nearest neighbors ...
std::list<Vertex> L;
std::list<Vertex>::const_iterator it;
PSet.nearest_neighbors(actual,5,back_inserter(L));
cout << "actual point: " << actual << "\n";
for (it=L.begin();it != L.end(); it++)
cout << PSet.pos(*it) << "\n";
w2=check1(L);
if (w1==0 && w2==0) return 0;
else return 1;
}
#endif

View File

@ -0,0 +1,175 @@
// ============================================================================
//
// Copyright (c) 1999 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------------
// release :
// release_date :
//
// file : examples/Point_set_2/range_search.C
// revision : 1.2.4
// revision_date : 14 September 1999
// author(s) : Kurt Mehlhorn, Stefan Naeher, Matthias Baesken
//
// coordinator : Matthias Baesken, Halle (<baesken@informatik.uni-trier.de>)
// ============================================================================
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA) || (__LEDA__ < 400)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <vector>
#include <CGAL/Point_set_2.h>
#include <CGAL/leda_rational.h>
using namespace CGAL;
using namespace std;
typedef Cartesian<leda_rational> REP;
typedef point_set_traits_2<REP> TRAITS;
typedef Point_set_2<TRAITS>::Edge Edge;
typedef Point_set_2<TRAITS>::Vertex Vertex;
Point_set_2<TRAITS> PSet;
Point_2<REP> ar1[6];
Point_2<REP> ar2[3];
Point_2<REP> ar3[3];
int check1(std::list<Vertex> L)
{
cout << "check 1!\n";
if (L.size() != 6) return 1;
std::list<Vertex>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar1[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int check2(std::list<Vertex> L)
{
cout << "check 2!\n";
if (L.size() != 3) return 1;
std::list<Vertex>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar2[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int check3(std::list<Vertex> L)
{
cout << "check 3!\n";
if (L.size() != 3) return 1;
std::list<Vertex>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar3[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int main()
{
Point_2<REP> pnew(120,62,10);
int w1,w2,w3;
std::list<Point_2<REP> > Lr;
Point_2<REP> p1(12,14,1);
Point_2<REP> p2(-12,14,1);
Point_2<REP> p3(2,11,1);
Point_2<REP> p4(5,6,1);
Point_2<REP> p5(67,38,10);
Point_2<REP> p6(11,20,1);
Point_2<REP> p7(-5,6,1);
Point_2<REP> p8(12,0,1);
Point_2<REP> p9(4,31,1);
Point_2<REP> p10(-10,-10,1);
// init
ar1[0]=p1; ar1[1]=p6; ar1[2]=p3; ar1[3]=p4; ar1[4]=p5; ar1[5]=pnew;
ar2[0]=p2; ar2[1]=p3; ar2[2]=p1;
ar3[0]=p7; ar3[1]=p10; ar3[2]=p3;
Lr.push_back(p1); Lr.push_back(p2); Lr.push_back(p3);
Lr.push_back(p4); Lr.push_back(p5); Lr.push_back(p6);
Lr.push_back(p7); Lr.push_back(p8); Lr.push_back(p9);
Lr.push_back(p10);
PSet.init(Lr.begin(),Lr.end());
cout << "insert!\n"; cout.flush();
PSet.insert(pnew);
cout << "range search for circle !\n";
Circle_2<REP> rc(p5,p6);
std::list<Vertex> LV;
PSet.range_search(rc,back_inserter(LV));
std::list<Vertex>::const_iterator it;
for (it=LV.begin();it != LV.end(); it++)
cout << PSet.pos(*it) << "\n";
w1 = check1(LV);
cout << "range search for triangle !\n";
LV.clear();
PSet.range_search(p1,p2,p3,back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
cout << PSet.pos(*it) << "\n";
w2 = check2(LV);
LV.clear();
cout << "range search for iso rectangle !\n";
Point_2<REP> pt1=p10; // lower left
Point_2<REP> pt3=p3; // upper right
Point_2<REP> pt2 = Point_2<REP>(pt3.x(),pt1.y());
Point_2<REP> pt4 = Point_2<REP>(pt1.x(),pt3.y());
PSet.range_search(pt1,pt2,pt3,pt4,back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
cout << PSet.pos(*it) << "\n";
w3 = check3(LV);
if (w1==0 && w2==0 && w3==0) return 0;
else return 1;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,296 @@
// ======================================================================
//
// Copyright (c) 1999 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------
//
// release :
// release_date : 2000, September 14
//
// file : include/CGAL/point_set_leda_traits_2.h
// package : Point_set_2 (1.2.4)
// maintainer : Matthias Baesken <baesken@informatik.uni-trier.de>
// revision : 1.2.4
// revision_date : 14 September 2000
// author(s) : Kurt Mehlhorn, Stefan Naeher, Matthias Baesken
//
// coordinator : Matthias Baesken, Halle (<baesken@informatik.uni-trier.de>)
// ======================================================================
#ifndef POINT_SET_2_LEDA_TRAITS
#define POINT_SET_2_LEDA_TRAITS
#if !defined(LEDA_ROOT_INCL_ID)
#define LEDA_ROOT_INCL_ID 400899
#include <LEDA/REDEFINE_NAMES.h>
#endif
#include <LEDA/point.h>
#include <LEDA/circle.h>
#include <LEDA/segment.h>
#include <LEDA/line.h>
#include <LEDA/rat_point.h>
#include <LEDA/rat_circle.h>
#include <LEDA/rat_segment.h>
#include <LEDA/rat_line.h>
CGAL_BEGIN_NAMESPACE
class Leda_compare_ratpoints : public leda_cmp_base<leda_rat_point> {
int operator()(const leda_rat_point& p1,const leda_rat_point& p2) const
{
return leda_rat_point::cmp_xy(p1,p2);
}
};
class Leda_compare_points : public leda_cmp_base<leda_point> {
int operator()(const leda_point& p1,const leda_point& p2) const
{
return leda_point::cmp_xy(p1,p2);
}
};
template<class T>
struct Leda_compare_dist {
Comparison_result operator()(const T& p1,const T& p2,const T& p3) const
{
int c = p1.cmp_dist(p2,p3);
switch (c){
case -1: return SMALLER;
case 0 : return EQUAL;
}
return LARGER;
}
};
template<class T>
struct Leda_orientation {
Orientation operator()(const T& p1,const T& p2,const T& p3) const
{
int o = ::orientation(p1,p2,p3);
switch(o){
case -1: return RIGHTTURN;
case 0: return COLLINEAR;
}
return LEFTTURN;
}
};
template<class T>
struct Leda_side_of_circle {
Oriented_side operator()(const T& p1,const T& p2,const T& p3, const T& p4) const
{
int s = side_of_circle(p1,p2,p3,p4);
switch(s){
case -1: return ON_NEGATIVE_SIDE;
case 0: return ON_ORIENTED_BOUNDARY;
}
return ON_POSITIVE_SIDE;
}
};
template<class T>
struct Leda_side_of_halfspace {
Orientation operator()(const T& p1,const T& p2, const T& p3) const
{
int o = side_of_halfspace(p1,p2,p3);
switch(o){
case -1: return RIGHTTURN;
case 0: return COLLINEAR;
}
return LEFTTURN;
}
};
template<class S, class T>
struct Leda_segment_contains {
bool operator()(const S& seg, const T& p) const
{ return seg.contains(p); }
};
template<class T, class Rep>
struct Leda_sqr_dist {
Rep operator()(const T& p1,const T& p2) const
{ return p1.sqr_dist(p2); }
};
template<class L,class T, class Rep>
struct Leda_line_sqr_dist {
Rep operator()(const L& l,const T& p) const
{ return l.sqr_dist(p); }
};
template<class C,class T>
struct Leda_circle_ptori {
Bounded_side operator()(const C& c, const T& p) const
{ int wt = c.orientation();
int so = c.side_of(p);
int bs = wt*so; // <0 outside, ==0 on the circle, >0 inside
switch (bs){
case -1: return ON_UNBOUNDED_SIDE;
case 0: return ON_BOUNDARY;
}
return ON_BOUNDED_SIDE;
}
};
template<class C,class T>
struct Leda_circle_center {
T operator()(const C& c) const
{ return c.center(); }
};
template<class C,class T>
struct Leda_create_circle_ppp {
C operator()(const T& p1,const T& p2,const T& p3) const
{ return C(p1,p2,p3); }
};
template<class C,class T>
struct Leda_create_segment_pp {
C operator()(const T& p1,const T& p2) const
{ return C(p1,p2); }
};
template<class C,class T>
struct Leda_create_line_pp {
C operator()(const T& p1,const T& p2) const
{ return C(p1,p2); }
};
class point_set_leda_float_traits_2 {
public:
typedef double FT;
typedef leda_point Point;
typedef leda_circle Circle;
typedef leda_segment Segment;
typedef leda_line Line;
typedef Leda_compare_points Compare_xy_2;
typedef Leda_compare_dist<Point> Compare_dist_2;
typedef Leda_orientation<Point> Orientation;
typedef Leda_side_of_circle<Point> Side_of_oriented_circle_2;
typedef Leda_side_of_halfspace<Point> Side_of_halfspace_2;
typedef Leda_segment_contains<Segment,Point> Segment_has_on_2;
typedef Leda_sqr_dist<Point,FT> Squared_distance;
typedef Leda_line_sqr_dist<Line,Point,FT> Squared_distance_to_line;
typedef Leda_circle_ptori<Circle,Point> Circle_bounded_side_2;
typedef Leda_circle_center<Circle,Point> Circle_center_2;
typedef Leda_create_circle_ppp<Circle,Point> Construct_circle_2;
typedef Leda_create_segment_pp<Segment,Point> Construct_segment_2;
typedef Leda_create_line_pp<Line,Point> Construct_line_2;
Orientation get_orientation_object() const
{ return Orientation(); }
Side_of_oriented_circle_2 get_side_of_oriented_circle_2_object() const
{ return Side_of_oriented_circle_2(); }
Side_of_halfspace_2 get_side_of_halfspace_2_object() const
{ return Side_of_halfspace_2(); }
Segment_has_on_2 get_segment_has_on_2_object() const
{ return Segment_has_on_2(); }
Squared_distance get_squared_distance_object() const
{ return Squared_distance(); }
Squared_distance_to_line get_squared_distance_to_line_object() const
{ return Squared_distance_to_line(); }
Circle_bounded_side_2 get_circle_bounded_side_2_object() const
{ return Circle_bounded_side_2(); }
Circle_center_2 get_circle_center_2_object() const
{ return Circle_center_2(); }
Construct_circle_2 get_construct_circle_2_object() const
{ return Construct_circle_2(); }
Construct_segment_2 get_construct_segment_2_object() const
{ return Construct_segment_2(); }
Construct_line_2 get_construct_line_2_object() const
{ return Construct_line_2(); }
point_set_leda_float_traits_2() { }
};
class point_set_leda_rat_traits_2 {
public:
typedef leda_rational FT;
typedef leda_rat_point Point;
typedef leda_rat_circle Circle;
typedef leda_rat_segment Segment;
typedef leda_rat_line Line;
typedef Leda_compare_ratpoints Compare_xy_2;
typedef Leda_compare_dist<Point> Compare_dist_2;
typedef Leda_orientation<Point> Orientation;
typedef Leda_side_of_circle<Point> Side_of_oriented_circle_2;
typedef Leda_side_of_halfspace<Point> Side_of_halfspace_2;
typedef Leda_segment_contains<Segment,Point> Segment_has_on_2;
typedef Leda_sqr_dist<Point,FT> Squared_distance;
typedef Leda_line_sqr_dist<Line,Point,FT> Squared_distance_to_line;
typedef Leda_circle_ptori<Circle,Point> Circle_bounded_side_2;
typedef Leda_circle_center<Circle,Point> Circle_center_2;
typedef Leda_create_circle_ppp<Circle,Point> Construct_circle_2;
typedef Leda_create_segment_pp<Segment,Point> Construct_segment_2;
typedef Leda_create_line_pp<Line,Point> Construct_line_2;
Orientation get_orientation_object() const
{ return Orientation(); }
Side_of_oriented_circle_2 get_side_of_oriented_circle_2_object() const
{ return Side_of_oriented_circle_2(); }
Side_of_halfspace_2 get_side_of_halfspace_2_object() const
{ return Side_of_halfspace_2(); }
Segment_has_on_2 get_segment_has_on_2_object() const
{ return Segment_has_on_2(); }
Squared_distance get_squared_distance_object() const
{ return Squared_distance(); }
Squared_distance_to_line get_squared_distance_to_line_object() const
{ return Squared_distance_to_line(); }
Circle_bounded_side_2 get_circle_bounded_side_2_object() const
{ return Circle_bounded_side_2(); }
Circle_center_2 get_circle_center_2_object() const
{ return Circle_center_2(); }
Construct_circle_2 get_construct_circle_2_object() const
{ return Construct_circle_2(); }
Construct_segment_2 get_construct_segment_2_object() const
{ return Construct_segment_2(); }
Construct_line_2 get_construct_line_2_object() const
{ return Construct_line_2(); }
point_set_leda_rat_traits_2() { }
};
CGAL_END_NAMESPACE
#if LEDA_ROOT_INCL_ID == 400899
#undef LEDA_ROOT_INCL_ID
#include <LEDA/UNDEFINE_NAMES.h>
#endif
#endif

View File

@ -0,0 +1,238 @@
// ======================================================================
//
// Copyright (c) 1999 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------
//
// release :
// release_date : 2000, September 14
//
// file : include/CGAL/point_set_traits_2.h
// package : Point_set_2 (1.2.4)
// maintainer : Matthias Baesken <baesken@informatik.uni-trier.de>
// revision : 1.2.4
// revision_date : 14 September 2000
// author(s) : Kurt Mehlhorn, Stefan Naeher, Matthias Baesken
//
// coordinator : Matthias Baesken, Halle (<baesken@informatik.uni-trier.de>)
// ======================================================================
#ifndef POINT_SET_2_TRAITS
#define POINT_SET_2_TRAITS
#if !defined(LEDA_ROOT_INCL_ID)
#define LEDA_ROOT_INCL_ID 400898
#include <LEDA/REDEFINE_NAMES.h>
#endif
#include <CGAL/Cartesian.h>
#include <CGAL/Homogeneous.h>
#include <CGAL/distance_predicates_2.h>
#include <CGAL/squared_distance_2.h>
#include <CGAL/Point_2.h>
#include <CGAL/Circle_2.h>
#include <CGAL/Segment_2.h>
#include <CGAL/Line_2.h>
#include <CGAL/Vector_2.h>
#include <CGAL/Direction_2.h>
CGAL_BEGIN_NAMESPACE
#if defined(LEDA_PREFIX)
#undef vector
#endif
template<class T>
class CG_Lex_xy : public leda_cmp_base<T> {
int operator()(const T& p1,const T& p2) const
{
Comparison_result c = compare_lexicographically_xy(p1,p2);
switch(c){
case SMALLER: return -1;
case LARGER: return 1;
case EQUAL: return 0;
}
return 0;
}
};
template<class T>
struct CG_compare_dist {
Comparison_result operator()(const T& p1,const T& p2,const T& p3) const
{
Comparison_result c= cmp_dist_to_point(p1,p2,p3);
return c;
}
};
template<class T>
struct CG_orientation {
Orientation operator()(const T& p1,const T& p2,const T& p3) const
{
Orientation or=orientation(p1,p2,p3);
return or;
}
};
template<class T>
struct CG_side_of_circle {
int operator()(const T& p1,const T& p2,const T& p3, const T& p4) const
{
Oriented_side s= side_of_oriented_circle(p1,p2,p3,p4);
return s;
}
};
template<class T>
struct CG_side_of_halfspace {
typedef typename T::R Repres;
Orientation operator()(const T& p1,const T& p2, const T& p3) const
{
Segment_2<Repres> s(p1,p2);
Direction_2<Repres> d = s.direction();
Vector_2<Repres> v(d.dx(),d.dy());
Vector_2<Repres> v2= v.perpendicular(CLOCKWISE);
Point_2<Repres> ph = p1 + v2;
Orientation or=orientation(p1,ph,p3);
return or;
}
};
template<class S, class T>
struct CG_segment_contains {
bool operator()(const S& seg, const T& p) const
{ return seg.has_on(p); }
};
template<class T, class Rep>
struct CG_sqr_dist {
Rep operator()(const T& p1,const T& p2) const
{ return squared_distance(p1,p2); }
};
template<class L,class T, class Rep>
struct CG_line_sqr_dist {
Rep operator()(const L& l,const T& p) const
{ return squared_distance(l,p); }
};
template<class C,class T>
struct CG_circle_ptori {
Bounded_side operator()(const C& c, const T& p) const
{
Bounded_side s = c.bounded_side(p);
return s;
}
};
template<class C,class T>
struct CG_circle_center {
T operator()(const C& c) const
{ return c.center(); }
};
template<class C,class T>
struct CG_create_circle_ppp {
C operator()(const T& p1,const T& p2,const T& p3) const
{ return C(p1,p2,p3); }
};
template<class C,class T>
struct CG_create_segment_pp {
C operator()(const T& p1,const T& p2) const
{ return C(p1,p2); }
};
template<class C,class T>
struct CG_create_line_pp {
C operator()(const T& p1,const T& p2) const
{ return C(p1,p2); }
};
template<class T>
class point_set_traits_2 {
public:
typedef typename T::FT FT;
typedef Point_2<T> Point;
typedef Circle_2<T> Circle;
typedef Segment_2<T> Segment;
typedef Line_2<T> Line;
typedef CG_Lex_xy<Point> Compare_xy_2;
typedef CG_compare_dist<Point> Compare_dist_2;
typedef CG_orientation<Point> Orientation;
typedef CG_side_of_circle<Point> Side_of_oriented_circle_2;
typedef CG_side_of_halfspace<Point> Side_of_halfspace_2;
typedef CG_segment_contains<Segment,Point> Segment_has_on_2;
typedef CG_sqr_dist<Point,FT> Squared_distance;
typedef CG_line_sqr_dist<Line,Point,FT> Squared_distance_to_line;
typedef CG_circle_ptori<Circle,Point> Circle_bounded_side_2;
typedef CG_circle_center<Circle,Point> Circle_center_2;
typedef CG_create_circle_ppp<Circle,Point> Construct_circle_2;
typedef CG_create_segment_pp<Segment,Point> Construct_segment_2;
typedef CG_create_line_pp<Line,Point> Construct_line_2;
Orientation get_orientation_object() const
{ return Orientation(); }
Side_of_oriented_circle_2 get_side_of_oriented_circle_2_object() const
{ return Side_of_oriented_circle_2(); }
Side_of_halfspace_2 get_side_of_halfspace_2_object() const
{ return Side_of_halfspace_2(); }
Segment_has_on_2 get_segment_has_on_2_object() const
{ return Segment_has_on_2(); }
Squared_distance get_squared_distance_object() const
{ return Squared_distance(); }
Squared_distance_to_line get_squared_distance_to_line_object() const
{ return Squared_distance_to_line(); }
Circle_bounded_side_2 get_circle_bounded_side_2_object() const
{ return Circle_bounded_side_2(); }
Circle_center_2 get_circle_center_2_object() const
{ return Circle_center_2(); }
Construct_circle_2 get_construct_circle_2_object() const
{ return Construct_circle_2(); }
Construct_segment_2 get_construct_segment_2_object() const
{ return Construct_segment_2(); }
Construct_line_2 get_construct_line_2_object() const
{ return Construct_line_2(); }
point_set_traits_2() { }
};
CGAL_END_NAMESPACE
#if LEDA_ROOT_INCL_ID == 400898
#undef LEDA_ROOT_INCL_ID
#include <LEDA/UNDEFINE_NAMES.h>
#endif
#endif

View File

@ -0,0 +1 @@
Matthias Baesken <baesken@informatik.uni-trier.de>

View File

@ -0,0 +1,67 @@
#! /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
/bin/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 ... "
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
#---------------------------------------------------------------------#
/bin/rm -f $ERRORFILE
touch $ERRORFILE
#---------------------------------------------------------------------#
# compile and run the tests
#---------------------------------------------------------------------#
compile_and_run range_search
compile_and_run nearest_nb1

View File

@ -0,0 +1,54 @@
# This is the makefile for compiling the CGAL Kernel test.
#---------------------------------------------------------------------#
# include platform specific settings
#---------------------------------------------------------------------#
# Choose the right include file from the <cgalroot>/make directory.
include $(CGAL_MAKEFILE)
#---------------------------------------------------------------------#
# compiler flags
#---------------------------------------------------------------------#
CXXFLAGS = \
$(TESTSUITE_CXXFLAGS) \
-DCGAL_CH_CHECK_EXPENSIVE \
$(CGAL_CXXFLAGS) \
$(EXTRA_FLAGS)
#---------------------------------------------------------------------#
# linker flags
#---------------------------------------------------------------------#
LIBPATH = \
$(TESTSUITE_LIBPATH) \
$(CGAL_LIBPATH)
LDFLAGS = \
$(TESTSUITE_LDFLAGS) \
$(CGAL_LDFLAGS)
#---------------------------------------------------------------------#
# target entries
#---------------------------------------------------------------------#
all: \
range_search \
nearest_nb1
range_search$(EXE_EXT) : range_search$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)range_search range_search$(OBJ_EXT) $(LDFLAGS)
nearest_nb1$(EXE_EXT) : nearest_nb1$(OBJ_EXT)
$(CGAL_CXX) $(LIBPATH) $(EXE_OPT)nearest_nb1 nearest_nb1$(OBJ_EXT) $(LDFLAGS)
clean: nearest_nb1.clean range_search.clean
#---------------------------------------------------------------------#
# suffix rules
#---------------------------------------------------------------------#
.C$(OBJ_EXT):
$(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $<

View File

@ -0,0 +1,137 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA) || (__LEDA__ < 400)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <vector>
#include <CGAL/Point_set_2.h>
#include <CGAL/leda_rational.h>
using namespace CGAL;
typedef Cartesian<leda_rational> REP;
typedef point_set_traits_2<REP> TRAITS;
typedef Point_set_2<TRAITS>::Edge Edge;
typedef Point_set_2<TRAITS>::Vertex Vertex;
Point_set_2<TRAITS> PSet;
Point_2<REP> ar1[5];
int check1(std::list<Vertex> L)
{
std::cout << "check 1!\n";
if (L.size() != 5) return 1;
std::list<Vertex>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar1[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int main()
{
std::list<Point_2<REP> > Lr;
int w1,w2;
Point_2<REP> p1(12,14,1);
Point_2<REP> p2(-12,14,1);
Point_2<REP> p3(2,11,1);
Point_2<REP> p4(5,6,1);
Point_2<REP> p5(67,38,10);
Point_2<REP> p6(11,20,1);
Point_2<REP> p7(-5,6,1);
Point_2<REP> p8(12,0,1);
Point_2<REP> p9(4,31,1);
Point_2<REP> p10(-10,-10,1);
Lr.push_back(p1); Lr.push_back(p2); Lr.push_back(p3);
Lr.push_back(p4); Lr.push_back(p5); Lr.push_back(p6);
Lr.push_back(p7); Lr.push_back(p8); Lr.push_back(p9);
Lr.push_back(p10);
PSet.init(Lr.begin(),Lr.end());
// init
ar1[0]=p4; ar1[1]=p5; ar1[2]=p3; ar1[3]=p7; ar1[4]=p8;
Point_2<REP> actual(30,45,10);
// nearest neighbor ...
Vertex v = PSet.nearest_neighbor(actual);
std::cout << "Nearest neighbor:" << PSet.pos(v) << "\n";
if (PSet.pos(v) == p4) w1=0; else w1=1;
// k nearest neighbors ...
std::list<Vertex> L;
std::list<Vertex>::const_iterator it;
PSet.nearest_neighbors(actual,5,std::back_inserter(L));
std::cout << "actual point: " << actual << "\n";
for (it=L.begin();it != L.end(); it++)
std::cout << PSet.pos(*it) << "\n";
w2=check1(L);
// construction ...
Point_set_2<TRAITS> PSet2;
Point_set_2<TRAITS> PSet3(Lr.begin(),Lr.end());
Point_set_2<TRAITS> PSet4(Lr);
// init ...
PSet2.init(Lr);
//get points/segments ...
std::list<Point_2<REP> > ptlist;
std::list<Segment_2<REP> > seglist;
PSet3.points(std::back_inserter(ptlist));
PSet3.segments(std::back_inserter(seglist));
std::cout << PSet3.is_empty() << "\n";
PSet3.clear();
Edge eakt = PSet4.locate(actual);
std::cout << PSet4.seg(eakt) << "\n";
PSet4.lookup(actual);
// insert/ delete
Vertex vnew = PSet4.insert(actual);
std::cout << PSet4.pos(vnew) << "\n";
PSet4.del(actual);
Edge he = PSet4.get_hull_edge();
std::cout << PSet4.is_diagram_edge(he) << "\n";
std::cout << PSet4.is_hull_edge(he) << "\n";
std::cout << PSet4.dim() << "\n";
if (w1==0 && w2==0) return 0;
else return 1;
}
#endif

View File

@ -0,0 +1,154 @@
#include <CGAL/basic.h>
#if !defined(CGAL_USE_LEDA) || (__LEDA__ < 400)
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "No LEDA installed!\n";
return 0;
}
#else
#include <CGAL/config.h>
#include <list>
#include <vector>
#include <CGAL/Point_set_2.h>
#include <CGAL/leda_rational.h>
using namespace CGAL;
using namespace std;
typedef Cartesian<leda_rational> REP;
typedef point_set_traits_2<REP> TRAITS;
typedef Point_set_2<TRAITS>::Edge Edge;
typedef Point_set_2<TRAITS>::Vertex Vertex;
Point_set_2<TRAITS> PSet;
Point_2<REP> ar1[6];
Point_2<REP> ar2[3];
Point_2<REP> ar3[3];
int check1(std::list<Vertex> L)
{
cout << "check 1!\n";
if (L.size() != 6) return 1;
std::list<Vertex>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar1[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int check2(std::list<Vertex> L)
{
cout << "check 2!\n";
if (L.size() != 3) return 1;
std::list<Vertex>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar2[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int check3(std::list<Vertex> L)
{
cout << "check 3!\n";
if (L.size() != 3) return 1;
std::list<Vertex>::const_iterator it = L.begin();
int i=0;
int w=0;
for(; it != L.end();it++){
if (ar3[i] != PSet.pos(*it)) w=1;
i++;
}
return w;
}
int main()
{
Point_2<REP> pnew(120,62,10);
int w1,w2,w3;
std::list<Point_2<REP> > Lr;
Point_2<REP> p1(12,14,1);
Point_2<REP> p2(-12,14,1);
Point_2<REP> p3(2,11,1);
Point_2<REP> p4(5,6,1);
Point_2<REP> p5(67,38,10);
Point_2<REP> p6(11,20,1);
Point_2<REP> p7(-5,6,1);
Point_2<REP> p8(12,0,1);
Point_2<REP> p9(4,31,1);
Point_2<REP> p10(-10,-10,1);
// init
ar1[0]=p1; ar1[1]=p6; ar1[2]=p3; ar1[3]=p4; ar1[4]=p5; ar1[5]=pnew;
ar2[0]=p2; ar2[1]=p3; ar2[2]=p1;
ar3[0]=p7; ar3[1]=p10; ar3[2]=p3;
Lr.push_back(p1); Lr.push_back(p2); Lr.push_back(p3);
Lr.push_back(p4); Lr.push_back(p5); Lr.push_back(p6);
Lr.push_back(p7); Lr.push_back(p8); Lr.push_back(p9);
Lr.push_back(p10);
PSet.init(Lr.begin(),Lr.end());
cout << "insert!\n"; cout.flush();
PSet.insert(pnew);
cout << "range search for circle !\n";
Circle_2<REP> rc(p5,p6);
std::list<Vertex> LV;
PSet.range_search(rc,back_inserter(LV));
std::list<Vertex>::const_iterator it;
for (it=LV.begin();it != LV.end(); it++)
cout << PSet.pos(*it) << "\n";
w1 = check1(LV);
cout << "range search for triangle !\n";
LV.clear();
PSet.range_search(p1,p2,p3,back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
cout << PSet.pos(*it) << "\n";
w2 = check2(LV);
LV.clear();
cout << "range search for iso rectangle !\n";
Point_2<REP> pt1=p10; // lower left
Point_2<REP> pt3=p3; // upper right
Point_2<REP> pt2 = Point_2<REP>(pt3.x(),pt1.y());
Point_2<REP> pt4 = Point_2<REP>(pt1.x(),pt3.y());
PSet.range_search(pt1,pt2,pt3,pt4,back_inserter(LV));
for (it=LV.begin();it != LV.end(); it++)
cout << PSet.pos(*it) << "\n";
w3 = check3(LV);
if (w1==0 && w2==0 && w3==0) return 0;
else return 1;
}
#endif

View File

@ -0,0 +1,2 @@
1.2.4 (14 September 2000)
maintainer: Matthias Baesken <baesken@informatik.uni-trier.de>

View File

@ -0,0 +1,31 @@
Timer Package: Release changes:
---------------------------------------------------------------------
1.8 (11 August 2000)
change to ccRefName in the manual
1.7 (14 April 2000)
changed the manual a bit
1.6 (1 Feb 2000)
some changes for Borland C++
Real_timer.h reorganized a bit
1.5 CGAL_CLIB_STD added at a few places
1.4 (20 Sept 1999)
endl 's removed
1.3 (17 Sept 1999)
added std:: to cerr
1.2 (13 Sept 1999)
Changes for Visual C++; uses _ftime on this platform for Real_timer
1.1 (05 Mar 1999)
Standard headers, std namespace and CGAL namespace.
This new package is spawned from the old Support_LK package
1.18 (07 Oct 1998). Timer.h and Real_timer.h are here separated
in their own package to reflect that they have their own chapter
in the manual.

View File

@ -0,0 +1 @@
Timer for user and real-time.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
% +------------------------------------------------------------------------+
% | CGAL Reference Manual: main.tex
% +------------------------------------------------------------------------+
% | Timer for CGAL
% |
% | 04.03.1999 Lutz Kettner
% +------------------------------------------------------------------------+
\input{timer}
%% EOF %%

View File

@ -0,0 +1,129 @@
% +------------------------------------------------------------------------+
% | CGAL Reference Manual: timer.tex
% +------------------------------------------------------------------------+
\ccParDims
\chapter{Timer}
\label{chapterTimer}
\ccChapterAuthor{Lutz Kettner, Matthias B\"asken}
\section{Introduction}
This chapter decribes classes for measuring user process time and real time.
\begin{ccRefClass}{Timer}
\ccSection{A Timer for User-Process Time}
\ccDefinition
\ccCreationVariable{t}
A timer \ccVar\ of type \ccRefName\ is an object with a state. It is
either {\em running\/} or it is {\em stopped}. The state is controlled
with \ccStyle{t.start()} and \ccStyle{t.stop()} . The timer counts the
time elapsed since its creation or last reset. It counts only the time
where it is in the running state. The time information is given in seconds.
The timer counts also the number of intervals it was running, i.e. it
counts the number of calls of the \ccc{start()} member function since the
last reset. If the reset occures while the timer is running it counts as the
first interval.
\ccInclude{CGAL/Timer.h}
\ccCreation
\ccSetThreeColumns{Timer&}{t.is_running();}{}
\ccPropagateThreeToTwoColumns
%\ccSetTwoColumns{Timer t( Timer r);}{}
\ccConstructor{Timer();}{state is {\em stopped.}}
\ccOperations
\ccMethod{void start();}{\ccPrecond state is {\em stopped}.}
\ccGlue
\ccMethod{void stop ();}{\ccPrecond state is {\em running}.}
\ccGlue
\ccMethod{void reset();}{reset timer to zero. The state is unaffected.}
\ccGlue
\ccMethod{bool is_running();}{\ccc{true} if the current state is running.}
\ccMethod{double time();}{user process time in seconds.}
\ccGlue
\ccMethod{int intervals();}{number of start/stop-intervals since
the last reset.}
\ccGlue
\ccMethod{double precision();}{smallest possible time step in seconds.}
\ccGlue
\ccMethod{double max();}{maximal representable time in seconds.}
\ccImplementation
The timer class is based in the C function \ccStyle{std::clock(\ldots)}
which measures the user and system times of the current process and
its subprocesses. The time granularity is reasonable fine with
currently 10 ms on IRIX and Solaris. However the counter wraps around
after only about 36 minutes. On Solaris machines the man page states
that the timer could fail. In that case an error message is printed
and the program aborted.
\end{ccRefClass}
% +----------------------------------------------------------+
\begin{ccRefClass}{Real_timer}
\ccSection{A Timer Measuring Real-Time}
\ccDefinition
\ccCreationVariable{t}
A timer \ccVar\ of type \ccRefName\ is an object with a state. It is
either {\em running\/} or it is {\em stopped}. The state is controlled
with \ccStyle{t.start()} and \ccStyle{t.stop()} . The timer counts the
time elapsed since its creation or last reset. It counts only the time
where it is in the running state. The time information is given in seconds.
The timer counts also the number of intervals it was running, i.e. it
counts the number of calls of the \ccc{start()} member function since the
last reset. If the reset occures while the timer is running it counts as the
first interval.
\ccInclude{CGAL/Real_timer.h}
\ccCreation
\ccSetThreeColumns{Real_timer&}{t.is_running();}{}
\ccPropagateThreeToTwoColumns
%\ccSetTwoColumns{Timer t( Timer r);}{}
\ccConstructor{Real_timer();}{state is {\em stopped.}}
\ccOperations
\ccMethod{void start();}{\ccPrecond state is {\em stopped}.}
\ccGlue
\ccMethod{void stop ();}{\ccPrecond state is {\em running}.}
\ccGlue
\ccMethod{void reset();}{reset timer to zero. The state is unaffected.}
\ccGlue
\ccMethod{bool is_running();}{\ccc{true} if the current state is running.}
\ccMethod{double time();}{real time in seconds.}
\ccGlue
\ccMethod{int intervals();}{number of start/stop-intervals since
the last reset.}
\ccGlue
\ccMethod{double precision();}{smallest possible time step in seconds; returns -1 if not available.}
\ccGlue
\ccMethod{double max();}{maximal representable time in seconds.}
\ccImplementation
The timer class is based in the C function \ccStyle{gettimeofday(\ldots)} on UNIX systems and
\ccStyle{_ftime(\ldots)} on MS Visual C++.
\end{ccRefClass}
% +--------------------------------------------------------+
% restore default column and paragraph layout
\ccParDims
% EOF

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
% +------------------------------------------------------------------------+
% | CGAL Reference Manual: main.tex
% +------------------------------------------------------------------------+
% | Timer for CGAL
% |
% | 04.03.1999 Lutz Kettner
% +------------------------------------------------------------------------+
\input{timer}
%% EOF %%

View File

@ -0,0 +1,129 @@
% +------------------------------------------------------------------------+
% | CGAL Reference Manual: timer.tex
% +------------------------------------------------------------------------+
\ccParDims
\chapter{Timer}
\label{chapterTimer}
\ccChapterAuthor{Lutz Kettner, Matthias B\"asken}
\section{Introduction}
This chapter decribes classes for measuring user process time and real time.
\begin{ccRefClass}{Timer}
\ccSection{A Timer for User-Process Time}
\ccDefinition
\ccCreationVariable{t}
A timer \ccVar\ of type \ccRefName\ is an object with a state. It is
either {\em running\/} or it is {\em stopped}. The state is controlled
with \ccStyle{t.start()} and \ccStyle{t.stop()} . The timer counts the
time elapsed since its creation or last reset. It counts only the time
where it is in the running state. The time information is given in seconds.
The timer counts also the number of intervals it was running, i.e. it
counts the number of calls of the \ccc{start()} member function since the
last reset. If the reset occures while the timer is running it counts as the
first interval.
\ccInclude{CGAL/Timer.h}
\ccCreation
\ccSetThreeColumns{Timer&}{t.is_running();}{}
\ccPropagateThreeToTwoColumns
%\ccSetTwoColumns{Timer t( Timer r);}{}
\ccConstructor{Timer();}{state is {\em stopped.}}
\ccOperations
\ccMethod{void start();}{\ccPrecond state is {\em stopped}.}
\ccGlue
\ccMethod{void stop ();}{\ccPrecond state is {\em running}.}
\ccGlue
\ccMethod{void reset();}{reset timer to zero. The state is unaffected.}
\ccGlue
\ccMethod{bool is_running();}{\ccc{true} if the current state is running.}
\ccMethod{double time();}{user process time in seconds.}
\ccGlue
\ccMethod{int intervals();}{number of start/stop-intervals since
the last reset.}
\ccGlue
\ccMethod{double precision();}{smallest possible time step in seconds.}
\ccGlue
\ccMethod{double max();}{maximal representable time in seconds.}
\ccImplementation
The timer class is based in the C function \ccStyle{std::clock(\ldots)}
which measures the user and system times of the current process and
its subprocesses. The time granularity is reasonable fine with
currently 10 ms on IRIX and Solaris. However the counter wraps around
after only about 36 minutes. On Solaris machines the man page states
that the timer could fail. In that case an error message is printed
and the program aborted.
\end{ccRefClass}
% +----------------------------------------------------------+
\begin{ccRefClass}{Real_timer}
\ccSection{A Timer Measuring Real-Time}
\ccDefinition
\ccCreationVariable{t}
A timer \ccVar\ of type \ccRefName\ is an object with a state. It is
either {\em running\/} or it is {\em stopped}. The state is controlled
with \ccStyle{t.start()} and \ccStyle{t.stop()} . The timer counts the
time elapsed since its creation or last reset. It counts only the time
where it is in the running state. The time information is given in seconds.
The timer counts also the number of intervals it was running, i.e. it
counts the number of calls of the \ccc{start()} member function since the
last reset. If the reset occures while the timer is running it counts as the
first interval.
\ccInclude{CGAL/Real_timer.h}
\ccCreation
\ccSetThreeColumns{Real_timer&}{t.is_running();}{}
\ccPropagateThreeToTwoColumns
%\ccSetTwoColumns{Timer t( Timer r);}{}
\ccConstructor{Real_timer();}{state is {\em stopped.}}
\ccOperations
\ccMethod{void start();}{\ccPrecond state is {\em stopped}.}
\ccGlue
\ccMethod{void stop ();}{\ccPrecond state is {\em running}.}
\ccGlue
\ccMethod{void reset();}{reset timer to zero. The state is unaffected.}
\ccGlue
\ccMethod{bool is_running();}{\ccc{true} if the current state is running.}
\ccMethod{double time();}{real time in seconds.}
\ccGlue
\ccMethod{int intervals();}{number of start/stop-intervals since
the last reset.}
\ccGlue
\ccMethod{double precision();}{smallest possible time step in seconds; returns -1 if not available.}
\ccGlue
\ccMethod{double max();}{maximal representable time in seconds.}
\ccImplementation
The timer class is based in the C function \ccStyle{gettimeofday(\ldots)} on UNIX systems and
\ccStyle{_ftime(\ldots)} on MS Visual C++.
\end{ccRefClass}
% +--------------------------------------------------------+
% restore default column and paragraph layout
\ccParDims
% EOF

View File

@ -0,0 +1,190 @@
// ======================================================================
//
// Copyright (c) 1997 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------
//
// release :
// release_date : 2000, August 11
//
// file : include/CGAL/Real_timer.h
// package : Timer (1.8)
// maintainer : Matthias Baesken <baesken@informatik.uni-trier.de>
// revision : 1.8
// revision_date : 11 August 2000
// author(s) : Lutz Kettner <kettner@inf.ethz.ch>
// Matthias Baesken <baesken@informatik.uni-halle.de>
// coordinator : INRIA, Sophia Antipolis
//
// A timer class to measure real-time.
// ======================================================================
#ifndef CGAL_REAL_TIMER_H
#define CGAL_REAL_TIMER_H 1
#ifndef CGAL_BASIC_H
#include <CGAL/basic.h>
#endif
#if defined (_MSC_VER)
#define CGAL_PROTECT_SYS_TIME_H
#include <sys/timeb.h>
#include <sys/types.h>
#endif
#if defined (__BORLANDC__)
#define CGAL_PROTECT_SYS_TIME_H
#include <sys/timeb>
#include <ctype>
#endif
// used for gettimeofday()
#ifndef CGAL_PROTECT_SYS_TIME_H
#include <sys/time.h>
#define CGAL_PROTECT_SYS_TIME_H
#endif // CGAL_PROTECT_SYS_TIME_H
CGAL_BEGIN_NAMESPACE
// SECTION: A Timer Measuring Real-Time
// ========================================================================
//
// DEFINITION
//
// A timer `t' of type Real_timer is an object with a state. It is
// either running or it is stopped. The state is controlled with
// `t.start()' and `t.stop()' . The timer counts the time elapsed since
// its creation or last reset. It counts only the time where it is in the
// running state. The time information is given in seconds.
class Real_timer {
private:
#if !defined (_MSC_VER) && !defined(__BORLANDC__)
typedef struct timeval Timetype;
#else
#if defined (_MSC_VER)
typedef struct _timeb Timetype; //MSC
#else
typedef struct timeb Timetype; //Borland
#endif
#endif
const inline int get_time(Timetype* t) const;
const inline void report_err() const;
const inline double recalc_time(const Timetype& t) const;
double elapsed;
Timetype started;
int interv;
bool running;
double eps;
public:
Real_timer() : elapsed(0), interv(0), running(false) {}
void start();
void stop ();
void reset();
bool is_running() const { return running; }
double time() const;
int intervals() const { return interv; }
double precision() const
{
return -1;
// change it ...
}
double max() const { return double(INT_MAX);}
};
/*****************************************************************************/
// private member functions.
// all the platform-specific functions are encapsulated here.
const inline int Real_timer::get_time(Timetype* t) const {
#if !defined(_MSC_VER) && !defined(__BORLANDC__)
return gettimeofday( t, NULL);
#else
#if defined (_MSC_VER)
_ftime(t);
#else
ftime(t);
#endif
return 0;
#endif
}
const inline void Real_timer::report_err() const {
#if !defined (_MSC_VER) && !defined(__BORLANDC__)
std::cerr << "Real_timer error: gettimeofday() returned -1.\n"
<< std::endl;
CGAL_CLIB_STD::abort();
#else
std::cout << "Real_timer error!.\n" << std::endl;
#endif
}
const inline double Real_timer::recalc_time(const Timetype& t) const {
#if !defined(_MSC_VER) && !defined(__BORLANDC__)
return double(t.tv_sec - started.tv_sec)
+ double(t.tv_usec - started.tv_usec) / 1000000;
#else
return ((double)(t.time - started.time))
+ ((double)(t.millitm - started.millitm))/1000.0;
#endif
}
// Member functions Real_timer
// ================================
inline void Real_timer::start() {
CGAL_assertion( ! running);
int res=0;
res = get_time(&started);
if ( res < 0) report_err();
running = true;
++ interv;
}
inline void Real_timer::stop() {
CGAL_assertion(running);
Timetype t;
int res=0;
res = get_time(&t);
if ( res < 0) report_err();
elapsed += recalc_time(t);
running = false;
}
inline void Real_timer::reset() {
interv = 0;
elapsed = 0;
if (running) {
int res = 0;
res = get_time(&started);
if ( res < 0) report_err();
++ interv;
}
}
inline double Real_timer::time() const {
if (running) {
Timetype t;
int res = 0;
res = get_time(&t);
if ( res < 0) report_err();
return elapsed + recalc_time(t);
}
return elapsed;
}
CGAL_END_NAMESPACE
#endif // CGAL_REAL_TIMER_H //
// EOF //

View File

@ -0,0 +1,128 @@
// ======================================================================
//
// Copyright (c) 1997 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------
//
// release :
// release_date : 2000, August 11
//
// file : include/CGAL/Timer.h
// package : Timer (1.8)
// maintainer : Matthias Baesken <baesken@informatik.uni-trier.de>
// revision : 1.8
// revision_date : 11 August 2000
// author(s) : Lutz Kettner <kettner@inf.ethz.ch>
// Matthias Baesken <baesken@informatik.uni-halle.de>
// coordinator : INRIA, Sophia Antipolis
//
// A timer class to measure cpu time of user-processes.
// ======================================================================
#ifndef CGAL_TIMER_H
#define CGAL_TIMER_H 1
#ifndef CGAL_BASIC_H
#include <CGAL/basic.h>
#endif
#ifndef CGAL_PROTECT_CSTDLIB
#include <cstdlib>
#define CGAL_PROTECT_CSTDLIB
#endif
#ifndef CGAL_PROTECT_CLIMITS
#include <climits>
#define CGAL_PROTECT_CLIMITS
#endif
// used for clock()
#ifndef CGAL_PROTECT_CTIME
#include <ctime>
#define CGAL_PROTECT_CTIME
#endif
CGAL_BEGIN_NAMESPACE
// SECTION: A Timer for User-Process Time
// ========================================================================
//
// DEFINITION
//
// A timer `t' of type Timer is an object with a state. It is either
// running or it is stopped. The state is controlled with `t.start()'
// and `t.stop()'. The timer counts the time elapsed since its creation
// or last reset. It counts only the time where it is in the running
// state. The time information is given in seconds.
class Timer {
private:
CGAL_CLIB_STD::clock_t elapsed;
CGAL_CLIB_STD::clock_t started;
int interv;
bool running;
public:
Timer() : elapsed(0), started(0), interv(0), running(false) {}
void start();
void stop ();
void reset();
bool is_running() const { return running; }
double time() const;
int intervals() const { return interv; }
double precision() const { return 0.01; }
double max() const { return 2146.0;}
};
/*****************************************************************************/
// Member functions Timer
// ===========================
inline void Timer::start() {
CGAL_assertion( ! running);
started = CGAL_CLIB_STD::clock();
if (started == (CGAL_CLIB_STD::clock_t)-1) {
// possible on Solaris according to man-page
#if defined (_MSC_VER)
std::cout << "Timer error: CGAL_CLIB_STD::clock() returned -1.\n";
#else
std::cerr << "Timer error: CGAL_CLIB_STD::clock() returned -1.\n";
#endif
CGAL_CLIB_STD::abort();
}
running = true;
++ interv;
}
inline void Timer::stop() {
CGAL_assertion( running);
elapsed += CGAL_CLIB_STD::clock() - started;
running = false;
}
inline void Timer::reset() {
interv = 0;
elapsed = 0;
if (running) {
started = CGAL_CLIB_STD::clock();
++ interv;
}
}
inline double Timer::time() const {
if (running) {
return double( elapsed + CGAL_CLIB_STD::clock() - started) / CLOCKS_PER_SEC;
}
return double(elapsed) / CLOCKS_PER_SEC;
}
CGAL_END_NAMESPACE
#endif // CGAL_TIMER_H //
// EOF //

View File

@ -0,0 +1,8 @@
Timer Package
---------------------------------------------------------------------
- CGAL/Timer.h Timer classes for user-process time.
- CGAL/Real_timer.h Timer class for real-time.
- test/Timer/test_timer.C Test program for both timer classes.
Lutz Kettner

View File

@ -0,0 +1,73 @@
#! /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="cat $1.cin | $COMMAND"
fi
echo "Executing $1 ... "
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 test_timer
fi

View File

@ -0,0 +1,88 @@
// ============================================================================
//
// Copyright (c) 1997 The CGAL Consortium
//
// This software and related documentation is part of an INTERNAL release
// of the Computational Geometry Algorithms Library (CGAL). It is not
// intended for general use.
//
// ----------------------------------------------------------------------------
//
// release : $CGAL_Revision: $
// release_date : $CGAL_Date: $
//
// file : test_timer.C
// chapter : $CGAL_Chapter: Timer $
// package : $CGAL_Package: Timer 1.4 (20 Sept 1999) $
// source : test_timer.C
// revision : $Revision$
// revision_date : $Date$
// author(s) : Lutz Kettner <kettner@inf.ethz.ch>
// Matthias Baesken <baesken@informatik.uni-halle.de>
// coordinator : INRIA, Sophia Antipolis
//
// test Timer.h and real_timer.h
// ============================================================================
#include <CGAL/basic.h>
#include <CGAL/Timer.h>
#include <CGAL/Real_timer.h>
void test_timer() {
CGAL::Timer t;
CGAL_assertion( ! t.is_running());
t.start();
CGAL_assertion( t.is_running());
t.reset();
CGAL_assertion( t.is_running());
t.stop();
CGAL_assertion( ! t.is_running());
CGAL_assertion( t.time() >= 0.0);
std::cout << t.time() << "\n";
CGAL_assertion( t.intervals() == 1);
CGAL_assertion( t.precision() >= 0.0);
std::cout << t.precision() << "\n";
CGAL_assertion( t.max() > 0.0);
}
void test_real_timer() {
CGAL::Real_timer t;
CGAL_assertion( ! t.is_running());
t.start();
CGAL_assertion( t.is_running());
t.reset();
CGAL_assertion( t.is_running());
t.stop();
CGAL_assertion( ! t.is_running());
CGAL_assertion( t.time() >= 0.0);
std::cout << t.time() << "\n";
CGAL_assertion( t.intervals() == 1);
CGAL_assertion( t.max() > 0.0);
}
int main(){
test_timer();
test_real_timer();
CGAL::Real_timer Tm;
CGAL::Timer Tm2;
Tm.start();
Tm2.start();
int i1,i2;
double p;
std::cout << "\n";
for (i1=0;i1<5;i1++) {
for (i2=0;i2<800000;i2++) p=p+1.0 ;
std::cout << Tm.time() << "\n";
}
std::cout << "\n";
for (i1=0;i1<5;i1++) {
for (i2=0;i2<800000;i2++) p=p+1.0 ;
std::cout << Tm2.time() << "\n";
}
std::cout << "\n";
return 0;
}
// EOF //

2
Packages/Timer/version Normal file
View File

@ -0,0 +1,2 @@
1.8 (11 August 2000)
maintainer: Matthias Baesken <baesken@informatik.uni-trier.de>