Geant4-11
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4Voxelizer.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// G4Voxelizer inline methods
27//
28// 19.10.12 Marek Gayer, created
29// --------------------------------------------------------------------
30
31template <typename T> inline
32G4int G4Voxelizer::BinarySearch(const std::vector<T>& vec, T value)
33{
34 typename std::vector<T>::const_iterator begin=vec.cbegin(), end=vec.cend();
35 return G4int(std::upper_bound(begin, end, value) - begin - 1);
36}
37
38inline
39const std::vector<G4VoxelBox>& G4Voxelizer::GetBoxes() const
40{
41 return fBoxes;
42}
43
44inline
45const std::vector<G4double>& G4Voxelizer::GetBoundary(G4int index) const
46{
47 return fBoundaries[index];
48}
49
50inline
51void G4Voxelizer::GetVoxel(std::vector<G4int>& curVoxel,
52 const G4ThreeVector& point) const
53{
54 for (auto i=0; i<=2; ++i)
55 {
56 const std::vector<double> &boundary = GetBoundary(i);
57 G4int n = BinarySearch(boundary, point[i]);
58 if (n == -1)
59 { n = 0; }
60 else if (n == G4int(boundary.size()) - 1)
61 { n--; }
62 curVoxel[i] = n;
63 }
64}
65
66inline
67G4int G4Voxelizer::GetBitsPerSlice () const
68{
69 return fNPerSlice*8*sizeof(unsigned int);
70}
71
72inline
73G4int G4Voxelizer::GetVoxelsIndex(G4int x, G4int y, G4int z) const
74{
75 if (x < 0 || y < 0 || z < 0) { return -1; }
76 std::size_t maxX = fBoundaries[0].size();
77 std::size_t maxY = fBoundaries[1].size();
78
79 return G4int(x + y*maxX + z*maxX*maxY);
80}
81
82inline
83G4int G4Voxelizer::GetVoxelsIndex(const std::vector<G4int>& voxels) const
84{
85 return GetVoxelsIndex(voxels[0], voxels[1], voxels[2]);
86}
87
88inline
89G4bool G4Voxelizer::GetPointVoxel(const G4ThreeVector& p,
90 std::vector<G4int>& voxels) const
91{
92 for (auto i = 0; i <= 2; ++i)
93 {
94 if (p[i] < *fBoundaries[i].begin() || p[i] > *fBoundaries[i].end())
95 {
96 return false;
97 }
98 }
99 for (auto i = 0; i <= 2; ++i)
100 {
101 voxels[i] = BinarySearch(fBoundaries[i], p[i]);
102 }
103
104 return true;
105}
106
107inline
108G4int G4Voxelizer::GetPointIndex(const G4ThreeVector& p) const
109{
110 std::size_t maxX = fBoundaries[0].size();
111 std::size_t maxY = fBoundaries[1].size();
112 G4int x = BinarySearch(fBoundaries[0], p[0]);
113 G4int y = BinarySearch(fBoundaries[1], p[1]);
114 G4int z = BinarySearch(fBoundaries[2], p[2]);
115
116 return G4int(x + y*maxX + z*maxX*maxY);
117}
118
119inline
120const G4SurfBits& G4Voxelizer::Empty() const
121{
122 return fEmpty;
123}
124
125inline
126G4bool G4Voxelizer::IsEmpty(G4int index) const
127{
128 return fEmpty[index];
129}
130
131inline
132G4int G4Voxelizer::GetMaxVoxels(G4ThreeVector& ratioOfReduction)
133{
134 ratioOfReduction = fReductionRatio;
135 return fMaxVoxels;
136}
137
138inline
139long long G4Voxelizer::GetCountOfVoxels() const
140{
141 return fCountOfVoxels;
142}
143
144inline
145long long G4Voxelizer::CountVoxels(std::vector<G4double> boundaries[]) const
146{
147 long long sx = boundaries[0].size() - 1;
148 long long sy = boundaries[1].size() - 1;
149 long long sz = boundaries[2].size() - 1;
150
151 return sx * sy *sz;
152}
153
154inline
155const std::vector<G4int>&
156G4Voxelizer::GetCandidates(std::vector<G4int>& curVoxel) const
157{
158 G4int voxelsIndex = GetVoxelsIndex(curVoxel);
159
160 if (voxelsIndex >= 0 && !fEmpty[voxelsIndex])
161 {
162 return fCandidates[voxelsIndex];
163 }
164 return fNoCandidates;
165}
166
167inline
168G4int G4Voxelizer::GetTotalCandidates() const
169{
170 return fTotalCandidates;
171}
172
173inline
174G4int G4Voxelizer::GetVoxelBoxesSize() const
175{
176 return G4int(fVoxelBoxes.size());
177}
178
179inline
180const G4VoxelBox &G4Voxelizer::GetVoxelBox(G4int i) const
181{
182 return fVoxelBoxes[i];
183}
184
185inline
186const std::vector<G4int>&
187G4Voxelizer::GetVoxelBoxCandidates(G4int i) const
188{
189 return fVoxelBoxesCandidates[i];
190}
191
192inline
193G4ThreeVector
194G4Voxelizer::GetGlobalPoint(const G4Transform3D& trans,
195 const G4ThreeVector& local) const
196{
197 // Returns global point coordinates converted from the local frame defined
198 // by the transformation. This is defined by multiplying this transformation
199 // with the local vector.
200
201 return trans*G4Point3D(local);
202}