cgma
KDDTreeNode.hpp
Go to the documentation of this file.
00001 //-----------------------------------------------------------------
00002 //- Class:   KDDTreeNode
00003 //- Author:  Kevin Albrecht 
00004 //- Created: 13 May 2003
00005 //- Updated: 8 Feb 2004
00006 //-
00007 //- Description:
00008 //-   Node for dynamic version of the k-d tree, where k=3.
00009 //-
00010 //- References:
00011 //-
00012 //-   Hanan Samet.  Design and Analysis of Spatial Data Structures.
00013 //-      Addison-Wesley, Reading, MA, 1990.
00014 //-
00015 //-   Jon Louis Bentley. Multidimensional binary search trees used
00016 //-     for associative searching. In Communications of the ACM,
00017 //-     18(9), pages 509-517, September 1975.
00018 //-----------------------------------------------------------------
00019 
00020 #ifndef KDDTREENODE_HPP
00021 #define KDDTREENODE_HPP
00022 
00023 #include "CubitDefines.h"
00024 #include "GeometryDefines.h"
00025 #include "CubitBox.hpp"
00026 
00027 //- constants that show the direction of discrimination
00028 enum DIMENSION
00029 {
00030   DIMX, DIMY, DIMZ
00031 };
00032 
00033 //- constants used to determine left vs. right
00034 enum DIRECTION
00035 {
00036   DIR_NULL, DIR_EITHER, DIR_LEFT, DIR_RIGHT
00037 };
00038 
00039 enum DISTDATA
00040 {
00041   DD_SAFETY, DD_LEAF
00042 };
00043 
00044 template <class X> class DLIList;
00045 
00046 template <class Y> class KDDTreeNode 
00047 {
00048   private:
00049     DIMENSION myDisc;         // dimension in which this node discriminates
00050     double myDist;            // used for nearest neigbhor searches
00051     DISTDATA myDistData;      // also used for nearest neigbhor searches
00052 
00053   public:
00054     KDDTreeNode<Y> *parent; // parent of this node
00055     KDDTreeNode<Y> *left;   // left subtree
00056     KDDTreeNode<Y> *right;  // right subtree
00057     double x, y, z;         // coordinates of center point
00058     Y data;                 // data with bounding box centered on this node
00059     CubitBoolean valid;     // false if this node should be deleted
00060 
00061     CubitBox safetyBox;   // bounding box of myData and the safetyBox's of children
00062     CubitBox boundingBox; // bounding box of myData
00063 
00064     //- Constructor/Destructor
00065     KDDTreeNode (Y aData, DIMENSION aDisc = DIMX);
00066     ~KDDTreeNode ();
00067 
00068     //- Get/set the child in the direction of "dir"
00069     KDDTreeNode<Y> *get_child (DIRECTION dir) const;
00070     void set_child (KDDTreeNode<Y> *node, DIRECTION dir);
00071 
00072     //- Get/set the "myDist" value
00073     double get_dist () const { return myDist; }
00074     void set_dist (double dist) { myDist = dist; }
00075 
00076     //- Get/set the "myDistData" value
00077     DISTDATA get_dist_data () const { return myDistData; }
00078     void set_dist_data (DISTDATA distData) { myDistData = distData; }
00079 
00080     //- Get/set the discriminating dimension of this node
00081     DIMENSION get_disc () const { return myDisc; }
00082     void set_disc (DIMENSION dim) { myDisc = dim; }
00083 
00084     //- Get the discriminator for the depth below this node
00085     DIMENSION next_disc () const;
00086 
00087     //- The KD_COMPARE function as defined by Samet
00088     DIRECTION compare (KDDTreeNode<Y> *Q) const;
00089     DIRECTION compare_with_equality (KDDTreeNode<Y> *Q) const;
00090 };
00091 
00092 #include "KDDTreeNode.cpp"
00093 
00094 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines