Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4KDNode.icc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr) 
0028 //
0029 // History:
0030 // -----------
0031 // 10 Oct 2011 M.Karamitros created
0032 //
0033 // -------------------------------------------------------------------
0034 
0035 //______________________________________________________________________
0036 template<typename PointT>
0037   G4KDNode<PointT>::G4KDNode(G4KDTree* tree,
0038                              PointT* point,
0039                              G4KDNode_Base* parent) :
0040       G4KDNode_Base(tree, parent)
0041   {
0042     fPoint = point;
0043     fValid = true;
0044   }
0045 
0046 // Copy constructor should not be used
0047 template<typename PointT>
0048   G4KDNode<PointT>::G4KDNode(const G4KDNode<PointT>& right) :
0049       G4KDNode_Base(right), fPoint(0)
0050   {
0051     fValid = false;
0052   }
0053 
0054 template<typename PointT>
0055   G4KDNode<PointT>::~G4KDNode() {} // NOLINT Intel ICC has ODR link failures if this is =default
0056                                    // It also cannot be inline, which includes it being inside the class body!
0057 
0058 // Assignement should not be used
0059 template<typename PointT>
0060   G4KDNode<PointT>& G4KDNode<PointT>::operator=(const G4KDNode<PointT>& right)
0061   {
0062     if(this == &right) return *this;
0063     fPoint = right.fPoint;
0064     fTree = right.fTree;
0065     fLeft = right.fLeft;
0066     fRight = right.fRight;
0067     fParent = right.fParent;
0068     fSide = right.fSide;
0069     fAxis = right.fAxis;
0070     return *this;
0071   }
0072 
0073 template<typename Position>
0074   G4KDNode_Base* G4KDNode_Base::FindParent(const Position& x0)
0075   {
0076     G4KDNode_Base* aParent = nullptr;
0077     G4KDNode_Base* next = this;
0078     G4int split = -1;
0079     while(next)
0080     {
0081       split = (G4int)next->fAxis;
0082       aParent = next;
0083 
0084       // works if node called "next" is valid
0085       if(x0[split] > (*next)[split]) next = next->fRight;
0086       else next = next->fLeft;
0087     }
0088     return aParent;
0089   }
0090 
0091 template<typename PointT>
0092   G4KDNode_Base* G4KDNode_Base::Insert(PointT* point)
0093   {
0094     G4KDNode_Base* aParent = FindParent(*point);
0095     // TODO check p == aParent->pos
0096     // Exception
0097 
0098     G4KDNode_Base* newNode = new G4KDNode<PointT>(fTree, point, aParent);
0099 
0100     if((*point)[(G4int)aParent->fAxis] > (*aParent)[aParent->fAxis])
0101     {
0102       aParent->fRight = newNode;
0103       newNode->fSide = 1;
0104     }
0105     else
0106     {
0107       aParent->fLeft = newNode;
0108       newNode->fSide = -1;
0109     }
0110 
0111     return newNode;
0112   }
0113 
0114 template<typename PointT>
0115   G4KDNode_Base* G4KDNode_Base::Insert(const PointT& point)
0116   {
0117     G4KDNode_Base* aParent = FindParent(point);
0118     // TODO check p == aParent->pos
0119     // Exception
0120 
0121     G4KDNode_Base* newNode = new G4KDNodeCopy<PointT>(fTree, point, aParent);
0122 
0123     if(point[aParent->fAxis] > (*aParent)[aParent->fAxis])
0124     {
0125       aParent->fRight = newNode;
0126       newNode->fSide = 1;
0127     }
0128     else
0129     {
0130       aParent->fLeft = newNode;
0131       newNode->fSide = -1;
0132     }
0133 
0134     return newNode;
0135   }
0136