Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions
UVoxelizer Class Reference

#include <UVoxelizer.hh>

Public Member Functions

void Voxelize (std::vector< VUSolid * > &solids, std::vector< UTransform3D * > &transforms)
 
void Voxelize (std::vector< VUFacet * > &facets)
 
void DisplayVoxelLimits ()
 
void DisplayBoundaries ()
 
void DisplayListNodes ()
 
 UVoxelizer ()
 
 ~UVoxelizer ()
 
void GetCandidatesVoxel (std::vector< int > &voxels)
 
int GetCandidatesVoxelArray (const UVector3 &point, std::vector< int > &list, UBits *crossed=NULL) const
 
int GetCandidatesVoxelArray (const std::vector< int > &voxels, const UBits bitmasks[], std::vector< int > &list, UBits *crossed=NULL) const
 
int GetCandidatesVoxelArray (const std::vector< int > &voxels, std::vector< int > &list, UBits *crossed=NULL) const
 
const std::vector< UVoxelBox > & GetBoxes () const
 
const std::vector< double > & GetBoundary (int index) const
 
bool UpdateCurrentVoxel (const UVector3 &point, const UVector3 &direction, std::vector< int > &curVoxel) const
 
void GetVoxel (std::vector< int > &curVoxel, const UVector3 &point) const
 
int GetBitsPerSlice () const
 
bool Contains (const UVector3 &point) const
 
double DistanceToNext (const UVector3 &point, const UVector3 &direction, std::vector< int > &curVoxel) const
 
double DistanceToFirst (const UVector3 &point, const UVector3 &direction) const
 
double SafetyToBoundingBox (const UVector3 &point) const
 
int GetVoxelsIndex (int x, int y, int z) const
 
int GetVoxelsIndex (const std::vector< int > &voxels) const
 
bool GetPointVoxel (const UVector3 &p, std::vector< int > &voxels) const
 
int GetPointIndex (const UVector3 &p) const
 
const UBitsEmpty () const
 
bool IsEmpty (int index) const
 
void SetMaxVoxels (int max)
 
void SetMaxVoxels (const UVector3 &reductionRatio)
 
int GetMaxVoxels (UVector3 &ratioOfReduction)
 
int AllocatedMemory ()
 
long long GetCountOfVoxels () const
 
long long CountVoxels (std::vector< double > boundaries[]) const
 
const std::vector< int > & GetCandidates (std::vector< int > &curVoxel) const
 
int GetVoxelBoxesSize () const
 
const UVoxelBoxGetVoxelBox (int i) const
 
const std::vector< int > & GetVoxelBoxCandidates (int i) const
 
int GetTotalCandidates () const
 
void BuildBoundingBox ()
 
void BuildBoundingBox (UVector3 &amin, UVector3 &amax, double tolerance=0)
 

Static Public Member Functions

template<typename T >
static int BinarySearch (const std::vector< T > &vec, T value)
 
static double MinDistanceToBox (const UVector3 &aPoint, const UVector3 &f)
 
static void SetDefaultVoxelsCount (int count)
 
static int GetDefaultVoxelsCount ()
 

Detailed Description

Definition at line 49 of file UVoxelizer.hh.

Constructor & Destructor Documentation

UVoxelizer::UVoxelizer ( )

Definition at line 31 of file UVoxelizer.cc.

References G4SolidStore::DeRegister(), G4SolidStore::GetInstance(), SetMaxVoxels(), and VUSolid::Tolerance().

31  : fBoundingBox("TessBBox", 1, 1, 1)
32 {
33  fCountOfVoxels = fNPerSlice = fTotalCandidates = 0;
34 
35  fTolerance = VUSolid::Tolerance();
36 
37  SetMaxVoxels(fDefaultVoxelsCount);
38 
39 #ifndef USOLIDSONLY
40  G4SolidStore::GetInstance()->DeRegister(&fBoundingBox);
41 #endif // USOLIDSONLY
42 }
static void DeRegister(G4VSolid *pSolid)
void SetMaxVoxels(int max)
Definition: UVoxelizer.cc:1124
static double Tolerance()
Definition: VUSolid.hh:127
static G4SolidStore * GetInstance()
UVoxelizer::~UVoxelizer ( )

Definition at line 45 of file UVoxelizer.cc.

46 {
47 }

Member Function Documentation

int UVoxelizer::AllocatedMemory ( )

Definition at line 1136 of file UVoxelizer.cc.

References UBits::GetNbytes(), and int().

1137 {
1138  int size = fEmpty.GetNbytes();
1139  size += fBoxes.capacity() * sizeof(UVoxelBox);
1140  size += sizeof(double) * (fBoundaries[0].capacity() + fBoundaries[1].capacity() + fBoundaries[2].capacity());
1141  size += sizeof(int) * (fCandidatesCounts[0].capacity() + fCandidatesCounts[1].capacity() + fCandidatesCounts[2].capacity());
1142  size += fBitmasks[0].GetNbytes() + fBitmasks[1].GetNbytes() + fBitmasks[2].GetNbytes();
1143 
1144  int csize = fCandidates.size();
1145  for (int i = 0; i < csize; ++i)
1146  size += sizeof(vector<int>) + fCandidates[i].capacity() * sizeof(int);
1147 
1148  return size;
1149 }
unsigned int GetNbytes() const
Definition: UBits.hh:124
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
template<typename T >
static int UVoxelizer::BinarySearch ( const std::vector< T > &  vec,
value 
)
inlinestatic

Definition at line 58 of file UVoxelizer.hh.

Referenced by GetCandidatesVoxelArray(), GetPointIndex(), GetPointVoxel(), UVCSGfaceted::GetSection(), UPolycone::GetSection(), GetVoxel(), UVCSGfaceted::SafetyFromInside(), and UPolycone::SafetyFromInside().

59  {
60  // Binary search in an array of doubles. If match is found, function returns
61  // position of element. If no match found, function gives nearest
62  // element smaller than value.
63  typename std::vector<T>::const_iterator begin = vec.begin(), end = vec.end();
64  int res = std::upper_bound(begin, end, value) - begin - 1;
65  return res;
66  }
const XML_Char int const XML_Char * value
void UVoxelizer::BuildBoundingBox ( )

Definition at line 424 of file UVoxelizer.cc.

References G4INCL::Math::max(), and G4INCL::Math::min().

425 {
426  UVector3 min(fBoundaries[0].front(), fBoundaries[1].front(), fBoundaries[2].front());
427  UVector3 max(fBoundaries[0].back(), fBoundaries[1].back(), fBoundaries[2].back());
429 }
void BuildBoundingBox()
Definition: UVoxelizer.cc:424
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
void UVoxelizer::BuildBoundingBox ( UVector3 amin,
UVector3 amax,
double  tolerance = 0 
)

Definition at line 431 of file UVoxelizer.cc.

References G4INCL::Math::min(), UVector3::x, UVector3::y, and UVector3::z.

432 {
433  for (int i = 0; i <= 2; ++i)
434  {
435  double min = amin[i];
436  double max = amax[i];
437  fBoundingBoxSize[i] = (max - min) / 2 + tolerance * 0.5;
438  fBoundingBoxCenter[i] = min + fBoundingBoxSize[i];
439  }
440  fBoundingBox = UBox("", fBoundingBoxSize.x, fBoundingBoxSize.y, fBoundingBoxSize.z);
441 }
double x
Definition: UVector3.hh:136
Definition: UBox.hh:33
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
double z
Definition: UVector3.hh:138
double y
Definition: UVector3.hh:137
bool UVoxelizer::Contains ( const UVector3 point) const

Definition at line 997 of file UVoxelizer.cc.

998 {
999  for (int i = 0; i < 3; ++i)
1000  if (point[i] < fBoundaries[i].front() || point[i] > fBoundaries[i].back())
1001  return false;
1002  return true;
1003 }
long long UVoxelizer::CountVoxels ( std::vector< double >  boundaries[]) const
inline

Definition at line 191 of file UVoxelizer.hh.

Referenced by Voxelize().

192  {
193  long long sx = boundaries[0].size() - 1;
194  long long sy = boundaries[1].size() - 1;
195  long long sz = boundaries[2].size() - 1;
196  return sx * sy * sz;
197  }
void UVoxelizer::DisplayBoundaries ( )

Definition at line 270 of file UVoxelizer.cc.

271 {
272  char axis[3] = {'X', 'Y', 'Z'};
273  for (int i = 0; i <= 2; ++i)
274  {
275  cout << " * " << axis[i] << " axis:" << endl << " | ";
276  DisplayBoundaries(fBoundaries[i]);
277  }
278 }
void DisplayBoundaries()
Definition: UVoxelizer.cc:270
void UVoxelizer::DisplayListNodes ( )

Definition at line 403 of file UVoxelizer.cc.

References int(), and UBits::Set().

404 {
405  char axis[3] = {'X', 'Y', 'Z'};
406  // Prints which solids are present in the slices previously elaborated.
407  int size = 8 * sizeof(int) * fNPerSlice;
408  UBits bits(size);
409 
410  for (int j = 0; j <= 2; ++j)
411  {
412  cout << " * " << axis[j] << " axis:" << endl;
413  int count = fBoundaries[j].size();
414  for (int i = 0; i < count - 1; ++i)
415  {
416  cout << " Slice #" << i + 1 << ": [" << fBoundaries[j][i] << " ; " << fBoundaries[j][i + 1] << "] -> ";
417  bits.Set(size, (const char*)fBitmasks[j].fAllBits + i * fNPerSlice * sizeof(int));
418  string result = GetCandidatesAsString(bits);
419  cout << "[ " << result.c_str() << "] " << endl;
420  }
421  }
422 }
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
Definition: UBits.hh:38
void UVoxelizer::DisplayVoxelLimits ( )

Definition at line 173 of file UVoxelizer.cc.

174 {
175  // "DisplayVoxelLimits" displays the dX, dY, dZ, pX, pY and pZ for each node
176  int numNodes = fBoxes.size();
177  int oldprc = cout.precision();
178  for (int i = 0; i < numNodes; ++i)
179  {
180  cout << setw(10) << setiosflags(ios::fixed) << setprecision(16) <<
181  " -> Node " << i + 1 << ":\n" <<
182  "\t * [x,y,z] = " << fBoxes[i].hlen <<
183  "\t * [x,y,z] = " << fBoxes[i].pos << "\n";
184  }
185  cout.precision(oldprc) ;
186 }
double UVoxelizer::DistanceToFirst ( const UVector3 point,
const UVector3 direction 
) const

Definition at line 1007 of file UVoxelizer.cc.

References UBox::DistanceToIn().

1008 {
1009  UVector3 pointShifted = point - fBoundingBoxCenter;
1010  double shift = fBoundingBox.DistanceToIn(pointShifted, direction);
1011  return shift;
1012 }
double DistanceToIn(const UVector3 &aPoint, const UVector3 &aDirection, double aPstep=UUtils::kInfinity) const
Definition: UBox.cc:117
double UVoxelizer::DistanceToNext ( const UVector3 point,
const UVector3 direction,
std::vector< int > &  curVoxel 
) const

Definition at line 1056 of file UVoxelizer.cc.

1057 {
1058  double shift = UUtils::kInfinity;
1059  int cur = 0; // the smallest index, which would be than increased
1060 
1061  for (int i = 0; i <= 2; ++i)
1062  {
1063  // Looking for the next voxels on the considered direction X,Y,Z axis
1064  const vector<double>& boundary = fBoundaries[i];
1065  int index = curVoxel[i];
1066  if (direction[i] >= 1e-10)
1067  {
1068  ++index;
1069 // if (boundary[++index] - point[i] < fTolerance)
1070 
1071 // if (++index >= (int) boundary.size() - 1)
1072 // exit = true;
1073 
1074 // make sure shift would be non-zero => not needed anymore
1075 
1076 // if (++index >= (int) boundary.size()) // the shift is not important, only is important to increase the boundary index, even if it would be zero, than we would in next steps always increase another dimension, so it would continue alright
1077 // continue;
1078  }
1079  else
1080  {
1081  if (direction[i] <= -1e-10)
1082  {
1083 // if (point[i] - boundary[index] < fTolerance) // make sure shift would be non-zero
1084 // if (--index < 0)
1085 // continue;
1086 
1087 // if (--index < 0)
1088 // exit = true;
1089  }
1090  else
1091  continue;
1092  }
1093  double dif = boundary[index] - point[i];
1094  double distance = dif / direction[i];
1095 
1096  if (shift > distance)
1097  {
1098  shift = distance;
1099  cur = i;
1100  }
1101  }
1102 
1103  if (shift != UUtils::kInfinity)
1104  {
1105  // updating current voxel using the index corresponding to the closest voxel boundary on the ray
1106  if (direction[cur] > 0)
1107  {
1108  if (++curVoxel[cur] >= (int) fBoundaries[cur].size() - 1)
1109  shift = UUtils::kInfinity;
1110  }
1111  else
1112  {
1113  if (--curVoxel[cur] < 0)
1114  shift = UUtils::kInfinity;
1115  }
1116  }
1117 
1118  return shift;
1119 }
const UBits& UVoxelizer::Empty ( ) const
inline

Definition at line 164 of file UVoxelizer.hh.

165  {
166  return fEmpty;
167  }
int UVoxelizer::GetBitsPerSlice ( ) const
inline

Definition at line 115 of file UVoxelizer.hh.

References int().

116  {
117  return fNPerSlice * 8 * sizeof(unsigned int);
118  }
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
const std::vector<double>& UVoxelizer::GetBoundary ( int  index) const
inline

Definition at line 96 of file UVoxelizer.hh.

Referenced by GetVoxel().

97  {
98  return fBoundaries[index];
99  }
const std::vector<UVoxelBox>& UVoxelizer::GetBoxes ( ) const
inline

Definition at line 92 of file UVoxelizer.hh.

93  {
94  return fBoxes;
95  }
const std::vector<int>& UVoxelizer::GetCandidates ( std::vector< int > &  curVoxel) const
inline

Definition at line 221 of file UVoxelizer.hh.

References GetVoxelsIndex().

222  {
223  int voxelsIndex = GetVoxelsIndex(curVoxel);
224  if (voxelsIndex >= 0 && !fEmpty[voxelsIndex])
225  {
226  return fCandidates[voxelsIndex];
227  }
228  return fNoCandidates;
229  }
int GetVoxelsIndex(int x, int y, int z) const
Definition: UVoxelizer.hh:128
void UVoxelizer::GetCandidatesVoxel ( std::vector< int > &  voxels)

Definition at line 777 of file UVoxelizer.cc.

References GetCandidatesVoxelArray().

778 {
779  cout << " Candidates in voxel [" << voxels[0] << " ; " << voxels[1] << " ; " << voxels[2] << "]: ";
780  vector<int> candidates;
781  int count = GetCandidatesVoxelArray(voxels, candidates);
782  cout << "[ ";
783  for (int i = 0; i < count; ++i) cout << candidates[i];
784  cout << "] " << endl;
785 }
int GetCandidatesVoxelArray(const UVector3 &point, std::vector< int > &list, UBits *crossed=NULL) const
Definition: UVoxelizer.cc:867
int UVoxelizer::GetCandidatesVoxelArray ( const UVector3 point,
std::vector< int > &  list,
UBits crossed = NULL 
) const

Definition at line 867 of file UVoxelizer.cc.

References BinarySearch(), UBits::fAllBits, findComponentsFastest(), UVector3::x, UVector3::y, and UVector3::z.

Referenced by GetCandidatesVoxel(), and GetCandidatesVoxelArray().

868 {
869  list.clear();
870 
871  for (int i = 0; i <= 2; ++i)
872  if (point[i] < fBoundaries[i].front() || point[i] >= fBoundaries[i].back())
873  return 0;
874 
875  if (fTotalCandidates == 1)
876  {
877  list.push_back(0);
878  return 1;
879  }
880  else
881  {
882  if (fNPerSlice == 1)
883  {
884  unsigned int mask = 0xFFffFFff;
885  int slice;
886  if (fBoundaries[0].size() > 2)
887  {
888  slice = BinarySearch(fBoundaries[0], point.x);
889  if (!(mask = ((unsigned int*) fBitmasks[0].fAllBits)[slice])) return 0;
890  }
891  if (fBoundaries[1].size() > 2)
892  {
893  slice = BinarySearch(fBoundaries[1], point.y);
894  if (!(mask &= ((unsigned int*) fBitmasks[1].fAllBits)[slice]
895  )) return 0;
896  }
897  if (fBoundaries[2].size() > 2)
898  {
899  slice = BinarySearch(fBoundaries[2], point.z);
900  if (!(mask &= ((unsigned int*) fBitmasks[2].fAllBits)[slice]
901  )) return 0;
902  }
903  if (crossed && (!(mask &= ~((unsigned int*)crossed->fAllBits)[0]))) return 0;
904 
905  findComponentsFastest(mask, list, 0);
906  }
907  else
908  {
909  unsigned int* masks[3], mask; // masks for X,Y,Z axis
910  for (int i = 0; i <= 2; ++i)
911  {
912  int slice = BinarySearch(fBoundaries[i], point[i]);
913  // if (slice < 0 || slice == fBoundaries[i].size()-1) return 0; // not neccesary anymore
914  masks[i] = ((unsigned int*) fBitmasks[i].fAllBits) + slice * fNPerSlice;
915  }
916  unsigned int* maskCrossed = crossed ? (unsigned int*)crossed->fAllBits : NULL;
917 
918  for (int i = 0 ; i < fNPerSlice; ++i)
919  {
920  // Logic "and" of the masks along the 3 axes x, y, z:
921  // removing "if (!" and ") continue" => slightly slower
922  if (!(mask = masks[0][i])) continue;
923  if (!(mask &= masks[1][i])) continue;
924  if (!(mask &= masks[2][i])) continue;
925  if (maskCrossed && !(mask &= ~maskCrossed[i])) continue;
926 
927  findComponentsFastest(mask, list, i);
928  }
929  }
930  }
931  return list.size();
932 }
void findComponentsFastest(unsigned int mask, vector< int > &list, int i)
Definition: UVoxelizer.cc:847
double x
Definition: UVector3.hh:136
static int BinarySearch(const std::vector< T > &vec, T value)
Definition: UVoxelizer.hh:58
unsigned char * fAllBits
Definition: UBits.hh:42
double z
Definition: UVector3.hh:138
double y
Definition: UVector3.hh:137
int UVoxelizer::GetCandidatesVoxelArray ( const std::vector< int > &  voxels,
const UBits  bitmasks[],
std::vector< int > &  list,
UBits crossed = NULL 
) const

Definition at line 938 of file UVoxelizer.cc.

References UBits::fAllBits, and findComponentsFastest().

939 {
940  list.clear();
941 
942  if (fTotalCandidates == 1)
943  {
944  list.push_back(0);
945  return 1;
946  }
947  else
948  {
949  if (fNPerSlice == 1)
950  {
951  unsigned int mask;
952  if (!(mask = ((unsigned int*) bitmasks[0].fAllBits)[voxels[0]]
953  )) return 0;
954  if (!(mask &= ((unsigned int*) bitmasks[1].fAllBits)[voxels[1]]
955  )) return 0;
956  if (!(mask &= ((unsigned int*) bitmasks[2].fAllBits)[voxels[2]]
957  )) return 0;
958  if (crossed && (!(mask &= ~((unsigned int*)crossed->fAllBits)[0]))) return 0;
959 
960  findComponentsFastest(mask, list, 0);
961  }
962  else
963  {
964  unsigned int* masks[3], mask; // masks for X,Y,Z axis
965  for (int i = 0; i <= 2; ++i)
966  masks[i] = ((unsigned int*) bitmasks[i].fAllBits) + voxels[i] * fNPerSlice;
967 
968  unsigned int* maskCrossed = crossed ? (unsigned int*)crossed->fAllBits : NULL;
969 
970  for (int i = 0 ; i < fNPerSlice; ++i)
971  {
972  // Logic "and" of the masks along the 3 axes x, y, z:
973  // removing "if (!" and ") continue" => slightly slower
974  if (!(mask = masks[0][i])) continue;
975  if (!(mask &= masks[1][i])) continue;
976  if (!(mask &= masks[2][i])) continue;
977  if (maskCrossed && !(mask &= ~maskCrossed[i])) continue;
978 
979  findComponentsFastest(mask, list, i);
980  }
981  }
982  }
983  return list.size();
984 }
void findComponentsFastest(unsigned int mask, vector< int > &list, int i)
Definition: UVoxelizer.cc:847
unsigned char * fAllBits
Definition: UBits.hh:42
int UVoxelizer::GetCandidatesVoxelArray ( const std::vector< int > &  voxels,
std::vector< int > &  list,
UBits crossed = NULL 
) const

Definition at line 990 of file UVoxelizer.cc.

References GetCandidatesVoxelArray().

991 {
992  return GetCandidatesVoxelArray(voxels, fBitmasks, list, crossed);
993 }
int GetCandidatesVoxelArray(const UVector3 &point, std::vector< int > &list, UBits *crossed=NULL) const
Definition: UVoxelizer.cc:867
long long UVoxelizer::GetCountOfVoxels ( ) const
inline

Definition at line 186 of file UVoxelizer.hh.

187  {
188  return fCountOfVoxels;
189  }
int UVoxelizer::GetDefaultVoxelsCount ( )
static

Definition at line 1156 of file UVoxelizer.cc.

1157 {
1158  return fDefaultVoxelsCount;
1159 }
int UVoxelizer::GetMaxVoxels ( UVector3 ratioOfReduction)
inline

Definition at line 178 of file UVoxelizer.hh.

179  {
180  ratioOfReduction = fReductionRatio;
181  return fMaxVoxels;
182  }
int UVoxelizer::GetPointIndex ( const UVector3 p) const
inline

Definition at line 153 of file UVoxelizer.hh.

References BinarySearch(), test::x, and z.

154  {
155  int maxX = fBoundaries[0].size();
156  int maxY = fBoundaries[1].size();
157  int x = BinarySearch(fBoundaries[0], p[0]);
158  int y = BinarySearch(fBoundaries[1], p[1]);
159  int z = BinarySearch(fBoundaries[2], p[2]);
160  int index = x + y * maxX + z * maxX * maxY;
161  return index;
162  }
G4double z
Definition: TRTMaterials.hh:39
static int BinarySearch(const std::vector< T > &vec, T value)
Definition: UVoxelizer.hh:58
bool UVoxelizer::GetPointVoxel ( const UVector3 p,
std::vector< int > &  voxels 
) const
inline

Definition at line 142 of file UVoxelizer.hh.

References BinarySearch().

143  {
144  for (int i = 0; i <= 2; ++i)
145  if (p[i] < *fBoundaries[i].begin() || p[i] > *fBoundaries[i].end()) return false;
146 
147  for (int i = 0; i <= 2; ++i)
148  voxels[i] = BinarySearch(fBoundaries[i], p[i]);
149 
150  return true;
151  }
static int BinarySearch(const std::vector< T > &vec, T value)
Definition: UVoxelizer.hh:58
int UVoxelizer::GetTotalCandidates ( ) const
inline

Definition at line 246 of file UVoxelizer.hh.

247  {
248  return fTotalCandidates;
249  }
void UVoxelizer::GetVoxel ( std::vector< int > &  curVoxel,
const UVector3 point 
) const
inline

Definition at line 103 of file UVoxelizer.hh.

References BinarySearch(), GetBoundary(), and n.

104  {
105  for (int i = 0; i <= 2; ++i)
106  {
107  const std::vector<double>& boundary = GetBoundary(i);
108  int n = BinarySearch(boundary, point[i]);
109  if (n == -1) n = 0;
110  else if (n == (int) boundary.size() - 1) n--;
111  curVoxel[i] = n;
112  }
113  }
const std::vector< double > & GetBoundary(int index) const
Definition: UVoxelizer.hh:96
static int BinarySearch(const std::vector< T > &vec, T value)
Definition: UVoxelizer.hh:58
const G4int n
const UVoxelBox& UVoxelizer::GetVoxelBox ( int  i) const
inline

Definition at line 236 of file UVoxelizer.hh.

237  {
238  return fVoxelBoxes[i];
239  }
const std::vector<int>& UVoxelizer::GetVoxelBoxCandidates ( int  i) const
inline

Definition at line 241 of file UVoxelizer.hh.

242  {
243  return fVoxelBoxesCandidates[i];
244  }
int UVoxelizer::GetVoxelBoxesSize ( ) const
inline

Definition at line 231 of file UVoxelizer.hh.

232  {
233  return fVoxelBoxes.size();
234  }
int UVoxelizer::GetVoxelsIndex ( int  x,
int  y,
int  z 
) const
inline

Definition at line 128 of file UVoxelizer.hh.

Referenced by GetCandidates(), and GetVoxelsIndex().

129  {
130  if (x < 0 || y < 0 || z < 0) return -1;
131  int maxX = fBoundaries[0].size();
132  int maxY = fBoundaries[1].size();
133  int index = x + y * maxX + z * maxX * maxY;
134  return index;
135  }
G4double z
Definition: TRTMaterials.hh:39
int UVoxelizer::GetVoxelsIndex ( const std::vector< int > &  voxels) const
inline

Definition at line 137 of file UVoxelizer.hh.

References GetVoxelsIndex().

138  {
139  return GetVoxelsIndex(voxels[0], voxels[1], voxels[2]);
140  }
int GetVoxelsIndex(int x, int y, int z) const
Definition: UVoxelizer.hh:128
bool UVoxelizer::IsEmpty ( int  index) const
inline

Definition at line 169 of file UVoxelizer.hh.

170  {
171  return fEmpty[index];
172  }
double UVoxelizer::MinDistanceToBox ( const UVector3 aPoint,
const UVector3 f 
)
static

Definition at line 1021 of file UVoxelizer.cc.

References UVector3::x, UVector3::y, and UVector3::z.

Referenced by SafetyToBoundingBox().

1022 {
1023  // Estimates the isotropic safety from a point outside the current solid to any
1024  // of its surfaces. The algorithm may be accurate or should provide a fast
1025  // underestimate.
1026  double safe, safx, safy, safz;
1027  safe = safx = -f.x + std::abs(aPoint.x);
1028  safy = -f.y + std::abs(aPoint.y);
1029  if (safy > safe) safe = safy;
1030  safz = -f.z + std::abs(aPoint.z);
1031  if (safz > safe) safe = safz;
1032  if (safe < 0.0) return 0.0; // point is inside
1033 // if (!aAccurate) return safe;
1034  double safsq = 0.0;
1035  int count = 0;
1036  if (safx > 0)
1037  {
1038  safsq += safx * safx;
1039  count++;
1040  }
1041  if (safy > 0)
1042  {
1043  safsq += safy * safy;
1044  count++;
1045  }
1046  if (safz > 0)
1047  {
1048  safsq += safz * safz;
1049  count++;
1050  }
1051  if (count == 1) return safe;
1052  return std::sqrt(safsq);
1053 }
double x
Definition: UVector3.hh:136
double z
Definition: UVector3.hh:138
double y
Definition: UVector3.hh:137
double UVoxelizer::SafetyToBoundingBox ( const UVector3 point) const

Definition at line 1014 of file UVoxelizer.cc.

References MinDistanceToBox().

1015 {
1016  UVector3 pointShifted = point - fBoundingBoxCenter;
1017  double shift = MinDistanceToBox(pointShifted, fBoundingBoxSize);
1018  return shift;
1019 }
static double MinDistanceToBox(const UVector3 &aPoint, const UVector3 &f)
Definition: UVoxelizer.cc:1021
void UVoxelizer::SetDefaultVoxelsCount ( int  count)
static

Definition at line 1151 of file UVoxelizer.cc.

1152 {
1153  fDefaultVoxelsCount = count;
1154 }
void UVoxelizer::SetMaxVoxels ( int  max)

Definition at line 1124 of file UVoxelizer.cc.

References G4INCL::Math::max(), and UVector3::Set().

Referenced by UVoxelizer().

1125 {
1126  fMaxVoxels = max;
1127  fReductionRatio.Set(0);
1128 }
void Set(double xx, double yy, double zz)
Definition: UVector3.hh:245
T max(const T t1, const T t2)
brief Return the largest of the two arguments
void UVoxelizer::SetMaxVoxels ( const UVector3 reductionRatio)

Definition at line 1130 of file UVoxelizer.cc.

1131 {
1132  fMaxVoxels = -1;
1133  fReductionRatio = ratioOfReduction;
1134 }
bool UVoxelizer::UpdateCurrentVoxel ( const UVector3 point,
const UVector3 direction,
std::vector< int > &  curVoxel 
) const
void UVoxelizer::Voxelize ( std::vector< VUSolid * > &  solids,
std::vector< UTransform3D * > &  transforms 
)
void UVoxelizer::Voxelize ( std::vector< VUFacet * > &  facets)

Definition at line 680 of file UVoxelizer.cc.

References UBits::Clear(), CountVoxels(), and int().

681 {
682  int maxVoxels = fMaxVoxels;
683  UVector3 reductionRatio = fReductionRatio;
684 
685  int size = facets.size();
686  if (size < 10)
687  for (int i = 0; i < (int) facets.size(); ++i)
688  if (facets[i]->GetNumberOfVertices() > 3) size++;
689 
690  if ((size >= 10 || maxVoxels > 0) && maxVoxels != 0 && maxVoxels != 1)
691  {
692  BuildVoxelLimits(facets);
693 
694  BuildBoundaries();
695 
696  BuildBitmasks(fBoundaries, NULL);
697 
698  if (maxVoxels < 0 && reductionRatio == UVector3())
699  {
700  /*
701  if (fTotalCandidates < 1000)
702  maxVoxels = 10 * fTotalCandidates;
703  else
704  {
705  if (fTotalCandidates < 10000) maxVoxels = 10000;
706  else maxVoxels = fTotalCandidates;
707  }
708  if (fTotalCandidates > 1000000) maxVoxels = 1000000;
709  */
710 
711  maxVoxels = fTotalCandidates;
712  if (fTotalCandidates > 1000000) maxVoxels = 1000000;
713  }
714 
715  SetReductionRatio(maxVoxels, reductionRatio);
716 
717  fCountOfVoxels = CountVoxels(fBoundaries);
718 
719 #ifdef USPECSDEBUG
720  cout << "Total number of voxels: " << fCountOfVoxels << endl;
721 #endif
722 
723  BuildReduceVoxels2(fBoundaries, reductionRatio);
724 
725  fCountOfVoxels = CountVoxels(fBoundaries);
726 
727 #ifdef USPECSDEBUG
728  cout << "Total number of voxels after reduction: " << fCountOfVoxels << endl;
729 #endif
730 
731  BuildBitmasks(fBoundaries, fBitmasks);
732 
733  UVector3 reductionRatioMini;
734 
735  UBits bitmasksMini[3];
736 
737  // section for building mini voxels
738  std::vector<double> miniBoundaries[3];
739 
740  for (int i = 0; i <= 2; ++i) miniBoundaries[i] = fBoundaries[i];
741 
742  int voxelsCountMini = (fCountOfVoxels >= 1000) ? 100 : fCountOfVoxels / 10;
743  // if (voxelCountMini < 8) voxelCountMini = 8;
744 
745 // voxelsCountMini = 1;
746 
747  SetReductionRatio(voxelsCountMini, reductionRatioMini);
748 
749  BuildReduceVoxels(miniBoundaries, reductionRatioMini);
750 
751 #ifdef USPECSDEBUG
752  int total = CountVoxels(miniBoundaries);
753  cout << "Total number of mini voxels: " << total << endl;
754 #endif
755 
756  BuildBitmasks(miniBoundaries, bitmasksMini);
757 
758  CreateMiniVoxels(miniBoundaries, bitmasksMini);
759 
760  BuildEmpty();
761 
762  // deallocate fields unnecessary during runtime
763  fBoxes.resize(0);
764 
765  for (int i = 0; i < 3; ++i)
766  {
767  fCandidatesCounts[i].resize(0);
768  fBitmasks[i].Clear();
769  }
770  }
771 }
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
void Clear()
Definition: UBits.cc:72
long long CountVoxels(std::vector< double > boundaries[]) const
Definition: UVoxelizer.hh:191
G4double total(Particle const *const p1, Particle const *const p2)
Definition: UBits.hh:38

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