Geant4 10.7.0
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 55 of file G4Voxelizer.cc.

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

◆ ~G4Voxelizer()

G4Voxelizer::~G4Voxelizer ( )

Definition at line 68 of file G4Voxelizer.cc.

69{
70}

Member Function Documentation

◆ AllocatedMemory()

G4int G4Voxelizer::AllocatedMemory ( )

Definition at line 1365 of file G4Voxelizer.cc.

1366{
1367 G4int size = fEmpty.GetNbytes();
1368 size += fBoxes.capacity() * sizeof(G4VoxelBox);
1369 size += sizeof(G4double) * (fBoundaries[0].capacity()
1370 + fBoundaries[1].capacity() + fBoundaries[2].capacity());
1371 size += sizeof(G4int) * (fCandidatesCounts[0].capacity()
1372 + fCandidatesCounts[1].capacity() + fCandidatesCounts[2].capacity());
1373 size += fBitmasks[0].GetNbytes() + fBitmasks[1].GetNbytes()
1374 + fBitmasks[2].GetNbytes();
1375
1376 G4int csize = fCandidates.size();
1377 for (G4int i = 0; i < csize; ++i)
1378 {
1379 size += sizeof(vector<G4int>) + fCandidates[i].capacity() * sizeof(G4int);
1380 }
1381
1382 return size;
1383}
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,
value 
)
inlinestatic

◆ Contains()

G4bool G4Voxelizer::Contains ( const G4ThreeVector point) const

Definition at line 1166 of file G4Voxelizer.cc.

1167{
1168 for (auto i = 0; i < 3; ++i)
1169 {
1170 if (point[i] < fBoundaries[i].front() || point[i] > fBoundaries[i].back())
1171 return false;
1172 }
1173 return true;
1174}

◆ CountVoxels()

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

Referenced by Voxelize().

◆ DisplayBoundaries()

void G4Voxelizer::DisplayBoundaries ( )

Definition at line 329 of file G4Voxelizer.cc.

330{
331 char axis[3] = {'X', 'Y', 'Z'};
332 for (auto i = 0; i <= 2; ++i)
333 {
334 G4cout << " * " << axis[i] << " axis:" << G4endl << " | ";
335 DisplayBoundaries(fBoundaries[i]);
336 }
337}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void DisplayBoundaries()
Definition: G4Voxelizer.cc:329

Referenced by DisplayBoundaries().

◆ DisplayListNodes()

void G4Voxelizer::DisplayListNodes ( ) const

Definition at line 436 of file G4Voxelizer.cc.

437{
438 // Prints which solids are present in the slices previously elaborated.
439
440 char axis[3] = {'X', 'Y', 'Z'};
441 G4int size=8*sizeof(G4int)*fNPerSlice;
442 G4SurfBits bits(size);
443
444 for (auto j = 0; j <= 2; ++j)
445 {
446 G4cout << " * " << axis[j] << " axis:" << G4endl;
447 G4int count = fBoundaries[j].size();
448 for(G4int i=0; i < count-1; ++i)
449 {
450 G4cout << " Slice #" << i+1 << ": [" << fBoundaries[j][i]
451 << " ; " << fBoundaries[j][i+1] << "] -> ";
452 bits.set(size,(const char *)fBitmasks[j].fAllBits+i
453 *fNPerSlice*sizeof(G4int));
454 G4String result = GetCandidatesAsString(bits);
455 G4cout << "[ " << result.c_str() << "] " << G4endl;
456 }
457 }
458}

◆ DisplayVoxelLimits()

void G4Voxelizer::DisplayVoxelLimits ( ) const

Definition at line 202 of file G4Voxelizer.cc.

203{
204 // "DisplayVoxelLimits" displays the dX, dY, dZ, pX, pY and pZ for each node
205
206 G4int numNodes = fBoxes.size();
207 G4int oldprec = G4cout.precision(16);
208 for(G4int i = 0; i < numNodes; ++i)
209 {
210 G4cout << setw(10) << setiosflags(ios::fixed) <<
211 " -> Node " << i+1 << ":\n" <<
212 "\t * [x,y,z] = " << fBoxes[i].hlen <<
213 "\t * [x,y,z] = " << fBoxes[i].pos << "\n";
214 }
215 G4cout.precision(oldprec);
216}

◆ DistanceToBoundingBox()

G4double G4Voxelizer::DistanceToBoundingBox ( const G4ThreeVector point) const

Definition at line 1188 of file G4Voxelizer.cc.

1189{
1190 G4ThreeVector pointShifted = point - fBoundingBoxCenter;
1191 G4double shift = MinDistanceToBox(pointShifted, fBoundingBoxSize);
1192 return shift;
1193}
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 1178 of file G4Voxelizer.cc.

1180{
1181 G4ThreeVector pointShifted = point - fBoundingBoxCenter;
1182 G4double shift = fBoundingBox.DistanceToIn(pointShifted, direction);
1183 return shift;
1184}
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
Definition: G4Box.cc:325

Referenced by G4MultiUnion::DistanceToIn().

◆ DistanceToNext()

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

Definition at line 1223 of file G4Voxelizer.cc.

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

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 901 of file G4Voxelizer.cc.

902{
903 // "GetCandidates" should compute which solids are possibly contained in
904 // the voxel defined by the three slices characterized by the passed indexes.
905
906 G4cout << " Candidates in voxel [" << voxels[0] << " ; " << voxels[1]
907 << " ; " << voxels[2] << "]: ";
908 std::vector<G4int> candidates;
909 G4int count = GetCandidatesVoxelArray(voxels, candidates);
910 G4cout << "[ ";
911 for (G4int i = 0; i < count; ++i) G4cout << candidates[i];
912 G4cout << "] " << G4endl;
913}
G4int GetCandidatesVoxelArray(const G4ThreeVector &point, std::vector< G4int > &list, G4SurfBits *crossed=nullptr) const
Definition: G4Voxelizer.cc:978

◆ GetCandidatesVoxelArray() [1/3]

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

Definition at line 978 of file G4Voxelizer.cc.

980{
981 // Method returning the candidates corresponding to the passed point
982
983 list.clear();
984
985 for (auto i = 0; i <= 2; ++i)
986 {
987 if(point[i] < fBoundaries[i].front() || point[i] >= fBoundaries[i].back())
988 return 0;
989 }
990
991 if (fTotalCandidates == 1)
992 {
993 list.push_back(0);
994 return 1;
995 }
996 else
997 {
998 if (fNPerSlice == 1)
999 {
1000 unsigned int mask = 0xFFffFFff;
1001 G4int slice;
1002 if (fBoundaries[0].size() > 2)
1003 {
1004 slice = BinarySearch(fBoundaries[0], point.x());
1005 if (!(mask = ((unsigned int*) fBitmasks[0].fAllBits)[slice]))
1006 return 0;
1007 }
1008 if (fBoundaries[1].size() > 2)
1009 {
1010 slice = BinarySearch(fBoundaries[1], point.y());
1011 if (!(mask &= ((unsigned int*) fBitmasks[1].fAllBits)[slice]))
1012 return 0;
1013 }
1014 if (fBoundaries[2].size() > 2)
1015 {
1016 slice = BinarySearch(fBoundaries[2], point.z());
1017 if (!(mask &= ((unsigned int*) fBitmasks[2].fAllBits)[slice]))
1018 return 0;
1019 }
1020 if (crossed && (!(mask &= ~((unsigned int*)crossed->fAllBits)[0])))
1021 return 0;
1022
1023 FindComponentsFastest(mask, list, 0);
1024 }
1025 else
1026 {
1027 unsigned int* masks[3], mask; // masks for X,Y,Z axis
1028 for (auto i = 0; i <= 2; ++i)
1029 {
1030 G4int slice = BinarySearch(fBoundaries[i], point[i]);
1031 masks[i] = ((unsigned int*) fBitmasks[i].fAllBits)
1032 + slice * fNPerSlice;
1033 }
1034 unsigned int* maskCrossed = crossed
1035 ? (unsigned int*)crossed->fAllBits : 0;
1036
1037 for (G4int i = 0 ; i < fNPerSlice; ++i)
1038 {
1039 // Logic "and" of the masks along the 3 axes x, y, z:
1040 // removing "if (!" and ") continue" => slightly slower
1041 //
1042 if (!(mask = masks[0][i])) continue;
1043 if (!(mask &= masks[1][i])) continue;
1044 if (!(mask &= masks[2][i])) continue;
1045 if (maskCrossed && !(mask &= ~maskCrossed[i])) continue;
1046
1047 FindComponentsFastest(mask, list, i);
1048 }
1049 }
1050/*
1051 if (fNPerSlice == 1)
1052 {
1053 unsigned int mask;
1054 G4int slice = BinarySearch(fBoundaries[0], point.x());
1055 if (!(mask = ((unsigned int *) fBitmasks[0].fAllBits)[slice]
1056 )) return 0;
1057 slice = BinarySearch(fBoundaries[1], point.y());
1058 if (!(mask &= ((unsigned int *) fBitmasks[1].fAllBits)[slice]
1059 )) return 0;
1060 slice = BinarySearch(fBoundaries[2], point.z());
1061 if (!(mask &= ((unsigned int *) fBitmasks[2].fAllBits)[slice]
1062 )) return 0;
1063 if (crossed && (!(mask &= ~((unsigned int *)crossed->fAllBits)[0])))
1064 return 0;
1065
1066 FindComponentsFastest(mask, list, 0);
1067 }
1068 else
1069 {
1070 unsigned int *masks[3], mask; // masks for X,Y,Z axis
1071 for (auto i = 0; i <= 2; ++i)
1072 {
1073 G4int slice = BinarySearch(fBoundaries[i], point[i]);
1074 masks[i] = ((unsigned int *) fBitmasks[i].fAllBits) + slice*fNPerSlice;
1075 }
1076 unsigned int *maskCrossed =
1077 crossed ? (unsigned int *)crossed->fAllBits : 0;
1078
1079 for (G4int i = 0 ; i < fNPerSlice; ++i)
1080 {
1081 // Logic "and" of the masks along the 3 axes x, y, z:
1082 // removing "if (!" and ") continue" => slightly slower
1083 //
1084 if (!(mask = masks[0][i])) continue;
1085 if (!(mask &= masks[1][i])) continue;
1086 if (!(mask &= masks[2][i])) continue;
1087 if (maskCrossed && !(mask &= ~maskCrossed[i])) continue;
1088
1089 FindComponentsFastest(mask, list, i);
1090 }
1091 }
1092*/
1093 }
1094 return list.size();
1095}
double z() const
double x() const
double y() const
unsigned char * fAllBits
Definition: G4SurfBits.hh:104
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 1099 of file G4Voxelizer.cc.

1103{
1104 list.clear();
1105
1106 if (fTotalCandidates == 1)
1107 {
1108 list.push_back(0);
1109 return 1;
1110 }
1111 else
1112 {
1113 if (fNPerSlice == 1)
1114 {
1115 unsigned int mask;
1116 if (!(mask = ((unsigned int *) bitmasks[0].fAllBits)[voxels[0]]))
1117 return 0;
1118 if (!(mask &= ((unsigned int *) bitmasks[1].fAllBits)[voxels[1]]))
1119 return 0;
1120 if (!(mask &= ((unsigned int *) bitmasks[2].fAllBits)[voxels[2]]))
1121 return 0;
1122 if (crossed && (!(mask &= ~((unsigned int *)crossed->fAllBits)[0])))
1123 return 0;
1124
1125 FindComponentsFastest(mask, list, 0);
1126 }
1127 else
1128 {
1129 unsigned int *masks[3], mask; // masks for X,Y,Z axis
1130 for (auto i = 0; i <= 2; ++i)
1131 {
1132 masks[i] = ((unsigned int *) bitmasks[i].fAllBits)
1133 + voxels[i]*fNPerSlice;
1134 }
1135 unsigned int *maskCrossed = crossed != nullptr
1136 ? (unsigned int *)crossed->fAllBits : 0;
1137
1138 for (G4int i = 0 ; i < fNPerSlice; ++i)
1139 {
1140 // Logic "and" of the masks along the 3 axes x, y, z:
1141 // removing "if (!" and ") continue" => slightly slower
1142 //
1143 if (!(mask = masks[0][i])) continue;
1144 if (!(mask &= masks[1][i])) continue;
1145 if (!(mask &= masks[2][i])) continue;
1146 if (maskCrossed && !(mask &= ~maskCrossed[i])) continue;
1147
1148 FindComponentsFastest(mask, list, i);
1149 }
1150 }
1151 }
1152 return list.size();
1153}

◆ GetCandidatesVoxelArray() [3/3]

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

Definition at line 1157 of file G4Voxelizer.cc.

1159{
1160 // Method returning the candidates corresponding to the passed point
1161
1162 return GetCandidatesVoxelArray(voxels, fBitmasks, list, crossed);
1163}

◆ GetCountOfVoxels()

◆ GetDefaultVoxelsCount()

G4int G4Voxelizer::GetDefaultVoxelsCount ( )
static

Definition at line 1359 of file G4Voxelizer.cc.

1360{
1361 return fDefaultVoxelsCount;
1362}

◆ 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 1197 of file G4Voxelizer.cc.

1199{
1200 // Estimates the isotropic safety from a point outside the current solid to
1201 // any of its surfaces. The algorithm may be accurate or should provide a
1202 // fast underestimate.
1203
1204 G4double safe, safx, safy, safz;
1205 safe = safx = -f.x() + std::abs(aPoint.x());
1206 safy = -f.y() + std::abs(aPoint.y());
1207 if ( safy > safe ) safe = safy;
1208 safz = -f.z() + std::abs(aPoint.z());
1209 if ( safz > safe ) safe = safz;
1210 if (safe < 0.0) return 0.0; // point is inside
1211
1212 G4double safsq = 0.0;
1213 G4int count = 0;
1214 if ( safx > 0 ) { safsq += safx*safx; ++count; }
1215 if ( safy > 0 ) { safsq += safy*safy; ++count; }
1216 if ( safz > 0 ) { safsq += safz*safz; ++count; }
1217 if (count == 1) return safe;
1218 return std::sqrt(safsq);
1219}

Referenced by DistanceToBoundingBox().

◆ SetDefaultVoxelsCount()

void G4Voxelizer::SetDefaultVoxelsCount ( G4int  count)
static

Definition at line 1353 of file G4Voxelizer.cc.

1354{
1355 fDefaultVoxelsCount = count;
1356}

◆ SetMaxVoxels() [1/2]

void G4Voxelizer::SetMaxVoxels ( const G4ThreeVector reductionRatio)

Definition at line 1346 of file G4Voxelizer.cc.

1347{
1348 fMaxVoxels = -1;
1349 fReductionRatio = ratioOfReduction;
1350}

◆ SetMaxVoxels() [2/2]

void G4Voxelizer::SetMaxVoxels ( G4int  max)

Definition at line 1339 of file G4Voxelizer.cc.

1340{
1341 fMaxVoxels = max;
1342 fReductionRatio.set(0,0,0);
1343}
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 1308 of file G4Voxelizer.cc.

1311{
1312 for (auto i = 0; i <= 2; ++i)
1313 {
1314 G4int index = curVoxel[i];
1315 const std::vector<G4double> &boundary = fBoundaries[i];
1316
1317 if (direction[i] > 0)
1318 {
1319 if (point[i] >= boundary[++index])
1320 if (++curVoxel[i] >= (G4int) boundary.size() - 1)
1321 return false;
1322 }
1323 else
1324 {
1325 if (point[i] < boundary[index])
1326 if (--curVoxel[i] < 0)
1327 return false;
1328 }
1329#ifdef G4SPECSDEBUG
1330 G4int indexOK = BinarySearch(boundary, point[i]);
1331 if (curVoxel[i] != indexOK)
1332 curVoxel[i] = indexOK; // put breakpoint here
1333#endif
1334 }
1335 return true;
1336}

◆ Voxelize() [1/2]

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

Definition at line 772 of file G4Voxelizer.cc.

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

720{
721 BuildVoxelLimits(solids, transforms);
722 BuildBoundaries();
723 BuildBitmasks(fBoundaries, fBitmasks);
724 BuildBoundingBox();
725 BuildEmpty(); // this does not work well for multi-union,
726 // actually only makes performance slower,
727 // these are only pre-calculated but not used by multi-union
728
729 for (auto i = 0; i < 3; ++i)
730 {
731 fCandidatesCounts[i].resize(0);
732 }
733}

Referenced by G4MultiUnion::Voxelize().


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