Geant4 11.1.1
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 1353 of file G4Voxelizer.cc.

1354{
1355 G4int size = fEmpty.GetNbytes();
1356 size += fBoxes.capacity() * sizeof(G4VoxelBox);
1357 size += sizeof(G4double) * (fBoundaries[0].capacity()
1358 + fBoundaries[1].capacity() + fBoundaries[2].capacity());
1359 size += sizeof(G4int) * (fCandidatesCounts[0].capacity()
1360 + fCandidatesCounts[1].capacity() + fCandidatesCounts[2].capacity());
1361 size += fBitmasks[0].GetNbytes() + fBitmasks[1].GetNbytes()
1362 + fBitmasks[2].GetNbytes();
1363
1364 G4int csize = (G4int)fCandidates.size();
1365 for (G4int i = 0; i < csize; ++i)
1366 {
1367 size += sizeof(vector<G4int>) + fCandidates[i].capacity() * sizeof(G4int);
1368 }
1369
1370 return size;
1371}
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 1154 of file G4Voxelizer.cc.

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

◆ CountVoxels()

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

Referenced by Voxelize().

◆ DisplayBoundaries()

void G4Voxelizer::DisplayBoundaries ( )

Definition at line 319 of file G4Voxelizer.cc.

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

Referenced by DisplayBoundaries().

◆ DisplayListNodes()

void G4Voxelizer::DisplayListNodes ( ) const

Definition at line 424 of file G4Voxelizer.cc.

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

◆ DisplayVoxelLimits()

void G4Voxelizer::DisplayVoxelLimits ( ) const

Definition at line 197 of file G4Voxelizer.cc.

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

◆ DistanceToBoundingBox()

G4double G4Voxelizer::DistanceToBoundingBox ( const G4ThreeVector point) const

Definition at line 1176 of file G4Voxelizer.cc.

1177{
1178 G4ThreeVector pointShifted = point - fBoundingBoxCenter;
1179 G4double shift = MinDistanceToBox(pointShifted, fBoundingBoxSize);
1180 return shift;
1181}
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 1166 of file G4Voxelizer.cc.

1168{
1169 G4ThreeVector pointShifted = point - fBoundingBoxCenter;
1170 G4double shift = fBoundingBox.DistanceToIn(pointShifted, direction);
1171 return shift;
1172}
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 1211 of file G4Voxelizer.cc.

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

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

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

◆ GetCandidatesVoxelArray() [1/3]

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

Definition at line 966 of file G4Voxelizer.cc.

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

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

◆ GetCandidatesVoxelArray() [3/3]

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

Definition at line 1145 of file G4Voxelizer.cc.

1147{
1148 // Method returning the candidates corresponding to the passed point
1149
1150 return GetCandidatesVoxelArray(voxels, fBitmasks, list, crossed);
1151}

◆ GetCountOfVoxels()

◆ GetDefaultVoxelsCount()

G4int G4Voxelizer::GetDefaultVoxelsCount ( )
static

Definition at line 1347 of file G4Voxelizer.cc.

1348{
1349 return fDefaultVoxelsCount;
1350}

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

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

Referenced by DistanceToBoundingBox().

◆ SetDefaultVoxelsCount()

void G4Voxelizer::SetDefaultVoxelsCount ( G4int  count)
static

Definition at line 1341 of file G4Voxelizer.cc.

1342{
1343 fDefaultVoxelsCount = count;
1344}

◆ SetMaxVoxels() [1/2]

void G4Voxelizer::SetMaxVoxels ( const G4ThreeVector reductionRatio)

Definition at line 1334 of file G4Voxelizer.cc.

1335{
1336 fMaxVoxels = -1;
1337 fReductionRatio = ratioOfReduction;
1338}

◆ SetMaxVoxels() [2/2]

void G4Voxelizer::SetMaxVoxels ( G4int  max)

Definition at line 1327 of file G4Voxelizer.cc.

1328{
1329 fMaxVoxels = max;
1330 fReductionRatio.set(0,0,0);
1331}
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 1296 of file G4Voxelizer.cc.

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

◆ Voxelize() [1/2]

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

Definition at line 760 of file G4Voxelizer.cc.

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

708{
709 BuildVoxelLimits(solids, transforms);
710 BuildBoundaries();
711 BuildBitmasks(fBoundaries, fBitmasks);
712 BuildBoundingBox();
713 BuildEmpty(); // this does not work well for multi-union,
714 // actually only makes performance slower,
715 // these are only pre-calculated but not used by multi-union
716
717 for (auto i = 0; i < 3; ++i)
718 {
719 fCandidatesCounts[i].resize(0);
720 }
721}

Referenced by G4MultiUnion::Voxelize().


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