2 // ********************************************************************
3 // * License and Disclaimer *
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. *
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. *
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 // ********************************************************************
26 // $Id: G4SurfaceVoxelizer.icc 72335 2013-07-16 09:01:49Z gcosmo $
27 // GEANT4 tag $Name: not supported by cvs2svn $
29 // --------------------------------------------------------------------
30 // GEANT 4 class header file
32 // G4SurfaceVoxelizer inline methods
35 // 19.10.12 Marek Gayer, created
36 // --------------------------------------------------------------------
39 template <typename T> inline
40 G4int G4SurfaceVoxelizer::BinarySearch(const std::vector<T> &vec, T value)
42 typename std::vector<T>::const_iterator begin=vec.begin(), end=vec.end();
43 G4int res = std::upper_bound(begin, end, value) - begin - 1;
48 const std::vector<G4VoxelBox> &G4SurfaceVoxelizer::GetBoxes() const
54 const std::vector<G4double> &G4SurfaceVoxelizer::GetBoundary(G4int index) const
56 return fBoundaries[index];
60 void G4SurfaceVoxelizer::GetVoxel(std::vector<G4int> &curVoxel,
61 const G4ThreeVector &point) const
63 for (G4int i=0; i<=2; ++i)
65 const std::vector<double> &boundary = GetBoundary(i);
66 G4int n = BinarySearch(boundary, point[i]);
69 else if (n == G4int(boundary.size()) - 1)
76 G4int G4SurfaceVoxelizer::GetBitsPerSlice () const
78 return fNPerSlice*8*sizeof(unsigned int);
82 G4int G4SurfaceVoxelizer::GetVoxelsIndex(G4int x, G4int y, G4int z) const
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;
93 G4int G4SurfaceVoxelizer::GetVoxelsIndex(const std::vector<G4int> &voxels) const
95 return GetVoxelsIndex(voxels[0], voxels[1], voxels[2]);
99 G4int G4SurfaceVoxelizer::GetPointIndex(const G4ThreeVector &p) const
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;
112 const G4SurfBits &G4SurfaceVoxelizer::Empty() const
118 G4bool G4SurfaceVoxelizer::IsEmpty(G4int index) const
120 return fEmpty[index];
124 G4int G4SurfaceVoxelizer::GetMaxVoxels(G4ThreeVector &ratioOfReduction)
126 ratioOfReduction = fReductionRatio;
131 long long G4SurfaceVoxelizer::GetCountOfVoxels() const
133 return fCountOfVoxels;
137 long long G4SurfaceVoxelizer::CountVoxels(std::vector<G4double> boundaries[]) const
139 long long sx = boundaries[0].size() - 1;
140 long long sy = boundaries[1].size() - 1;
141 long long sz = boundaries[2].size() - 1;
147 const std::vector<G4int>&
148 G4SurfaceVoxelizer::GetCandidates(std::vector<G4int> &curVoxel) const
150 G4int voxelsIndex = GetVoxelsIndex(curVoxel);
152 if (voxelsIndex >= 0 && !fEmpty[voxelsIndex])
154 return fCandidates[voxelsIndex];
156 return fNoCandidates;
160 G4int G4SurfaceVoxelizer::GetVoxelBoxesSize() const
162 return fVoxelBoxes.size();
166 const G4VoxelBox &G4SurfaceVoxelizer::GetVoxelBox(G4int i) const
168 return fVoxelBoxes[i];
172 const std::vector<G4int>&
173 G4SurfaceVoxelizer::GetVoxelBoxCandidates(G4int i) const
175 return fVoxelBoxesCandidates[i];