Fixed segfault error with the information/statistics display
[mldemos:mldemos.git] / _AlgorithmsPlugins / KNN / ANN / bd_tree.h
1 //----------------------------------------------------------------------\r
2 // File:                        bd_tree.h\r
3 // Programmer:          David Mount\r
4 // Description:         Declarations for standard bd-tree routines\r
5 // Last modified:       01/04/05 (Version 1.0)\r
6 //----------------------------------------------------------------------\r
7 // Copyright (c) 1997-2005 University of Maryland and Sunil Arya and\r
8 // David Mount.  All Rights Reserved.\r
9 // \r
10 // This software and related documentation is part of the Approximate\r
11 // Nearest Neighbor Library (ANN).  This software is provided under\r
12 // the provisions of the Lesser GNU Public License (LGPL).  See the\r
13 // file ../ReadMe.txt for further information.\r
14 // \r
15 // The University of Maryland (U.M.) and the authors make no\r
16 // representations about the suitability or fitness of this software for\r
17 // any purpose.  It is provided "as is" without express or implied\r
18 // warranty.\r
19 //----------------------------------------------------------------------\r
20 // History:\r
21 //      Revision 0.1  03/04/98\r
22 //              Initial release\r
23 //      Revision 1.0  04/01/05\r
24 //              Changed IN, OUT to ANN_IN, ANN_OUT\r
25 //----------------------------------------------------------------------\r
26 \r
27 #ifndef ANN_bd_tree_H\r
28 #define ANN_bd_tree_H\r
29 \r
30 #include <ANN/ANNx.h>                                   // all ANN includes\r
31 #include "kd_tree.h"                                    // kd-tree includes\r
32 \r
33 //----------------------------------------------------------------------\r
34 //      bd-tree shrinking node.\r
35 //              The main addition in the bd-tree is the shrinking node, which\r
36 //              is declared here.\r
37 //\r
38 //              Shrinking nodes are defined by list of orthogonal halfspaces.\r
39 //              These halfspaces define a (possibly unbounded) orthogonal\r
40 //              rectangle.  There are two children, in and out.  Points that\r
41 //              lie within this rectangle are stored in the in-child, and the\r
42 //              other points are stored in the out-child.\r
43 //\r
44 //              We use a list of orthogonal halfspaces rather than an\r
45 //              orthogonal rectangle object because typically the number of\r
46 //              sides of the shrinking box will be much smaller than the\r
47 //              worst case bound of 2*dim.\r
48 //\r
49 //              BEWARE: Note that constructor just copies the pointer to the\r
50 //              bounding array, but the destructor deallocates it.  This is\r
51 //              rather poor practice, but happens to be convenient.  The list\r
52 //              is allocated in the bd-tree building procedure rbd_tree() just\r
53 //              prior to construction, and is used for no other purposes.\r
54 //\r
55 //              WARNING: In the near neighbor searching code it is assumed that\r
56 //              the list of bounding halfspaces is irredundant, meaning that there\r
57 //              are no two distinct halfspaces in the list with the same outward\r
58 //              pointing normals.\r
59 //----------------------------------------------------------------------\r
60 \r
61 class ANNbd_shrink : public ANNkd_node  // splitting node of a kd-tree\r
62 {\r
63         int                                     n_bnds;                 // number of bounding halfspaces\r
64         ANNorthHSArray          bnds;                   // list of bounding halfspaces\r
65         ANNkd_ptr                       child[2];               // in and out children\r
66 public:\r
67         ANNbd_shrink(                                           // constructor\r
68                 int                             nb,                             // number of bounding halfspaces\r
69                 ANNorthHSArray  bds,                    // list of bounding halfspaces\r
70                 ANNkd_ptr ic=NULL, ANNkd_ptr oc=NULL)   // children\r
71                 {\r
72                         n_bnds                  = nb;                           // cutting dimension\r
73                         bnds                    = bds;                          // assign bounds\r
74                         child[ANN_IN]   = ic;                           // set children\r
75                         child[ANN_OUT]  = oc;\r
76                 }\r
77 \r
78         ~ANNbd_shrink()                                         // destructor\r
79                 {\r
80                         if (child[ANN_IN]!= NULL && child[ANN_IN]!=  KD_TRIVIAL) \r
81                                 delete child[ANN_IN];\r
82                         if (child[ANN_OUT]!= NULL&& child[ANN_OUT]!= KD_TRIVIAL) \r
83                                 delete child[ANN_OUT];\r
84                         if (bnds != NULL)\r
85                                 delete [] bnds;                 // delete bounds\r
86                 }\r
87 \r
88         virtual void getStats(                                          // get tree statistics\r
89                                 int dim,                                                // dimension of space\r
90                                 ANNkdStats &st,                                 // statistics\r
91                                 ANNorthRect &bnd_box);                  // bounding box\r
92         virtual void print(int level, ostream &out);// print node\r
93         virtual void dump(ostream &out);                        // dump node\r
94 \r
95         virtual void ann_search(ANNdist);                       // standard search\r
96         virtual void ann_pri_search(ANNdist);           // priority search\r
97         virtual void ann_FR_search(ANNdist);            // fixed-radius search\r
98 };\r
99 \r
100 #endif\r