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

#include <UVCSGfaceted.hh>

Inheritance diagram for UVCSGfaceted:
VUSolid UGenericPolycone UPolyhedra

Public Member Functions

 UVCSGfaceted (const std::string &name)
 
virtual ~UVCSGfaceted ()
 
 UVCSGfaceted (const UVCSGfaceted &source)
 
UVCSGfacetedoperator= (const UVCSGfaceted &source)
 
VUSolid::EnumInside InsideNoVoxels (const UVector3 &p) const
 
virtual VUSolid::EnumInside Inside (const UVector3 &p) const
 
virtual bool Normal (const UVector3 &p, UVector3 &n) const
 
double DistanceToInNoVoxels (const UVector3 &p, const UVector3 &v) const
 
virtual double DistanceToIn (const UVector3 &p, const UVector3 &v, double aPstep=UUtils::kInfinity) const
 
virtual double SafetyFromOutside (const UVector3 &aPoint, bool aAccurate=false) const
 
double DistanceTo (const UVector3 &p, const bool outgoing) const
 
double DistanceToOutNoVoxels (const UVector3 &p, const UVector3 &v, UVector3 &n, bool &aConvex) const
 
virtual double DistanceToOut (const UVector3 &p, const UVector3 &v, UVector3 &n, bool &aConvex, double aPstep=UUtils::kInfinity) const
 
virtual double SafetyFromInside (const UVector3 &aPoint, bool aAccurate=false) const
 
virtual double SafetyFromInsideNoVoxels (const UVector3 &aPoint, bool aAccurate=false) const
 
virtual UGeometryType GetEntityType () const
 
virtual std::ostream & StreamInfo (std::ostream &os) const
 
int GetCubVolStatistics () const
 
double GetCubVolEpsilon () const
 
void SetCubVolStatistics (int st)
 
void SetCubVolEpsilon (double ep)
 
int GetAreaStatistics () const
 
double GetAreaAccuracy () const
 
void SetAreaStatistics (int st)
 
void SetAreaAccuracy (double ep)
 
virtual double Capacity ()
 
virtual double SurfaceArea ()
 
- Public Member Functions inherited from VUSolid
 VUSolid ()
 
 VUSolid (const std::string &name)
 
virtual ~VUSolid ()
 
double GetCarTolerance () const
 
double GetRadTolerance () const
 
double GetAngTolerance () const
 
void SetCarTolerance (double eps)
 
void SetRadTolerance (double eps)
 
void SetAngTolerance (double eps)
 
virtual void ExtentAxis (EAxisType aAxis, double &aMin, double &aMax) const
 
virtual void Extent (UVector3 &aMin, UVector3 &aMax) const =0
 
const std::string & GetName () const
 
void SetName (const std::string &aName)
 
virtual void SamplePointsInside (int, UVector3 *) const
 
virtual void SamplePointsOnSurface (int, UVector3 *) const
 
virtual void SamplePointsOnEdge (int, UVector3 *) const
 
virtual void GetParametersList (int aNumber, double *aArray) const =0
 
virtual VUSolidClone () const =0
 
virtual UVector3 GetPointOnSurface () const =0
 
double EstimateCubicVolume (int nStat, double epsilon) const
 
double EstimateSurfaceArea (int nStat, double ell) const
 

Protected Member Functions

double SafetyFromInsideSection (int index, const UVector3 &p, UBits &bits) const
 
int GetSection (double z) const
 
UVector3 GetPointOnSurfaceGeneric () const
 
void CopyStuff (const UVCSGfaceted &source)
 
void DeleteStuff ()
 
void FindCandidates (double z, std::vector< int > &candidates, bool sides=false)
 
void InitVoxels (UReduciblePolygon &z, double radius)
 
- Protected Member Functions inherited from VUSolid
virtual void ComputeBBox (UBBox *aBox, bool aStore=false)=0
 

Protected Attributes

int numFace
 
UVCSGface ** faces
 
double fCubicVolume
 
double fSurfaceArea
 
std::vector< double > fZs
 
std::vector< std::vector< int > > fCandidates
 
int fMaxSection
 
UBox fBox
 
double fBoxShift
 
bool fNoVoxels
 

Additional Inherited Members

- Public Types inherited from VUSolid
enum  EnumInside { eInside =0, eSurface =1, eOutside =2 }
 
enum  EAxisType { eXaxis =0, eYaxis =1, eZaxis =2 }
 
- Static Public Member Functions inherited from VUSolid
static double Tolerance ()
 
- Static Protected Attributes inherited from VUSolid
static double fgTolerance = 1.0E-9
 
static double frTolerance = 1.0E-9
 
static double faTolerance = 1.0E-9
 

Detailed Description

Definition at line 33 of file UVCSGfaceted.hh.

Constructor & Destructor Documentation

UVCSGfaceted::UVCSGfaceted ( const std::string &  name)

Definition at line 31 of file UVCSGfaceted.cc.

32  : VUSolid(name),
33  numFace(0), faces(0), fCubicVolume(0.), fSurfaceArea(0.),
34  fMaxSection(0),fBoxShift(0.), fNoVoxels(true),fStatistics(1000000), fCubVolEpsilon(0.001), fAreaAccuracy(-1.)
35 {
36 }
VUSolid()
Definition: VUSolid.cc:18
double fBoxShift
double fSurfaceArea
const XML_Char * name
double fCubicVolume
UVCSGface ** faces
UVCSGfaceted::~UVCSGfaceted ( )
virtual

Definition at line 41 of file UVCSGfaceted.cc.

References DeleteStuff().

42 {
43  DeleteStuff();
44 }
void DeleteStuff()
UVCSGfaceted::UVCSGfaceted ( const UVCSGfaceted source)

Definition at line 49 of file UVCSGfaceted.cc.

References CopyStuff().

50  : VUSolid(source)
51 {
52  fStatistics = source.fStatistics;
53  fCubVolEpsilon = source.fCubVolEpsilon;
54  fAreaAccuracy = source.fAreaAccuracy;
55 
56  CopyStuff(source);
57 }
VUSolid()
Definition: VUSolid.cc:18
void CopyStuff(const UVCSGfaceted &source)
Definition: UVCSGfaceted.cc:91

Member Function Documentation

double UVCSGfaceted::Capacity ( )
virtual

Implements VUSolid.

Definition at line 519 of file UVCSGfaceted.cc.

References VUSolid::EstimateCubicVolume(), and fCubicVolume.

520 {
521  if (fCubicVolume != 0.)
522  {
523  ;
524  }
525  else
526  {
527  fCubicVolume = EstimateCubicVolume(fStatistics, fCubVolEpsilon);
528  }
529  return fCubicVolume;
530 }
double EstimateCubicVolume(int nStat, double epsilon) const
Definition: VUSolid.cc:214
double fCubicVolume
void UVCSGfaceted::CopyStuff ( const UVCSGfaceted source)
protected

Definition at line 91 of file UVCSGfaceted.cc.

References UVCSGface::Clone(), faces, fBox, fBoxShift, fCubicVolume, fMaxSection, fNoVoxels, fSurfaceArea, fZs, and numFace.

Referenced by operator=(), and UVCSGfaceted().

92 {
93  numFace = source.numFace;
94  if (numFace == 0)
95  {
96  return; // odd, but permissable?
97  }
98 
99  faces = new UVCSGface*[numFace];
100 
101  UVCSGface** face = faces,
102  **sourceFace = source.faces;
103  do
104  {
105  *face = (*sourceFace)->Clone();
106  }
107  while (++sourceFace, ++face < faces + numFace);
108  fCubicVolume = source.fCubicVolume;
109  fSurfaceArea = source.fSurfaceArea;
110 
111  fMaxSection = source.fMaxSection;
112  fNoVoxels = source.fNoVoxels;
113  fZs = source.fZs;
114  fBox = source.fBox;
115  fBoxShift = source.fBoxShift;
116 }
double fBoxShift
double fSurfaceArea
virtual UVCSGface * Clone()=0
std::vector< double > fZs
double fCubicVolume
UVCSGface ** faces
void UVCSGfaceted::DeleteStuff ( )
protected

Definition at line 124 of file UVCSGfaceted.cc.

References faces, and numFace.

Referenced by UPolyhedra::Reset(), and ~UVCSGfaceted().

125 {
126  if (numFace)
127  {
128  UVCSGface** face = faces;
129  do
130  {
131  delete *face;
132  }
133  while (++face < faces + numFace);
134 
135  delete [] faces;
136  }
137 }
UVCSGface ** faces
double UVCSGfaceted::DistanceTo ( const UVector3 p,
const bool  outgoing 
) const

Definition at line 399 of file UVCSGfaceted.cc.

References faces, VUSolid::fgTolerance, and numFace.

Referenced by SafetyFromInsideNoVoxels(), and SafetyFromOutside().

401 {
402  UVCSGface** face = faces;
403  double best = UUtils::kInfinity;
404  do
405  {
406  double distance = (*face)->Safety(p, outgoing);
407  if (distance < best) best = distance;
408  }
409  while (++face < faces + numFace);
410 
411  return (best < 0.5 * fgTolerance) ? 0 : best;
412 }
static double fgTolerance
Definition: VUSolid.hh:30
UVCSGface ** faces
double UVCSGfaceted::DistanceToIn ( const UVector3 p,
const UVector3 v,
double  aPstep = UUtils::kInfinity 
) const
virtual

Implements VUSolid.

Reimplemented in UPolyhedra, and UGenericPolycone.

Definition at line 670 of file UVCSGfaceted.cc.

References UVCSGface::Distance(), UBox::DistanceToIn(), DistanceToInNoVoxels(), faces, fBox, fBoxShift, fCandidates, VUSolid::fgTolerance, fMaxSection, fNoVoxels, fZs, GetSection(), numFace, UVCSGface::Safety(), UBits::SetBitNumber(), UVector3::x, UVector3::y, z, and UVector3::z.

Referenced by UGenericPolycone::DistanceToIn(), and UPolyhedra::DistanceToIn().

671 {
672  if (fNoVoxels) return DistanceToInNoVoxels(p, v);
673 
674  UVector3 pb(p.x, p.y, p.z - fBoxShift);
675 
676  double idistance, shift;
677  idistance = fBox.DistanceToIn(pb, v); // using only box, this appears
678  // to be faster than: idistance = enclosingCylinder->DistanceTo(pb, v);
679  if (idistance >= UUtils::kInfinity) return idistance;
680 
681  // this line can be here or not. not a big difference in performance
682  // TODO: fix enclosingCylinder for polyhedra!!! - the current radius appears to be too small
683  // if (enclosingCylinder->ShouldMiss(p, v)) return UUtils::kInfinity;
684 
685  // this just takes too much time
686  // idistance = enclosingCylinder->DistanceTo(pb, v);
687  // if (idistance == UUtils::kInfinity) return idistance;
688 
689  double z = p.z + idistance * v.z;
690  int index = GetSection(z);
691  int increment = (v.z > 0) ? 1 : -1;
692  if (std::fabs(v.z) < fgTolerance) increment = 0;
693 
694  double distance = UUtils::kInfinity;
695  double distFromSurface = UUtils::kInfinity;
696  UVCSGface* bestFace = 0;
697  UBits bits(numFace);
698  UVector3 faceNormal;
699 
700  do
701  {
702  const vector<int>& candidates = fCandidates[index];
703  int size = candidates.size();
704  for (int i = 0; i < size; ++i)
705  {
706  int candidate = candidates[i];
707  if (!bits[candidate])
708  {
709  bits.SetBitNumber(candidate);
710  UVCSGface& face = *faces[candidate];
711 
712  double faceDistance,
713  faceDistFromSurface;
714  bool faceAllBehind;
715  if (face.Distance(p, v, false, fgTolerance * 0.5,
716  faceDistance, faceDistFromSurface,
717  faceNormal, faceAllBehind))
718  {
719  // Intersecting face
720  if (faceDistance < distance)
721  {
722  distance = faceDistance;
723  distFromSurface = faceDistFromSurface;
724  bestFace = &face;
725  if (distFromSurface <= 0) return 0;
726  }
727  }
728  }
729  }
730 
731  if (!increment)
732  break;
733 
734  index += increment;
735  if (index < 0 || index > fMaxSection)
736  break;
737  int newz = increment > 0 ? index : index + 1;
738  shift = (fZs[newz] - z) / v.z;
739  }
740  while (idistance + shift < distance);
741 
742  if (distance < UUtils::kInfinity && distFromSurface < fgTolerance / 2)
743  {
744  if (bestFace->Safety(p, false) < fgTolerance / 2)
745  {
746  distance = 0;
747  }
748  }
749 
750  return distance;
751 }
virtual bool Distance(const UVector3 &p, const UVector3 &v, bool outgoing, double surfTolerance, double &distance, double &distFromSurface, UVector3 &normal, bool &allBehind)=0
double fBoxShift
G4double z
Definition: TRTMaterials.hh:39
static double fgTolerance
Definition: VUSolid.hh:30
double x
Definition: UVector3.hh:136
std::vector< double > fZs
int GetSection(double z) const
virtual double Safety(const UVector3 &p, bool outgoing)=0
double DistanceToIn(const UVector3 &aPoint, const UVector3 &aDirection, double aPstep=UUtils::kInfinity) const
Definition: UBox.cc:117
double DistanceToInNoVoxels(const UVector3 &p, const UVector3 &v) const
std::vector< std::vector< int > > fCandidates
UVCSGface ** faces
double z
Definition: UVector3.hh:138
double y
Definition: UVector3.hh:137
Definition: UBits.hh:38
double UVCSGfaceted::DistanceToInNoVoxels ( const UVector3 p,
const UVector3 v 
) const
inline

Definition at line 272 of file UVCSGfaceted.cc.

References faces, VUSolid::fgTolerance, numFace, and UVCSGface::Safety().

Referenced by DistanceToIn().

274 {
275  double distance = UUtils::kInfinity;
276  double distFromSurface = UUtils::kInfinity;
277  UVCSGface** face = faces;
278  UVCSGface* bestFace = *face;
279  static double htol = fgTolerance * 0.5;
280  UVector3 faceNormal;
281 
282  do
283  {
284  double faceDistance, faceDistFromSurface;
285  bool faceAllBehind;
286  if ((*face)->Distance(p, v, false, htol,
287  faceDistance, faceDistFromSurface,
288  faceNormal, faceAllBehind))
289  {
290  //
291  // Intersecting face
292  //
293  if (faceDistance < distance)
294  {
295  distance = faceDistance;
296  distFromSurface = faceDistFromSurface;
297  bestFace = *face;
298  if (distFromSurface <= 0)
299  {
300  return 0;
301  }
302  }
303  }
304  }
305  while (++face < faces + numFace);
306 
307  if (distance < UUtils::kInfinity && distFromSurface < htol)
308  {
309  if (bestFace->Safety(p, false) < htol)
310  {
311  distance = 0;
312  }
313  }
314 
315  return distance;
316 }
static double fgTolerance
Definition: VUSolid.hh:30
virtual double Safety(const UVector3 &p, bool outgoing)=0
UVCSGface ** faces
double UVCSGfaceted::DistanceToOut ( const UVector3 p,
const UVector3 v,
UVector3 n,
bool &  aConvex,
double  aPstep = UUtils::kInfinity 
) const
virtual

Implements VUSolid.

Definition at line 755 of file UVCSGfaceted.cc.

References UVCSGface::Distance(), DistanceToOutNoVoxels(), VUSolid::eSurface, faces, fCandidates, VUSolid::fgTolerance, fMaxSection, fNoVoxels, fZs, GetSection(), Inside(), numFace, UVCSGface::Safety(), UBits::SetBitNumber(), and UVector3::z.

756 {
757  if (fNoVoxels) return DistanceToOutNoVoxels(p, v, n, aConvex);
758 
759  int index = GetSection(p.z);
760  int increment = (v.z > 0) ? 1 : -1;
761 
762  bool allBehind = true;
763  double distance = UUtils::kInfinity;
764  double distFromSurface = UUtils::kInfinity;
765  UVector3 normal, faceNormal;
766  double shift;
767 
768  UVCSGface* bestFace = 0;
769  UBits bits(numFace);
770 
771  do
772  {
773  const vector<int>& candidates = fCandidates[index];
774  int size = candidates.size();
775  for (int i = 0; i < size; ++i)
776  {
777  int candidate = candidates[i];
778  if (!bits[candidate])
779  {
780  bits.SetBitNumber(candidate);
781  UVCSGface& face = *faces[candidate];
782 
783  double faceDistance, faceDistFromSurface;
784  bool faceAllBehind;
785  if ((face.Distance(p, v, true, fgTolerance * 0.5, faceDistance, faceDistFromSurface,
786  faceNormal, faceAllBehind)))
787  {
788  // Intersecting face
789  if ((distance < UUtils::kInfinity) || (!faceAllBehind))
790  {
791  allBehind = false;
792  }
793  if (faceDistance < distance)
794  {
795  distance = faceDistance;
796  distFromSurface = faceDistFromSurface;
797  normal = faceNormal;
798  bestFace = &face;
799  if (distFromSurface <= 0) break;
800  }
801  }
802  }
803  }
804 
805  if (distFromSurface <= 0) break;
806  if (!increment) break;
807 
808  index += increment;
809  if (index < 0 || index > fMaxSection)
810  break;
811  int newz = increment > 0 ? index : index + 1;
812  shift = (fZs[newz] - p.z) / v.z;
813  }
814  while (shift < distance);
815 
816  if (distance < UUtils::kInfinity)
817  {
818  if (distFromSurface <= 0)
819  {
820  distance = 0;
821  }
822  else if (distFromSurface < fgTolerance / 2)
823  {
824  if (bestFace->Safety(p, true) < fgTolerance * 0.5)
825  {
826  distance = 0;
827  }
828  }
829 
830  aConvex = allBehind;
831  n = normal;
832  }
833  else
834  {
835  if (Inside(p) == eSurface)
836  {
837  distance = 0;
838  }
839  aConvex = false;
840  }
841 
842  return distance;
843 }
virtual bool Distance(const UVector3 &p, const UVector3 &v, bool outgoing, double surfTolerance, double &distance, double &distFromSurface, UVector3 &normal, bool &allBehind)=0
static double fgTolerance
Definition: VUSolid.hh:30
double DistanceToOutNoVoxels(const UVector3 &p, const UVector3 &v, UVector3 &n, bool &aConvex) const
std::vector< double > fZs
int GetSection(double z) const
virtual double Safety(const UVector3 &p, bool outgoing)=0
std::vector< std::vector< int > > fCandidates
UVCSGface ** faces
double z
Definition: UVector3.hh:138
virtual VUSolid::EnumInside Inside(const UVector3 &p) const
Definition: UBits.hh:38
double UVCSGfaceted::DistanceToOutNoVoxels ( const UVector3 p,
const UVector3 v,
UVector3 n,
bool &  aConvex 
) const
inline

Definition at line 325 of file UVCSGfaceted.cc.

References VUSolid::eSurface, faces, VUSolid::fgTolerance, Inside(), numFace, and UVCSGface::Safety().

Referenced by DistanceToOut().

326 {
327  bool allBehind = true;
328  double distance = UUtils::kInfinity;
329  double distFromSurface = UUtils::kInfinity;
330  UVector3 normal, faceNormal;
331 
332  UVCSGface** face = faces;
333  UVCSGface* bestFace = *face;
334  do
335  {
336  double faceDistance, faceDistFromSurface;
337  bool faceAllBehind;
338  if ((*face)->Distance(p, v, true, fgTolerance / 2,
339  faceDistance, faceDistFromSurface,
340  faceNormal, faceAllBehind))
341  {
342  // Intersecting face
343  if ((distance < UUtils::kInfinity) || (!faceAllBehind))
344  {
345  allBehind = false;
346  }
347  if (faceDistance < distance)
348  {
349  distance = faceDistance;
350  distFromSurface = faceDistFromSurface;
351  normal = faceNormal;
352  bestFace = *face;
353  if (distFromSurface <= 0)
354  {
355  break;
356  }
357  }
358  }
359  }
360  while (++face < faces + numFace);
361 
362  if (distance < UUtils::kInfinity)
363  {
364  if (distFromSurface <= 0)
365  {
366  distance = 0;
367  }
368  else if (distFromSurface < fgTolerance / 2)
369  {
370  if (bestFace->Safety(p, true) < fgTolerance / 2)
371  {
372  distance = 0;
373  }
374  }
375 
376  aConvex = allBehind;
377  n = normal;
378  }
379  else
380  {
381  if (Inside(p) == eSurface)
382  {
383  distance = 0;
384  }
385  aConvex = false;
386  }
387 
388  return distance;
389 }
static double fgTolerance
Definition: VUSolid.hh:30
virtual double Safety(const UVector3 &p, bool outgoing)=0
UVCSGface ** faces
virtual VUSolid::EnumInside Inside(const UVector3 &p) const
void UVCSGfaceted::FindCandidates ( double  z,
std::vector< int > &  candidates,
bool  sides = false 
)
protected

Definition at line 653 of file UVCSGfaceted.cc.

References UVCSGface::Extent(), faces, VUSolid::fgTolerance, and numFace.

Referenced by InitVoxels().

654 {
655  for (int j = 0; j < numFace; j++)
656  {
657  UVCSGface* face = faces[j];
658  double minZ = -face->Extent(UVector3(0, 0, -1)) ;
659  double maxZ = face->Extent(UVector3(0, 0, 1));
660  if (z >= minZ - fgTolerance * 10 && z <= maxZ + fgTolerance * 10)
661  {
662  if (!sides || std::fabs(minZ - maxZ) < fgTolerance * 10)
663  if (std::find(candidates.begin(), candidates.end(), j) == candidates.end())
664  candidates.push_back(j);
665  }
666  }
667 }
G4double z
Definition: TRTMaterials.hh:39
static double fgTolerance
Definition: VUSolid.hh:30
virtual double Extent(const UVector3 axis)=0
UVCSGface ** faces
double UVCSGfaceted::GetAreaAccuracy ( ) const

Definition at line 490 of file UVCSGfaceted.cc.

491 {
492  return fAreaAccuracy;
493 }
int UVCSGfaceted::GetAreaStatistics ( ) const

Definition at line 481 of file UVCSGfaceted.cc.

482 {
483  return fStatistics;
484 }
double UVCSGfaceted::GetCubVolEpsilon ( ) const

Definition at line 452 of file UVCSGfaceted.cc.

453 {
454  return fCubVolEpsilon;
455 }
int UVCSGfaceted::GetCubVolStatistics ( ) const

Definition at line 443 of file UVCSGfaceted.cc.

444 {
445  return fStatistics;
446 }
UGeometryType UVCSGfaceted::GetEntityType ( ) const
virtual

Implements VUSolid.

Reimplemented in UPolyhedra, and UGenericPolycone.

Definition at line 417 of file UVCSGfaceted.cc.

418 {
419  return std::string("UCSGfaceted");
420 }
UVector3 UVCSGfaceted::GetPointOnSurfaceGeneric ( ) const
protected

Definition at line 553 of file UVCSGfaceted.cc.

References faces, numFace, UUtils::Random(), and UVCSGface::SurfaceArea().

Referenced by UGenericPolycone::GetPointOnSurface(), and UPolyhedra::GetPointOnSurface().

554 {
555  // Preparing variables
556  //
557  UVector3 answer = UVector3(0., 0., 0.);
558  UVCSGface** face = faces;
559  double area = 0;
560  int i;
561  std::vector<double> areas;
562 
563  // First step: calculate surface areas
564  //
565  do
566  {
567  double result = (*face)->SurfaceArea();
568  areas.push_back(result);
569  area = area + result;
570  }
571  while (++face < faces + numFace);
572 
573  // Second Step: choose randomly one surface
574  //
575  UVCSGface** face1 = faces;
576  double chose = area * UUtils::Random();
577  double Achose1, Achose2;
578  Achose1 = 0;
579  Achose2 = 0.;
580  i = 0;
581 
582  do
583  {
584  Achose2 += areas[i];
585  if (chose >= Achose1 && chose < Achose2)
586  {
587  UVector3 point;
588  point = (*face1)->GetPointOnFace();
589  return point;
590  }
591  i++;
592  Achose1 = Achose2;
593  }
594  while (++face1 < faces + numFace);
595 
596  return answer;
597 }
UVCSGface ** faces
virtual double SurfaceArea()=0
double Random(double min=0.0, double max=1.0)
Definition: UUtils.cc:69
int UVCSGfaceted::GetSection ( double  z) const
inlineprotected

Definition at line 104 of file UVCSGfaceted.hh.

References UVoxelizer::BinarySearch(), fMaxSection, and fZs.

Referenced by DistanceToIn(), DistanceToOut(), Inside(), and Normal().

105  {
106  int section = UVoxelizer::BinarySearch(fZs, z);
107  if (section < 0) section = 0;
108  else if (section > fMaxSection) section = fMaxSection;
109  return section;
110  }
G4double z
Definition: TRTMaterials.hh:39
std::vector< double > fZs
static int BinarySearch(const std::vector< T > &vec, T value)
Definition: UVoxelizer.hh:58
void UVCSGfaceted::InitVoxels ( UReduciblePolygon z,
double  radius 
)
protected

Definition at line 615 of file UVCSGfaceted.cc.

References UReduciblePolygon::CopyVertices(), fBox, fBoxShift, fCandidates, FindCandidates(), fMaxSection, fZs, UBox::GetZHalfLength(), left, UReduciblePolygon::NumVertices(), right, UBox::Set(), sort(), test::v, and z.

Referenced by UGenericPolycone::Create(), and UPolyhedra::Create().

616 {
617  int size = rz.NumVertices() + 1;
618  vector<double> r(size), z(size), zs;
619  rz.CopyVertices(&r[0], &z[0]);
620 
621  fZs.clear();
622  for (int i = 0; i < size; ++i)
623  {
624  double v = z[i];
625  if (std::find(fZs.begin(), fZs.end(), v) == fZs.end())
626  {
627  fZs.push_back(v);
628  }
629  std::sort(fZs.begin(), fZs.end());
630  }
631 
632  size = fZs.size();
633  fMaxSection = size - 2;
634 
635  for (int i = 0; i <= fMaxSection; ++i)
636  {
637  vector<int> candidates;
638 
639  double left = fZs[i], right = fZs[i + 1];
640  double middle = (left + right) / 2;
641  FindCandidates(middle, candidates);
642 
643  FindCandidates(left, candidates, true);
644  FindCandidates(right, candidates, true);
645 
646  fCandidates.push_back(candidates);
647  }
648 
649  fBox.Set(radius, radius, (fZs.back() - fZs.front()) / 2);
650  fBoxShift = fZs[0] + fBox.GetZHalfLength();
651 }
double fBoxShift
G4double z
Definition: TRTMaterials.hh:39
void FindCandidates(double z, std::vector< int > &candidates, bool sides=false)
subroutine sort(A, N)
Definition: dpm25nuc7.f:4670
std::vector< double > fZs
double GetZHalfLength() const
Definition: UBox.hh:121
std::vector< std::vector< int > > fCandidates
void Set(double dx, double dy, double dz)
Definition: UBox.cc:43
VUSolid::EnumInside UVCSGfaceted::Inside ( const UVector3 p) const
virtual

Implements VUSolid.

Reimplemented in UPolyhedra, and UGenericPolycone.

Definition at line 846 of file UVCSGfaceted.cc.

References VUSolid::eOutside, VUSolid::eSurface, faces, fCandidates, VUSolid::fgTolerance, fMaxSection, fNoVoxels, fZs, GetSection(), UVCSGface::Inside(), InsideNoVoxels(), numFace, UBits::SetBitNumber(), and UVector3::z.

Referenced by DistanceToOut(), DistanceToOutNoVoxels(), UGenericPolycone::Inside(), and UPolyhedra::Inside().

847 {
848  if (fNoVoxels) return InsideNoVoxels(p);
849 
850 // if (fEnclosingCylinder->MustBeOutside(p)) return eOutside;
851 
852  int index = GetSection(p.z);
853  double shift;
854 
855  UBits bits(numFace);
856  double best = UUtils::kInfinity;
857  VUSolid::EnumInside answer = eOutside;
858  int middle = index;
859 
860  do
861  {
862  const vector<int>& candidates = fCandidates[index];
863  int size = candidates.size();
864  for (int i = 0; i < size; ++i)
865  {
866  int candidate = candidates[i];
867  if (!bits[candidate])
868  {
869  UVCSGface& face = *faces[candidate];
870 
871  double distance;
872  VUSolid::EnumInside result = face.Inside(p, fgTolerance * 0.5, &distance);
873  if (result == eSurface) return eSurface;
874  if (distance < best)
875  {
876  best = distance;
877  answer = result;
878  }
879  bits.SetBitNumber(candidate);
880  }
881  }
882 
883  if (index <= middle)
884  {
885  if (--index >= 0)
886  {
887  shift = fZs[index + 1] - p.z;
888  if (shift < best) continue;
889  }
890  index = middle;
891  }
892  if (++index > fMaxSection) break;
893  shift = p.z - fZs[index];
894  }
895  while (shift > best);
896 
897  return answer;
898 }
static double fgTolerance
Definition: VUSolid.hh:30
std::vector< double > fZs
virtual VUSolid::EnumInside Inside(const UVector3 &p, double tolerance, double *bestDistance)=0
int GetSection(double z) const
EnumInside
Definition: VUSolid.hh:23
std::vector< std::vector< int > > fCandidates
UVCSGface ** faces
double z
Definition: UVector3.hh:138
VUSolid::EnumInside InsideNoVoxels(const UVector3 &p) const
Definition: UBits.hh:38
VUSolid::EnumInside UVCSGfaceted::InsideNoVoxels ( const UVector3 p) const
inline

Definition at line 179 of file UVCSGfaceted.cc.

References VUSolid::eOutside, VUSolid::eSurface, faces, VUSolid::fgTolerance, and numFace.

Referenced by Inside().

180 {
181  VUSolid::EnumInside answer = eOutside;
182  UVCSGface** face = faces;
183  double best = UUtils::kInfinity;
184  do
185  {
186  double distance;
187  VUSolid::EnumInside result = (*face)->Inside(p, fgTolerance * 0.5, &distance);
188  if (result == eSurface)
189  {
190  return eSurface;
191  }
192  if (distance < best)
193  {
194  best = distance;
195  answer = result;
196  }
197  }
198  while (++face < faces + numFace);
199 
200  return answer;
201 }
static double fgTolerance
Definition: VUSolid.hh:30
EnumInside
Definition: VUSolid.hh:23
UVCSGface ** faces
bool UVCSGfaceted::Normal ( const UVector3 p,
UVector3 n 
) const
virtual

Implements VUSolid.

Definition at line 209 of file UVCSGfaceted.cc.

References faces, fCandidates, VUSolid::fgTolerance, GetSection(), UVCSGface::Normal(), numFace, UBits::SetBitNumber(), and UVector3::z.

210 {
211  UVector3 answer;
212  double best = UUtils::kInfinity;
213  UVector3 normal;
214 
215  UBits bits(numFace);
216 
217  int index = GetSection(p.z);
218  const vector<int>& candidates = fCandidates[index];
219  int size = candidates.size();
220  for (int i = 0; i < size; ++i)
221  {
222  int candidate = candidates[i];
223  if (!bits[candidate])
224  {
225  bits.SetBitNumber(candidate);
226  UVCSGface& face = *faces[candidate];
227  double distance;
228  normal = face.Normal(p, &distance);
229  if (distance < best)
230  {
231  best = distance;
232  answer = normal;
233  if (distance < fgTolerance)
234  break;
235  }
236  }
237  }
238  n = answer;
239  return true;
240 }
static double fgTolerance
Definition: VUSolid.hh:30
int GetSection(double z) const
std::vector< std::vector< int > > fCandidates
virtual UVector3 Normal(const UVector3 &p, double *bestDistance)=0
UVCSGface ** faces
double z
Definition: UVector3.hh:138
Definition: UBits.hh:38
UVCSGfaceted & UVCSGfaceted::operator= ( const UVCSGfaceted source)

Definition at line 63 of file UVCSGfaceted.cc.

References CopyStuff().

Referenced by UGenericPolycone::operator=(), and UPolyhedra::operator=().

64 {
65  if (&source == this)
66  {
67  return *this;
68  }
69 
70  // Copy base class data
71  //
72  VUSolid::operator=(source);
73 
74  // Copy data
75  //
76  fStatistics = source.fStatistics;
77  fCubVolEpsilon = source.fCubVolEpsilon;
78  fAreaAccuracy = source.fAreaAccuracy;
79 
80  CopyStuff(source);
81 
82  return *this;
83 }
void CopyStuff(const UVCSGfaceted &source)
Definition: UVCSGfaceted.cc:91
double UVCSGfaceted::SafetyFromInside ( const UVector3 aPoint,
bool  aAccurate = false 
) const
virtual

Implements VUSolid.

Definition at line 921 of file UVCSGfaceted.cc.

References UVoxelizer::BinarySearch(), VUSolid::fgTolerance, fMaxSection, fNoVoxels, fZs, numFace, SafetyFromInsideNoVoxels(), SafetyFromInsideSection(), and UVector3::z.

922 {
923  if (fNoVoxels) return SafetyFromInsideNoVoxels(p);
924 
925  int index = UVoxelizer::BinarySearch(fZs, p.z);
926  if (index < 0 || index > fMaxSection) return 0;
927 
928  UBits bits(numFace);
929  double minSafety = SafetyFromInsideSection(index, p, bits);
930 
931  if (minSafety > UUtils::kInfinity) return 0;
932  if (minSafety < 1e-6) return 0;
933 
934  double zbase = fZs[index + 1];
935  for (int i = index + 1; i <= fMaxSection; ++i)
936  {
937  double dz = fZs[i] - zbase;
938  if (dz >= minSafety) break;
939  double safety = SafetyFromInsideSection(i, p, bits);
940  if (safety < minSafety) minSafety = safety;
941  }
942 
943  if (index > 0)
944  {
945  zbase = fZs[index - 1];
946  for (int i = index - 1; i >= 0; --i)
947  {
948  double dz = zbase - fZs[i];
949  if (dz >= minSafety) break;
950  double safety = SafetyFromInsideSection(i, p, bits);
951  if (safety < minSafety) minSafety = safety;
952  }
953  }
954  return (minSafety < 0.5 * fgTolerance) ? 0 : minSafety;
955 }
static double fgTolerance
Definition: VUSolid.hh:30
const char * p
Definition: xmltok.h:285
virtual double SafetyFromInsideNoVoxels(const UVector3 &aPoint, bool aAccurate=false) const
std::vector< double > fZs
static int BinarySearch(const std::vector< T > &vec, T value)
Definition: UVoxelizer.hh:58
double SafetyFromInsideSection(int index, const UVector3 &p, UBits &bits) const
Definition: UBits.hh:38
double UVCSGfaceted::SafetyFromInsideNoVoxels ( const UVector3 aPoint,
bool  aAccurate = false 
) const
virtual

Definition at line 609 of file UVCSGfaceted.cc.

References DistanceTo().

Referenced by SafetyFromInside().

610 {
611  return DistanceTo(p, true);
612 }
double DistanceTo(const UVector3 &p, const bool outgoing) const
const char * p
Definition: xmltok.h:285
double UVCSGfaceted::SafetyFromInsideSection ( int  index,
const UVector3 p,
UBits bits 
) const
protected

Definition at line 900 of file UVCSGfaceted.cc.

References faces, fCandidates, UVCSGface::Safety(), and UBits::SetBitNumber().

Referenced by SafetyFromInside().

901 {
902  double best = UUtils::kInfinity;
903 
904  const vector<int>& candidates = fCandidates[index];
905  int size = candidates.size();
906  for (int i = 0; i < size; ++i)
907  {
908  int candidate = candidates[i];
909  if (!bits[candidate])
910  {
911  bits.SetBitNumber(candidate);
912  UVCSGface& face = *faces[candidate];
913 
914  double distance = face.Safety(p, true);
915  if (distance < best) best = distance;
916  }
917  }
918  return best;
919 }
virtual double Safety(const UVector3 &p, bool outgoing)=0
void SetBitNumber(unsigned int bitnumber, bool value=true)
Definition: UBits.hh:172
std::vector< std::vector< int > > fCandidates
UVCSGface ** faces
double UVCSGfaceted::SafetyFromOutside ( const UVector3 aPoint,
bool  aAccurate = false 
) const
virtual

Implements VUSolid.

Reimplemented in UPolyhedra.

Definition at line 599 of file UVCSGfaceted.cc.

References DistanceTo(), fBox, fBoxShift, UBox::SafetyFromOutside(), UVector3::x, UVector3::y, and UVector3::z.

Referenced by UPolyhedra::SafetyFromOutside().

600 {
601  if (!accurate)
602  {
603  UVector3 pb(p.x, p.y, p.z - fBoxShift);
604  return fBox.SafetyFromOutside(pb);
605  }
606  return DistanceTo(p, false);
607 }
double DistanceTo(const UVector3 &p, const bool outgoing) const
double fBoxShift
const char * p
Definition: xmltok.h:285
double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const
Definition: UBox.cc:295
void UVCSGfaceted::SetAreaAccuracy ( double  ep)

Definition at line 509 of file UVCSGfaceted.cc.

References fSurfaceArea.

510 {
511  fSurfaceArea = 0.;
512  fAreaAccuracy = ep;
513 }
double fSurfaceArea
void UVCSGfaceted::SetAreaStatistics ( int  st)

Definition at line 499 of file UVCSGfaceted.cc.

References fSurfaceArea.

500 {
501  fSurfaceArea = 0.;
502  fStatistics = st;
503 }
double fSurfaceArea
void UVCSGfaceted::SetCubVolEpsilon ( double  ep)

Definition at line 471 of file UVCSGfaceted.cc.

References fCubicVolume.

472 {
473  fCubicVolume = 0.;
474  fCubVolEpsilon = ep;
475 }
double fCubicVolume
void UVCSGfaceted::SetCubVolStatistics ( int  st)

Definition at line 461 of file UVCSGfaceted.cc.

References fCubicVolume.

462 {
463  fCubicVolume = 0.;
464  fStatistics = st;
465 }
double fCubicVolume
std::ostream & UVCSGfaceted::StreamInfo ( std::ostream &  os) const
virtual

Implements VUSolid.

Reimplemented in UPolyhedra, and UGenericPolycone.

Definition at line 426 of file UVCSGfaceted.cc.

References VUSolid::GetName(), and numFace.

427 {
428  os << "-----------------------------------------------------------\n"
429  << " *** Dump for solid - " << GetName() << " ***\n"
430  << " ===================================================\n"
431  << " Solid type: UVCSGfaceted\n"
432  << " Parameters: \n"
433  << " number of faces: " << numFace << "\n"
434  << "-----------------------------------------------------------\n";
435 
436  return os;
437 }
const std::string & GetName() const
Definition: VUSolid.hh:103
double UVCSGfaceted::SurfaceArea ( )
virtual

Implements VUSolid.

Definition at line 536 of file UVCSGfaceted.cc.

References VUSolid::EstimateSurfaceArea(), and fSurfaceArea.

537 {
538  if (fSurfaceArea != 0.)
539  {
540  ;
541  }
542  else
543  {
544  fSurfaceArea = EstimateSurfaceArea(fStatistics, fAreaAccuracy);
545  }
546  return fSurfaceArea;
547 }
double fSurfaceArea
double EstimateSurfaceArea(int nStat, double ell) const
Definition: VUSolid.cc:268

Field Documentation

UVCSGface** UVCSGfaceted::faces
protected
UBox UVCSGfaceted::fBox
mutableprotected

Definition at line 121 of file UVCSGfaceted.hh.

Referenced by CopyStuff(), DistanceToIn(), InitVoxels(), and SafetyFromOutside().

double UVCSGfaceted::fBoxShift
protected

Definition at line 122 of file UVCSGfaceted.hh.

Referenced by CopyStuff(), DistanceToIn(), InitVoxels(), and SafetyFromOutside().

std::vector<std::vector<int> > UVCSGfaceted::fCandidates
protected
double UVCSGfaceted::fCubicVolume
protected

Definition at line 114 of file UVCSGfaceted.hh.

Referenced by Capacity(), CopyStuff(), SetCubVolEpsilon(), and SetCubVolStatistics().

int UVCSGfaceted::fMaxSection
protected
bool UVCSGfaceted::fNoVoxels
protected
double UVCSGfaceted::fSurfaceArea
protected

Definition at line 115 of file UVCSGfaceted.hh.

Referenced by CopyStuff(), SetAreaAccuracy(), SetAreaStatistics(), and SurfaceArea().

std::vector<double> UVCSGfaceted::fZs
protected
int UVCSGfaceted::numFace
protected

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