Geant4  10.00.p02
G4KDMap.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 #include "G4KDMap.hh"
27 #include <algorithm>
28 
29 using namespace std;
30 
31 //typedef std::_Deque_iterator<G4KDNode*,G4KDNode*&,G4KDNode**> _deq_iterator ;
32 typedef std::deque<G4KDNode*>::iterator _deq_iterator ;
33 
34 __1DSortOut::__1DSortOut(int dimension) : fSortOutNDim(dimension)
35 {}
36 
38 {
39  return fSortOutNDim.fDimension;
40 }
41 
42 G4KDNode* __1DSortOut::GetMidle(int& main_middle)
43 {
44  int contSize = fContainer.size();
45  main_middle = (int) ceil(contSize/2.); // ceil = round up
46  return fContainer[main_middle];
47 }
48 
50 {
51  return fContainer.insert(fContainer.end(),pos);
52 }
53 
55 {
56  int middle;
57  G4KDNode* pos = GetMidle(middle);
58  _deq_iterator deq_pos = fContainer.begin()+middle;
59  fContainer.erase(deq_pos);
60  return pos;
61 }
62 
64 {
65  sort(fContainer.begin(),fContainer.end(),fSortOutNDim);
66 }
67 
69 {
70  fContainer.erase(deq_pos);
71 }
72 
74 {
75  vector<_deq_iterator>& vit = fMap[pos];
76 
77  size_t maxSize = fSortOut.size();
78 
79  cout << maxSize << endl;
80  cout << fSortOut.capacity() << endl;
81 
82  vit.reserve(maxSize);
83 
84  for (size_t i = 0; i < fSortOut.size(); ++i)
85  {
86  vit[i]=fSortOut[i]->Insert(pos);
87  }
88 
89  fIsSorted = false;
90 }
91 
93 {
94  if(fIsSorted == false) Sort();
95  G4KDNode* output_node = fSortOut[dimension]->PopOutMiddle();
96 
97  std::map<G4KDNode*, std::vector<_deq_iterator> >::iterator fMap_it
98  = fMap.find(output_node);
99 
100  std::vector<_deq_iterator>& vit = fMap_it->second;
101 
102  for(int i = 0 ; i < (int) fSortOut.size() ; i++)
103  {
104  if(i != dimension) fSortOut[i]->Erase(vit[i]);
105  }
106 
107  fMap.erase(fMap_it);
108 
109  return output_node;
110 }
111 
113 {
114  for (size_t i = 0; i < fSortOut.size(); ++i)
115  {
116  fSortOut[i]->Sort();
117  }
118 
119  fIsSorted = true;
120 }
G4KDNode * PopOutMiddle(int dimension)
Definition: G4KDMap.cc:92
G4KDNode * GetMidle(int &G4KDNode_deque)
Definition: G4KDMap.cc:42
void Sort()
Definition: G4KDMap.cc:112
G4KDNode * PopOutMiddle()
Definition: G4KDMap.cc:54
std::deque< G4KDNode * > fContainer
Definition: G4KDMap.hh:69
__1DSortOut(int dimension)
Definition: G4KDMap.cc:34
void Erase(std::deque< G4KDNode * >::iterator &)
Definition: G4KDMap.cc:68
G4KDNode stores one entity in G4KDTree This class is for internal use only.
Definition: G4KDNode.hh:50
std::deque< G4KDNode * >::iterator _deq_iterator
Definition: G4KDMap.cc:32
std::map< G4KDNode *, std::vector< std::deque< G4KDNode * >::iterator > > fMap
Definition: G4KDMap.hh:104
sortOutNDim fSortOutNDim
Definition: G4KDMap.hh:70
std::vector< __1DSortOut * > fSortOut
Definition: G4KDMap.hh:101
int GetDimension()
Definition: G4KDMap.cc:37
std::deque< G4KDNode * >::iterator Insert(G4KDNode *)
Definition: G4KDMap.cc:49
void Sort()
Definition: G4KDMap.cc:63
bool fIsSorted
Definition: G4KDMap.hh:100
static const G4double pos
void Insert(G4KDNode *pos)
Definition: G4KDMap.cc:73