G4KDTree.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id: G4KDTree.hh 64057 2012-10-30 15:04:49Z gcosmo $
00027 //
00028 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr) 
00029 //
00030 // WARNING : This class is released as a prototype.
00031 // It might strongly evolve or even disapear in the next releases.
00032 //
00033 // History:
00034 // -----------
00035 // 10 Oct 2011 M.Karamitros created
00036 //
00037 // -------------------------------------------------------------------
00038 
00039 #ifndef G4KDTREE_HH
00040 #define G4KDTREE_HH
00041 
00042 #include <vector>
00043 #include "G4KDTreeResult.hh"
00044 
00045 //__________________________________
00046 // Methods to act on kdnode
00047 // Methods defined in G4KDNode.cc :
00048 void InactiveNode(G4KDNode*);
00049 void Free(G4KDNode*&);
00050 void* GetData(G4KDNode*);
00051 const double* GetNodePosition(G4KDNode*);
00052 //__________________________________
00053 
00060 class G4KDTree
00061 {
00062     friend class G4KDNode ;
00063     int fDim;
00064     struct HyperRect *fRect;
00065     void (*fDestr)(void*);
00066     int fNbNodes;
00067 
00068 protected :
00069     G4KDNode *fRoot;
00070 
00071 public :
00072     G4KDTree(int dim = 3);
00073     virtual ~G4KDTree();
00074 
00075     void Clear();
00076 
00077     inline int GetDim();
00078     inline void SetDataDestructor(void (*fDestr)(void*));
00079 
00080     int GetNbNodes()    { return fNbNodes;  }
00081     G4KDNode* GetRoot() { return fRoot ;    }
00082 
00083     // Insert and attache the data to a node at the specified position
00084     // In return, it gives you the corresponding node
00085     G4KDNode* Insert(const double *pos, void *data);
00086     G4KDNode* Insert(const double& x, const double& y, const double& z, void *data); // 3D
00087 
00088     /* Find one of the nearest nodes from the specified point.
00089      *
00090      * This function returns a pointer to a result set with at most one element.
00091      */
00092     G4KDTreeResultHandle Nearest( const double *pos);
00093     G4KDTreeResultHandle Nearest( const double& x, const double& y, const double& z); // 3D
00094     G4KDTreeResultHandle Nearest( G4KDNode* node);
00095 
00096     /* Find any nearest nodes from the specified point within a range.
00097      *
00098      * This function returns a pointer to a result set, which can be manipulated
00099      * by the G4KDTreeResult.
00100      * The returned pointer can be null as an indication of an error. Otherwise
00101      * a valid result set is always returned which may contain 0 or more elements.
00102      */
00103     G4KDTreeResultHandle NearestInRange( const double *pos, const double& range);
00104     G4KDTreeResultHandle NearestInRange( const double& x,
00105                                     const double& y,
00106                                     const double& z,
00107                                     const double& range); // 3D
00108     G4KDTreeResultHandle NearestInRange( G4KDNode* node, const double& range);
00109 
00110 protected :
00111     void __Clear_Rec(G4KDNode *node) ;
00112 
00113     int __NearestInRange(G4KDNode *node,
00114                          const double *pos,
00115                          const double& range_sq,
00116                          const double& range,
00117                          G4KDTreeResult& list,
00118                          int ordered,
00119                          G4KDNode *source_node = 0);
00120 
00121     void __NearestToPosition(G4KDNode *node,
00122                              const double *pos,
00123                              G4KDNode *&result,
00124                              double *result_dist_sq,
00125                              struct HyperRect* fRect);
00126 
00127     void __NearestToNode(G4KDNode *source_node,
00128                          G4KDNode *node,
00129                          const double *pos,
00130                          std::vector<G4KDNode*>& result,
00131                          double *result_dist_sq,
00132                          struct HyperRect* fRect,
00133                          int& nbresult) ;
00134 };
00135 
00136 inline int G4KDTree::GetDim()
00137 {
00138     return fDim ;
00139 }
00140 
00141 void G4KDTree::SetDataDestructor(void (*fct)(void*))
00142 {
00143     fDestr = fct;
00144 }
00145 
00146 #endif // G4KDTREE_HH

Generated on Mon May 27 17:48:43 2013 for Geant4 by  doxygen 1.4.7