File indexing completed on 2025-01-18 09:59:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 template <typename T> inline
0032 G4int G4Voxelizer::BinarySearch(const std::vector<T>& vec, T value)
0033 {
0034 auto begin=vec.cbegin(), end=vec.cend();
0035 return G4int(std::upper_bound(begin, end, value) - begin - 1);
0036 }
0037
0038 inline
0039 const std::vector<G4VoxelBox>& G4Voxelizer::GetBoxes() const
0040 {
0041 return fBoxes;
0042 }
0043
0044 inline
0045 const std::vector<G4double>& G4Voxelizer::GetBoundary(G4int index) const
0046 {
0047 return fBoundaries[index];
0048 }
0049
0050 inline
0051 void G4Voxelizer::GetVoxel(std::vector<G4int>& curVoxel,
0052 const G4ThreeVector& point) const
0053 {
0054 for (auto i=0; i<=2; ++i)
0055 {
0056 const std::vector<double> &boundary = GetBoundary(i);
0057 G4int n = BinarySearch(boundary, point[i]);
0058 if (n == -1)
0059 { n = 0; }
0060 else if (n == G4int(boundary.size()) - 1)
0061 { n--; }
0062 curVoxel[i] = n;
0063 }
0064 }
0065
0066 inline
0067 G4int G4Voxelizer::GetBitsPerSlice () const
0068 {
0069 return fNPerSlice*8*sizeof(unsigned int);
0070 }
0071
0072 inline
0073 G4int G4Voxelizer::GetVoxelsIndex(G4int x, G4int y, G4int z) const
0074 {
0075 if (x < 0 || y < 0 || z < 0) { return -1; }
0076 std::size_t maxX = fBoundaries[0].size();
0077 std::size_t maxY = fBoundaries[1].size();
0078
0079 return G4int(x + y*maxX + z*maxX*maxY);
0080 }
0081
0082 inline
0083 G4int G4Voxelizer::GetVoxelsIndex(const std::vector<G4int>& voxels) const
0084 {
0085 return GetVoxelsIndex(voxels[0], voxels[1], voxels[2]);
0086 }
0087
0088 inline
0089 G4bool G4Voxelizer::GetPointVoxel(const G4ThreeVector& p,
0090 std::vector<G4int>& voxels) const
0091 {
0092 for (auto i = 0; i <= 2; ++i)
0093 {
0094 auto begin = fBoundaries[i].cbegin(), end = fBoundaries[i].cend();
0095 if (p[i] < *begin || p[i] > *end)
0096 {
0097 return false;
0098 }
0099 }
0100 for (auto i = 0; i <= 2; ++i)
0101 {
0102 voxels[i] = BinarySearch(fBoundaries[i], p[i]);
0103 }
0104
0105 return true;
0106 }
0107
0108 inline
0109 G4int G4Voxelizer::GetPointIndex(const G4ThreeVector& p) const
0110 {
0111 std::size_t maxX = fBoundaries[0].size();
0112 std::size_t maxY = fBoundaries[1].size();
0113 G4int x = BinarySearch(fBoundaries[0], p[0]);
0114 G4int y = BinarySearch(fBoundaries[1], p[1]);
0115 G4int z = BinarySearch(fBoundaries[2], p[2]);
0116
0117 return G4int(x + y*maxX + z*maxX*maxY);
0118 }
0119
0120 inline
0121 const G4SurfBits& G4Voxelizer::Empty() const
0122 {
0123 return fEmpty;
0124 }
0125
0126 inline
0127 G4bool G4Voxelizer::IsEmpty(G4int index) const
0128 {
0129 return fEmpty[index];
0130 }
0131
0132 inline
0133 G4int G4Voxelizer::GetMaxVoxels(G4ThreeVector& ratioOfReduction)
0134 {
0135 ratioOfReduction = fReductionRatio;
0136 return fMaxVoxels;
0137 }
0138
0139 inline
0140 long long G4Voxelizer::GetCountOfVoxels() const
0141 {
0142 return fCountOfVoxels;
0143 }
0144
0145 inline
0146 long long G4Voxelizer::CountVoxels(std::vector<G4double> boundaries[]) const
0147 {
0148 long long sx = boundaries[0].size() - 1;
0149 long long sy = boundaries[1].size() - 1;
0150 long long sz = boundaries[2].size() - 1;
0151
0152 return sx * sy *sz;
0153 }
0154
0155 inline
0156 const std::vector<G4int>&
0157 G4Voxelizer::GetCandidates(std::vector<G4int>& curVoxel) const
0158 {
0159 G4int voxelsIndex = GetVoxelsIndex(curVoxel);
0160
0161 if (voxelsIndex >= 0 && !fEmpty[voxelsIndex])
0162 {
0163 return fCandidates[voxelsIndex];
0164 }
0165 return fNoCandidates;
0166 }
0167
0168 inline
0169 G4int G4Voxelizer::GetTotalCandidates() const
0170 {
0171 return fTotalCandidates;
0172 }
0173
0174 inline
0175 G4int G4Voxelizer::GetVoxelBoxesSize() const
0176 {
0177 return G4int(fVoxelBoxes.size());
0178 }
0179
0180 inline
0181 const G4VoxelBox &G4Voxelizer::GetVoxelBox(G4int i) const
0182 {
0183 return fVoxelBoxes[i];
0184 }
0185
0186 inline
0187 const std::vector<G4int>&
0188 G4Voxelizer::GetVoxelBoxCandidates(G4int i) const
0189 {
0190 return fVoxelBoxesCandidates[i];
0191 }
0192
0193 inline
0194 G4ThreeVector
0195 G4Voxelizer::GetGlobalPoint(const G4Transform3D& trans,
0196 const G4ThreeVector& local) const
0197 {
0198
0199
0200
0201
0202 return trans*G4Point3D(local);
0203 }