00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 template <typename T> inline
00039 G4int G4SurfaceVoxelizer::BinarySearch(const std::vector<T> &vec, T value)
00040 {
00041 typename std::vector<T>::const_iterator begin=vec.begin(), end=vec.end();
00042 G4int res = std::upper_bound(begin, end, value) - begin - 1;
00043 return res;
00044 }
00045
00046 inline
00047 const std::vector<G4VoxelBox> &G4SurfaceVoxelizer::GetBoxes() const
00048 {
00049 return fBoxes;
00050 }
00051
00052 inline
00053 const std::vector<G4double> &G4SurfaceVoxelizer::GetBoundary(G4int index) const
00054 {
00055 return fBoundaries[index];
00056 }
00057
00058 inline
00059 void G4SurfaceVoxelizer::GetVoxel(std::vector<G4int> &curVoxel,
00060 const G4ThreeVector &point) const
00061 {
00062 for (G4int i=0; i<=2; ++i)
00063 {
00064 curVoxel[i] = BinarySearch(GetBoundary(i), point[i]);
00065 }
00066 }
00067
00068 inline
00069 G4int G4SurfaceVoxelizer::GetBitsPerSlice () const
00070 {
00071 return fNPerSlice*8*sizeof(unsigned int);
00072 }
00073
00074 inline
00075 G4int G4SurfaceVoxelizer::GetVoxelsIndex(G4int x, G4int y, G4int z) const
00076 {
00077 if (x < 0 || y < 0 || z < 0) { return -1; }
00078 G4int maxX = fBoundaries[0].size();
00079 G4int maxY = fBoundaries[1].size();
00080 G4int index = x + y*maxX + z*maxX*maxY;
00081
00082 return index;
00083 }
00084
00085 inline
00086 G4int G4SurfaceVoxelizer::GetVoxelsIndex(const std::vector<G4int> &voxels) const
00087 {
00088 return GetVoxelsIndex(voxels[0], voxels[1], voxels[2]);
00089 }
00090
00091 inline
00092 G4int G4SurfaceVoxelizer::GetPointIndex(const G4ThreeVector &p) const
00093 {
00094 G4int maxX = fBoundaries[0].size();
00095 G4int maxY = fBoundaries[1].size();
00096 G4int x = BinarySearch(fBoundaries[0], p[0]);
00097 G4int y = BinarySearch(fBoundaries[1], p[1]);
00098 G4int z = BinarySearch(fBoundaries[2], p[2]);
00099 G4int index = x + y*maxX + z*maxX*maxY;
00100
00101 return index;
00102 }
00103
00104 inline
00105 const G4SurfBits &G4SurfaceVoxelizer::Empty() const
00106 {
00107 return fEmpty;
00108 }
00109
00110 inline
00111 G4bool G4SurfaceVoxelizer::IsEmpty(G4int index) const
00112 {
00113 return fEmpty[index];
00114 }
00115
00116 inline
00117 G4int G4SurfaceVoxelizer::GetMaxVoxels(G4ThreeVector &ratioOfReduction)
00118 {
00119 ratioOfReduction = fReductionRatio;
00120 return fMaxVoxels;
00121 }
00122
00123 inline
00124 long long G4SurfaceVoxelizer::GetCountOfVoxels() const
00125 {
00126 return fCountOfVoxels;
00127 }
00128
00129 inline
00130 long long G4SurfaceVoxelizer::CountVoxels(std::vector<G4double> boundaries[]) const
00131 {
00132 long long sx = boundaries[0].size() - 1;
00133 long long sy = boundaries[1].size() - 1;
00134 long long sz = boundaries[2].size() - 1;
00135
00136 return sx * sy *sz;
00137 }
00138
00139 inline
00140 const std::vector<G4int>&
00141 G4SurfaceVoxelizer::GetCandidates(std::vector<G4int> &curVoxel) const
00142 {
00143 G4int voxelsIndex = GetVoxelsIndex(curVoxel);
00144
00145 if (voxelsIndex >= 0 && !fEmpty[voxelsIndex])
00146 {
00147 return fCandidates[voxelsIndex];
00148 }
00149 return fNoCandidates;
00150 }
00151
00152 inline
00153 G4int G4SurfaceVoxelizer::GetVoxelBoxesSize() const
00154 {
00155 return fVoxelBoxes.size();
00156 }
00157
00158 inline
00159 const G4VoxelBox &G4SurfaceVoxelizer::GetVoxelBox(G4int i) const
00160 {
00161 return fVoxelBoxes[i];
00162 }
00163
00164 inline
00165 const std::vector<G4int>&
00166 G4SurfaceVoxelizer::GetVoxelBoxCandidates(G4int i) const
00167 {
00168 return fVoxelBoxesCandidates[i];
00169 }