From 1c355ef42afd4a94571940cd5d85c797b9628d7b Mon Sep 17 00:00:00 2001 From: Waqar Khan Date: Fri, 7 Mar 2014 16:13:44 +0100 Subject: [PATCH] 1. "Snap_rounding_traits_2.h" "Snap_rounding_kd_2.h" "Kd_tree.h" "snap_rounding_data.cpp", Changed the File header signature to match the templated signatures. 2. Made the required changes in the concepts i.e. in "Snap_rounding_2/doc/Snap_rounding_2/Concepts/SnapRoundingTraits_2.h" 3. Added documentation for the reserve() method of Kd_tree 4. Deleted the un maintained olk kd_tree package --- .../Concepts/SnapRoundingTraits_2.h | 20 + .../Snap_rounding_2/snap_rounding_data.cpp | 22 +- .../include/CGAL/Snap_rounding_kd_2.h | 23 +- .../include/CGAL/Snap_rounding_traits_2.h | 26 +- .../doc/Spatial_searching/CGAL/Kd_tree.h | 6 + Spatial_searching/include/CGAL/Kd_tree.h | 25 +- kdtree/dont_submit | 1 - kdtree/examples/kdtrees/example1.cin | 5 - kdtree/examples/kdtrees/example1.cpp | 80 -- kdtree/examples/kdtrees/example2.cpp | 93 -- kdtree/examples/kdtrees/example3.cpp | 155 --- kdtree/examples/kdtrees/example4.cpp | 86 -- kdtree/include/CGAL/kdtree_d.h | 1060 ----------------- kdtree/package_info/kdtree/copyright | 1 - kdtree/package_info/kdtree/description.txt | 1 - kdtree/package_info/kdtree/license.txt | 1 - .../package_info/kdtree/long_description.txt | 11 - kdtree/package_info/kdtree/maintainer | 1 - 18 files changed, 75 insertions(+), 1542 deletions(-) delete mode 100644 kdtree/dont_submit delete mode 100644 kdtree/examples/kdtrees/example1.cin delete mode 100644 kdtree/examples/kdtrees/example1.cpp delete mode 100644 kdtree/examples/kdtrees/example2.cpp delete mode 100644 kdtree/examples/kdtrees/example3.cpp delete mode 100644 kdtree/examples/kdtrees/example4.cpp delete mode 100644 kdtree/include/CGAL/kdtree_d.h delete mode 100644 kdtree/package_info/kdtree/copyright delete mode 100644 kdtree/package_info/kdtree/description.txt delete mode 100644 kdtree/package_info/kdtree/license.txt delete mode 100644 kdtree/package_info/kdtree/long_description.txt delete mode 100644 kdtree/package_info/kdtree/maintainer diff --git a/Snap_rounding_2/doc/Snap_rounding_2/Concepts/SnapRoundingTraits_2.h b/Snap_rounding_2/doc/Snap_rounding_2/Concepts/SnapRoundingTraits_2.h index a4f44c9912c..ef9cbdd51d1 100644 --- a/Snap_rounding_2/doc/Snap_rounding_2/Concepts/SnapRoundingTraits_2.h +++ b/Snap_rounding_2/doc/Snap_rounding_2/Concepts/SnapRoundingTraits_2.h @@ -41,6 +41,11 @@ Models the concept `SRTraits_2::IsoRectangle_2` */ typedef unspecified_type Iso_rectangle_2; +/*! +Models the concept `SearchTraits::Cartesian_const_iterator_2` +*/ +typedef unspecified_type Cartesian_const_iterator_2; + /// @} /// \name Functor Types @@ -93,6 +98,21 @@ Models the concept `SRTraits_2::MinkowskiSumWithPixel_2`. */ typedef unspecified_type Minkowski_sum_with_pixel_2; +/*! +Models the concept `ArrTraits::ConstructMinVertex_2`. +*/ +typedef unspecified_type Construct_min_vertex_2; + +/*! +Models the concept `ArrTraits::ConstructMaxVertex_2`. +*/ +typedef unspecified_type Construct_max_vertex_2; + +/*! +Models the concept `SearchTraits::Construct_cartesian_const_iterator_2`. +*/ +typedef unspecified_type Construct_cartesian_const_iterator_2; + /// @} /// \name Accessing Functor Objects diff --git a/Snap_rounding_2/examples/Snap_rounding_2/snap_rounding_data.cpp b/Snap_rounding_2/examples/Snap_rounding_2/snap_rounding_data.cpp index 52a27bd492d..73354ee89b7 100644 --- a/Snap_rounding_2/examples/Snap_rounding_2/snap_rounding_data.cpp +++ b/Snap_rounding_2/examples/Snap_rounding_2/snap_rounding_data.cpp @@ -1,21 +1,21 @@ -// Copyright (c) 1999 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. +// Copyright 2009,2014 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. // -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // // $URL$ // $Id$ -// +// +// // author(s) : Waqar Khan diff --git a/Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h b/Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h index 9c43b6eb466..feaa2636430 100755 --- a/Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h +++ b/Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h @@ -1,14 +1,14 @@ -// Copyright (c) 1999 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. +// Copyright (c) 2001 Tel-Aviv University (Israel). +// 2009,2014 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. // -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. @@ -17,7 +17,8 @@ // $Id$ // // -// author(s) : Eli Packer , Waqar Khan +// author(s) : Eli Packer , +// Waqar Khan #ifndef CGAL_SNAP_ROUNDING_KD_2_H #define CGAL_SNAP_ROUNDING_KD_2_H diff --git a/Snap_rounding_2/include/CGAL/Snap_rounding_traits_2.h b/Snap_rounding_2/include/CGAL/Snap_rounding_traits_2.h index 9ac8530e9af..b475ad5dedf 100755 --- a/Snap_rounding_2/include/CGAL/Snap_rounding_traits_2.h +++ b/Snap_rounding_2/include/CGAL/Snap_rounding_traits_2.h @@ -1,23 +1,24 @@ -// Copyright (c) 1999 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. +// Copyright (c) 2001 Tel-Aviv University (Israel). +// 2009,2014 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. // -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // // $URL$ // $Id$ +// // -// -// author(s) : Eli Packer , Waqar Khan +// author(s) : Eli Packer , +// Waqar Khan #ifndef CGAL_SNAP_ROUNDING_2_TRAITS_H #define CGAL_SNAP_ROUNDING_2_TRAITS_H @@ -201,7 +202,6 @@ public: return k.construct_iso_rectangle_2_object(); } - }; } //namespace CGAL diff --git a/Spatial_searching/doc/Spatial_searching/CGAL/Kd_tree.h b/Spatial_searching/doc/Spatial_searching/CGAL/Kd_tree.h index 7303ff40aa0..e182425602b 100644 --- a/Spatial_searching/doc/Spatial_searching/CGAL/Kd_tree.h +++ b/Spatial_searching/doc/Spatial_searching/CGAL/Kd_tree.h @@ -105,6 +105,12 @@ The value type of the `InputIterator` must be `Point_d`. */ template void insert(InputIterator first, InputIterator beyond); + +/* +Reserve the memory for the 'Points' vector to the 'size' +*/ +void reserve(size_t size); + /*! Reports the points that are approximately contained by `q`. The types `FuzzyQueryItem::Point_d` and `Point_d` must be equivalent. diff --git a/Spatial_searching/include/CGAL/Kd_tree.h b/Spatial_searching/include/CGAL/Kd_tree.h index a8549b9013a..bbd62f1f310 100644 --- a/Spatial_searching/include/CGAL/Kd_tree.h +++ b/Spatial_searching/include/CGAL/Kd_tree.h @@ -1,22 +1,23 @@ -// Copyright (c) 1999 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. +// Copyright (c) 2002,2011 Utrecht University (The Netherlands). +// 2009,2014 Max-Planck-Institute Saarbruecken (Germany) +// All rights reserved. // -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // // $URL$ // $Id$ -// -// Author(s) : Hans Tangelder (), Waqar Khan +// +// Author(s) : Hans Tangelder (), +// : Waqar Khan #ifndef CGAL_KD_TREE_H #define CGAL_KD_TREE_H diff --git a/kdtree/dont_submit b/kdtree/dont_submit deleted file mode 100644 index 1e107f52e47..00000000000 --- a/kdtree/dont_submit +++ /dev/null @@ -1 +0,0 @@ -examples diff --git a/kdtree/examples/kdtrees/example1.cin b/kdtree/examples/kdtrees/example1.cin deleted file mode 100644 index ba884a49aa2..00000000000 --- a/kdtree/examples/kdtrees/example1.cin +++ /dev/null @@ -1,5 +0,0 @@ -3 -3 -7 -7 - diff --git a/kdtree/examples/kdtrees/example1.cpp b/kdtree/examples/kdtrees/example1.cpp deleted file mode 100644 index af45b7f6b66..00000000000 --- a/kdtree/examples/kdtrees/example1.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 1997 Tel-Aviv University (Israel). -// All rights reserved. -// -// This file is part of an example program for CGAL. This example -// program may be used, distributed and modified without limitation. -// - -/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* - * example1.C - - * Simple example the CGAL KD-tree module. - * - * Written by Sariel Har-Peled - * Iddo Hanniel -\*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ - -#include - -#include -#include -#include -#include -#include -#include - -#include - -typedef CGAL::Cartesian K; -typedef K::Point_2 point; -typedef CGAL::Kdtree_interface_2d kd_interface; -typedef CGAL::Kdtree_d kd_tree; -typedef kd_tree::Box box; -typedef std::list points_list; - -int main() -{ - CGAL::Kdtree_d tree(2); - points_list l, res; - - std::srand( (unsigned)time(NULL) ); - - 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++) - { - point p(i,j); - l.push_front(p); - } - - // building the tree - tree.build( l ); - - // checking validity - if ( ! tree.is_valid() ) - tree.dump(); - assert( tree.is_valid() ); - - // Defining and searching the box r - double lx,ly,rx,ry; - std::cout << "Define your query square.\nEnter left x coordinate: " ; - std::cin >> lx ; - std::cout << "Enter left y coordinate: "; - std::cin >> ly; - std::cout << "Enter right x coordinate: " ; - std::cin >> rx ; - std::cout << "Enter right y coordinate: "; - std::cin >> ry; - std::cout << std::endl; - - box r(point(lx,ly), point(rx,ry) ,2); - - tree.search( std::back_inserter( res ), r ); - - std::cout << "Listing of the points in the square: \n" ; - std::copy (res.begin(),res.end(),std::ostream_iterator(std::cout," \n") ); - std::cout << std::endl; - - tree.delete_all(); - - return 0; -} diff --git a/kdtree/examples/kdtrees/example2.cpp b/kdtree/examples/kdtrees/example2.cpp deleted file mode 100644 index 8584c14eb3a..00000000000 --- a/kdtree/examples/kdtrees/example2.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) 1997 Tel-Aviv University (Israel). -// All rights reserved. -// -// This file is part of an example program for CGAL. This example -// program may be used, distributed and modified without limitation. -// - -/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* - * example2.C - - * Simple example the CGAL KD-tree module. - * - * Written by Sariel Har-Peled - * Iddo Hanniel -\*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ - -#include - -#include -#include -#include -#include -#include -#include - -#include - -typedef CGAL::Cartesian K; -typedef K::Point_3 point; -typedef CGAL::Kdtree_interface_3d kd_interface; -typedef CGAL::Kdtree_d kd_tree; -typedef kd_tree::Box box; -typedef std::list points_list; - -//RANDOM FUNCTIONS -// dblRand - a random number between 0..1 -#ifndef RAND_MAX -#define RAND_MAX 0x7fffffff -#endif - -inline double dblRand( void ) -{ - return (double)std::rand() / (double)RAND_MAX; -} - -void random_points( int num, points_list &l ) -{ - double x,y,z; - - for (int j = 0; j < num; j++) - { - x = dblRand()*10 ; - y = dblRand()*10 ; - z = dblRand()*10 ; - point p(x,y,z); - l.push_front(p); - } -} - -int main() -{ - CGAL::Kdtree_d tree(3); - - std::srand( (unsigned)time(NULL) ); - - std::cout << "Choosing randomly 30 points in the cube (0,0,0)-(10,10,10)\n" ; - - points_list l , res; - random_points( 30, l); - - std::cout << "Listing of random points:\n" ; - std::copy (l.begin(),l.end(),std::ostream_iterator(std::cout,"\n") ); - std::cout << std::endl; - - // Building the tree for the random points - tree.build( l ); - - // Checking validity - if ( ! tree.is_valid() ) - tree.dump(); - assert( tree.is_valid() ); - - // Searching the box r - box r(point(2,2,2), point(7,7,7) ,3); - tree.search( std::back_inserter( res ), r ); - - std::cout << "Listing of the points in the box (2,2,2)-(7,7,7) : \n" ; - std::copy (res.begin(),res.end(),std::ostream_iterator(std::cout,"\n") ); - std::cout << std::endl; - - tree.delete_all(); - - return 0; -} diff --git a/kdtree/examples/kdtrees/example3.cpp b/kdtree/examples/kdtrees/example3.cpp deleted file mode 100644 index 13b2f6509e3..00000000000 --- a/kdtree/examples/kdtrees/example3.cpp +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (c) 1997 Tel-Aviv University (Israel). -// All rights reserved. -// -// This file is part of an example program for CGAL. This example -// program may be used, distributed and modified without limitation. -// - -/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* - * example3.C - - * Simple example the CGAL KD-tree module. - * Example with user defined point_d. - * - * Written by Sariel Har-Peled - * Iddo Hanniel -\*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ - -#include - -#include -#include -#include -#include -#include -#include - -#include - -template -class Point_float_d -{ -private: - double vec[ DIM ]; - -public: - Point_float_d() - { - for ( int ind = 0; ind < DIM; ind++ ) - vec[ ind ] = 0; - } - - int dimension() const - { - return DIM; - } - -//not essential by specification but needed for initializing a general d-point - void set_coord(int k, double x) - { - assert( 0 <= k && k < DIM ); - vec[ k ] = x; - } - - double & operator[](int k) - { - assert( 0 <= k && k < DIM ); - return vec[ k ]; - } - - double operator[](int k) const - { - assert( 0 <= k && k < DIM ); - return vec[ k ]; - } -}; - -// not essential by specification but nice to have -template -std::ostream &operator<<(std::ostream &os, const Point_float_d &p) -{ - std::cout << "("; - for(int i = 0; i < DIM; i++) - { - std::cout << p[i] ; - if (i < p.dimension() - 1) std::cout << ", "; - } - std::cout << ")"; - return os; -} - -typedef Point_float_d<4> point; -typedef CGAL::Kdtree_interface kd_interface; -typedef CGAL::Kdtree_d kd_tree; -typedef kd_tree::Box box; -typedef std::list points_list; - -//RANDOM FUNCTIONS -// dblRand - a random number between 0..1 -#ifndef RAND_MAX -#define RAND_MAX 0x7fffffff -#endif - -inline double dblRand( void ) -{ - return (double)std::rand() / (double)RAND_MAX; -} - -void random_points( int num, points_list &l, int DIM) -{ - double x; - - for (int j = 0; j < num; j++) - { - point p; - for (int i=0; i tree(3); - - std::srand( (unsigned)time(NULL) ); - - std::cout << "Choosing randomly 30 points in the cube (0,0,0)-(10,10,10)\n" ; - - 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(std::cout,"\n") ); - std::cout << std::endl; - - // Building the tree for the random points - tree.build( l ); - - // Checking validity - if ( ! tree.is_valid() ) - tree.dump(); - assert( tree.is_valid() ); - - // Searching the box r - point p,q; - for (int k=0;k<4;k++) - { - p.set_coord(k,2); - q.set_coord(k,8); - } - - box r(p, q, 4); - tree.search( std::back_inserter( res ), r ); - - std::cout << "Listing of the points in the box (2,2,2,2)-(8,8,8,8) : \n" ; - std::copy (res.begin(),res.end(), - std::ostream_iterator(std::cout,"\n") ); - std::cout << std::endl; - - tree.delete_all(); - - return 0; -} diff --git a/kdtree/examples/kdtrees/example4.cpp b/kdtree/examples/kdtrees/example4.cpp deleted file mode 100644 index bc2fc9b0fea..00000000000 --- a/kdtree/examples/kdtrees/example4.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 1997 Tel-Aviv University (Israel). -// All rights reserved. -// -// This file is part of an example program for CGAL. This example -// program may be used, distributed and modified without limitation. -// - -/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* - * example2.C - bench mark - * Simple example the CGAL KD-tree module. - * - * Written by Sariel Har-Peled - * Iddo Hanniel -\*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -typedef CGAL::Cartesian K; -typedef K::Point_3 Point; -typedef CGAL::Kdtree_interface_3d kd_interface; -typedef CGAL::Kdtree_d kd_tree; -typedef kd_tree::Box box; -typedef std::list points_list; - -int main() -{ - CGAL::Kdtree_d tree(3); - CGAL::Timer t; - const int dim=3; - - // const int data_point_number=1000000; - const int data_point_number=10000; - - - - - - - typedef std::list point_list; - point_list data_points,res; - - // get data points - - // add random points of dimension dim to data_points - CGAL::Random Rnd; - // std::cout << "started tstrandom()" << std::endl; - for (int i1=0; i1 -#include -#include -#include -using std::list; // to avoid compiler crash on MSVC++ - -namespace CGAL { - -/*======================================================================= - * Kdtree_interface - - * This is the default interface of point. It assume that PT (the - * point type have the following properties: - * default constructor - * int dimension() - * const coord_type & operator[]( int ) const - * ... operator=( const Pt & ) - copy operator -\*=======================================================================*/ - -template -class Kdtree_interface -{ -public: - typedef PT Point; - - static int dimension( const PT & pnt ) - { - // return pnt.dimensions(); - return pnt.dimension(); - } - - static int compare( int d, const PT & a, const PT & b ) - { - if ( a[ d ] < b[ d ] ) - return -1; - if ( a[ d ] > b[ d ] ) - return 1; - - return 0; - } - static void copy_coord( int d, PT & a, const PT & b ) - { - a[ d ] = b[ d ]; - } -}; - - - -template -class Kdtree_interface_2d -{ -public: - typedef PT Point; - - static int dimension( const PT & pnt ) - { - // return pnt.dimensions(); - return pnt.dimension(); - } - - static int compare( int d, const PT & a, const PT & b ) - { - if ( a[ d ] < b[ d ] ) - return -1; - if ( a[ d ] > b[ d ] ) - return 1; - - return 0; - } - static void copy_coord( int d, PT & a, const PT & b ) - { - if ( d == 0 ) - a = PT( b[ 0 ], a[1] ); - else - if ( d == 1 ) - a = PT( a[ 0 ], b[1] ); - else { - CGAL_error(); - } - } -}; - - -template -class Kdtree_interface_3d -{ -public: - typedef PT Point; - - static int dimension( const PT & pnt ) - { - // return pnt.dimensions(); - return pnt.dimension(); - } - - static int compare( int d, const PT & a, const PT & b ) - { - if ( a[ d ] < b[ d ] ) - return -1; - if ( a[ d ] > b[ d ] ) - return 1; - - return 0; - } - static void copy_coord( int d, PT & a, const PT & b ) - { - if ( d == 0 ) - a = PT( b[ 0 ], a[1], a[ 2 ] ); - else - if ( d == 1 ) - a = PT( a[ 0 ], b[1], a[ 2 ] ); - else - if ( d == 2 ) - a = PT( a[ 0 ], a[1], b[ 2 ] ); - else { - CGAL_error(); - } - } -}; - - -/*========================================================================= - * kdtree_d - - * A the kdtree class. - * - * Remark: The kd-trees allocates all the memory it needs in advance, - * This results in a rather efficient memory management, and a fast - * iplementation. -\*=========================================================================*/ -template -class Kdtree_d -{ - class Plane; - -public: - typedef typename Traits::Point Point; - typedef list List_points; - - - //------------------------------------------------------------------------- - // Extended_Point_d - - // A class for representing an extended d-dimal point: with - // ability to support +/- infinity. Templated by the kd-treee interface - // type. - //------------------------------------------------------------------------- - class ExtPoint - { - private: - class coordinate_type - { - public: - const Point * p_pnt; - int type; - //signed char type; - }; - - coordinate_type * p_arr; - int dim; - Point def_pnt; - - void init( int _dim ) - { - CGAL_precondition( _dim > 0 ); - dim = _dim; - - p_arr = (coordinate_type *)std::malloc( sizeof( coordinate_type ) - * dim ); - //printf( "p_arr(new): %p\n", (void *)p_arr ); - CGAL_assertion( p_arr != NULL ); - - std::memset( p_arr, 0, sizeof( coordinate_type ) * dim ); - } - - public: - enum { MINUS_INFINITY = -1, FINITE = 0, PLUS_INFINITY = 1 }; - - ExtPoint( int _type, int _dim ) - { - CGAL_precondition( _type == MINUS_INFINITY || _type == PLUS_INFINITY ); - init( _dim ); - - for ( int ind = 0; ind < dim; ind++ ) - p_arr[ ind ].type = _type; - } - - ExtPoint() - { - p_arr = NULL; - dim = -1; - } - - ExtPoint( const ExtPoint & p ) - { - init( p.dim ); - - def_pnt = p.def_pnt; - for ( int ind = 0; ind < dim; ind++ ) { - p_arr[ ind ] = p.p_arr[ ind ]; - if ( p.p_arr[ ind ].p_pnt == &p.def_pnt ) - p_arr[ ind ].p_pnt = &def_pnt; - } - } - - ExtPoint & operator=( const ExtPoint & p ) - { - term(); - - init( p.dim ); - - def_pnt = p.def_pnt; - for ( int ind = 0; ind < dim; ind++ ) { - p_arr[ ind ] = p.p_arr[ ind ]; - if ( p.p_arr[ ind ].p_pnt == &p.def_pnt ) - p_arr[ ind ].p_pnt = &def_pnt; - } - - return *this; - } - - ExtPoint( const Point & point, int _dim ) - { - init( _dim ); - - def_pnt = point; - for ( int ind = 0; ind < _dim; ind++ ) { - p_arr[ ind ].p_pnt = &def_pnt; - p_arr[ ind ].type = FINITE; - } - } - - void term() - { - if ( p_arr != NULL ) { - //printf( "a: %p\n", p_arr ); - std::free( p_arr ); - //printf( "_a\n" ); - p_arr = NULL; - } - dim = 0; - } - - ~ExtPoint() - { - term(); - } - - void set_coord( int k, Point & point ) - { - CGAL_precondition( 0 <= k && k < dim ); - - p_arr[ k ].type = FINITE; - //p_arr[ k ].p_pnt = &point; - - Traits::copy_coord( k, def_pnt, point ); - p_arr[ k ].p_pnt = &def_pnt; - } - - void set_coord( int k, const ExtPoint & point ) - { - CGAL_precondition( 0 <= k && k < dim ); - CGAL_precondition( 0 <= k && k < point.dim ); - - p_arr[ k ] = point.p_arr[ k ]; - if ( p_arr[ k ].type == FINITE ) { - Traits::copy_coord( k, def_pnt, *(p_arr[ k ].p_pnt) ); - p_arr[ k ].p_pnt = &def_pnt; - } - } - - int compare( int k, const ExtPoint & point ) const - { - CGAL_precondition( 0 <= k && k < dim ); - // the following does not compile on msvc++... - // coordinate_type & a( p_arr[ k ] ), - // & b( point.p_arr[ k ] ); - coordinate_type & a = p_arr[ k ]; - coordinate_type & b = point.p_arr[ k ]; - - if ( a.type != FINITE ) { - if ( b.type != FINITE ) { - return a.type - b.type; - } else { - return a.type; - } - } else { - if ( b.type != FINITE ) - return -b.type; - else - return Traits::compare( k, *a.p_pnt, *b.p_pnt ); - } - } - - - int compare_vector( const ExtPoint & point ) const - { - int ind, res; - - for ( ind = 0; ind < dim; ind++ ) { - res = compare( ind, point ); - if ( res != 0 ) - return res; - } - - return 0; - } - - int compare( int k, const Point & point ) const - { - CGAL_precondition( 0 <= k && k < dim ); - - // coordinate_type & a( p_arr[ k ] ); - coordinate_type & a = p_arr[ k ]; - - if ( a.type != FINITE ) - return a.type; - else - return Traits::compare( k, *a.p_pnt, point ); - } - - int dimension() const - { - return dim; - } - - int get_coord_status( int d ) const - { - CGAL_precondition( 0 <= d && d < dim ); - - return p_arr[ d ].type; - } - - - const Point * get_coord_point( int d ) const - { - CGAL_precondition( 0 <= d && d < dim ); - - return p_arr[ d ].p_pnt; - } - }; - - - // Box - represents an axis parallel box. - class Box - { - public: - int dim; - ExtPoint left, right; - - private: - friend class Plane; - - ExtPoint & get_vertex( bool f_left ) - { - return f_left? left : right; - } - - public: - // constructors - - //CHECK - Box() - { - } - - Box( const Box & box ) - { - dim = box.dim; - left = box.left; - right = box.right; - } - - - Box( const Point &l, const Point &r, int _dim ) - { - dim = _dim; - left = ExtPoint( l, dim ); - right = ExtPoint( r, dim ); - } - - Box( int _dim ) : left( ExtPoint::MINUS_INFINITY, _dim ), - right( ExtPoint::PLUS_INFINITY, _dim ) - { - dim = _dim; - } - - - // data access - void set_left( Point &l) - { - left = ExtPoint( l, dim ); - }; - - void set_right( Point &r) - { - right = ExtPoint( r, dim ); - } - - const ExtPoint &get_left() const - { - return left; - } - - const ExtPoint &get_right() const - { - return right; - } - - - void set_coord_left( int k, Point & p ) - { - left.set_coord( k, p ); - } - - - void set_coord_right( int k, Point & p ) - { - right.set_coord( k, p ); - } - - - // operations - bool is_in( const Box &o) const - // checks if o is completely inside - { - int dim = left.dimension(); - - for (int i = 0; i < dim; i++) - { - if ( (left.compare(i, o.get_left()) > 0 ) - || (right.compare(i, o.get_right()) < 0 ) ) - return false; - } - - return true; - } - - - bool is_in( const Point & o ) const - // checks if o is completely inside - { - int _dim = left.dimension(); - for (int i = 0; i < _dim; i++) - { - if ( (left.compare( i, o ) > 0 ) || - (right.compare( i, o ) <= 0 ) ) - return false; - } - return true; - } - - - bool is_coord_in_range( int k, const Point & o ) const - // checks if o is completely inside - { - return ( ! ( (left.compare( k, o ) > 0 ) - || (right.compare( k, o ) <= 0 ) ) ); - } - - - bool is_intersect( const Box &o) const - // checks if there is an intersection between o and this - { - int dim = left.dimension(); - for (int i = 0; i < dim; i++) - { - if ( (left.compare(i, o.get_right()) >= 0) || - (right.compare(i, o.get_left()) <= 0) ) - return false; - } - return true; - } - - - // checks if there is an intersection between o and this box - // only in a specific coordinate... - bool is_intersect_in_dim( int d, const Box & o ) const - { - return (! ( (left.compare( d, o.get_right() ) >= 0 ) - || (right.compare( d, o.get_left() ) <= 0) )); - } - - - // checks if there is an intersection between o and this box - // only in a specific coordinate... - bool is_intersect_in_dim_closed( int d, const Box & o ) const - { - return (! ( (left.compare( d, o.get_right() ) > 0 ) - || (right.compare( d, o.get_left() ) < 0) )); - } - - - bool intersect(Box &o) - // intersects this with o. the intersection will be in this - // returns false if intersection is empty - { - int dim = left.dimension(); - for (int i = 0; i < dim; i++) - { - // left is the maximal of the lefts - if (left.compare(i, o.get_left()) == -1) - left.set_coord(i, o.get_left()); - - // right is the minimal of the rights - if (right.compare(i, o.get_right()) == 1) - right.set_coord(i, o.get_right()); - } - return !(is_empty()); - } - - bool is_empty() const - // return true if this is not an interval (left[k] > right[k]) - { - int dim = left.dimension(); - for (int i = 0; i < dim; i++) - { - if (left.compare(i, right) == 1) - return true; - } - return false; - } - - bool is_empty_open() const - // return true if this is not an interval (left[k] > right[k]) - { - int dim = left.dimension(); - for (int i = 0; i < dim; i++) - { - if ( left.compare(i, right) >= 0 ) - return true; - } - return false; - } - - int comp( const Box & o ) const - { - int res; - - res = left.compare_vector( o.left ); - if ( res != 0 ) - return res; - - return right.compare_vector( o.right ); - } - // destructor - needed in ...recursive ... DVP - - ~Box() - { - left.term(); - right.term(); - dim = 0; - } - - }; - - -private: - class Plane - { - private: - int coord; - Point * normal; - bool f_plus; // orientation of half space - // is (0, 0, ... , +inifinity, 0, ..., 0) inside plane - - public: - Plane() - { - normal = NULL; - coord = 0; - } - - Plane( int k, Point & p ) - { - normal = &p; - coord = k; - } - - Plane( const Plane & p ) - { - coord = p.coord; - normal = p.normal; - } - - void dump( void ) - { - std::cout << "(" << coord << ": " << *normal << ")"; - } - - bool is_in( const Point & p ) const - { - int cmp; - - cmp = Traits::compare( coord, p, *normal ); - - if ( ! f_plus ) - cmp = -cmp; - - return cmp >= 0; - } - - void set_plane(int k, Point &p) - { - coord = k; - normal = &p; - //normal->copy( coord, p ); - } - - void split( Box & region, bool f_neg ) - { - ExtPoint * p_p = &(region.get_vertex( ! f_neg )); - - if ( f_neg ) { - if ( p_p->compare( coord, *normal ) > 0 ) - p_p->set_coord( coord, *normal ); - } else - if ( p_p->compare( coord, *normal ) < 0 ) - p_p->set_coord( coord, *normal ); - } - - void orient_half_space( bool f_neg_side ) - { - f_plus = ! f_neg_side; - } - - int get_coord() const - { - return coord; - } - }; - -private: - class Node - { - public: - Plane plane; - Point * pnt; - - Node * left, * right; - - enum { LEFT, RIGHT }; - - const Plane & get_hs( int side ) const - { - - ((Plane *)&plane)->orient_half_space( side == LEFT ); - - return plane; - } - - - bool is_points_in_hs( const Plane & pl ) const - { - if ( is_point() ) - return pl.is_in( *pnt ); - - if ( left != NULL && ( ! left->is_points_in_hs( pl ) ) ) - return false; - if ( right != NULL && ( ! right->is_points_in_hs( pl ) ) ) - return false; - - return true; - } - - - bool is_valid() const - { - if ( is_point() ) - return true; - - if ( left != NULL ) - if ( ! left->is_points_in_hs( get_hs( LEFT ) ) ) - return false; - if ( right != NULL ) - if ( ! right->is_points_in_hs( get_hs( RIGHT ) ) ) - return false; - - return true; - } - - - void dump( int depth ) - { - int ind; - - for ( ind = 0; ind < depth; ind++ ) - std::cout << " "; - - if ( is_point() ) { - std::cout << *pnt << "\n"; - return; - } - - plane.dump(); - std::cout << "\n"; - left->dump( depth + 1 ); - for ( ind = 0; ind < depth; ind++ ) - std::cout << " "; - - std::cout << "!!!!!!!!!!!!\n"; - right->dump( depth + 1 ); - } - - bool is_point() const - { - return ((left == NULL) && (right == NULL)); - } - - typedef std::back_insert_iterator back_iter; - - Node() : plane() - { - left = right = NULL; - } - - void copy_subtree_points( back_iter & result, - const Box & rect ) - { - if ( is_point() ) { - if ( rect.is_in( *pnt ) ) - (*result++) = *pnt; - return; - } - if ( left != NULL ) - left->copy_subtree_points( result, rect ); - if ( right != NULL ) - right->copy_subtree_points( result, rect ); - } - - static void search_recursive( back_iter & result, - Node * node, - const Box & rect, - Box & _region, - Plane & plane, - bool f_split_plus ) - { - //printf( "search_recusrive\n" ); - Box * p_r = new Box( _region ); - - //printf( "z" ); - //fflush( stdout ); - - plane.split( *p_r, f_split_plus ); - - //printf( "c" ); - //fflush( stdout ); - CGAL_precondition( node != NULL ); - - //printf( "b" ); - //fflush( stdout ); - if ( rect.is_in( *p_r ) ) - { - //printf( "5" ); - //fflush( stdout ); - node->copy_subtree_points( result, rect ); - //printf( "\tsearch_recursive done...\n" ); - //printf( "6" ); - //fflush( stdout ); - delete p_r; - return; - } - - //printf( "v" ); - //fflush( stdout ); - - if ( rect.is_intersect_in_dim_closed( plane.get_coord(), *p_r ) ) - node->search( result, rect, *p_r ); - //printf( "x" ); - //fflush( stdout ); - delete p_r; - } - - void search( std::back_insert_iterator result, - const Box &rect, Box ®ion ) - { - if (is_point()) { - if ( rect.is_in( *pnt ) ) - (*result++) = *pnt; - return; - } - - //this is not a point so it is a hypeplane - if ( left != NULL ) - search_recursive( result, left, rect, - region, plane, true ); - if ( right != NULL ) - search_recursive( result, right, rect, - region, plane, false ); - } - }; - - typedef Point * Point_ptr; - - int size; - Point * p_arr_pt; - Node *root; - int dim; - - Node * p_node_arr; - int node_count; - - Node * malloc_node( void ) - { - Node * p_ret; - - p_ret = &(p_node_arr[ node_count ]); - node_count++; - - CGAL_assertion( node_count <= ( 2 * size )); - - *p_ret = Node(); - - return p_ret; - } - - static int comp( const Point & a, const Point & b, int dim ) - { - return Traits::compare( dim, a, b ); - } - - static int partition( Point_ptr * arr, int left, int right, - Point * p_pivot, int dim ) - { - int i, j; - Point_ptr tmp; - - if ( left >= right ) - return left; - - i = left; - j = right; - - while ( i < j ) { - if ( comp( *(arr[ i ]), *(arr[ j ]), dim ) > 0 ) { - tmp = arr[ i ]; - arr[ i ] = arr[ j ]; - arr[ j ] = tmp; - } - if ( comp( *(arr[ i ]), *p_pivot, dim ) < 0 ) { - i++; - } else - if ( comp( *p_pivot, *(arr[ j ]), dim ) <= 0 ) - j--; - } - - return (i > left)? i - 1 : left; - } - - - /* split the array into two sub-arrays, such that all the elements - * from left to pos_mid are smaller than the elements from pos+1 to - * right. - */ - static void split_arr( Point_ptr * arr, - int left, - int right, - int pos_mid, - int dim ) - { - int pos; - - if ( left >= right ) - return; - - pos = partition( arr, left, right, arr[ (left + right ) / 2 ], - dim ); - if ( pos == pos_mid ) - return; - - if ( pos < pos_mid ) - split_arr( arr, pos+1, right, pos_mid, dim ); - else - split_arr( arr, left, pos, pos_mid, dim ); - } - - - static Point_ptr get_max_element( Point_ptr * arr, - int left, int right, int d ) - { - int max_pos = left; - Point mx = *(arr[ max_pos ]); - - for ( int ind = left + 1; ind <= right; ind++ ) - if ( comp( mx, *(arr[ ind ]), d ) < 0 ) { - mx = *(arr[ ind ]); - max_pos = ind; - } - - return arr[ max_pos ]; - } - - Node *build_r( Point_ptr * arr, int left, int right, - int d ) - { - int num, pos, next_d; - Node * n; - - num = right - left + 1; - - if ( num < 1) - return NULL; - - // if the list contains only one point, - // construct a leaf for this node - if ( num == 1) { - //n = new node; - n = malloc_node(); - n->pnt = arr[ left ]; - - return n; - } - - // else divide space into two regions in - // dim-dim and cotinue recursively - pos = (left + right) / 2; - split_arr( arr, left, right, pos, d ); - - Point * p_median = get_max_element( arr, left, pos, d ); - - // create division plane; - Plane plane( d, *p_median ); - //n = new node; - // CGAL_assertion( n != NULL ); - n = malloc_node(); - - n->plane = plane; - - next_d = d + 1; - if ( next_d >= dim ) - next_d = 0; - - // build left sub-tree - n->left = build_r( arr, left, pos, next_d ); - - // build right sub-tree - n->right = build_r( arr, pos + 1, right, next_d ); - - return n; - } - -public: - typedef list list_points; - - Kdtree_d(int k = 2) - { - dim = k; - root = NULL; - p_arr_pt = NULL; - p_node_arr = NULL; - } - - ~Kdtree_d() - { - delete_all(); - } - - - bool is_valid( bool verbose = false, int level = 0 ) const - { - (void)verbose; - (void)level; - - if ( root == NULL ) - return true; - - return root->is_valid(); - } - - - void dump() - { - root->dump( 0); - } - - void delete_all() - { - root = NULL; - - if ( p_arr_pt != NULL ) - delete[] p_arr_pt; - p_arr_pt = NULL; - if ( p_node_arr != NULL ) - delete[] p_node_arr; - p_node_arr = NULL; - } - - void search( std::back_insert_iterator result, - Box & rect ) - { - if (root == NULL) - return; // it is an empty tree - nothing to search in - - Box region = Box( dim ); - - root->search( result, rect, region ); - } - - void build(list &l) - { - int i; - Point_ptr * p_arr; - - size = l.size(); - p_arr_pt = new Point[ size ]; - CGAL_assertion( p_arr_pt != NULL ); - - p_arr = new Point_ptr[ size ]; - CGAL_assertion( p_arr != NULL ); - - p_node_arr = new Node[ 2 * size ]; - CGAL_assertion( p_node_arr != NULL ); - - node_count = 0; - - /* fill the array */ - i = 0; - for ( typename std::list::iterator j = l.begin(); - j != l.end(); - j++ ) - { - p_arr_pt[ i ] = (*j); - p_arr[ i ] = p_arr_pt + i; - i++; - } - - // recursively build the tree from the sorted list - // starting to divide it in coordinate 0 - root = build_r( p_arr, 0, size - 1, 0 ); - - //printf( "b\n" ); - delete[] p_arr; - } -}; - - -} //namespace CGAL - -#endif /* CGAL_KDTREE_D_H */ diff --git a/kdtree/package_info/kdtree/copyright b/kdtree/package_info/kdtree/copyright deleted file mode 100644 index 930771b9d2c..00000000000 --- a/kdtree/package_info/kdtree/copyright +++ /dev/null @@ -1 +0,0 @@ -Tel-Aviv University (Israel). diff --git a/kdtree/package_info/kdtree/description.txt b/kdtree/package_info/kdtree/description.txt deleted file mode 100644 index 12bb7366575..00000000000 --- a/kdtree/package_info/kdtree/description.txt +++ /dev/null @@ -1 +0,0 @@ -The KD-tree implementation . diff --git a/kdtree/package_info/kdtree/license.txt b/kdtree/package_info/kdtree/license.txt deleted file mode 100644 index 8bb8efcb72b..00000000000 --- a/kdtree/package_info/kdtree/license.txt +++ /dev/null @@ -1 +0,0 @@ -GPL (v3 or later) diff --git a/kdtree/package_info/kdtree/long_description.txt b/kdtree/package_info/kdtree/long_description.txt deleted file mode 100644 index efdd3de5314..00000000000 --- a/kdtree/package_info/kdtree/long_description.txt +++ /dev/null @@ -1,11 +0,0 @@ -CGAL KD-tree impelementation ----------------------------- - - The following contains the CGAL KD-tree implementation. The examples/kdtrees/ -directory contains three simple examples for the use of kd-trees in 2D, 3D -(using points from the Cgal kernel) and 4D (using user-defined points). - - The source is under include/CGAL/kdtree_d.h, and it can be used -independently from the rest of CGAL. - ------------------------------------------------------------------------ diff --git a/kdtree/package_info/kdtree/maintainer b/kdtree/package_info/kdtree/maintainer deleted file mode 100644 index 7e028c78627..00000000000 --- a/kdtree/package_info/kdtree/maintainer +++ /dev/null @@ -1 +0,0 @@ -cgal-develop