Geant4  10.01
G4SurfaceVoxelizer.icc
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 // $Id: G4SurfaceVoxelizer.icc 72335 2013-07-16 09:01:49Z gcosmo $
27 // GEANT4 tag $Name: not supported by cvs2svn $
28 //
29 // --------------------------------------------------------------------
30 // GEANT 4 class header file
31 //
32 // G4SurfaceVoxelizer inline methods
33 //
34 // History:
35 // 19.10.12 Marek Gayer, created
36 // --------------------------------------------------------------------
37 
38 
39 template <typename T> inline
40 G4int G4SurfaceVoxelizer::BinarySearch(const std::vector<T> &vec, T value)
41 {
42  typename std::vector<T>::const_iterator begin=vec.begin(), end=vec.end();
43  G4int res = std::upper_bound(begin, end, value) - begin - 1;
44  return res;
45 }
46 
47 inline
48 const std::vector<G4VoxelBox> &G4SurfaceVoxelizer::GetBoxes() const
49 {
50  return fBoxes;
51 }
52 
53 inline
54 const std::vector<G4double> &G4SurfaceVoxelizer::GetBoundary(G4int index) const
55 {
56  return fBoundaries[index];
57 }
58 
59 inline
60 void G4SurfaceVoxelizer::GetVoxel(std::vector<G4int> &curVoxel,
61  const G4ThreeVector &point) const
62 {
63  for (G4int i=0; i<=2; ++i)
64  {
65  const std::vector<double> &boundary = GetBoundary(i);
66  G4int n = BinarySearch(boundary, point[i]);
67  if (n == -1)
68  { n = 0; }
69  else if (n == G4int(boundary.size()) - 1)
70  { n--; }
71  curVoxel[i] = n;
72  }
73 }
74 
75 inline
76 G4int G4SurfaceVoxelizer::GetBitsPerSlice () const
77 {
78  return fNPerSlice*8*sizeof(unsigned int);
79 }
80 
81 inline
82 G4int G4SurfaceVoxelizer::GetVoxelsIndex(G4int x, G4int y, G4int z) const
83 {
84  if (x < 0 || y < 0 || z < 0) { return -1; }
85  G4int maxX = fBoundaries[0].size();
86  G4int maxY = fBoundaries[1].size();
87  G4int index = x + y*maxX + z*maxX*maxY;
88 
89  return index;
90 }
91 
92 inline
93 G4int G4SurfaceVoxelizer::GetVoxelsIndex(const std::vector<G4int> &voxels) const
94 {
95  return GetVoxelsIndex(voxels[0], voxels[1], voxels[2]);
96 }
97 
98 inline
99 G4int G4SurfaceVoxelizer::GetPointIndex(const G4ThreeVector &p) const
100 {
101  G4int maxX = fBoundaries[0].size();
102  G4int maxY = fBoundaries[1].size();
103  G4int x = BinarySearch(fBoundaries[0], p[0]);
104  G4int y = BinarySearch(fBoundaries[1], p[1]);
105  G4int z = BinarySearch(fBoundaries[2], p[2]);
106  G4int index = x + y*maxX + z*maxX*maxY;
107 
108  return index;
109 }
110 
111 inline
112 const G4SurfBits &G4SurfaceVoxelizer::Empty() const
113 {
114  return fEmpty;
115 }
116 
117 inline
118 G4bool G4SurfaceVoxelizer::IsEmpty(G4int index) const
119 {
120  return fEmpty[index];
121 }
122 
123 inline
124 G4int G4SurfaceVoxelizer::GetMaxVoxels(G4ThreeVector &ratioOfReduction)
125 {
126  ratioOfReduction = fReductionRatio;
127  return fMaxVoxels;
128 }
129 
130 inline
131 long long G4SurfaceVoxelizer::GetCountOfVoxels() const
132 {
133  return fCountOfVoxels;
134 }
135 
136 inline
137 long long G4SurfaceVoxelizer::CountVoxels(std::vector<G4double> boundaries[]) const
138 {
139  long long sx = boundaries[0].size() - 1;
140  long long sy = boundaries[1].size() - 1;
141  long long sz = boundaries[2].size() - 1;
142 
143  return sx * sy *sz;
144 }
145 
146 inline
147 const std::vector<G4int>&
148 G4SurfaceVoxelizer::GetCandidates(std::vector<G4int> &curVoxel) const
149 {
150  G4int voxelsIndex = GetVoxelsIndex(curVoxel);
151 
152  if (voxelsIndex >= 0 && !fEmpty[voxelsIndex])
153  {
154  return fCandidates[voxelsIndex];
155  }
156  return fNoCandidates;
157 }
158 
159 inline
160 G4int G4SurfaceVoxelizer::GetVoxelBoxesSize() const
161 {
162  return fVoxelBoxes.size();
163 }
164 
165 inline
166 const G4VoxelBox &G4SurfaceVoxelizer::GetVoxelBox(G4int i) const
167 {
168  return fVoxelBoxes[i];
169 }
170 
171 inline
172 const std::vector<G4int>&
173 G4SurfaceVoxelizer::GetVoxelBoxCandidates(G4int i) const
174 {
175  return fVoxelBoxesCandidates[i];
176 }