Example code cleanups.

This commit is contained in:
Sylvain Pion 2001-06-22 06:58:08 +00:00
parent 1742890831
commit 2b5e820a30
4 changed files with 41 additions and 107 deletions

View File

@ -1,3 +1,5 @@
2.2.16 Example code cleanups.
2.2.15 Small corrections in documentation
2.2.13 Hans Tangelder adapted style of documentation by

View File

@ -6,38 +6,30 @@
* Iddo Hanniel
\*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
//might be needed when compiling with g++-2.7.2
//#ifdef __GNUG__
//#include <typeinfo>
//#endif /* __GNUG__ */
#include <CGAL/config.h>
#include <CGAL/Cartesian.h>
#include <iostream>
#include <ctime>
#include <cassert>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_2.h>
#include <list>
#include <CGAL/kdtree_d.h>
#include <CGAL/kdtree_d.h>
typedef CGAL::Point_2<CGAL::Cartesian<double> > point;
typedef CGAL::Cartesian<double> K;
typedef K::Point_2 point;
typedef CGAL::Kdtree_interface_2d<point> kd_interface;
typedef CGAL::Kdtree_d<kd_interface> kd_tree;
typedef kd_tree::Box box;
typedef std::list<point> points_list;
typedef CGAL::Kdtree_d<kd_interface> kd_tree;
typedef kd_tree::Box box;
typedef std::list<point> points_list;
int main()
int main()
{
CGAL::Kdtree_d<kd_interface> tree(2);
points_list l , res;
CGAL::Kdtree_d<kd_interface> tree(2);
points_list l, res;
srand( (unsigned)time(NULL) );
std::cout << "Insering evenly 81 points in the square (0,0)-(10,10) ...\n\n" ;
std::cout << "Insering evenly 81 points in the square (0,0)-(10,10) ...\n\n";
for (int i=1; i<10; i++)
for (int j=1; j<10; j++)
{
@ -48,13 +40,12 @@ int main()
// building the tree for the random points
tree.build( l );
//checking validity
// checking validity
if ( ! tree.is_valid() )
tree.dump();
assert( tree.is_valid() );
//defining and searching the box r
// Defining and searching the box r
double lx,ly,rx,ry;
std::cout << "Define your query square.\nEnter left x coordinate: " ;
std::cin >> lx ;
@ -76,12 +67,5 @@ int main()
tree.delete_all();
return 0;
}

View File

@ -6,44 +6,33 @@
* Iddo Hanniel
\*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
//might be needed when compiling with g++-2.7.2
//#ifdef __GNUG__
//#include <typeinfo>
//#endif /* __GNUG__ */
#include <CGAL/config.h>
#include <CGAL/Cartesian.h>
#include <iostream>
#include <ctime>
#include <cassert>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_3.h>
#include <list>
#include <CGAL/kdtree_d.h>
typedef CGAL::Point_3<CGAL::Cartesian<double> > point;
typedef CGAL::Cartesian<double> K;
typedef K::Point_3 point;
typedef CGAL::Kdtree_interface_3d<point> kd_interface;
typedef CGAL::Kdtree_d<kd_interface> kd_tree;
typedef kd_tree::Box box;
typedef std::list<point> points_list;
typedef CGAL::Kdtree_d<kd_interface> kd_tree;
typedef kd_tree::Box box;
typedef std::list<point> points_list;
//RANDOM FUNCTIONS
// dblRand - a random number between 0..1
#ifndef RAND_MAX
#define RAND_MAX 0x7fffffff
#endif // RAND_MAX
#endif
static inline double dblRand( void )
inline double dblRand( void )
{
return (double)rand() / (double)RAND_MAX;
return (double)rand() / (double)RAND_MAX;
}
void random_points( int num, points_list &l )
{
double x,y,z;
@ -56,13 +45,10 @@ void random_points( int num, points_list &l )
point p(x,y,z);
l.push_front(p);
}
}
int main()
int main()
{
CGAL::Kdtree_d<kd_interface> tree(3);
srand( (unsigned)time(NULL) );
@ -72,21 +58,19 @@ int main()
points_list l , res;
random_points( 30, l);
std::cout << "Listing of random points:\n" ;
std::copy (l.begin(),l.end(),std::ostream_iterator<point>(std::cout,"\n") );
std::cout << std::endl;
// building the tree for the random points
// Building the tree for the random points
tree.build( l );
//checking validity
// Checking validity
if ( ! tree.is_valid() )
tree.dump();
assert( tree.is_valid() );
//searching the box r
// Searching the box r
box r(point(2,2,2), point(7,7,7) ,3);
tree.search( std::back_inserter( res ), r );
@ -96,15 +80,5 @@ int main()
tree.delete_all();
return 0;
return 0;
}

View File

@ -7,23 +7,14 @@
* Iddo Hanniel
\*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
//might be needed when compiling with g++-2.7.2
//#ifdef __GNUG__
//#include <typeinfo>
//#endif /* __GNUG__ */
#include <CGAL/config.h>
#include <CGAL/Cartesian.h>
#include <iostream>
#include <ctime>
#include <cassert>
#include <CGAL/Cartesian.h>
#include <CGAL/Point_3.h>
#include <list>
#include <CGAL/kdtree_d.h>
#include <CGAL/kdtree_d.h>
template <int DIM>
class Point_float_d
@ -76,7 +67,6 @@ std::ostream &operator<<(std::ostream &os, const Point_float_d<DIM> &p)
std::cout << ")";
return os;
}
typedef Point_float_d<4> point;
typedef CGAL::Kdtree_interface<point> kd_interface;
@ -84,19 +74,17 @@ typedef CGAL::Kdtree_d<kd_interface> kd_tree;
typedef kd_tree::Box box;
typedef std::list<point> points_list;
//RANDOM FUNCTIONS
// dblRand - a random number between 0..1
#ifndef RAND_MAX
#define RAND_MAX 0x7fffffff
#endif // RAND_MAX
#endif
static inline double dblRand( void )
inline double dblRand( void )
{
return (double)rand() / (double)RAND_MAX;
}
void random_points( int num, points_list &l, int DIM)
{
double x;
@ -113,10 +101,8 @@ void random_points( int num, points_list &l, int DIM)
}
}
int main()
int main()
{
CGAL::Kdtree_d<kd_interface> tree(3);
srand( (unsigned)time(NULL) );
@ -126,21 +112,19 @@ int main()
points_list l , res;
random_points( 30, l , 4);
std::cout << "Listing of random points:\n" ;
std::copy (l.begin(),l.end(),std::ostream_iterator<point>(std::cout,"\n") );
std::cout << std::endl;
// building the tree for the random points
// Building the tree for the random points
tree.build( l );
//checking validity
// Checking validity
if ( ! tree.is_valid() )
tree.dump();
assert( tree.is_valid() );
//searching the box r
// Searching the box r
point p,q;
for (int k=0;k<4;k++)
{
@ -157,16 +141,6 @@ int main()
std::cout << std::endl;
tree.delete_all();
return 0;
return 0;
}