Geant4  10.02.p03
G4SurfaceVoxelizer Class Reference

#include <G4SurfaceVoxelizer.hh>

Collaboration diagram for G4SurfaceVoxelizer:

Classes

class  G4VoxelComparator
 

Public Member Functions

void Voxelize (std::vector< G4VFacet *> &facets)
 
void DisplayVoxelLimits ()
 
void DisplayBoundaries ()
 
void DisplayListNodes () const
 
 G4SurfaceVoxelizer ()
 
 ~G4SurfaceVoxelizer ()
 
void GetCandidatesVoxel (std::vector< G4int > &voxels)
 
G4int GetCandidatesVoxelArray (const G4ThreeVector &point, std::vector< G4int > &list, G4SurfBits *crossed=0) const
 
G4int GetCandidatesVoxelArray (const std::vector< G4int > &voxels, const G4SurfBits bitmasks[], std::vector< G4int > &list, G4SurfBits *crossed=0) const
 
G4int GetCandidatesVoxelArray (const std::vector< G4int > &voxels, std::vector< G4int > &list, G4SurfBits *crossed=0) 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, const 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
 
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 G4int SetDefaultVoxelsCount (G4int count)
 
static G4int GetDefaultVoxelsCount ()
 

Private Member Functions

void BuildEmpty ()
 
G4String GetCandidatesAsString (const G4SurfBits &bits) const
 
void CreateSortedBoundary (std::vector< G4double > &boundaryRaw, G4int axis)
 
void BuildBoundaries ()
 
void BuildReduceVoxels (std::vector< G4double > fBoundaries[], G4ThreeVector reductionRatio)
 
void BuildReduceVoxels2 (std::vector< G4double > fBoundaries[], G4ThreeVector reductionRatio)
 
void BuildVoxelLimits (std::vector< G4VFacet *> &facets)
 
void DisplayBoundaries (std::vector< G4double > &fBoundaries)
 
void BuildBitmasks (std::vector< G4double > fBoundaries[], G4SurfBits bitmasks[], G4bool countsOnly=false)
 
void BuildBoundingBox ()
 
void SetReductionRatio (G4int maxVoxels, G4ThreeVector &reductionRatio)
 
void CreateMiniVoxels (std::vector< G4double > fBoundaries[], G4SurfBits bitmasks[])
 

Static Private Member Functions

static void FindComponentsFastest (unsigned int mask, std::vector< G4int > &list, G4int i)
 

Private Attributes

std::vector< G4VoxelBoxfVoxelBoxes
 
std::vector< std::vector< G4int > > fVoxelBoxesCandidates
 
std::map< G4int, std::vector< G4int > > fCandidates
 
const std::vector< G4intfNoCandidates
 
long long fCountOfVoxels
 
G4int fNPerSlice
 
std::vector< G4VoxelBoxfBoxes
 
std::vector< G4doublefBoundaries [3]
 
std::vector< G4intfCandidatesCounts [3]
 
G4int fTotalCandidates
 
G4SurfBits fBitmasks [3]
 
G4ThreeVector fBoundingBoxCenter
 
G4Box fBoundingBox
 
G4ThreeVector fBoundingBoxSize
 
G4ThreeVector fReductionRatio
 
G4int fMaxVoxels
 
G4double fTolerance
 
G4SurfBits fEmpty
 

Static Private Attributes

static G4ThreadLocal G4int fDefaultVoxelsCount = -1
 

Detailed Description

Definition at line 66 of file G4SurfaceVoxelizer.hh.

Constructor & Destructor Documentation

◆ G4SurfaceVoxelizer()

G4SurfaceVoxelizer::G4SurfaceVoxelizer ( )

Definition at line 60 of file G4SurfaceVoxelizer.cc.

61  : fBoundingBox("TessBBox", 1, 1, 1)
62 {
64 
66 
68 
70 }
static void DeRegister(G4VSolid *pSolid)
G4double GetSurfaceTolerance() const
static G4ThreadLocal G4int fDefaultVoxelsCount
static G4SolidStore * GetInstance()
void SetMaxVoxels(G4int max)
static G4GeometryTolerance * GetInstance()
Here is the call graph for this function:

◆ ~G4SurfaceVoxelizer()

G4SurfaceVoxelizer::~G4SurfaceVoxelizer ( )

Definition at line 73 of file G4SurfaceVoxelizer.cc.

74 {
75 }

Member Function Documentation

◆ AllocatedMemory()

G4int G4SurfaceVoxelizer::AllocatedMemory ( )

Definition at line 1083 of file G4SurfaceVoxelizer.cc.

1084 {
1085  G4int size = fEmpty.GetNbytes();
1086  size += fBoxes.capacity() * sizeof(G4VoxelBox);
1087  size += sizeof(G4double) * (fBoundaries[0].capacity()
1088  + fBoundaries[1].capacity() + fBoundaries[2].capacity());
1089  size += sizeof(G4int) * (fCandidatesCounts[0].capacity()
1090  + fCandidatesCounts[1].capacity() + fCandidatesCounts[2].capacity());
1091  size += fBitmasks[0].GetNbytes() + fBitmasks[1].GetNbytes()
1092  + fBitmasks[2].GetNbytes();
1093 
1094  G4int csize = fCandidates.size();
1095  for (G4int i = 0; i < csize; i++)
1096  {
1097  size += sizeof(vector<G4int>) + fCandidates[i].capacity() * sizeof(G4int);
1098  }
1099 
1100  return size;
1101 }
std::vector< G4int > fCandidatesCounts[3]
int G4int
Definition: G4Types.hh:78
std::map< G4int, std::vector< G4int > > fCandidates
std::vector< G4VoxelBox > fBoxes
std::vector< G4double > fBoundaries[3]
unsigned int GetNbytes() const
Definition: G4SurfBits.hh:102
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BinarySearch()

template<typename T >
static G4int G4SurfaceVoxelizer::BinarySearch ( const std::vector< T > &  vec,
value 
)
inlinestatic
Here is the caller graph for this function:

◆ BuildBitmasks()

void G4SurfaceVoxelizer::BuildBitmasks ( std::vector< G4double fBoundaries[],
G4SurfBits  bitmasks[],
G4bool  countsOnly = false 
)
private

Definition at line 308 of file G4SurfaceVoxelizer.cc.

310 {
311  // "BuildListNodes" stores in the bitmasks solids present in each slice
312  // along an axis.
313 
314  G4int numNodes = fBoxes.size();
315  G4int bitsPerSlice = GetBitsPerSlice();
316 
317  for (G4int k = 0; k < 3; k++)
318  {
319  G4int total = 0;
320  vector<G4double> &boundary = boundaries[k];
321  G4int voxelsCount = boundary.size() - 1;
322  G4SurfBits &bitmask = bitmasks[k];
323 
324  if (!countsOnly)
325  {
326  bitmask.Clear();
327 #ifdef G4SPECSDEBUG
328  G4cout << "Allocating bitmask..." << G4endl;
329 #endif
330  bitmask.SetBitNumber(voxelsCount*bitsPerSlice-1, false);
331  // it is here so we can set the maximum number of bits. this line
332  // will rellocate the memory and set all to zero
333  }
334  vector<G4int> &candidatesCount = fCandidatesCounts[k];
335  candidatesCount.resize(voxelsCount);
336 
337  for(G4int i = 0 ; i < voxelsCount; ++i) { candidatesCount[i] = 0; }
338 
339  // Loop on the nodes, number of slices per axis
340  //
341  for(G4int j = 0 ; j < numNodes; j++)
342  {
343  // Determination of the minimum and maximum position along x
344  // of the bounding boxe of each node
345  //
346  G4double p = fBoxes[j].pos[k], d = fBoxes[j].hlen[k];
347 
348  G4double min = p - d; // - localTolerance;
349  G4double max = p + d; // + localTolerance;
350 
351  G4int i = BinarySearch(boundary, min);
352  if (i < 0) { i = 0; }
353 
354  do // Loop checking, 13.08.2015, G.Cosmo
355  {
356  if (!countsOnly)
357  {
358  G4int index = i*bitsPerSlice+j;
359  bitmask.SetBitNumber(index);
360  }
361  candidatesCount[i]++;
362  total++;
363  i++;
364  }
365  while (max > boundary[i] && i < voxelsCount);
366  }
367  }
368 #ifdef G4SPECSDEBUG
369  G4cout << "Build list nodes completed." << G4endl;
370 #endif
371 }
void Clear()
Definition: G4SurfBits.cc:92
Float_t d
Int_t index
std::vector< G4int > fCandidatesCounts[3]
int G4int
Definition: G4Types.hh:78
void SetBitNumber(unsigned int bitnumber, G4bool value=true)
Definition: G4SurfBits.hh:123
static G4int BinarySearch(const std::vector< T > &vec, T value)
G4GLOB_DLL std::ostream G4cout
std::vector< G4VoxelBox > fBoxes
G4int GetBitsPerSlice() const
G4double total(Particle const *const p1, Particle const *const p2)
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BuildBoundaries()

void G4SurfaceVoxelizer::BuildBoundaries ( )
private

Definition at line 201 of file G4SurfaceVoxelizer.cc.

202 {
203  // "SortBoundaries" orders the boundaries along each axis (increasing order)
204  // and also does not take into account redundant boundaries, i.e. if two
205  // boundaries are separated by a distance strictly inferior to "tolerance".
206  // The sorted boundaries are respectively stored in:
207  // * boundaries[0..2]
208 
209  // In addition, the number of elements contained in the three latter arrays
210  // are precise thanks to variables: boundariesCountX, boundariesCountY and
211  // boundariesCountZ.
212 
213  if (G4int numNodes = fBoxes.size())
214  {
215  const G4double tolerance = fTolerance / 100.0;
216  // Minimal distance to discriminate two boundaries.
217 
218  vector<G4double> sortedBoundary(2*numNodes);
219 
220  G4int considered;
221 
222  for (G4int j = 0; j <= 2; ++j)
223  {
224  CreateSortedBoundary(sortedBoundary, j);
225  vector<G4double> &boundary = fBoundaries[j];
226  boundary.clear();
227 
228  considered = 0;
229 
230  for(G4int i = 0 ; i < 2*numNodes; ++i)
231  {
232  G4double newBoundary = sortedBoundary[i];
233 #ifdef G4SPECSDEBUG
234  if (j == 0) G4cout << "Examining " << newBoundary << "..." << G4endl;
235 #endif
236  G4int size = boundary.size();
237  if(!size || abs(boundary[size-1] - newBoundary) > tolerance)
238  {
239  considered++;
240  {
241 #ifdef G4SPECSDEBUG
242  if (j == 0) G4cout << "Adding boundary " << newBoundary << "..."
243  << G4endl;
244 #endif
245  boundary.push_back(newBoundary);
246  continue;
247  }
248  }
249  // If two successive boundaries are too close from each other,
250  // only the first one is considered
251  }
252 
253  G4int n = boundary.size();
254  G4int max = 100000;
255  if (n > max/2)
256  {
257  G4int skip = n / (max /2); // n has to be 2x bigger then 50.000.
258  // therefore only from 100.000 reduced
259  vector<G4double> reduced;
260  for (G4int i = 0; i < n; i++)
261  {
262  // 50 ok for 2k, 1000, 2000
263  G4int size = boundary.size();
264  if (i % skip == 0 || i == 0 || i == size - 1)
265  {
266  // this condition of merging boundaries was wrong,
267  // it did not count with right part, which can be
268  // completely ommited and not included in final consideration.
269  // Now should be OK
270  //
271  reduced.push_back(boundary[i]);
272  }
273  }
274  boundary = reduced;
275  }
276  }
277  }
278 }
static const G4double tolerance
int G4int
Definition: G4Types.hh:78
Char_t n[5]
G4GLOB_DLL std::ostream G4cout
std::vector< G4VoxelBox > fBoxes
std::vector< G4double > fBoundaries[3]
#define G4endl
Definition: G4ios.hh:61
void CreateSortedBoundary(std::vector< G4double > &boundaryRaw, G4int axis)
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BuildBoundingBox()

void G4SurfaceVoxelizer::BuildBoundingBox ( )
private

Definition at line 414 of file G4SurfaceVoxelizer.cc.

415 {
416  G4ThreeVector toleranceVector;
417  toleranceVector.set(fTolerance/100,fTolerance/100,fTolerance/100);
418  for (G4int i = 0; i <= 2; ++i)
419  {
420  G4double min = fBoundaries[i].front();
421  G4double max = fBoundaries[i].back();
422  fBoundingBoxSize[i] = (max-min)/2;
423  fBoundingBoxCenter[i] = min + fBoundingBoxSize[i];
424  }
425  // sizes -= toleranceVector;
426  fBoundingBox = G4Box("TessBBox", fBoundingBoxSize.x(),
428 }
void set(double x, double y, double z)
G4ThreeVector fBoundingBoxSize
G4ThreeVector fBoundingBoxCenter
Definition: G4Box.hh:64
int G4int
Definition: G4Types.hh:78
std::vector< G4double > fBoundaries[3]
double x() const
double y() const
double z() const
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BuildEmpty()

void G4SurfaceVoxelizer::BuildEmpty ( )
private

Definition at line 78 of file G4SurfaceVoxelizer.cc.

79 {
80  // by reserving the size of candidates, we would avoid reallocation of
81  // the vector which could cause fragmentation
82  //
83  vector<G4int> xyz(3), max(3), candidates(fTotalCandidates);
84  const vector<G4int> empty(0);
85 
86  for (G4int i = 0; i <= 2; i++) max[i] = fBoundaries[i].size();
87  unsigned int size = max[0] * max[1] * max[2];
88 
89  fEmpty.Clear();
90  fEmpty.ResetBitNumber(size-1);
91  fEmpty.ResetAllBits(true);
92 
93  for (xyz[2] = 0; xyz[2] < max[2]; ++xyz[2])
94  {
95  for (xyz[1] = 0; xyz[1] < max[1]; ++xyz[1])
96  {
97  for (xyz[0] = 0; xyz[0] < max[0]; ++xyz[0])
98  {
99  G4int index = GetVoxelsIndex(xyz);
100  if (GetCandidatesVoxelArray(xyz, candidates))
101  {
102  fEmpty.SetBitNumber(index, false);
103 
104  // rather than assigning directly with:
105  // "fCandidates[index] = candidates;", in an effort to ensure that
106  // capacity would be just exact, we rather use following 3 lines
107  //
108  vector<G4int> &c = (fCandidates[index] = empty);
109  c.reserve(candidates.size());
110  c.assign(candidates.begin(), candidates.end());
111  }
112  }
113  }
114  }
115 #ifdef G4SPECSDEBUG
116  G4cout << "Non-empty voxels count: " << fCandidates.size() << G4endl;
117 #endif
118 }
void ResetBitNumber(unsigned int bitnumber)
Definition: G4SurfBits.hh:161
void Clear()
Definition: G4SurfBits.cc:92
Int_t index
G4int GetCandidatesVoxelArray(const G4ThreeVector &point, std::vector< G4int > &list, G4SurfBits *crossed=0) const
int G4int
Definition: G4Types.hh:78
void SetBitNumber(unsigned int bitnumber, G4bool value=true)
Definition: G4SurfBits.hh:123
std::map< G4int, std::vector< G4int > > fCandidates
G4GLOB_DLL std::ostream G4cout
std::vector< G4double > fBoundaries[3]
void ResetAllBits(G4bool value=false)
Definition: G4SurfBits.cc:154
G4int GetVoxelsIndex(G4int x, G4int y, G4int z) const
#define G4endl
Definition: G4ios.hh:61
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BuildReduceVoxels()

void G4SurfaceVoxelizer::BuildReduceVoxels ( std::vector< G4double fBoundaries[],
G4ThreeVector  reductionRatio 
)
private

Definition at line 461 of file G4SurfaceVoxelizer.cc.

463 {
464  for (G4int k = 0; k <= 2; ++k)
465  {
466  vector<G4int> &candidatesCount = fCandidatesCounts[k];
467  G4int max = candidatesCount.size();
468  vector<G4VoxelInfo> voxels(max);
469  G4VoxelComparator comp(voxels);
470  set<G4int, G4VoxelComparator> voxelSet(comp);
471  vector<G4int> mergings;
472 
473  for (G4int j = 0; j < max; ++j)
474  {
475  G4VoxelInfo &voxel = voxels[j];
476  voxel.count = candidatesCount[j];
477  voxel.previous = j - 1;
478  voxel.next = j + 1;
479  voxels[j] = voxel;
480  }
481 
482  for (G4int j = 0; j < max - 1; ++j) { voxelSet.insert(j); }
483  // we go to size-1 to make sure we will not merge the last element
484 
485  G4int count = 0;
486  while (true) // Loop checking, 13.08.2015, G.Cosmo
487  {
488  G4double reduction = reductionRatio[k];
489  if (reduction == 0)
490  break;
491  G4int currentCount = voxelSet.size();
492  if (currentCount <= 2)
493  break;
494  G4double currentRatio = 1 - (G4double) count / max;
495  if (currentRatio <= reduction && currentCount <= 1000)
496  break;
497  const G4int pos = *voxelSet.begin();
498  mergings.push_back(pos);
499 
500  G4VoxelInfo &voxel = voxels[pos];
501  G4VoxelInfo &nextVoxel = voxels[voxel.next];
502 
503  voxelSet.erase(pos);
504  if (voxel.next != max - 1) { voxelSet.erase(voxel.next); }
505  if (voxel.previous != -1) { voxelSet.erase(voxel.previous); }
506 
507  nextVoxel.count += voxel.count;
508  voxel.count = 0;
509  nextVoxel.previous = voxel.previous;
510 
511  if (voxel.next != max - 1)
512  voxelSet.insert(voxel.next);
513 
514  if (voxel.previous != -1)
515  {
516  voxels[voxel.previous].next = voxel.next;
517  voxelSet.insert(voxel.previous);
518  }
519  count++;
520  }
521 
522  if (mergings.size())
523  {
524  sort(mergings.begin(), mergings.end());
525 
526  vector<G4double> &boundary = boundaries[k];
527  vector<G4double> reducedBoundary(boundary.size() - mergings.size());
528  G4int skip = mergings[0] + 1, cur = 0, i = 0;
529  max = boundary.size();
530  for (G4int j = 0; j < max; ++j)
531  {
532  if (j != skip)
533  {
534  reducedBoundary[cur++] = boundary[j];
535  }
536  else
537  {
538  if (++i < (G4int)mergings.size()) { skip = mergings[i] + 1; }
539  }
540  }
541  boundaries[k] = reducedBoundary;
542  }
543  }
544 }
std::vector< G4int > fCandidatesCounts[3]
int G4int
Definition: G4Types.hh:78
double G4double
Definition: G4Types.hh:76
static const G4double pos
Here is the caller graph for this function:

◆ BuildReduceVoxels2()

void G4SurfaceVoxelizer::BuildReduceVoxels2 ( std::vector< G4double fBoundaries[],
G4ThreeVector  reductionRatio 
)
private

Definition at line 547 of file G4SurfaceVoxelizer.cc.

549 {
550  for (G4int k = 0; k <= 2; ++k)
551  {
552  vector<G4int> &candidatesCount = fCandidatesCounts[k];
553  G4int max = candidatesCount.size();
554  G4int total = 0;
555  for (G4int i = 0; i < max; i++) total += candidatesCount[i];
556 
557  G4double reduction = reductionRatio[k];
558  if (reduction == 0)
559  break;
560 
561  G4int destination = (G4int) (reduction * max) + 1;
562  if (destination > 1000) destination = 1000;
563  if (destination < 2) destination = 2;
564  G4double average = ((G4double)total / max) / reduction;
565 
566  vector<G4int> mergings;
567 
568  vector<G4double> &boundary = boundaries[k];
569  vector<G4double> reducedBoundary(destination);
570 
571  G4int sum = 0, cur = 0;
572  for (G4int i = 0; i < max; i++)
573  {
574  sum += candidatesCount[i];
575  if (sum > average * (cur + 1) || i == 0)
576  {
577  G4double val = boundary[i];
578  reducedBoundary[cur] = val;
579  cur++;
580  if (cur == destination)
581  break;
582  }
583  }
584  reducedBoundary[destination-1] = boundary[max];
585  boundaries[k] = reducedBoundary;
586  }
587 }
std::vector< G4int > fCandidatesCounts[3]
int G4int
Definition: G4Types.hh:78
G4double total(Particle const *const p1, Particle const *const p2)
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BuildVoxelLimits()

void G4SurfaceVoxelizer::BuildVoxelLimits ( std::vector< G4VFacet *> &  facets)
private

Definition at line 121 of file G4SurfaceVoxelizer.cc.

122 {
123  // "BuildVoxelLimits"'s aim is to store the coordinates of the origin as well
124  // as the half lengths related to the bounding box of each node.
125  // These quantities are stored in the array "fBoxes" (6 different values per
126  // node.
127 
128  if (G4int numNodes = facets.size()) // Number of nodes
129  {
130  fBoxes.resize(numNodes); // Array which will store the half lengths
131  fNPerSlice = 1+(fBoxes.size()-1)/(8*sizeof(unsigned int));
132 
133  G4ThreeVector toleranceVector;
134  toleranceVector.set(10 * fTolerance,10 * fTolerance,10 * fTolerance);
135 
136  for (G4int i = 0; i < numNodes; ++i)
137  {
138  G4VFacet &facet = *facets[i];
140  G4ThreeVector x(1,0,0), y(0,1,0), z(0,0,1);
141  G4ThreeVector extent;
142  max.set (facet.Extent(x), facet.Extent(y), facet.Extent(z));
143  min.set (-facet.Extent(-x), -facet.Extent(-y), -facet.Extent(-z));
144  min -= toleranceVector; max += toleranceVector;
145  G4ThreeVector hlen = (max - min) / 2;
146  fBoxes[i].hlen = hlen;
147  fBoxes[i].pos = min + hlen;
148  }
149  fTotalCandidates = fBoxes.size();
150  }
151 }
void set(double x, double y, double z)
int G4int
Definition: G4Types.hh:78
Double_t y
std::vector< G4VoxelBox > fBoxes
virtual G4double Extent(const G4ThreeVector)=0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Contains()

G4bool G4SurfaceVoxelizer::Contains ( const G4ThreeVector point) const

Definition at line 926 of file G4SurfaceVoxelizer.cc.

927 {
928  for (G4int i = 0; i < 3; ++i)
929  {
930  if (point[i] < fBoundaries[i].front() || point[i] > fBoundaries[i].back())
931  return false;
932  }
933  return true;
934 }
int G4int
Definition: G4Types.hh:78
std::vector< G4double > fBoundaries[3]
Here is the caller graph for this function:

◆ CountVoxels()

long long G4SurfaceVoxelizer::CountVoxels ( std::vector< G4double boundaries[]) const
inline
Here is the caller graph for this function:

◆ CreateMiniVoxels()

void G4SurfaceVoxelizer::CreateMiniVoxels ( std::vector< G4double fBoundaries[],
G4SurfBits  bitmasks[] 
)
private

Definition at line 590 of file G4SurfaceVoxelizer.cc.

592 {
593  vector<G4int> voxel(3), maxVoxels(3);
594  for (G4int i = 0; i <= 2; ++i) maxVoxels[i] = boundaries[i].size();
595 
596  G4ThreeVector point;
597  for (voxel[2] = 0; voxel[2] < maxVoxels[2] - 1; ++voxel[2])
598  {
599  for (voxel[1] = 0; voxel[1] < maxVoxels[1] - 1; ++voxel[1])
600  {
601  for (voxel[0] = 0; voxel[0] < maxVoxels[0] - 1; ++voxel[0])
602  {
603  vector<G4int> candidates;
604  if (GetCandidatesVoxelArray(voxel, bitmasks, candidates, 0))
605  {
606  // find a box for corresponding non-empty voxel
607  G4VoxelBox box;
608  for (G4int i = 0; i <= 2; ++i)
609  {
610  G4int index = voxel[i];
611  const vector<G4double> &boundary = boundaries[i];
612  G4double hlen = 0.5 * (boundary[index+1] - boundary[index]);
613  box.hlen[i] = hlen;
614  box.pos[i] = boundary[index] + hlen;
615  }
616  fVoxelBoxes.push_back(box);
617  vector<G4int>(candidates).swap(candidates);
618  fVoxelBoxesCandidates.push_back(candidates);
619  }
620  }
621  }
622  }
623 }
std::vector< G4VoxelBox > fVoxelBoxes
Int_t index
G4int GetCandidatesVoxelArray(const G4ThreeVector &point, std::vector< G4int > &list, G4SurfBits *crossed=0) const
int G4int
Definition: G4Types.hh:78
std::vector< std::vector< G4int > > fVoxelBoxesCandidates
G4ThreeVector pos
double G4double
Definition: G4Types.hh:76
G4ThreeVector hlen
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateSortedBoundary()

void G4SurfaceVoxelizer::CreateSortedBoundary ( std::vector< G4double > &  boundaryRaw,
G4int  axis 
)
private

Definition at line 171 of file G4SurfaceVoxelizer.cc.

173 {
174  // "CreateBoundaries"'s aim is to determine the slices induced by the
175  // bounding fBoxes, along each axis. The created boundaries are stored
176  // in the array "boundariesRaw"
177 
178  G4int numNodes = fBoxes.size(); // Number of nodes in structure
179 
180  // Determination of the boundaries along x, y and z axis
181  //
182  for(G4int i = 0 ; i < numNodes; ++i)
183  {
184  // For each node, the boundaries are created by using the array "fBoxes"
185  // built in method "BuildVoxelLimits"
186  //
187  G4double p = fBoxes[i].pos[axis], d = fBoxes[i].hlen[axis];
188 
189  // x boundaries
190  //
191 #ifdef G4SPECSDEBUG
192  G4cout << "Boundary " << p - d << " - " << p + d << G4endl;
193 #endif
194  boundary[2*i] = p - d;
195  boundary[2*i+1] = p + d;
196  }
197  sort(boundary.begin(), boundary.end());
198 }
Float_t d
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
std::vector< G4VoxelBox > fBoxes
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
Here is the caller graph for this function:

◆ DisplayBoundaries() [1/2]

void G4SurfaceVoxelizer::DisplayBoundaries ( )

Definition at line 281 of file G4SurfaceVoxelizer.cc.

282 {
283  char axis[3] = {'X', 'Y', 'Z'};
284  for (G4int i = 0; i <= 2; ++i)
285  {
286  G4cout << " * " << axis[i] << " axis:" << G4endl << " | ";
288  }
289 }
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
std::vector< G4double > fBoundaries[3]
#define G4endl
Definition: G4ios.hh:61

◆ DisplayBoundaries() [2/2]

void G4SurfaceVoxelizer::DisplayBoundaries ( std::vector< G4double > &  fBoundaries)
private

Definition at line 292 of file G4SurfaceVoxelizer.cc.

293 {
294  // Prints the positions of the boundaries of the slices on the three axes
295 
296  G4int count = boundaries.size();
297  G4int oldprec = G4cout.precision(16);
298  for(G4int i = 0; i < count; ++i)
299  {
300  G4cout << setw(10) << setiosflags(ios::fixed) << boundaries[i];
301  if(i != count-1) G4cout << "-> ";
302  }
303  G4cout << "|" << G4endl << "Number of boundaries: " << count << G4endl;
304  G4cout.precision(oldprec);
305 }
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61

◆ DisplayListNodes()

void G4SurfaceVoxelizer::DisplayListNodes ( ) const

Definition at line 389 of file G4SurfaceVoxelizer.cc.

390 {
391  // Prints which solids are present in the slices previously elaborated.
392 
393  char axis[3] = {'X', 'Y', 'Z'};
394  G4int size=8*sizeof(G4int)*fNPerSlice;
395  G4SurfBits bits(size);
396 
397  for (G4int j = 0; j <= 2; ++j)
398  {
399  G4cout << " * " << axis[j] << " axis:" << G4endl;
400  G4int count = fBoundaries[j].size();
401  for(G4int i=0; i < count-1; ++i)
402  {
403  G4cout << " Slice #" << i+1 << ": [" << fBoundaries[j][i]
404  << " ; " << fBoundaries[j][i+1] << "] -> ";
405  bits.set(size,(const char *)fBitmasks[j].fAllBits+i
406  *fNPerSlice*sizeof(G4int));
407  G4String result = GetCandidatesAsString(bits);
408  G4cout << "[ " << result.c_str() << "] " << G4endl;
409  }
410  }
411 }
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
std::vector< G4double > fBoundaries[3]
G4String GetCandidatesAsString(const G4SurfBits &bits) const
#define G4endl
Definition: G4ios.hh:61
Here is the call graph for this function:

◆ DisplayVoxelLimits()

void G4SurfaceVoxelizer::DisplayVoxelLimits ( )

Definition at line 154 of file G4SurfaceVoxelizer.cc.

155 {
156  // "DisplayVoxelLimits" displays the dX, dY, dZ, pX, pY and pZ for each node
157 
158  G4int numNodes = fBoxes.size();
159  G4int oldprec = G4cout.precision(16);
160  for(G4int i = 0; i < numNodes; ++i)
161  {
162  G4cout << setw(10) << setiosflags(ios::fixed) <<
163  " -> Node " << i+1 << ":\n" <<
164  "\t * [x,y,z] = " << fBoxes[i].hlen <<
165  "\t * [x,y,z] = " << fBoxes[i].pos << "\n";
166  }
167  G4cout.precision(oldprec);
168 }
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
std::vector< G4VoxelBox > fBoxes

◆ DistanceToBoundingBox()

G4double G4SurfaceVoxelizer::DistanceToBoundingBox ( const G4ThreeVector point) const

Definition at line 948 of file G4SurfaceVoxelizer.cc.

949 {
950  G4ThreeVector pointShifted = point - fBoundingBoxCenter;
951  G4double shift = MinDistanceToBox(pointShifted, fBoundingBoxSize);
952  return shift;
953 }
G4ThreeVector fBoundingBoxSize
G4ThreeVector fBoundingBoxCenter
static G4double MinDistanceToBox(const G4ThreeVector &aPoint, const G4ThreeVector &f)
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DistanceToFirst()

G4double G4SurfaceVoxelizer::DistanceToFirst ( const G4ThreeVector point,
const G4ThreeVector direction 
) const

Definition at line 938 of file G4SurfaceVoxelizer.cc.

940 {
941  G4ThreeVector pointShifted = point - fBoundingBoxCenter;
942  G4double shift = fBoundingBox.DistanceToIn(pointShifted, direction);
943  return shift;
944 }
G4ThreeVector fBoundingBoxCenter
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
Definition: G4Box.cc:555
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DistanceToNext()

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

Definition at line 983 of file G4SurfaceVoxelizer.cc.

986 {
987  G4double shift = kInfinity;
988 
989  for (G4int i = 0; i <= 2; ++i)
990  {
991  // Looking for the next voxels on the considered direction X,Y,Z axis
992  //
993  const vector<G4double> &boundary = fBoundaries[i];
994  G4int cur = curVoxel[i];
995  if(direction[i] >= 1e-10)
996  {
997  if (boundary[++cur] - point[i] < fTolerance) // make sure shift would
998  if (++cur >= (G4int) boundary.size()) // be non-zero
999  continue;
1000  }
1001  else
1002  {
1003  if(direction[i] <= -1e-10)
1004  {
1005  if (point[i] - boundary[cur] < fTolerance) // make sure shift would
1006  if (--cur < 0) // be non-zero
1007  continue;
1008  }
1009  else
1010  continue;
1011  }
1012  G4double dif = boundary[cur] - point[i];
1013  G4double distance = dif / direction[i];
1014 
1015  if (shift > distance)
1016  shift = distance;
1017  }
1018 
1019  return shift;
1020 }
static const G4double kInfinity
Definition: geomdefs.hh:42
int G4int
Definition: G4Types.hh:78
std::vector< G4double > fBoundaries[3]
double G4double
Definition: G4Types.hh:76
Here is the caller graph for this function:

◆ Empty()

const G4SurfBits& G4SurfaceVoxelizer::Empty ( ) const
inline
Here is the caller graph for this function:

◆ FindComponentsFastest()

void G4SurfaceVoxelizer::FindComponentsFastest ( unsigned int  mask,
std::vector< G4int > &  list,
G4int  i 
)
staticprivate

Definition at line 773 of file G4SurfaceVoxelizer.cc.

775 {
776  for (G4int byte = 0; byte < (G4int) (sizeof(unsigned int)); byte++)
777  {
778  if (G4int maskByte = mask & 0xFF)
779  {
780  for (G4int bit = 0; bit < 8; bit++)
781  {
782  if (maskByte & 1)
783  { list.push_back(8*(sizeof(unsigned int)*i+ byte) + bit); }
784  if (!(maskByte >>= 1)) break;
785  }
786  }
787  mask >>= 8;
788  }
789 }
static ush mask[]
Definition: csz_inflate.cc:317
int G4int
Definition: G4Types.hh:78
Here is the caller graph for this function:

◆ GetBitsPerSlice()

G4int G4SurfaceVoxelizer::GetBitsPerSlice ( ) const
inline
Here is the caller graph for this function:

◆ GetBoundary()

const std::vector<G4double>& G4SurfaceVoxelizer::GetBoundary ( G4int  index) const
inline
Here is the caller graph for this function:

◆ GetBoxes()

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

◆ GetCandidates()

const std::vector<G4int>& G4SurfaceVoxelizer::GetCandidates ( std::vector< G4int > &  curVoxel) const
inline
Here is the caller graph for this function:

◆ GetCandidatesAsString()

G4String G4SurfaceVoxelizer::GetCandidatesAsString ( const G4SurfBits bits) const
private

Definition at line 374 of file G4SurfaceVoxelizer.cc.

375 {
376  // Decodes the candidates in mask as G4String.
377 
378  stringstream ss;
379  G4int numNodes = fBoxes.size();
380 
381  for(G4int i=0; i<numNodes; ++i)
382  {
383  if (bits.TestBitNumber(i)) { ss << i+1 << " "; }
384  }
385  return ss.str();
386 }
int G4int
Definition: G4Types.hh:78
G4bool TestBitNumber(unsigned int bitnumber) const
Definition: G4SurfBits.hh:148
std::vector< G4VoxelBox > fBoxes
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCandidatesVoxel()

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

Definition at line 758 of file G4SurfaceVoxelizer.cc.

759 {
760  // "GetCandidates" should compute which solids are possibly contained in
761  // the voxel defined by the three slices characterized by the passed indexes.
762 
763  G4cout << " Candidates in voxel [" << voxels[0] << " ; " << voxels[1]
764  << " ; " << voxels[2] << "]: ";
765  vector<G4int> candidates;
766  G4int count = GetCandidatesVoxelArray(voxels, candidates);
767  G4cout << "[ ";
768  for (G4int i = 0; i < count; ++i) G4cout << candidates[i];
769  G4cout << "] " << G4endl;
770 }
G4int GetCandidatesVoxelArray(const G4ThreeVector &point, std::vector< G4int > &list, G4SurfBits *crossed=0) const
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
Here is the call graph for this function:

◆ GetCandidatesVoxelArray() [1/3]

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

Definition at line 792 of file G4SurfaceVoxelizer.cc.

794 {
795  // Method returning the candidates corresponding to the passed point
796 
797  list.clear();
798 
799  for (G4int i = 0; i <= 2; ++i)
800  {
801  if(point[i] < fBoundaries[i].front() || point[i] >= fBoundaries[i].back())
802  return 0;
803  }
804 
805  if (fTotalCandidates == 1)
806  {
807  list.push_back(0);
808  return 1;
809  }
810  else
811  {
812  if (fNPerSlice == 1)
813  {
814  unsigned int mask;
815  G4int slice = BinarySearch(fBoundaries[0], point.x());
816  if (!(mask = ((unsigned int *) fBitmasks[0].fAllBits)[slice]
817  )) return 0;
818  slice = BinarySearch(fBoundaries[1], point.y());
819  if (!(mask &= ((unsigned int *) fBitmasks[1].fAllBits)[slice]
820  )) return 0;
821  slice = BinarySearch(fBoundaries[2], point.z());
822  if (!(mask &= ((unsigned int *) fBitmasks[2].fAllBits)[slice]
823  )) return 0;
824  if (crossed && (!(mask &= ~((unsigned int *)crossed->fAllBits)[0])))
825  return 0;
826 
827  FindComponentsFastest(mask, list, 0);
828  }
829  else
830  {
831  unsigned int *masks[3], mask; // masks for X,Y,Z axis
832  for (G4int i = 0; i <= 2; ++i)
833  {
834  G4int slice = BinarySearch(fBoundaries[i], point[i]);
835  masks[i] = ((unsigned int *) fBitmasks[i].fAllBits) + slice*fNPerSlice;
836  }
837  unsigned int *maskCrossed =
838  crossed ? (unsigned int *)crossed->fAllBits : 0;
839 
840  for (G4int i = 0 ; i < fNPerSlice; ++i)
841  {
842  // Logic "and" of the masks along the 3 axes x, y, z:
843  // removing "if (!" and ") continue" => slightly slower
844  //
845  if (!(mask = masks[0][i])) continue;
846  if (!(mask &= masks[1][i])) continue;
847  if (!(mask &= masks[2][i])) continue;
848  if (maskCrossed && !(mask &= ~maskCrossed[i])) continue;
849 
850  FindComponentsFastest(mask, list, i);
851  }
852  }
853  }
854  return list.size();
855 }
static ush mask[]
Definition: csz_inflate.cc:317
for(Int_t i=0;i< nentries;i++)
Definition: comparison.C:30
int G4int
Definition: G4Types.hh:78
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
static G4int BinarySearch(const std::vector< T > &vec, T value)
std::vector< G4double > fBoundaries[3]
double x() const
double y() const
double z() const
static void FindComponentsFastest(unsigned int mask, std::vector< G4int > &list, G4int i)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCandidatesVoxelArray() [2/3]

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

Definition at line 859 of file G4SurfaceVoxelizer.cc.

863 {
864  list.clear();
865 
866  if (fTotalCandidates == 1)
867  {
868  list.push_back(0);
869  return 1;
870  }
871  else
872  {
873  if (fNPerSlice == 1)
874  {
875  unsigned int mask;
876  if (!(mask = ((unsigned int *) bitmasks[0].fAllBits)[voxels[0]]
877  )) return 0;
878  if (!(mask &= ((unsigned int *) bitmasks[1].fAllBits)[voxels[1]]
879  )) return 0;
880  if (!(mask &= ((unsigned int *) bitmasks[2].fAllBits)[voxels[2]]
881  )) return 0;
882  if (crossed && (!(mask &= ~((unsigned int *)crossed->fAllBits)[0])))
883  return 0;
884 
885  FindComponentsFastest(mask, list, 0);
886  }
887  else
888  {
889  unsigned int *masks[3], mask; // masks for X,Y,Z axis
890  for (G4int i = 0; i <= 2; ++i)
891  {
892  masks[i] = ((unsigned int *) bitmasks[i].fAllBits)
893  + voxels[i]*fNPerSlice;
894  }
895  unsigned int *maskCrossed =
896  crossed ? (unsigned int *)crossed->fAllBits : 0;
897 
898  for (G4int i = 0 ; i < fNPerSlice; ++i)
899  {
900  // Logic "and" of the masks along the 3 axes x, y, z:
901  // removing "if (!" and ") continue" => slightly slower
902  //
903  if (!(mask = masks[0][i])) continue;
904  if (!(mask &= masks[1][i])) continue;
905  if (!(mask &= masks[2][i])) continue;
906  if (maskCrossed && !(mask &= ~maskCrossed[i])) continue;
907 
908  FindComponentsFastest(mask, list, i);
909  }
910  }
911  }
912  return list.size();
913 }
static ush mask[]
Definition: csz_inflate.cc:317
for(Int_t i=0;i< nentries;i++)
Definition: comparison.C:30
int G4int
Definition: G4Types.hh:78
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
static void FindComponentsFastest(unsigned int mask, std::vector< G4int > &list, G4int i)
Here is the call graph for this function:

◆ GetCandidatesVoxelArray() [3/3]

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

Definition at line 917 of file G4SurfaceVoxelizer.cc.

919 {
920  // Method returning the candidates corresponding to the passed point
921 
922  return GetCandidatesVoxelArray(voxels, fBitmasks, list, crossed);
923 }
G4int GetCandidatesVoxelArray(const G4ThreeVector &point, std::vector< G4int > &list, G4SurfBits *crossed=0) const
Here is the call graph for this function:

◆ GetCountOfVoxels()

long long G4SurfaceVoxelizer::GetCountOfVoxels ( ) const
inline
Here is the caller graph for this function:

◆ GetDefaultVoxelsCount()

G4int G4SurfaceVoxelizer::GetDefaultVoxelsCount ( )
static

Definition at line 1077 of file G4SurfaceVoxelizer.cc.

1078 {
1079  return fDefaultVoxelsCount;
1080 }
static G4ThreadLocal G4int fDefaultVoxelsCount

◆ GetMaxVoxels()

G4int G4SurfaceVoxelizer::GetMaxVoxels ( G4ThreeVector ratioOfReduction)
inline
Here is the caller graph for this function:

◆ GetPointIndex()

G4int G4SurfaceVoxelizer::GetPointIndex ( const G4ThreeVector p) const
inline
Here is the caller graph for this function:

◆ GetTotalCandidates()

G4int G4SurfaceVoxelizer::GetTotalCandidates ( ) const
inline

◆ GetVoxel()

void G4SurfaceVoxelizer::GetVoxel ( std::vector< G4int > &  curVoxel,
const G4ThreeVector point 
) const
inline
Here is the caller graph for this function:

◆ GetVoxelBox()

const G4VoxelBox& G4SurfaceVoxelizer::GetVoxelBox ( G4int  i) const
inline
Here is the caller graph for this function:

◆ GetVoxelBoxCandidates()

const std::vector<G4int>& G4SurfaceVoxelizer::GetVoxelBoxCandidates ( G4int  i) const
inline
Here is the caller graph for this function:

◆ GetVoxelBoxesSize()

G4int G4SurfaceVoxelizer::GetVoxelBoxesSize ( ) const
inline
Here is the caller graph for this function:

◆ GetVoxelsIndex() [1/2]

G4int G4SurfaceVoxelizer::GetVoxelsIndex ( G4int  x,
G4int  y,
G4int  z 
) const
inline
Here is the caller graph for this function:

◆ GetVoxelsIndex() [2/2]

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

◆ IsEmpty()

G4bool G4SurfaceVoxelizer::IsEmpty ( G4int  index) const
inline
Here is the caller graph for this function:

◆ MinDistanceToBox()

G4double G4SurfaceVoxelizer::MinDistanceToBox ( const G4ThreeVector aPoint,
const G4ThreeVector f 
)
static

Definition at line 957 of file G4SurfaceVoxelizer.cc.

959 {
960  // Estimates the isotropic safety from a point outside the current solid to
961  // any of its surfaces. The algorithm may be accurate or should provide a
962  // fast underestimate.
963 
964  G4double safe, safx, safy, safz;
965  safe = safx = -f.x() + std::abs(aPoint.x());
966  safy = -f.y() + std::abs(aPoint.y());
967  if ( safy > safe ) safe = safy;
968  safz = -f.z() + std::abs(aPoint.z());
969  if ( safz > safe ) safe = safz;
970  if (safe < 0.0) return 0.0; // point is inside
971  // if (!aAccurate) return safe;
972  G4double safsq = 0.0;
973  G4int count = 0;
974  if ( safx > 0 ) { safsq += safx*safx; count++; }
975  if ( safy > 0 ) { safsq += safy*safy; count++; }
976  if ( safz > 0 ) { safsq += safz*safz; count++; }
977  if (count == 1) return safe;
978  return std::sqrt(safsq);
979 }
int G4int
Definition: G4Types.hh:78
double x() const
double y() const
double z() const
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetDefaultVoxelsCount()

G4int G4SurfaceVoxelizer::SetDefaultVoxelsCount ( G4int  count)
static

Definition at line 1069 of file G4SurfaceVoxelizer.cc.

1070 {
1071  G4int res = fDefaultVoxelsCount;
1072  fDefaultVoxelsCount = count;
1073  return res;
1074 }
int G4int
Definition: G4Types.hh:78
static G4ThreadLocal G4int fDefaultVoxelsCount

◆ SetMaxVoxels() [1/2]

void G4SurfaceVoxelizer::SetMaxVoxels ( G4int  max)

Definition at line 1055 of file G4SurfaceVoxelizer.cc.

1056 {
1057  fMaxVoxels = max;
1058  fReductionRatio.set(0,0,0);
1059 }
void set(double x, double y, double z)
G4ThreeVector fReductionRatio
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetMaxVoxels() [2/2]

void G4SurfaceVoxelizer::SetMaxVoxels ( const G4ThreeVector reductionRatio)

Definition at line 1062 of file G4SurfaceVoxelizer.cc.

1063 {
1064  fMaxVoxels = -1;
1065  fReductionRatio = ratioOfReduction;
1066 }
G4ThreeVector fReductionRatio

◆ SetReductionRatio()

void G4SurfaceVoxelizer::SetReductionRatio ( G4int  maxVoxels,
G4ThreeVector reductionRatio 
)
private

Definition at line 445 of file G4SurfaceVoxelizer.cc.

447 {
448  G4double maxTotal = (G4double) fCandidatesCounts[0].size()
449  * fCandidatesCounts[1].size() * fCandidatesCounts[2].size();
450 
451  if (maxVoxels > 0 && maxVoxels < maxTotal)
452  {
453  G4double ratio = (G4double) maxVoxels / maxTotal;
454  ratio = pow(ratio, 1./3.);
455  if (ratio > 1) { ratio = 1; }
456  reductionRatio.set(ratio,ratio,ratio);
457  }
458 }
void set(double x, double y, double z)
std::vector< G4int > fCandidatesCounts[3]
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateCurrentVoxel()

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

Definition at line 1024 of file G4SurfaceVoxelizer.cc.

1027 {
1028  for (G4int i = 0; i <= 2; ++i)
1029  {
1030  G4int index = curVoxel[i];
1031  const vector<G4double> &boundary = fBoundaries[i];
1032 
1033  if (direction[i] > 0)
1034  {
1035  if (point[i] >= boundary[++index])
1036  if (++curVoxel[i] >= (G4int) boundary.size() - 1)
1037  return false;
1038  }
1039  else
1040  {
1041  if (point[i] < boundary[index])
1042  if (--curVoxel[i] < 0)
1043  return false;
1044  }
1045 #ifdef G4SPECSDEBUG
1046  G4int indexOK = BinarySearch(boundary, point[i]);
1047  if (curVoxel[i] != indexOK)
1048  curVoxel[i] = indexOK; // put breakpoint here
1049 #endif
1050  }
1051  return true;
1052 }
Int_t index
int G4int
Definition: G4Types.hh:78
static G4int BinarySearch(const std::vector< T > &vec, T value)
std::vector< G4double > fBoundaries[3]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Voxelize()

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

Definition at line 626 of file G4SurfaceVoxelizer.cc.

627 {
628  G4int maxVoxels = fMaxVoxels;
629  G4ThreeVector reductionRatio = fReductionRatio;
630 
631  G4int size = facets.size();
632  if (size < 10)
633  {
634  for (G4int i = 0; i < (G4int) facets.size(); i++)
635  {
636  if (facets[i]->GetNumberOfVertices() > 3) size++;
637  }
638  }
639 
640  if ((size >= 10 || maxVoxels > 0) && maxVoxels != 0 && maxVoxels != 1)
641  {
642 #ifdef G4SPECSDEBUG
643  G4cout << "Building voxel limits..." << G4endl;
644 #endif
645 
646  BuildVoxelLimits(facets);
647 
648 #ifdef G4SPECSDEBUG
649  G4cout << "Building boundaries..." << G4endl;
650 #endif
651 
652  BuildBoundaries();
653 
654 #ifdef G4SPECSDEBUG
655  G4cout << "Building bitmasks..." << G4endl;
656 #endif
657 
658  BuildBitmasks(fBoundaries, 0, true);
659 
660  if (maxVoxels < 0 && reductionRatio == G4ThreeVector())
661  {
662  maxVoxels = fTotalCandidates;
663  if (fTotalCandidates > 1000000) maxVoxels = 1000000;
664  }
665 
666  SetReductionRatio(maxVoxels, reductionRatio);
667 
669 
670 #ifdef G4SPECSDEBUG
671  G4cout << "Total number of voxels: " << fCountOfVoxels << G4endl;
672 #endif
673 
674  BuildReduceVoxels2(fBoundaries, reductionRatio);
675 
677 
678 #ifdef G4SPECSDEBUG
679  G4cout << "Total number of voxels after reduction: "
680  << fCountOfVoxels << G4endl;
681 #endif
682 
683 #ifdef G4SPECSDEBUG
684  G4cout << "Building bitmasks..." << G4endl;
685 #endif
686 
688 
689  G4ThreeVector reductionRatioMini;
690 
691  G4SurfBits bitmasksMini[3];
692 
693  // section for building mini voxels
694 
695  vector<G4double> miniBoundaries[3];
696 
697  for (G4int i = 0; i <= 2; ++i) { miniBoundaries[i] = fBoundaries[i]; }
698 
699  G4int voxelsCountMini = (fCountOfVoxels >= 1000)
700  ? 100 : fCountOfVoxels / 10;
701 
702  // if (voxelCountMini < 8) voxelCountMini = 8;
703  // voxelsCountMini = 1;
704 
705  SetReductionRatio(voxelsCountMini, reductionRatioMini);
706 
707 #ifdef G4SPECSDEBUG
708  G4cout << "Building reduced voxels..." << G4endl;
709 #endif
710 
711  BuildReduceVoxels(miniBoundaries, reductionRatioMini);
712 
713 #ifdef G4SPECSDEBUG
714  G4int total = CountVoxels(miniBoundaries);
715  G4cout << "Total number of mini voxels: " << total << G4endl;
716 #endif
717 
718 #ifdef G4SPECSDEBUG
719  G4cout << "Building mini bitmasks..." << G4endl;
720 #endif
721 
722  BuildBitmasks(miniBoundaries, bitmasksMini);
723 
724 #ifdef G4SPECSDEBUG
725  G4cout << "Creating Mini Voxels..." << G4endl;
726 #endif
727 
728  CreateMiniVoxels(miniBoundaries, bitmasksMini);
729 
730 #ifdef G4SPECSDEBUG
731  G4cout << "Building bounding box..." << G4endl;
732 #endif
733 
735 
736 #ifdef G4SPECSDEBUG
737  G4cout << "Building empty..." << G4endl;
738 #endif
739 
740  BuildEmpty();
741 
742 #ifdef G4SPECSDEBUG
743  G4cout << "Deallocating unnecessary fields during runtime..." << G4endl;
744 #endif
745  // deallocate fields unnecessary during runtime
746  //
747  fBoxes.resize(0);
748  for (G4int i = 0; i < 3; i++)
749  {
750  fCandidatesCounts[i].resize(0);
751  fBitmasks[i].Clear();
752  }
753  }
754 }
void Clear()
Definition: G4SurfBits.cc:92
void BuildReduceVoxels(std::vector< G4double > fBoundaries[], G4ThreeVector reductionRatio)
CLHEP::Hep3Vector G4ThreeVector
std::vector< G4int > fCandidatesCounts[3]
int G4int
Definition: G4Types.hh:78
void SetReductionRatio(G4int maxVoxels, G4ThreeVector &reductionRatio)
G4GLOB_DLL std::ostream G4cout
long long CountVoxels(std::vector< G4double > boundaries[]) const
void CreateMiniVoxels(std::vector< G4double > fBoundaries[], G4SurfBits bitmasks[])
void BuildBitmasks(std::vector< G4double > fBoundaries[], G4SurfBits bitmasks[], G4bool countsOnly=false)
std::vector< G4VoxelBox > fBoxes
std::vector< G4double > fBoundaries[3]
G4double total(Particle const *const p1, Particle const *const p2)
G4ThreeVector fReductionRatio
void BuildReduceVoxels2(std::vector< G4double > fBoundaries[], G4ThreeVector reductionRatio)
#define G4endl
Definition: G4ios.hh:61
void BuildVoxelLimits(std::vector< G4VFacet *> &facets)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ fBitmasks

G4SurfBits G4SurfaceVoxelizer::fBitmasks[3]
private

Definition at line 236 of file G4SurfaceVoxelizer.hh.

◆ fBoundaries

std::vector<G4double> G4SurfaceVoxelizer::fBoundaries[3]
private

Definition at line 229 of file G4SurfaceVoxelizer.hh.

◆ fBoundingBox

G4Box G4SurfaceVoxelizer::fBoundingBox
private

Definition at line 240 of file G4SurfaceVoxelizer.hh.

◆ fBoundingBoxCenter

G4ThreeVector G4SurfaceVoxelizer::fBoundingBoxCenter
private

Definition at line 238 of file G4SurfaceVoxelizer.hh.

◆ fBoundingBoxSize

G4ThreeVector G4SurfaceVoxelizer::fBoundingBoxSize
private

Definition at line 242 of file G4SurfaceVoxelizer.hh.

◆ fBoxes

std::vector<G4VoxelBox> G4SurfaceVoxelizer::fBoxes
private

Definition at line 226 of file G4SurfaceVoxelizer.hh.

◆ fCandidates

std::map<G4int, std::vector<G4int> > G4SurfaceVoxelizer::fCandidates
mutableprivate

Definition at line 218 of file G4SurfaceVoxelizer.hh.

◆ fCandidatesCounts

std::vector<G4int> G4SurfaceVoxelizer::fCandidatesCounts[3]
private

Definition at line 232 of file G4SurfaceVoxelizer.hh.

◆ fCountOfVoxels

long long G4SurfaceVoxelizer::fCountOfVoxels
private

Definition at line 222 of file G4SurfaceVoxelizer.hh.

◆ fDefaultVoxelsCount

G4ThreadLocal G4int G4SurfaceVoxelizer::fDefaultVoxelsCount = -1
staticprivate

Definition at line 183 of file G4SurfaceVoxelizer.hh.

◆ fEmpty

G4SurfBits G4SurfaceVoxelizer::fEmpty
private

Definition at line 250 of file G4SurfaceVoxelizer.hh.

◆ fMaxVoxels

G4int G4SurfaceVoxelizer::fMaxVoxels
private

Definition at line 246 of file G4SurfaceVoxelizer.hh.

◆ fNoCandidates

const std::vector<G4int> G4SurfaceVoxelizer::fNoCandidates
private

Definition at line 220 of file G4SurfaceVoxelizer.hh.

◆ fNPerSlice

G4int G4SurfaceVoxelizer::fNPerSlice
private

Definition at line 224 of file G4SurfaceVoxelizer.hh.

◆ fReductionRatio

G4ThreeVector G4SurfaceVoxelizer::fReductionRatio
private

Definition at line 244 of file G4SurfaceVoxelizer.hh.

◆ fTolerance

G4double G4SurfaceVoxelizer::fTolerance
private

Definition at line 248 of file G4SurfaceVoxelizer.hh.

◆ fTotalCandidates

G4int G4SurfaceVoxelizer::fTotalCandidates
private

Definition at line 234 of file G4SurfaceVoxelizer.hh.

◆ fVoxelBoxes

std::vector<G4VoxelBox> G4SurfaceVoxelizer::fVoxelBoxes
private

Definition at line 216 of file G4SurfaceVoxelizer.hh.

◆ fVoxelBoxesCandidates

std::vector<std::vector<G4int> > G4SurfaceVoxelizer::fVoxelBoxesCandidates
private

Definition at line 217 of file G4SurfaceVoxelizer.hh.


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