Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Voxelizer Class Reference

#include <G4Voxelizer.hh>

Public Member Functions

void Voxelize (std::vector< G4VSolid * > &solids, std::vector< G4Transform3D > &transforms)
 
void Voxelize (std::vector< G4VFacet * > &facets)
 
void DisplayVoxelLimits () const
 
void DisplayBoundaries ()
 
void DisplayListNodes () const
 
 G4Voxelizer ()
 
 ~G4Voxelizer ()
 
void GetCandidatesVoxel (std::vector< G4int > &voxels)
 
G4int GetCandidatesVoxelArray (const G4ThreeVector &point, std::vector< G4int > &list, G4SurfBits *crossed=nullptr) const
 
G4int GetCandidatesVoxelArray (const std::vector< G4int > &voxels, const G4SurfBits bitmasks[], std::vector< G4int > &list, G4SurfBits *crossed=nullptr) const
 
G4int GetCandidatesVoxelArray (const std::vector< G4int > &voxels, std::vector< G4int > &list, G4SurfBits *crossed=nullptr) const
 
const std::vector< G4VoxelBox > & GetBoxes () const
 
const std::vector< G4double > & GetBoundary (G4int index) const
 
G4bool UpdateCurrentVoxel (const G4ThreeVector &point, const G4ThreeVector &direction, std::vector< G4int > &curVoxel) const
 
void GetVoxel (std::vector< G4int > &curVoxel, const G4ThreeVector &point) const
 
G4int GetBitsPerSlice () const
 
G4bool Contains (const G4ThreeVector &point) const
 
G4double DistanceToNext (const G4ThreeVector &point, const G4ThreeVector &direction, std::vector< G4int > &curVoxel) const
 
G4double DistanceToFirst (const G4ThreeVector &point, const G4ThreeVector &direction) const
 
G4double DistanceToBoundingBox (const G4ThreeVector &point) const
 
G4int GetVoxelsIndex (G4int x, G4int y, G4int z) const
 
G4int GetVoxelsIndex (const std::vector< G4int > &voxels) const
 
G4bool GetPointVoxel (const G4ThreeVector &p, std::vector< G4int > &voxels) const
 
G4int GetPointIndex (const G4ThreeVector &p) const
 
const G4SurfBitsEmpty () const
 
G4bool IsEmpty (G4int index) const
 
void SetMaxVoxels (G4int max)
 
void SetMaxVoxels (const G4ThreeVector &reductionRatio)
 
G4int GetMaxVoxels (G4ThreeVector &ratioOfReduction)
 
G4int AllocatedMemory ()
 
long long GetCountOfVoxels () const
 
long long CountVoxels (std::vector< G4double > boundaries[]) const
 
const std::vector< G4int > & GetCandidates (std::vector< G4int > &curVoxel) const
 
G4int GetVoxelBoxesSize () const
 
const G4VoxelBoxGetVoxelBox (G4int i) const
 
const std::vector< G4int > & GetVoxelBoxCandidates (G4int i) const
 
G4int GetTotalCandidates () const
 

Static Public Member Functions

template<typename T >
static G4int BinarySearch (const std::vector< T > &vec, T value)
 
static G4double MinDistanceToBox (const G4ThreeVector &aPoint, const G4ThreeVector &f)
 
static void SetDefaultVoxelsCount (G4int count)
 
static G4int GetDefaultVoxelsCount ()
 

Detailed Description

Definition at line 62 of file G4Voxelizer.hh.

Constructor & Destructor Documentation

◆ G4Voxelizer()

G4Voxelizer::G4Voxelizer ( )

Definition at line 54 of file G4Voxelizer.cc.

55 : fBoundingBox("VoxBBox", 1, 1, 1)
56{
57 fCountOfVoxels = fNPerSlice = fTotalCandidates = 0;
58
60
61 SetMaxVoxels(fDefaultVoxelsCount);
62
63 G4SolidStore::GetInstance()->DeRegister(&fBoundingBox);
64}
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()
static void DeRegister(G4VSolid *pSolid)
static G4SolidStore * GetInstance()
void SetMaxVoxels(G4int max)

◆ ~G4Voxelizer()

G4Voxelizer::~G4Voxelizer ( )
default

Member Function Documentation

◆ AllocatedMemory()

G4int G4Voxelizer::AllocatedMemory ( )

Definition at line 1350 of file G4Voxelizer.cc.

1351{
1352 G4int size = fEmpty.GetNbytes();
1353 size += fBoxes.capacity() * sizeof(G4VoxelBox);
1354 size += sizeof(G4double) * (fBoundaries[0].capacity()
1355 + fBoundaries[1].capacity() + fBoundaries[2].capacity());
1356 size += sizeof(G4int) * (fCandidatesCounts[0].capacity()
1357 + fCandidatesCounts[1].capacity() + fCandidatesCounts[2].capacity());
1358 size += fBitmasks[0].GetNbytes() + fBitmasks[1].GetNbytes()
1359 + fBitmasks[2].GetNbytes();
1360
1361 auto csize = (G4int)fCandidates.size();
1362 for (G4int i = 0; i < csize; ++i)
1363 {
1364 size += sizeof(vector<G4int>) + fCandidates[i].capacity() * sizeof(G4int);
1365 }
1366
1367 return size;
1368}
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
unsigned int GetNbytes() const
Definition G4SurfBits.hh:93

Referenced by G4TessellatedSolid::AllocatedMemory().

◆ BinarySearch()

template<typename T >
static G4int G4Voxelizer::BinarySearch ( const std::vector< T > & vec,
T value )
inlinestatic

◆ Contains()

G4bool G4Voxelizer::Contains ( const G4ThreeVector & point) const

Definition at line 1151 of file G4Voxelizer.cc.

1152{
1153 for (auto i = 0; i < 3; ++i)
1154 {
1155 if (point[i] < fBoundaries[i].front() || point[i] > fBoundaries[i].back())
1156 return false;
1157 }
1158 return true;
1159}

◆ CountVoxels()

long long G4Voxelizer::CountVoxels ( std::vector< G4double > boundaries[]) const
inline

Referenced by Voxelize().

◆ DisplayBoundaries()

void G4Voxelizer::DisplayBoundaries ( )

Definition at line 316 of file G4Voxelizer.cc.

317{
318 char axis[3] = {'X', 'Y', 'Z'};
319 for (auto i = 0; i <= 2; ++i)
320 {
321 G4cout << " * " << axis[i] << " axis:" << G4endl << " | ";
322 DisplayBoundaries(fBoundaries[i]);
323 }
324}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
void DisplayBoundaries()

Referenced by DisplayBoundaries().

◆ DisplayListNodes()

void G4Voxelizer::DisplayListNodes ( ) const

Definition at line 421 of file G4Voxelizer.cc.

422{
423 // Prints which solids are present in the slices previously elaborated.
424
425 char axis[3] = {'X', 'Y', 'Z'};
426 G4int size=8*sizeof(G4int)*fNPerSlice;
427 G4SurfBits bits(size);
428
429 for (auto j = 0; j <= 2; ++j)
430 {
431 G4cout << " * " << axis[j] << " axis:" << G4endl;
432 auto count = (G4int)fBoundaries[j].size();
433 for(G4int i=0; i < count-1; ++i)
434 {
435 G4cout << " Slice #" << i+1 << ": [" << fBoundaries[j][i]
436 << " ; " << fBoundaries[j][i+1] << "] -> ";
437 bits.set(size,(const char *)fBitmasks[j].fAllBits+i
438 *fNPerSlice*sizeof(G4int));
439 G4String result = GetCandidatesAsString(bits);
440 G4cout << "[ " << result.c_str() << "] " << G4endl;
441 }
442 }
443}

◆ DisplayVoxelLimits()

void G4Voxelizer::DisplayVoxelLimits ( ) const

Definition at line 194 of file G4Voxelizer.cc.

195{
196 // "DisplayVoxelLimits" displays the dX, dY, dZ, pX, pY and pZ for each node
197
198 std::size_t numNodes = fBoxes.size();
199 G4long oldprec = G4cout.precision(16);
200 for(std::size_t i = 0; i < numNodes; ++i)
201 {
202 G4cout << setw(10) << setiosflags(ios::fixed) <<
203 " -> Node " << i+1 << ":\n" <<
204 "\t * [x,y,z] = " << fBoxes[i].hlen <<
205 "\t * [x,y,z] = " << fBoxes[i].pos << "\n";
206 }
207 G4cout.precision(oldprec);
208}
long G4long
Definition G4Types.hh:87

◆ DistanceToBoundingBox()

G4double G4Voxelizer::DistanceToBoundingBox ( const G4ThreeVector & point) const

Definition at line 1173 of file G4Voxelizer.cc.

1174{
1175 G4ThreeVector pointShifted = point - fBoundingBoxCenter;
1176 G4double shift = MinDistanceToBox(pointShifted, fBoundingBoxSize);
1177 return shift;
1178}
static G4double MinDistanceToBox(const G4ThreeVector &aPoint, const G4ThreeVector &f)

Referenced by G4MultiUnion::DistanceToIn(), and G4TessellatedSolid::SafetyFromOutside().

◆ DistanceToFirst()

G4double G4Voxelizer::DistanceToFirst ( const G4ThreeVector & point,
const G4ThreeVector & direction ) const

Definition at line 1163 of file G4Voxelizer.cc.

1165{
1166 G4ThreeVector pointShifted = point - fBoundingBoxCenter;
1167 G4double shift = fBoundingBox.DistanceToIn(pointShifted, direction);
1168 return shift;
1169}
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
Definition G4Box.cc:320

Referenced by G4MultiUnion::DistanceToIn().

◆ DistanceToNext()

G4double G4Voxelizer::DistanceToNext ( const G4ThreeVector & point,
const G4ThreeVector & direction,
std::vector< G4int > & curVoxel ) const

Definition at line 1208 of file G4Voxelizer.cc.

1211{
1212 G4double shift = kInfinity;
1213
1214 G4int cur = 0; // the smallest index, which would be than increased
1215 for (G4int i = 0; i <= 2; ++i)
1216 {
1217 // Looking for the next voxels on the considered direction X,Y,Z axis
1218 //
1219 const std::vector<G4double>& boundary = fBoundaries[i];
1220 G4int index = curVoxel[i];
1221 if (direction[i] >= 1e-10)
1222 {
1223 ++index;
1224 }
1225 else
1226 {
1227 if (direction[i] > -1e-10)
1228 continue;
1229 }
1230 G4double dif = boundary[index] - point[i];
1231 G4double distance = dif / direction[i];
1232
1233 if (shift > distance)
1234 {
1235 shift = distance;
1236 cur = i;
1237 }
1238 }
1239
1240 if (shift != kInfinity)
1241 {
1242 // updating current voxel using the index corresponding
1243 // to the closest voxel boundary on the ray
1244
1245 if (direction[cur] > 0)
1246 {
1247 if (++curVoxel[cur] >= (G4int) fBoundaries[cur].size() - 1)
1248 shift = kInfinity;
1249 }
1250 else
1251 {
1252 if (--curVoxel[cur] < 0)
1253 shift = kInfinity;
1254 }
1255 }
1256
1257/*
1258 for (auto i = 0; i <= 2; ++i)
1259 {
1260 // Looking for the next voxels on the considered direction X,Y,Z axis
1261 //
1262 const std::vector<G4double> &boundary = fBoundaries[i];
1263 G4int cur = curVoxel[i];
1264 if(direction[i] >= 1e-10)
1265 {
1266 if (boundary[++cur] - point[i] < fTolerance) // make sure shift would
1267 if (++cur >= (G4int) boundary.size()) // be non-zero
1268 continue;
1269 }
1270 else
1271 {
1272 if(direction[i] <= -1e-10)
1273 {
1274 if (point[i] - boundary[cur] < fTolerance) // make sure shift would
1275 if (--cur < 0) // be non-zero
1276 continue;
1277 }
1278 else
1279 continue;
1280 }
1281 G4double dif = boundary[cur] - point[i];
1282 G4double distance = dif / direction[i];
1283
1284 if (shift > distance)
1285 shift = distance;
1286 }
1287*/
1288 return shift;
1289}

Referenced by G4MultiUnion::DistanceToIn().

◆ Empty()

const G4SurfBits & G4Voxelizer::Empty ( ) const
inline

◆ GetBitsPerSlice()

G4int G4Voxelizer::GetBitsPerSlice ( ) const
inline

◆ GetBoundary()

const std::vector< G4double > & G4Voxelizer::GetBoundary ( G4int index) const
inline

◆ GetBoxes()

const std::vector< G4VoxelBox > & G4Voxelizer::GetBoxes ( ) const
inline

◆ GetCandidates()

const std::vector< G4int > & G4Voxelizer::GetCandidates ( std::vector< G4int > & curVoxel) const
inline

◆ GetCandidatesVoxel()

void G4Voxelizer::GetCandidatesVoxel ( std::vector< G4int > & voxels)

Definition at line 886 of file G4Voxelizer.cc.

887{
888 // "GetCandidates" should compute which solids are possibly contained in
889 // the voxel defined by the three slices characterized by the passed indexes.
890
891 G4cout << " Candidates in voxel [" << voxels[0] << " ; " << voxels[1]
892 << " ; " << voxels[2] << "]: ";
893 std::vector<G4int> candidates;
894 G4int count = GetCandidatesVoxelArray(voxels, candidates);
895 G4cout << "[ ";
896 for (G4int i = 0; i < count; ++i) G4cout << candidates[i];
897 G4cout << "] " << G4endl;
898}
G4int GetCandidatesVoxelArray(const G4ThreeVector &point, std::vector< G4int > &list, G4SurfBits *crossed=nullptr) const

◆ GetCandidatesVoxelArray() [1/3]

G4int G4Voxelizer::GetCandidatesVoxelArray ( const G4ThreeVector & point,
std::vector< G4int > & list,
G4SurfBits * crossed = nullptr ) const

Definition at line 963 of file G4Voxelizer.cc.

965{
966 // Method returning the candidates corresponding to the passed point
967
968 list.clear();
969
970 for (auto i = 0; i <= 2; ++i)
971 {
972 if(point[i] < fBoundaries[i].front() || point[i] >= fBoundaries[i].back())
973 return 0;
974 }
975
976 if (fTotalCandidates == 1)
977 {
978 list.push_back(0);
979 return 1;
980 }
981 else
982 {
983 if (fNPerSlice == 1)
984 {
985 unsigned int mask = 0xFFffFFff;
986 G4int slice;
987 if (fBoundaries[0].size() > 2)
988 {
989 slice = BinarySearch(fBoundaries[0], point.x());
990 if ((mask = ((unsigned int*) fBitmasks[0].fAllBits)[slice]) == 0u)
991 return 0;
992 }
993 if (fBoundaries[1].size() > 2)
994 {
995 slice = BinarySearch(fBoundaries[1], point.y());
996 if ((mask &= ((unsigned int*) fBitmasks[1].fAllBits)[slice]) == 0u)
997 return 0;
998 }
999 if (fBoundaries[2].size() > 2)
1000 {
1001 slice = BinarySearch(fBoundaries[2], point.z());
1002 if ((mask &= ((unsigned int*) fBitmasks[2].fAllBits)[slice]) == 0u)
1003 return 0;
1004 }
1005 if ((crossed != nullptr) && ((mask &= ~((unsigned int*)crossed->fAllBits)[0]) == 0u))
1006 return 0;
1007
1008 FindComponentsFastest(mask, list, 0);
1009 }
1010 else
1011 {
1012 unsigned int* masks[3], mask; // masks for X,Y,Z axis
1013 for (auto i = 0; i <= 2; ++i)
1014 {
1015 G4int slice = BinarySearch(fBoundaries[i], point[i]);
1016 masks[i] = ((unsigned int*) fBitmasks[i].fAllBits)
1017 + slice * fNPerSlice;
1018 }
1019 unsigned int* maskCrossed = crossed != nullptr
1020 ? (unsigned int*)crossed->fAllBits : nullptr;
1021
1022 for (G4int i = 0 ; i < fNPerSlice; ++i)
1023 {
1024 // Logic "and" of the masks along the 3 axes x, y, z:
1025 // removing "if (!" and ") continue" => slightly slower
1026 //
1027 if ((mask = masks[0][i]) == 0u) continue;
1028 if ((mask &= masks[1][i]) == 0u) continue;
1029 if ((mask &= masks[2][i]) == 0u) continue;
1030 if ((maskCrossed != nullptr) && ((mask &= ~maskCrossed[i]) == 0u)) continue;
1031
1032 FindComponentsFastest(mask, list, i);
1033 }
1034 }
1035/*
1036 if (fNPerSlice == 1)
1037 {
1038 unsigned int mask;
1039 G4int slice = BinarySearch(fBoundaries[0], point.x());
1040 if (!(mask = ((unsigned int *) fBitmasks[0].fAllBits)[slice]
1041 )) return 0;
1042 slice = BinarySearch(fBoundaries[1], point.y());
1043 if (!(mask &= ((unsigned int *) fBitmasks[1].fAllBits)[slice]
1044 )) return 0;
1045 slice = BinarySearch(fBoundaries[2], point.z());
1046 if (!(mask &= ((unsigned int *) fBitmasks[2].fAllBits)[slice]
1047 )) return 0;
1048 if (crossed && (!(mask &= ~((unsigned int *)crossed->fAllBits)[0])))
1049 return 0;
1050
1051 FindComponentsFastest(mask, list, 0);
1052 }
1053 else
1054 {
1055 unsigned int *masks[3], mask; // masks for X,Y,Z axis
1056 for (auto i = 0; i <= 2; ++i)
1057 {
1058 G4int slice = BinarySearch(fBoundaries[i], point[i]);
1059 masks[i] = ((unsigned int *) fBitmasks[i].fAllBits) + slice*fNPerSlice;
1060 }
1061 unsigned int *maskCrossed =
1062 crossed ? (unsigned int *)crossed->fAllBits : 0;
1063
1064 for (G4int i = 0 ; i < fNPerSlice; ++i)
1065 {
1066 // Logic "and" of the masks along the 3 axes x, y, z:
1067 // removing "if (!" and ") continue" => slightly slower
1068 //
1069 if (!(mask = masks[0][i])) continue;
1070 if (!(mask &= masks[1][i])) continue;
1071 if (!(mask &= masks[2][i])) continue;
1072 if (maskCrossed && !(mask &= ~maskCrossed[i])) continue;
1073
1074 FindComponentsFastest(mask, list, i);
1075 }
1076 }
1077*/
1078 }
1079 return (G4int)list.size();
1080}
double z() const
double x() const
double y() const
unsigned char * fAllBits
static G4int BinarySearch(const std::vector< T > &vec, T value)

Referenced by G4MultiUnion::DistanceToIn(), G4MultiUnion::DistanceToOut(), G4MultiUnion::DistanceToOutVoxels(), GetCandidatesVoxel(), GetCandidatesVoxelArray(), and G4MultiUnion::SurfaceNormal().

◆ GetCandidatesVoxelArray() [2/3]

G4int G4Voxelizer::GetCandidatesVoxelArray ( const std::vector< G4int > & voxels,
const G4SurfBits bitmasks[],
std::vector< G4int > & list,
G4SurfBits * crossed = nullptr ) const

Definition at line 1084 of file G4Voxelizer.cc.

1088{
1089 list.clear();
1090
1091 if (fTotalCandidates == 1)
1092 {
1093 list.push_back(0);
1094 return 1;
1095 }
1096 else
1097 {
1098 if (fNPerSlice == 1)
1099 {
1100 unsigned int mask;
1101 if ((mask = ((unsigned int *) bitmasks[0].fAllBits)[voxels[0]]) == 0u)
1102 return 0;
1103 if ((mask &= ((unsigned int *) bitmasks[1].fAllBits)[voxels[1]]) == 0u)
1104 return 0;
1105 if ((mask &= ((unsigned int *) bitmasks[2].fAllBits)[voxels[2]]) == 0u)
1106 return 0;
1107 if ((crossed != nullptr) && ((mask &= ~((unsigned int *)crossed->fAllBits)[0]) == 0u))
1108 return 0;
1109
1110 FindComponentsFastest(mask, list, 0);
1111 }
1112 else
1113 {
1114 unsigned int *masks[3], mask; // masks for X,Y,Z axis
1115 for (auto i = 0; i <= 2; ++i)
1116 {
1117 masks[i] = ((unsigned int *) bitmasks[i].fAllBits)
1118 + voxels[i]*fNPerSlice;
1119 }
1120 unsigned int *maskCrossed = crossed != nullptr
1121 ? (unsigned int *)crossed->fAllBits : nullptr;
1122
1123 for (G4int i = 0 ; i < fNPerSlice; ++i)
1124 {
1125 // Logic "and" of the masks along the 3 axes x, y, z:
1126 // removing "if (!" and ") continue" => slightly slower
1127 //
1128 if ((mask = masks[0][i]) == 0u) continue;
1129 if ((mask &= masks[1][i]) == 0u) continue;
1130 if ((mask &= masks[2][i]) == 0u) continue;
1131 if ((maskCrossed != nullptr) && ((mask &= ~maskCrossed[i]) == 0u)) continue;
1132
1133 FindComponentsFastest(mask, list, i);
1134 }
1135 }
1136 }
1137 return (G4int)list.size();
1138}

◆ GetCandidatesVoxelArray() [3/3]

G4int G4Voxelizer::GetCandidatesVoxelArray ( const std::vector< G4int > & voxels,
std::vector< G4int > & list,
G4SurfBits * crossed = nullptr ) const

Definition at line 1142 of file G4Voxelizer.cc.

1144{
1145 // Method returning the candidates corresponding to the passed point
1146
1147 return GetCandidatesVoxelArray(voxels, fBitmasks, list, crossed);
1148}

◆ GetCountOfVoxels()

◆ GetDefaultVoxelsCount()

G4int G4Voxelizer::GetDefaultVoxelsCount ( )
static

Definition at line 1344 of file G4Voxelizer.cc.

1345{
1346 return fDefaultVoxelsCount;
1347}

◆ GetMaxVoxels()

G4int G4Voxelizer::GetMaxVoxels ( G4ThreeVector & ratioOfReduction)
inline

◆ GetPointIndex()

G4int G4Voxelizer::GetPointIndex ( const G4ThreeVector & p) const
inline

◆ GetPointVoxel()

G4bool G4Voxelizer::GetPointVoxel ( const G4ThreeVector & p,
std::vector< G4int > & voxels ) const
inline

◆ GetTotalCandidates()

G4int G4Voxelizer::GetTotalCandidates ( ) const
inline

◆ GetVoxel()

void G4Voxelizer::GetVoxel ( std::vector< G4int > & curVoxel,
const G4ThreeVector & point ) const
inline

◆ GetVoxelBox()

const G4VoxelBox & G4Voxelizer::GetVoxelBox ( G4int i) const
inline

◆ GetVoxelBoxCandidates()

const std::vector< G4int > & G4Voxelizer::GetVoxelBoxCandidates ( G4int i) const
inline

◆ GetVoxelBoxesSize()

G4int G4Voxelizer::GetVoxelBoxesSize ( ) const
inline

◆ GetVoxelsIndex() [1/2]

G4int G4Voxelizer::GetVoxelsIndex ( const std::vector< G4int > & voxels) const
inline

◆ GetVoxelsIndex() [2/2]

G4int G4Voxelizer::GetVoxelsIndex ( G4int x,
G4int y,
G4int z ) const
inline

◆ IsEmpty()

G4bool G4Voxelizer::IsEmpty ( G4int index) const
inline

◆ MinDistanceToBox()

G4double G4Voxelizer::MinDistanceToBox ( const G4ThreeVector & aPoint,
const G4ThreeVector & f )
static

Definition at line 1182 of file G4Voxelizer.cc.

1184{
1185 // Estimates the isotropic safety from a point outside the current solid to
1186 // any of its surfaces. The algorithm may be accurate or should provide a
1187 // fast underestimate.
1188
1189 G4double safe, safx, safy, safz;
1190 safe = safx = -f.x() + std::abs(aPoint.x());
1191 safy = -f.y() + std::abs(aPoint.y());
1192 if ( safy > safe ) safe = safy;
1193 safz = -f.z() + std::abs(aPoint.z());
1194 if ( safz > safe ) safe = safz;
1195 if (safe < 0.0) return 0.0; // point is inside
1196
1197 G4double safsq = 0.0;
1198 G4int count = 0;
1199 if ( safx > 0 ) { safsq += safx*safx; ++count; }
1200 if ( safy > 0 ) { safsq += safy*safy; ++count; }
1201 if ( safz > 0 ) { safsq += safz*safz; ++count; }
1202 if (count == 1) return safe;
1203 return std::sqrt(safsq);
1204}

Referenced by DistanceToBoundingBox().

◆ SetDefaultVoxelsCount()

void G4Voxelizer::SetDefaultVoxelsCount ( G4int count)
static

Definition at line 1338 of file G4Voxelizer.cc.

1339{
1340 fDefaultVoxelsCount = count;
1341}

◆ SetMaxVoxels() [1/2]

void G4Voxelizer::SetMaxVoxels ( const G4ThreeVector & reductionRatio)

Definition at line 1331 of file G4Voxelizer.cc.

1332{
1333 fMaxVoxels = -1;
1334 fReductionRatio = ratioOfReduction;
1335}

◆ SetMaxVoxels() [2/2]

void G4Voxelizer::SetMaxVoxels ( G4int max)

Definition at line 1324 of file G4Voxelizer.cc.

1325{
1326 fMaxVoxels = max;
1327 fReductionRatio.set(0,0,0);
1328}
void set(double x, double y, double z)
T max(const T t1, const T t2)
brief Return the largest of the two arguments

Referenced by G4Voxelizer(), and G4TessellatedSolid::SetMaxVoxels().

◆ UpdateCurrentVoxel()

G4bool G4Voxelizer::UpdateCurrentVoxel ( const G4ThreeVector & point,
const G4ThreeVector & direction,
std::vector< G4int > & curVoxel ) const

Definition at line 1293 of file G4Voxelizer.cc.

1296{
1297 for (auto i = 0; i <= 2; ++i)
1298 {
1299 G4int index = curVoxel[i];
1300 const std::vector<G4double> &boundary = fBoundaries[i];
1301
1302 if (direction[i] > 0)
1303 {
1304 if (point[i] >= boundary[++index])
1305 if (++curVoxel[i] >= (G4int) boundary.size() - 1)
1306 return false;
1307 }
1308 else
1309 {
1310 if (point[i] < boundary[index])
1311 if (--curVoxel[i] < 0)
1312 return false;
1313 }
1314#ifdef G4SPECSDEBUG
1315 G4int indexOK = BinarySearch(boundary, point[i]);
1316 if (curVoxel[i] != indexOK)
1317 curVoxel[i] = indexOK; // put breakpoint here
1318#endif
1319 }
1320 return true;
1321}

◆ Voxelize() [1/2]

void G4Voxelizer::Voxelize ( std::vector< G4VFacet * > & facets)

Definition at line 757 of file G4Voxelizer.cc.

758{
759 G4int maxVoxels = fMaxVoxels;
760 G4ThreeVector reductionRatio = fReductionRatio;
761
762 std::size_t size = facets.size();
763 if (size < 10)
764 {
765 for (const auto & facet : facets)
766 {
767 if (facet->GetNumberOfVertices() > 3) ++size;
768 }
769 }
770
771 if ((size >= 10 || maxVoxels > 0) && maxVoxels != 0 && maxVoxels != 1)
772 {
773#ifdef G4SPECSDEBUG
774 G4cout << "Building voxel limits..." << G4endl;
775#endif
776
777 BuildVoxelLimits(facets);
778
779#ifdef G4SPECSDEBUG
780 G4cout << "Building boundaries..." << G4endl;
781#endif
782
783 BuildBoundaries();
784
785#ifdef G4SPECSDEBUG
786 G4cout << "Building bitmasks..." << G4endl;
787#endif
788
789 BuildBitmasks(fBoundaries, nullptr, true);
790
791 if (maxVoxels < 0 && reductionRatio == G4ThreeVector())
792 {
793 maxVoxels = fTotalCandidates;
794 if (fTotalCandidates > 1000000) maxVoxels = 1000000;
795 }
796
797 SetReductionRatio(maxVoxels, reductionRatio);
798
799 fCountOfVoxels = CountVoxels(fBoundaries);
800
801#ifdef G4SPECSDEBUG
802 G4cout << "Total number of voxels: " << fCountOfVoxels << G4endl;
803#endif
804
805 BuildReduceVoxels2(fBoundaries, reductionRatio);
806
807 fCountOfVoxels = CountVoxels(fBoundaries);
808
809#ifdef G4SPECSDEBUG
810 G4cout << "Total number of voxels after reduction: "
811 << fCountOfVoxels << G4endl;
812#endif
813
814#ifdef G4SPECSDEBUG
815 G4cout << "Building bitmasks..." << G4endl;
816#endif
817
818 BuildBitmasks(fBoundaries, fBitmasks);
819
820 G4ThreeVector reductionRatioMini;
821
822 G4SurfBits bitmasksMini[3];
823
824 // section for building mini voxels
825
826 std::vector<G4double> miniBoundaries[3];
827
828 for (auto i = 0; i <= 2; ++i) { miniBoundaries[i] = fBoundaries[i]; }
829
830 G4int voxelsCountMini = (fCountOfVoxels >= 1000)
831 ? 100 : G4int(fCountOfVoxels / 10);
832
833 SetReductionRatio(voxelsCountMini, reductionRatioMini);
834
835#ifdef G4SPECSDEBUG
836 G4cout << "Building reduced voxels..." << G4endl;
837#endif
838
839 BuildReduceVoxels(miniBoundaries, reductionRatioMini);
840
841#ifdef G4SPECSDEBUG
842 G4int total = CountVoxels(miniBoundaries);
843 G4cout << "Total number of mini voxels: " << total << G4endl;
844#endif
845
846#ifdef G4SPECSDEBUG
847 G4cout << "Building mini bitmasks..." << G4endl;
848#endif
849
850 BuildBitmasks(miniBoundaries, bitmasksMini);
851
852#ifdef G4SPECSDEBUG
853 G4cout << "Creating Mini Voxels..." << G4endl;
854#endif
855
856 CreateMiniVoxels(miniBoundaries, bitmasksMini);
857
858#ifdef G4SPECSDEBUG
859 G4cout << "Building bounding box..." << G4endl;
860#endif
861
862 BuildBoundingBox();
863
864#ifdef G4SPECSDEBUG
865 G4cout << "Building empty..." << G4endl;
866#endif
867
868 BuildEmpty();
869
870#ifdef G4SPECSDEBUG
871 G4cout << "Deallocating unnecessary fields during runtime..." << G4endl;
872#endif
873 // deallocate fields unnecessary during runtime
874 //
875 fBoxes.resize(0);
876 for (auto i = 0; i < 3; ++i)
877 {
878 fCandidatesCounts[i].resize(0);
879 fBitmasks[i].Clear();
880 }
881 }
882}
CLHEP::Hep3Vector G4ThreeVector
void Clear()
Definition G4SurfBits.cc:89
long long CountVoxels(std::vector< G4double > boundaries[]) const
G4double total(Particle const *const p1, Particle const *const p2)

◆ Voxelize() [2/2]

void G4Voxelizer::Voxelize ( std::vector< G4VSolid * > & solids,
std::vector< G4Transform3D > & transforms )

Definition at line 703 of file G4Voxelizer.cc.

705{
706 BuildVoxelLimits(solids, transforms);
707 BuildBoundaries();
708 BuildBitmasks(fBoundaries, fBitmasks);
709 BuildBoundingBox();
710 BuildEmpty(); // this does not work well for multi-union,
711 // actually only makes performance slower,
712 // these are only pre-calculated but not used by multi-union
713
714 for (auto & fCandidatesCount : fCandidatesCounts)
715 {
716 fCandidatesCount.resize(0);
717 }
718}

Referenced by G4MultiUnion::Voxelize().


The documentation for this class was generated from the following files: