Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Kdtree_d< Traits > Class Template Reference

#include <kdtree_d.h>

Collaboration diagram for Kdtree_d< Traits >:

Classes

class  Box
 
class  ExtPoint
 
class  Node
 

Public Types

typedef Traits::Point Point
 
typedef std::vector< PointList_points
 
typedef std::vector< Pointlist_points
 

Public Member Functions

 Kdtree_d (int k=2)
 
 ~Kdtree_d ()
 
bool is_valid (bool verbose=false, int level=0) const
 
void dump ()
 
void delete_all ()
 
void search (std::back_insert_iterator< list_points > result, Box &rect)
 
void build (std::vector< Point > &v)
 

Private Types

typedef PointPoint_ptr
 

Private Member Functions

Nodemalloc_node (void)
 
Nodebuild_r (Point_ptr *arr, int left, int right, int d)
 

Static Private Member Functions

static int comp (const Point &a, const Point &b, int dim)
 
static int partition (Point_ptr *arr, int left, int right, Point *p_pivot, int dim)
 
static void split_arr (Point_ptr *arr, int left, int right, int pos_mid, int dim)
 
static Point_ptr get_max_element (Point_ptr *arr, int left, int right, int d)
 

Private Attributes

int size
 
Pointp_arr_pt
 
Noderoot
 
int dim
 
Nodep_node_arr
 
int node_count
 

Detailed Description

template<class Traits>
class Kdtree_d< Traits >

Definition at line 138 of file kdtree_d.h.

Member Typedef Documentation

typedef std::vector<Point> List_points

Definition at line 143 of file kdtree_d.h.

typedef std::vector<Point> list_points

Definition at line 933 of file kdtree_d.h.

typedef Traits::Point Point

Definition at line 142 of file kdtree_d.h.

typedef Point* Point_ptr
private

Definition at line 782 of file kdtree_d.h.

Constructor & Destructor Documentation

Kdtree_d ( int  k = 2)
inlineexplicit

Definition at line 935 of file kdtree_d.h.

References Kdtree_d< Traits >::dim, k, Kdtree_d< Traits >::p_arr_pt, Kdtree_d< Traits >::p_node_arr, and Kdtree_d< Traits >::root.

936  {
937  dim = k;
938  root = NULL;
939  p_arr_pt = NULL;
940  p_node_arr = NULL;
941  }
Node * root
Definition: kdtree_d.h:786
j indices k indices k
Definition: Indexing.h:6
int dim
Definition: kdtree_d.h:787
Node * p_node_arr
Definition: kdtree_d.h:789
Point * p_arr_pt
Definition: kdtree_d.h:785
~Kdtree_d ( )
inline

Definition at line 943 of file kdtree_d.h.

References Kdtree_d< Traits >::delete_all().

944  {
945  delete_all();
946  }
void delete_all()
Definition: kdtree_d.h:966

Here is the call graph for this function:

Member Function Documentation

void build ( std::vector< Point > &  v)
inline

Definition at line 989 of file kdtree_d.h.

References Kdtree_d< Traits >::build_r(), i, j, Kdtree_d< Traits >::node_count, Kdtree_d< Traits >::p_arr_pt, Kdtree_d< Traits >::p_node_arr, Kdtree_d< Traits >::root, and Kdtree_d< Traits >::size.

Referenced by buildversionstring().

990  {
991  int i;
992  Point_ptr * p_arr;
993 
994  size = v.size();
995  p_arr_pt = new Point[ size ];
996  assert( p_arr_pt != NULL );
997 
998  p_arr = new Point_ptr[ size ];
999  assert( p_arr != NULL );
1000 
1001  p_node_arr = new Node[ 2 * size ];
1002  assert( p_node_arr != NULL );
1003 
1004  node_count = 0;
1005 
1006  /* fill the array */
1007  i = 0;
1008  for ( typename std::vector<Point>::iterator j = v.begin();
1009  j != v.end();
1010  j++ )
1011  {
1012  p_arr_pt[ i ] = (*j);
1013  p_arr[ i ] = p_arr_pt + i;
1014  i++;
1015  }
1016 
1017  // recursively build the tree from the sorted list
1018  // starting to divide it in coordinate 0
1019  root = build_r( p_arr, 0, size - 1, 0 );
1020 
1021  //printf( "b\n" );
1022  delete[] p_arr;
1023  }
int size
Definition: kdtree_d.h:784
Node * root
Definition: kdtree_d.h:786
Node * build_r(Point_ptr *arr, int left, int right, int d)
Definition: kdtree_d.h:883
This class encapsulate a node over a window manifold.
Definition: Manifold_2.h:370
Traits::Point Point
Definition: kdtree_d.h:142
Point * Point_ptr
Definition: kdtree_d.h:782
blockLoc i
Definition: read.cpp:79
Node * p_node_arr
Definition: kdtree_d.h:789
j indices j
Definition: Indexing.h:6
int node_count
Definition: kdtree_d.h:790
Point * p_arr_pt
Definition: kdtree_d.h:785

Here is the call graph for this function:

Here is the caller graph for this function:

Node* build_r ( Point_ptr arr,
int  left,
int  right,
int  d 
)
inlineprivate

Definition at line 883 of file kdtree_d.h.

References Kdtree_d< Traits >::dim, Kdtree_d< Traits >::get_max_element(), Kdtree_d< Traits >::Node::left, Kdtree_d< Traits >::malloc_node(), n, Kdtree_d< Traits >::Node::plane, Kdtree_d< Traits >::Node::pnt, Kdtree_d< Traits >::Node::right, and Kdtree_d< Traits >::split_arr().

Referenced by Kdtree_d< Traits >::build().

885  {
886  int num, pos, next_d;
887  Node * n;
888 
889  num = right - left + 1;
890 
891  if ( num < 1)
892  return NULL;
893 
894  // if the list contains only one point,
895  // construct a leaf for this node
896  if ( num == 1) {
897  //n = new node;
898  n = malloc_node();
899  n->pnt = arr[ left ];
900 
901  return n;
902  }
903 
904  // else divide space into two regions in
905  // dim-dim and cotinue recursively
906  pos = (left + right) / 2;
907  split_arr( arr, left, right, pos, d );
908 
909  Point * p_median = get_max_element( arr, left, pos, d );
910 
911  // create division plane;
912  typename Node::Plane plane( d, *p_median );
913  //n = new node;
914  // assert( n != NULL );
915  n = malloc_node();
916 
917  n->plane = plane;
918 
919  next_d = d + 1;
920  if ( next_d >= dim )
921  next_d = 0;
922 
923  // build left sub-tree
924  n->left = build_r( arr, left, pos, next_d );
925 
926  // build right sub-tree
927  n->right = build_r( arr, pos + 1, right, next_d );
928 
929  return n;
930  }
static Point_ptr get_max_element(Point_ptr *arr, int left, int right, int d)
Definition: kdtree_d.h:868
Node * build_r(Point_ptr *arr, int left, int right, int d)
Definition: kdtree_d.h:883
This class encapsulate a node over a window manifold.
Definition: Manifold_2.h:370
const NT & d
static void split_arr(Point_ptr *arr, int left, int right, int pos_mid, int dim)
Definition: kdtree_d.h:845
Node * malloc_node(void)
Definition: kdtree_d.h:792
Traits::Point Point
Definition: kdtree_d.h:142
int dim
Definition: kdtree_d.h:787
const NT & n

Here is the call graph for this function:

Here is the caller graph for this function:

static int comp ( const Point a,
const Point b,
int  dim 
)
inlinestaticprivate

Definition at line 807 of file kdtree_d.h.

References CGAL::compare().

Referenced by Kdtree_d< Traits >::get_max_element(), and Kdtree_d< Traits >::partition().

808  {
809  return Traits::compare( dim, a, b );
810  }
int dim
Definition: kdtree_d.h:787
CGAL_KERNEL_INLINE Comparison_result compare(const NT &n1, const NT &n2)
Definition: number_utils.h:143

Here is the call graph for this function:

Here is the caller graph for this function:

void delete_all ( )
inline

Definition at line 966 of file kdtree_d.h.

References Kdtree_d< Traits >::p_arr_pt, Kdtree_d< Traits >::p_node_arr, and Kdtree_d< Traits >::root.

Referenced by Kdtree_d< Traits >::~Kdtree_d().

967  {
968  root = NULL;
969 
970  if ( p_arr_pt != NULL )
971  delete[] p_arr_pt;
972  p_arr_pt = NULL;
973  if ( p_node_arr != NULL )
974  delete[] p_node_arr;
975  p_node_arr = NULL;
976  }
Node * root
Definition: kdtree_d.h:786
Node * p_node_arr
Definition: kdtree_d.h:789
Point * p_arr_pt
Definition: kdtree_d.h:785

Here is the caller graph for this function:

void dump ( )
inline

Definition at line 961 of file kdtree_d.h.

References Kdtree_d< Traits >::Node::dump(), and Kdtree_d< Traits >::root.

962  {
963  root->dump( 0);
964  }
Node * root
Definition: kdtree_d.h:786
void dump(int depth)
Definition: kdtree_d.h:670

Here is the call graph for this function:

static Point_ptr get_max_element ( Point_ptr arr,
int  left,
int  right,
int  d 
)
inlinestaticprivate

Definition at line 868 of file kdtree_d.h.

References Kdtree_d< Traits >::comp().

Referenced by Kdtree_d< Traits >::build_r().

870  {
871  int max_pos = left;
872  Point mx = *(arr[ max_pos ]);
873 
874  for ( int ind = left + 1; ind <= right; ind++ )
875  if ( comp( mx, *(arr[ ind ]), d ) < 0 ) {
876  mx = *(arr[ ind ]);
877  max_pos = ind;
878  }
879 
880  return arr[ max_pos ];
881  }
const NT & d
Traits::Point Point
Definition: kdtree_d.h:142
static int comp(const Point &a, const Point &b, int dim)
Definition: kdtree_d.h:807

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_valid ( bool  verbose = false,
int  level = 0 
) const
inline

Definition at line 949 of file kdtree_d.h.

References Kdtree_d< Traits >::Node::is_valid(), and Kdtree_d< Traits >::root.

950  {
951  (void)verbose;
952  (void)level;
953 
954  if ( root == NULL )
955  return true;
956 
957  return root->is_valid();
958  }
Node * root
Definition: kdtree_d.h:786
bool is_valid() const
Definition: kdtree_d.h:654

Here is the call graph for this function:

Node* malloc_node ( void  )
inlineprivate

Definition at line 792 of file kdtree_d.h.

References n, Kdtree_d< Traits >::node_count, Kdtree_d< Traits >::p_node_arr, and Kdtree_d< Traits >::size.

Referenced by Kdtree_d< Traits >::build_r().

793  {
794  Node * p_ret;
795 
796  p_ret = &(p_node_arr[ node_count ]);
797  node_count++;
798 
799  assert( node_count <= ( 2 * size ));
800 
801  Node n;
802  *p_ret = n;
803 
804  return p_ret;
805  }
int size
Definition: kdtree_d.h:784
This class encapsulate a node over a window manifold.
Definition: Manifold_2.h:370
const NT & n
Node * p_node_arr
Definition: kdtree_d.h:789
int node_count
Definition: kdtree_d.h:790

Here is the caller graph for this function:

static int partition ( Point_ptr arr,
int  left,
int  right,
Point p_pivot,
int  dim 
)
inlinestaticprivate

Definition at line 812 of file kdtree_d.h.

References Kdtree_d< Traits >::comp(), i, and j.

Referenced by Kdtree_d< Traits >::split_arr().

814  {
815  int i, j;
816  Point_ptr tmp;
817 
818  if ( left >= right )
819  return left;
820 
821  i = left;
822  j = right;
823 
824  while ( i < j ) {
825  if ( comp( *(arr[ i ]), *(arr[ j ]), dim ) > 0 ) {
826  tmp = arr[ i ];
827  arr[ i ] = arr[ j ];
828  arr[ j ] = tmp;
829  }
830  if ( comp( *(arr[ i ]), *p_pivot, dim ) < 0 ) {
831  i++;
832  } else
833  if ( comp( *p_pivot, *(arr[ j ]), dim ) <= 0 )
834  j--;
835  }
836 
837  return (i > left)? i - 1 : left;
838  }
Point * Point_ptr
Definition: kdtree_d.h:782
int dim
Definition: kdtree_d.h:787
blockLoc i
Definition: read.cpp:79
static int comp(const Point &a, const Point &b, int dim)
Definition: kdtree_d.h:807
j indices j
Definition: Indexing.h:6

Here is the call graph for this function:

Here is the caller graph for this function:

void search ( std::back_insert_iterator< list_points result,
Box rect 
)
inline

Definition at line 978 of file kdtree_d.h.

References Kdtree_d< Traits >::dim, Kdtree_d< Traits >::root, and Kdtree_d< Traits >::Node::search().

980  {
981  if (root == NULL)
982  return; // it is an empty tree - nothing to search in
983 
984  Box region = Box( dim );
985 
986  root->search( result, rect, region );
987  }
Node * root
Definition: kdtree_d.h:786
void search(std::back_insert_iterator< List_points > result, const Box &rect, Box &region)
Definition: kdtree_d.h:762
int dim
Definition: kdtree_d.h:787

Here is the call graph for this function:

static void split_arr ( Point_ptr arr,
int  left,
int  right,
int  pos_mid,
int  dim 
)
inlinestaticprivate

Definition at line 845 of file kdtree_d.h.

References Kdtree_d< Traits >::partition().

Referenced by Kdtree_d< Traits >::build_r().

850  {
851  int pos;
852 
853  if ( left >= right )
854  return;
855 
856  pos = partition( arr, left, right, arr[ (left + right ) / 2 ],
857  dim );
858  if ( pos == pos_mid )
859  return;
860 
861  if ( pos < pos_mid )
862  split_arr( arr, pos+1, right, pos_mid, dim );
863  else
864  split_arr( arr, left, pos, pos_mid, dim );
865  }
static void split_arr(Point_ptr *arr, int left, int right, int pos_mid, int dim)
Definition: kdtree_d.h:845
int dim
Definition: kdtree_d.h:787
static int partition(Point_ptr *arr, int left, int right, Point *p_pivot, int dim)
Definition: kdtree_d.h:812

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

int dim
private
int node_count
private

Definition at line 790 of file kdtree_d.h.

Referenced by Kdtree_d< Traits >::build(), and Kdtree_d< Traits >::malloc_node().

Point* p_arr_pt
private
int size
private

Definition at line 784 of file kdtree_d.h.

Referenced by Kdtree_d< Traits >::build(), and Kdtree_d< Traits >::malloc_node().


The documentation for this class was generated from the following file: