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

G4Voxelizer is a tool for generating the optimisation structure of tessellated surfaces and solids positioned in 3D space; it is used in G4TessellatedSolid and G4MultiUnion. More...

#include <G4Voxelizer.hh>

Public Member Functions

 G4Voxelizer ()
 ~G4Voxelizer ()=default
void Voxelize (std::vector< G4VSolid * > &solids, std::vector< G4Transform3D > &transforms)
void Voxelize (std::vector< G4VFacet * > &facets)
void DisplayVoxelLimits () const
void DisplayBoundaries ()
void DisplayListNodes () const
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
G4double MinDistanceToBox (const G4ThreeVector &p, const G4ThreeVector &f) 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

static void SetDefaultVoxelsCount (G4int count)
static G4int GetDefaultVoxelsCount ()

Detailed Description

G4Voxelizer is a tool for generating the optimisation structure of tessellated surfaces and solids positioned in 3D space; it is used in G4TessellatedSolid and G4MultiUnion.

Definition at line 68 of file G4Voxelizer.hh.

Constructor & Destructor Documentation

◆ G4Voxelizer()

G4Voxelizer::G4Voxelizer ( )

Constructor and default Destructor.

Definition at line 51 of file G4Voxelizer.cc.

52 : fBoundingBox("VoxBBox", 1, 1, 1)
53{
54 fCountOfVoxels = fNPerSlice = fTotalCandidates = 0;
55
57
58 SetMaxVoxels(fDefaultVoxelsCount);
59
60 G4SolidStore::GetInstance()->DeRegister(&fBoundingBox);
61}
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 ( )

Logger returning the size of total allocated memory.

Definition at line 1253 of file G4Voxelizer.cc.

1254{
1255 G4int size = fEmpty.GetNbytes();
1256 size += fBoxes.capacity() * sizeof(G4VoxelBox);
1257 size += sizeof(G4double) * (fBoundaries[0].capacity()
1258 + fBoundaries[1].capacity() + fBoundaries[2].capacity());
1259 size += sizeof(G4int) * (fCandidatesCounts[0].capacity()
1260 + fCandidatesCounts[1].capacity() + fCandidatesCounts[2].capacity());
1261 size += fBitmasks[0].GetNbytes() + fBitmasks[1].GetNbytes()
1262 + fBitmasks[2].GetNbytes();
1263
1264 auto csize = (G4int)fCandidates.size();
1265 for (G4int i = 0; i < csize; ++i)
1266 {
1267 size += sizeof(vector<G4int>) + fCandidates[i].capacity() * sizeof(G4int);
1268 }
1269
1270 return size;
1271}
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85

◆ Contains()

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

Returns true if 'point' is contained within boundaries.

Definition at line 1079 of file G4Voxelizer.cc.

1080{
1081 for (auto i = 0; i < 3; ++i)
1082 {
1083 if (point[i] < fBoundaries[i].front() || point[i] > fBoundaries[i].back())
1084 {
1085 return false;
1086 }
1087 }
1088 return true;
1089}

◆ CountVoxels()

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

Referenced by Voxelize().

◆ DisplayBoundaries()

void G4Voxelizer::DisplayBoundaries ( )

Prints the positions of the boundaries of the slices on the three axes.

Definition at line 313 of file G4Voxelizer.cc.

314{
315 char axis[3] = {'X', 'Y', 'Z'};
316 for (auto i = 0; i <= 2; ++i)
317 {
318 G4cout << " * " << axis[i] << " axis:" << G4endl << " | ";
319 DisplayBoundaries(fBoundaries[i]);
320 }
321}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
void DisplayBoundaries()
const axis_t axis_to_type< N >::axis
Definition pugixml.cc:9668

Referenced by DisplayBoundaries().

◆ DisplayListNodes()

void G4Voxelizer::DisplayListNodes ( ) const

Prints which solids are present in the slices previously elaborated.

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

Displays the dX, dY, dZ, pX, pY and pZ for each node.

Definition at line 191 of file G4Voxelizer.cc.

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

◆ DistanceToBoundingBox()

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

Returns the minimum distance of 'point' to the bounding box.

Definition at line 1103 of file G4Voxelizer.cc.

1104{
1105 G4ThreeVector pointShifted = point - fBoundingBoxCenter;
1106 G4double shift = MinDistanceToBox(pointShifted, fBoundingBoxSize);
1107 return shift;
1108}
CLHEP::Hep3Vector G4ThreeVector
G4double MinDistanceToBox(const G4ThreeVector &p, const G4ThreeVector &f) const

◆ DistanceToFirst()

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

Returns the distance to first bounding box, given 'point' and 'direction'.

Definition at line 1093 of file G4Voxelizer.cc.

1095{
1096 G4ThreeVector pointShifted = point - fBoundingBoxCenter;
1097 G4double shift = fBoundingBox.DistanceToIn(pointShifted, direction);
1098 return shift;
1099}

◆ DistanceToNext()

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

Returns the distance to next boundary, given 'point' and 'direction' and updates current voxel 'curVoxel', using the index corresponding to the closest voxel boundary on the ray.

Definition at line 1138 of file G4Voxelizer.cc.

1141{
1142 G4double shift = kInfinity;
1143
1144 G4int cur = 0; // the smallest index, which would be than increased
1145 for (G4int i = 0; i <= 2; ++i)
1146 {
1147 // Looking for the next voxels on the considered direction X,Y,Z axis
1148 //
1149 const std::vector<G4double>& boundary = fBoundaries[i];
1150 G4int index = curVoxel[i];
1151 if (direction[i] >= 1e-10)
1152 {
1153 ++index;
1154 }
1155 else
1156 {
1157 if (direction[i] > -1e-10) { continue; }
1158 }
1159 G4double dif = boundary[index] - point[i];
1160 G4double distance = dif / direction[i];
1161
1162 if (shift > distance)
1163 {
1164 shift = distance;
1165 cur = i;
1166 }
1167 }
1168
1169 if (shift != kInfinity)
1170 {
1171 // updating current voxel using the index corresponding
1172 // to the closest voxel boundary on the ray
1173
1174 if (direction[cur] > 0)
1175 {
1176 if (++curVoxel[cur] >= (G4int) fBoundaries[cur].size() - 1)
1177 {
1178 shift = kInfinity;
1179 }
1180 }
1181 else
1182 {
1183 if (--curVoxel[cur] < 0)
1184 {
1185 shift = kInfinity;
1186 }
1187 }
1188 }
1189 return shift;
1190}

◆ Empty()

const G4SurfBits & G4Voxelizer::Empty ( ) const
inline

Returns the empty bits container.

◆ GetBitsPerSlice()

G4int G4Voxelizer::GetBitsPerSlice ( ) const
inline

Returns memory size of a slice.

◆ GetBoundary()

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

Returns the boundary vector, given an 'index'.

◆ GetBoxes()

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

Returns the pointer to the array containing the characteristics of each box.

◆ GetCandidates()

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

◆ GetCandidatesVoxel()

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

Displays the nodes located in a voxel characterised by its three indexes.

Definition at line 838 of file G4Voxelizer.cc.

839{
840 // "GetCandidates" should compute which solids are possibly contained in
841 // the voxel defined by the three slices characterized by the passed indexes.
842
843 G4cout << " Candidates in voxel [" << voxels[0] << " ; " << voxels[1]
844 << " ; " << voxels[2] << "]: ";
845 std::vector<G4int> candidates;
846 G4int count = GetCandidatesVoxelArray(voxels, candidates);
847 G4cout << "[ ";
848 for (G4int i = 0; i < count; ++i)
849 {
850 G4cout << candidates[i];
851 }
852 G4cout << "] " << G4endl;
853}
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

Methods returning in a vector container the nodes located in a voxel characterised by its three indexes.

Returns
The total candidates number.

Definition at line 918 of file G4Voxelizer.cc.

920{
921 // Method returning the candidates corresponding to the passed point
922
923 list.clear();
924
925 for (auto i = 0; i <= 2; ++i)
926 {
927 if(point[i] < fBoundaries[i].front() || point[i] >= fBoundaries[i].back())
928 {
929 return 0;
930 }
931 }
932
933 if (fTotalCandidates == 1)
934 {
935 list.push_back(0);
936 return 1;
937 }
938
939 if (fNPerSlice == 1)
940 {
941 unsigned int mask = 0xFFffFFff;
942 G4int slice;
943 if (fBoundaries[0].size() > 2)
944 {
945 slice = BinarySearch(fBoundaries[0], point.x());
946 if ((mask = ((unsigned int*) fBitmasks[0].fAllBits)[slice]) == 0u)
947 {
948 return 0;
949 }
950 }
951 if (fBoundaries[1].size() > 2)
952 {
953 slice = BinarySearch(fBoundaries[1], point.y());
954 if ((mask &= ((unsigned int*) fBitmasks[1].fAllBits)[slice]) == 0u)
955 {
956 return 0;
957 }
958 }
959 if (fBoundaries[2].size() > 2)
960 {
961 slice = BinarySearch(fBoundaries[2], point.z());
962 if ((mask &= ((unsigned int*) fBitmasks[2].fAllBits)[slice]) == 0u)
963 {
964 return 0;
965 }
966 }
967 if ((crossed != nullptr) && ((mask &= ~((unsigned int*)crossed->fAllBits)[0]) == 0u))
968 {
969 return 0;
970 }
971 FindComponentsFastest(mask, list, 0);
972 }
973 else
974 {
975 unsigned int* masks[3], mask; // masks for X,Y,Z axis
976 for (auto i = 0; i <= 2; ++i)
977 {
978 G4int slice = BinarySearch(fBoundaries[i], point[i]);
979 masks[i] = ((unsigned int*) fBitmasks[i].fAllBits)
980 + slice * fNPerSlice;
981 }
982 unsigned int* maskCrossed = crossed != nullptr
983 ? (unsigned int*)crossed->fAllBits : nullptr;
984
985 for (G4int i = 0 ; i < fNPerSlice; ++i)
986 {
987 // Logic "and" of the masks along the 3 axes x, y, z:
988 // removing "if (!" and ") continue" => slightly slower
989 //
990 if ((mask = masks[0][i]) == 0u) { continue; }
991 if ((mask &= masks[1][i]) == 0u) { continue; }
992 if ((mask &= masks[2][i]) == 0u) { continue; }
993 if ((maskCrossed != nullptr) && ((mask &= ~maskCrossed[i]) == 0u))
994 {
995 continue;
996 }
997 FindComponentsFastest(mask, list, i);
998 }
999 }
1000 return (G4int)list.size();
1001}
double z() const
double x() const
double y() const
unsigned char * fAllBits

Referenced by GetCandidatesVoxel(), and GetCandidatesVoxelArray().

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

1009{
1010 list.clear();
1011
1012 if (fTotalCandidates == 1)
1013 {
1014 list.push_back(0);
1015 return 1;
1016 }
1017
1018 if (fNPerSlice == 1)
1019 {
1020 unsigned int mask;
1021 if ((mask = ((unsigned int *) bitmasks[0].fAllBits)[voxels[0]]) == 0u)
1022 {
1023 return 0;
1024 }
1025 if ((mask &= ((unsigned int *) bitmasks[1].fAllBits)[voxels[1]]) == 0u)
1026 {
1027 return 0;
1028 }
1029 if ((mask &= ((unsigned int *) bitmasks[2].fAllBits)[voxels[2]]) == 0u)
1030 {
1031 return 0;
1032 }
1033 if ((crossed != nullptr) && ((mask &= ~((unsigned int *)crossed->fAllBits)[0]) == 0u))
1034 {
1035 return 0;
1036 }
1037 FindComponentsFastest(mask, list, 0);
1038 }
1039 else
1040 {
1041 unsigned int *masks[3], mask; // masks for X,Y,Z axis
1042 for (auto i = 0; i <= 2; ++i)
1043 {
1044 masks[i] = ((unsigned int *) bitmasks[i].fAllBits)
1045 + voxels[i]*fNPerSlice;
1046 }
1047 unsigned int *maskCrossed = crossed != nullptr
1048 ? (unsigned int *)crossed->fAllBits : nullptr;
1049
1050 for (G4int i = 0 ; i < fNPerSlice; ++i)
1051 {
1052 // Logic "and" of the masks along the 3 axes x, y, z:
1053 // removing "if (!" and ") continue" => slightly slower
1054 //
1055 if ((mask = masks[0][i]) == 0u) { continue; }
1056 if ((mask &= masks[1][i]) == 0u) { continue; }
1057 if ((mask &= masks[2][i]) == 0u) { continue; }
1058 if ((maskCrossed != nullptr) && ((mask &= ~maskCrossed[i]) == 0u))
1059 {
1060 continue;
1061 }
1062 FindComponentsFastest(mask, list, i);
1063 }
1064 }
1065 return (G4int)list.size();
1066}

◆ GetCandidatesVoxelArray() [3/3]

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

Definition at line 1070 of file G4Voxelizer.cc.

1072{
1073 // Method returning the candidates corresponding to the passed point
1074
1075 return GetCandidatesVoxelArray(voxels, fBitmasks, list, crossed);
1076}

◆ GetCountOfVoxels()

long long G4Voxelizer::GetCountOfVoxels ( ) const
inline

Utility accessors/functions for voxels.

◆ GetDefaultVoxelsCount()

G4int G4Voxelizer::GetDefaultVoxelsCount ( )
static

Definition at line 1247 of file G4Voxelizer.cc.

1248{
1249 return fDefaultVoxelsCount;
1250}

◆ 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

Updates current voxel based on provided 'point'.

◆ 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

Accessors for voxels and points.

◆ IsEmpty()

G4bool G4Voxelizer::IsEmpty ( G4int index) const
inline

Returns true if empty bit in container, given an 'index'.

◆ MinDistanceToBox()

G4double G4Voxelizer::MinDistanceToBox ( const G4ThreeVector & p,
const G4ThreeVector & f ) const

Utility for estimating the isotropic safety from a point 'p' outside the current solid to any of its surfaces. The algorithm may be accurate or should provide a fast underestimate, based on safety point 'f'.

Definition at line 1112 of file G4Voxelizer.cc.

1114{
1115 // Estimates the isotropic safety from a point outside the current solid to
1116 // any of its surfaces. The algorithm may be accurate or should provide a
1117 // fast underestimate.
1118
1119 G4double safe, safx, safy, safz;
1120 safe = safx = -f.x() + std::abs(aPoint.x());
1121 safy = -f.y() + std::abs(aPoint.y());
1122 if ( safy > safe ) { safe = safy; }
1123 safz = -f.z() + std::abs(aPoint.z());
1124 if ( safz > safe ) { safe = safz; }
1125 if (safe < 0.0) { return 0.0; } // point is inside
1126
1127 G4double safsq = 0.0;
1128 G4int count = 0;
1129 if ( safx > 0 ) { safsq += safx*safx; ++count; }
1130 if ( safy > 0 ) { safsq += safy*safy; ++count; }
1131 if ( safz > 0 ) { safsq += safz*safz; ++count; }
1132 if (count == 1) { return safe; }
1133 return std::sqrt(safsq);
1134}

Referenced by DistanceToBoundingBox().

◆ SetDefaultVoxelsCount()

void G4Voxelizer::SetDefaultVoxelsCount ( G4int count)
static

Definition at line 1241 of file G4Voxelizer.cc.

1242{
1243 fDefaultVoxelsCount = count;
1244}

◆ SetMaxVoxels() [1/2]

void G4Voxelizer::SetMaxVoxels ( const G4ThreeVector & reductionRatio)

Definition at line 1234 of file G4Voxelizer.cc.

1235{
1236 fMaxVoxels = -1;
1237 fReductionRatio = ratioOfReduction;
1238}

◆ SetMaxVoxels() [2/2]

void G4Voxelizer::SetMaxVoxels ( G4int max)

Setters/getter for the maximum number of voxels.

Definition at line 1227 of file G4Voxelizer.cc.

1228{
1229 fMaxVoxels = max;
1230 fReductionRatio.set(0,0,0);
1231}
T max(const T t1, const T t2)
brief Return the largest of the two arguments

Referenced by G4Voxelizer().

◆ UpdateCurrentVoxel()

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

Utility method for checking/updating current voxel given in input.

Definition at line 1194 of file G4Voxelizer.cc.

1197{
1198 for (auto i = 0; i <= 2; ++i)
1199 {
1200 G4int index = curVoxel[i];
1201 const std::vector<G4double> &boundary = fBoundaries[i];
1202
1203 if (direction[i] > 0)
1204 {
1205 if (point[i] >= boundary[++index])
1206 {
1207 if (++curVoxel[i] >= (G4int) boundary.size() - 1) { return false; }
1208 }
1209 }
1210 else
1211 {
1212 if (point[i] < boundary[index])
1213 {
1214 if (--curVoxel[i] < 0) { return false; }
1215 }
1216 }
1217#ifdef G4SPECSDEBUG
1218 G4int indexOK = BinarySearch(boundary, point[i]);
1219 if (curVoxel[i] != indexOK)
1220 curVoxel[i] = indexOK; // put breakpoint here
1221#endif
1222 }
1223 return true;
1224}

◆ Voxelize() [1/2]

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

Builds the voxelisation structure for facets forming a shape.

Parameters
[in]facetsThe list of facets.

Definition at line 706 of file G4Voxelizer.cc.

707{
708 G4int maxVoxels = fMaxVoxels;
709 G4ThreeVector reductionRatio = fReductionRatio;
710
711 std::size_t size = facets.size();
712 if (size < 10)
713 {
714 for (const auto & facet : facets)
715 {
716 if (facet->GetNumberOfVertices() > 3) { ++size; }
717 }
718 }
719
720 if ((size >= 10 || maxVoxels > 0) && maxVoxels != 0 && maxVoxels != 1)
721 {
722#ifdef G4SPECSDEBUG
723 G4cout << "Building voxel limits..." << G4endl;
724#endif
725
726 BuildVoxelLimits(facets);
727
728#ifdef G4SPECSDEBUG
729 G4cout << "Building boundaries..." << G4endl;
730#endif
731
732 BuildBoundaries();
733
734#ifdef G4SPECSDEBUG
735 G4cout << "Building bitmasks..." << G4endl;
736#endif
737
738 BuildBitmasks(fBoundaries, nullptr, true);
739
740 if (maxVoxels < 0 && reductionRatio == G4ThreeVector())
741 {
742 maxVoxels = fTotalCandidates;
743 if (fTotalCandidates > 1000000) { maxVoxels = 1000000; }
744 }
745
746 SetReductionRatio(maxVoxels, reductionRatio);
747
748 fCountOfVoxels = CountVoxels(fBoundaries);
749
750#ifdef G4SPECSDEBUG
751 G4cout << "Total number of voxels: " << fCountOfVoxels << G4endl;
752#endif
753
754 BuildReduceVoxels2(fBoundaries, reductionRatio);
755
756 fCountOfVoxels = CountVoxels(fBoundaries);
757
758#ifdef G4SPECSDEBUG
759 G4cout << "Total number of voxels after reduction: "
760 << fCountOfVoxels << G4endl;
761#endif
762
763#ifdef G4SPECSDEBUG
764 G4cout << "Building bitmasks..." << G4endl;
765#endif
766
767 BuildBitmasks(fBoundaries, fBitmasks);
768
769 G4ThreeVector reductionRatioMini;
770
771 G4SurfBits bitmasksMini[3];
772
773 // section for building mini voxels
774
775 std::vector<G4double> miniBoundaries[3];
776
777 for (auto i = 0; i <= 2; ++i)
778 {
779 miniBoundaries[i] = fBoundaries[i];
780 }
781
782 G4int voxelsCountMini = (fCountOfVoxels >= 1000)
783 ? 100 : G4int(fCountOfVoxels / 10);
784
785 SetReductionRatio(voxelsCountMini, reductionRatioMini);
786
787#ifdef G4SPECSDEBUG
788 G4cout << "Building reduced voxels..." << G4endl;
789#endif
790
791 BuildReduceVoxels(miniBoundaries, reductionRatioMini);
792
793#ifdef G4SPECSDEBUG
794 G4int total = CountVoxels(miniBoundaries);
795 G4cout << "Total number of mini voxels: " << total << G4endl;
796#endif
797
798#ifdef G4SPECSDEBUG
799 G4cout << "Building mini bitmasks..." << G4endl;
800#endif
801
802 BuildBitmasks(miniBoundaries, bitmasksMini);
803
804#ifdef G4SPECSDEBUG
805 G4cout << "Creating Mini Voxels..." << G4endl;
806#endif
807
808 CreateMiniVoxels(miniBoundaries, bitmasksMini);
809
810#ifdef G4SPECSDEBUG
811 G4cout << "Building bounding box..." << G4endl;
812#endif
813
814 BuildBoundingBox();
815
816#ifdef G4SPECSDEBUG
817 G4cout << "Building empty..." << G4endl;
818#endif
819
820 BuildEmpty();
821
822#ifdef G4SPECSDEBUG
823 G4cout << "Deallocating unnecessary fields during runtime..." << G4endl;
824#endif
825 // deallocate fields unnecessary during runtime
826 //
827 fBoxes.resize(0);
828 for (auto i = 0; i < 3; ++i)
829 {
830 fCandidatesCounts[i].resize(0);
831 fBitmasks[i].Clear();
832 }
833 }
834}
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 )

Builds the voxelisation structure for solids positioned in space.

Parameters
[in]solidsThe list of solids.
[in]transformsThe associated transformation in space.

Definition at line 649 of file G4Voxelizer.cc.

651{
652 BuildVoxelLimits(solids, transforms);
653 BuildBoundaries();
654 BuildBitmasks(fBoundaries, fBitmasks);
655 BuildBoundingBox();
656 BuildEmpty(); // this does not work well for multi-union,
657 // actually only makes performance slower,
658 // these are only pre-calculated but not used by multi-union
659
660 for (auto & fCandidatesCount : fCandidatesCounts)
661 {
662 fCandidatesCount.resize(0);
663 }
664}

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