56 : fBoundingBox(
"VoxBBox", 1, 1, 1)
79 const std::vector<G4int> empty(0);
82 unsigned int size =
max[0] *
max[1] *
max[2];
88 for (xyz[2] = 0; xyz[2] < max[2]; ++xyz[2])
90 for (xyz[1] = 0; xyz[1] < max[1]; ++xyz[1])
92 for (xyz[0] = 0; xyz[0] < max[0]; ++xyz[0])
104 c.reserve(candidates.size());
105 c.assign(candidates.begin(), candidates.end());
117 std::vector<G4Transform3D>& transforms)
128 if (
G4int numNodes = solids.size())
138 for (
G4int i = 0; i < numNodes; ++i)
150 orbToleranceVector.
set(tolerance,tolerance,tolerance);
151 min -= orbToleranceVector;
152 max += orbToleranceVector;
156 min -= toleranceVector;
157 max += toleranceVector;
176 if (
G4int numNodes = facets.size())
183 for (
G4int i = 0; i < numNodes; ++i)
191 min -= toleranceVector;
192 max += toleranceVector;
195 fBoxes[i].pos = min + hlen;
208 for(
G4int i = 0; i < numNodes; ++i)
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";
215 G4cout.precision(oldprec);
230 for(
G4int i = 0 ; i < numNodes; ++i)
242 boundary[2*i] = p -
d;
243 boundary[2*i+1] = p +
d;
245 std::sort(boundary.begin(), boundary.end());
266 std::vector<G4double> sortedBoundary(2*numNodes);
270 for (
auto j = 0; j <= 2; ++j)
278 for(
G4int i = 0 ; i < 2*numNodes; ++i)
280 G4double newBoundary = sortedBoundary[i];
282 if (j == 0)
G4cout <<
"Examining " << newBoundary <<
"..." <<
G4endl;
284 G4int size = boundary.size();
285 if(!size ||
std::abs(boundary[size-1] - newBoundary) > tolerance)
290 if (j == 0)
G4cout <<
"Adding boundary " << newBoundary <<
"..."
293 boundary.push_back(newBoundary);
301 G4int n = boundary.size();
307 std::vector<G4double> reduced;
308 for (
G4int i = 0; i <
n; ++i)
311 G4int size = boundary.size();
312 if (i % skip == 0 || i == 0 || i == size - 1)
319 reduced.push_back(boundary[i]);
331 char axis[3] = {
'X',
'Y',
'Z'};
332 for (
auto i = 0; i <= 2; ++i)
334 G4cout <<
" * " << axis[i] <<
" axis:" <<
G4endl <<
" | ";
344 G4int count = boundaries.size();
346 for(
G4int i = 0; i < count; ++i)
348 G4cout << setw(10) << setiosflags(ios::fixed) << boundaries[i];
349 if(i != count-1)
G4cout <<
"-> ";
352 G4cout.precision(oldprec);
365 for (
auto k = 0;
k < 3; ++
k)
368 std::vector<G4double>& boundary = boundaries[
k];
369 G4int voxelsCount = boundary.size() - 1;
378 bitmask.
SetBitNumber(voxelsCount*bitsPerSlice-1,
false);
383 candidatesCount.resize(voxelsCount);
385 for(
G4int i = 0 ; i < voxelsCount; ++i) { candidatesCount[i] = 0; }
389 for(
G4int j = 0 ; j < numNodes; ++j)
400 if (i < 0) { i = 0; }
408 candidatesCount[i]++;
412 while (max > boundary[i] && i < voxelsCount);
428 for(
G4int i=0; i<numNodes; ++i)
440 char axis[3] = {
'X',
'Y',
'Z'};
444 for (
auto j = 0; j <= 2; ++j)
448 for(
G4int i=0; i < count-1; ++i)
477 for (
auto i = 0; i <= 2; ++i)
510 if (maxVoxels > 0 && maxVoxels < maxTotal)
513 ratio = std::pow(ratio, 1./3.);
514 if (ratio > 1) { ratio = 1; }
515 reductionRatio.
set(ratio,ratio,ratio);
523 for (
auto k = 0;
k <= 2; ++
k)
527 std::vector<G4VoxelInfo> voxels(max);
529 std::set<G4int, G4VoxelComparator> voxelSet(comp);
530 std::vector<G4int> mergings;
535 voxel.
count = candidatesCount[j];
541 for (
G4int j = 0; j < max - 1; ++j) { voxelSet.insert(j); }
547 G4int count = 0, currentCount;
548 while ((currentCount = voxelSet.size()) > 2)
551 if ((currentRatio <= reduction) && (currentCount <= 1000))
553 const G4int pos = *voxelSet.begin();
554 mergings.push_back(pos + 1);
559 if (voxelSet.erase(pos) != 1)
563 if (voxel.
next != max - 1)
564 if (voxelSet.erase(voxel.
next) != 1)
569 if (voxelSet.erase(voxel.
previous) != 1)
577 if (voxel.
next != max - 1)
578 voxelSet.insert(voxel.
next);
591 std::sort(mergings.begin(), mergings.end());
593 const std::vector<G4double>& boundary = boundaries[
k];
594 int mergingsSize = mergings.size();
595 vector<G4double> reducedBoundary;
597 max = boundary.size();
602 reducedBoundary.push_back(boundary[j]);
604 else if (++i < mergingsSize)
609 boundaries[
k] = reducedBoundary;
678 for (
auto k = 0;
k <= 2; ++
k)
683 for (
G4int i = 0; i <
max; ++i) total += candidatesCount[i];
689 G4int destination = (
G4int) (reduction * max) + 1;
690 if (destination > 1000) destination = 1000;
691 if (destination < 2) destination = 2;
694 std::vector<G4int> mergings;
696 std::vector<G4double> &boundary = boundaries[
k];
697 std::vector<G4double> reducedBoundary(destination);
702 sum += candidatesCount[i];
703 if (sum > average * (cur + 1) || i == 0)
706 reducedBoundary[cur] = val;
708 if (cur == destination)
712 reducedBoundary[destination-1] = boundary[
max];
713 boundaries[
k] = reducedBoundary;
719 std::vector<G4Transform3D>& transforms)
729 for (
auto i = 0; i < 3; ++i)
739 std::vector<G4int> voxel(3), maxVoxels(3);
740 for (
auto i = 0; i <= 2; ++i) maxVoxels[i] = boundaries[i].size();
743 for (voxel[2] = 0; voxel[2] < maxVoxels[2] - 1; ++voxel[2])
745 for (voxel[1] = 0; voxel[1] < maxVoxels[1] - 1; ++voxel[1])
747 for (voxel[0] = 0; voxel[0] < maxVoxels[0] - 1; ++voxel[0])
749 std::vector<G4int> candidates;
754 for (
auto i = 0; i <= 2; ++i)
756 G4int index = voxel[i];
757 const std::vector<G4double> &boundary = boundaries[i];
758 G4double hlen = 0.5 * (boundary[index+1] - boundary[index]);
760 box.
pos[i] = boundary[index] + hlen;
763 std::vector<G4int>(candidates).
swap(candidates);
777 G4int size = facets.size();
780 for (
G4int i = 0; i < (
G4int) facets.size(); ++i)
782 if (facets[i]->GetNumberOfVertices() > 3) size++;
786 if ((size >= 10 || maxVoxels > 0) && maxVoxels != 0 && maxVoxels != 1)
825 G4cout <<
"Total number of voxels after reduction: "
841 std::vector<G4double> miniBoundaries[3];
843 for (
auto i = 0; i <= 2; ++i) { miniBoundaries[i] =
fBoundaries[i]; }
858 G4cout <<
"Total number of mini voxels: " << total <<
G4endl;
886 G4cout <<
"Deallocating unnecessary fields during runtime..." <<
G4endl;
891 for (
auto i = 0; i < 3; ++i)
906 G4cout <<
" Candidates in voxel [" << voxels[0] <<
" ; " << voxels[1]
907 <<
" ; " << voxels[2] <<
"]: ";
908 std::vector<G4int> candidates;
911 for (
G4int i = 0; i < count; ++i)
G4cout << candidates[i];
917 std::vector<G4int>& list,
G4int i)
919 for (
G4int byte = 0; byte < (
G4int) (
sizeof(
unsigned int)); ++byte)
921 if (
G4int maskByte = mask & 0xFF)
923 for (
G4int bit = 0; bit < 8; ++bit)
926 { list.push_back(8*(
sizeof(
unsigned int)*i+ byte) + bit); }
927 if (!(maskByte >>= 1))
break;
959 for (
G4int i = 0 ; i < limit; ++i)
966 if (current.
x() > max.
x()) max.
setX(current.
x());
967 if (current.
x() < min.
x()) min.
setX(current.
x());
969 if (current.
y() > max.
y()) max.
setY(current.
y());
970 if (current.
y() < min.
y()) min.
setY(current.
y());
972 if (current.
z() > max.
z()) max.
setZ(current.
z());
973 if (current.
z() < min.
z()) min.
setZ(current.
z());
979 std::vector<G4int> &list,
G4SurfBits *crossed)
const
985 for (
auto i = 0; i <= 2; ++i)
1000 unsigned int mask = 0xFFffFFff;
1005 if (!(mask = ((
unsigned int*)
fBitmasks[0].fAllBits)[slice]))
1011 if (!(mask &= ((
unsigned int*)
fBitmasks[1].fAllBits)[slice]))
1017 if (!(mask &= ((
unsigned int*)
fBitmasks[2].fAllBits)[slice]))
1020 if (crossed && (!(mask &= ~((
unsigned int*)crossed->
fAllBits)[0])))
1027 unsigned int* masks[3],
mask;
1028 for (
auto i = 0; i <= 2; ++i)
1031 masks[i] = ((
unsigned int*)
fBitmasks[i].fAllBits)
1034 unsigned int* maskCrossed = crossed
1035 ? (
unsigned int*)crossed->
fAllBits : 0;
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;
1101 std::vector<G4int>& list,
1116 if (!(mask = ((
unsigned int *) bitmasks[0].fAllBits)[voxels[0]]))
1118 if (!(mask &= ((
unsigned int *) bitmasks[1].fAllBits)[voxels[1]]))
1120 if (!(mask &= ((
unsigned int *) bitmasks[2].fAllBits)[voxels[2]]))
1122 if (crossed && (!(mask &= ~((
unsigned int *)crossed->
fAllBits)[0])))
1129 unsigned int *masks[3],
mask;
1130 for (
auto i = 0; i <= 2; ++i)
1132 masks[i] = ((
unsigned int *) bitmasks[i].fAllBits)
1135 unsigned int *maskCrossed = crossed !=
nullptr
1136 ? (
unsigned int *)crossed->
fAllBits : 0;
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;
1158 std::vector<G4int>& list,
G4SurfBits* crossed)
const
1168 for (
auto i = 0; i < 3; ++i)
1207 if ( safy > safe ) safe = safy;
1209 if ( safz > safe ) safe = safz;
1210 if (safe < 0.0)
return 0.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);
1225 std::vector<G4int>& curVoxel)
const
1230 for (
G4int i = 0; i <= 2; ++i)
1234 const std::vector<G4double>& boundary =
fBoundaries[i];
1235 G4int index = curVoxel[i];
1236 if (direction[i] >= 1
e-10)
1242 if (direction[i] > -1
e-10)
1245 G4double dif = boundary[index] - point[i];
1246 G4double distance = dif / direction[i];
1248 if (shift > distance)
1260 if (direction[cur] > 0)
1267 if (--curVoxel[cur] < 0)
1310 std::vector<G4int>& curVoxel)
const
1312 for (
auto i = 0; i <= 2; ++i)
1314 G4int index = curVoxel[i];
1315 const std::vector<G4double> &boundary =
fBoundaries[i];
1317 if (direction[i] > 0)
1319 if (point[i] >= boundary[++index])
1320 if (++curVoxel[i] >= (
G4int) boundary.size() - 1)
1325 if (point[i] < boundary[index])
1326 if (--curVoxel[i] < 0)
1331 if (curVoxel[i] != indexOK)
1332 curVoxel[i] = indexOK;
1377 for (
G4int i = 0; i < csize; ++i)