33 numFace(0), faces(0), fCubicVolume(0.), fSurfaceArea(0.),
34 fMaxSection(0),fBoxShift(0.), fNoVoxels(true),fStatistics(1000000), fCubVolEpsilon(0.001), fAreaAccuracy(-1.)
72 VUSolid::operator=(source);
102 **sourceFace = source.
faces;
105 *face = (*sourceFace)->
Clone();
218 const vector<int>& candidates =
fCandidates[index];
219 int size = candidates.size();
220 for (
int i = 0; i < size; ++i)
222 int candidate = candidates[i];
223 if (!bits[candidate])
228 normal = face.
Normal(p, &distance);
284 double faceDistance, faceDistFromSurface;
286 if ((*face)->Distance(p, v,
false, htol,
287 faceDistance, faceDistFromSurface,
288 faceNormal, faceAllBehind))
293 if (faceDistance < distance)
295 distance = faceDistance;
296 distFromSurface = faceDistFromSurface;
298 if (distFromSurface <= 0)
309 if (bestFace->
Safety(p,
false) < htol)
327 bool allBehind =
true;
336 double faceDistance, faceDistFromSurface;
339 faceDistance, faceDistFromSurface,
340 faceNormal, faceAllBehind))
347 if (faceDistance < distance)
349 distance = faceDistance;
350 distFromSurface = faceDistFromSurface;
353 if (distFromSurface <= 0)
364 if (distFromSurface <= 0)
400 const bool outgoing)
const
406 double distance = (*face)->Safety(p, outgoing);
407 if (distance < best) best = distance;
419 return std::string(
"UCSGfaceted");
428 os <<
"-----------------------------------------------------------\n"
429 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
430 <<
" ===================================================\n"
431 <<
" Solid type: UVCSGfaceted\n"
433 <<
" number of faces: " <<
numFace <<
"\n"
434 <<
"-----------------------------------------------------------\n";
561 std::vector<double> areas;
568 areas.push_back(result);
569 area = area + result;
577 double Achose1, Achose2;
585 if (chose >= Achose1 && chose < Achose2)
588 point = (*face1)->GetPointOnFace();
618 vector<double> r(size),
z(size), zs;
622 for (
int i = 0; i < size; ++i)
625 if (std::find(
fZs.begin(),
fZs.end(), v) ==
fZs.end())
629 std::sort(
fZs.begin(),
fZs.end());
637 vector<int> candidates;
640 double middle = (left +
right) / 2;
655 for (
int j = 0; j <
numFace; j++)
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);
676 double idistance, shift;
689 double z = p.
z + idistance * v.
z;
691 int increment = (v.
z > 0) ? 1 : -1;
702 const vector<int>& candidates =
fCandidates[index];
703 int size = candidates.size();
704 for (
int i = 0; i < size; ++i)
706 int candidate = candidates[i];
707 if (!bits[candidate])
716 faceDistance, faceDistFromSurface,
717 faceNormal, faceAllBehind))
720 if (faceDistance < distance)
722 distance = faceDistance;
723 distFromSurface = faceDistFromSurface;
725 if (distFromSurface <= 0)
return 0;
737 int newz = increment > 0 ? index : index + 1;
738 shift = (
fZs[newz] -
z) / v.
z;
740 while (idistance + shift < distance);
760 int increment = (v.
z > 0) ? 1 : -1;
762 bool allBehind =
true;
773 const vector<int>& candidates =
fCandidates[index];
774 int size = candidates.size();
775 for (
int i = 0; i < size; ++i)
777 int candidate = candidates[i];
778 if (!bits[candidate])
783 double faceDistance, faceDistFromSurface;
786 faceNormal, faceAllBehind)))
793 if (faceDistance < distance)
795 distance = faceDistance;
796 distFromSurface = faceDistFromSurface;
799 if (distFromSurface <= 0)
break;
805 if (distFromSurface <= 0)
break;
806 if (!increment)
break;
811 int newz = increment > 0 ? index : index + 1;
812 shift = (
fZs[newz] - p.
z) / v.
z;
814 while (shift < distance);
818 if (distFromSurface <= 0)
862 const vector<int>& candidates =
fCandidates[index];
863 int size = candidates.size();
864 for (
int i = 0; i < size; ++i)
866 int candidate = candidates[i];
867 if (!bits[candidate])
887 shift =
fZs[index + 1] - p.
z;
888 if (shift < best)
continue;
893 shift = p.
z -
fZs[index];
895 while (shift > best);
904 const vector<int>& candidates =
fCandidates[index];
905 int size = candidates.size();
906 for (
int i = 0; i < size; ++i)
908 int candidate = candidates[i];
909 if (!bits[candidate])
914 double distance = face.
Safety(p,
true);
915 if (distance < best) best = distance;
932 if (minSafety < 1e-6)
return 0;
934 double zbase =
fZs[index + 1];
937 double dz =
fZs[i] - zbase;
938 if (dz >= minSafety)
break;
940 if (safety < minSafety) minSafety = safety;
945 zbase =
fZs[index - 1];
946 for (
int i = index - 1; i >= 0; --i)
948 double dz = zbase -
fZs[i];
949 if (dz >= minSafety)
break;
951 if (safety < minSafety) minSafety = safety;
954 return (minSafety < 0.5 *
fgTolerance) ? 0 : minSafety;
void SetCubVolStatistics(int st)
double DistanceTo(const UVector3 &p, const bool outgoing) const
virtual bool Distance(const UVector3 &p, const UVector3 &v, bool outgoing, double surfTolerance, double &distance, double &distFromSurface, UVector3 &normal, bool &allBehind)=0
const std::string & GetName() const
static double fgTolerance
virtual bool Normal(const UVector3 &p, UVector3 &n) const
void FindCandidates(double z, std::vector< int > &candidates, bool sides=false)
double EstimateCubicVolume(int nStat, double epsilon) const
double DistanceToOutNoVoxels(const UVector3 &p, const UVector3 &v, UVector3 &n, bool &aConvex) const
void SetAreaStatistics(int st)
void CopyVertices(double a[], double b[]) const
double EstimateSurfaceArea(int nStat, double ell) const
virtual UVCSGface * Clone()=0
int GetCubVolStatistics() const
static double normal(HepRandomEngine *eptr)
virtual double SafetyFromInsideNoVoxels(const UVector3 &aPoint, bool aAccurate=false) const
void SetCubVolEpsilon(double ep)
std::vector< double > fZs
virtual VUSolid::EnumInside Inside(const UVector3 &p, double tolerance, double *bestDistance)=0
static int BinarySearch(const std::vector< T > &vec, T value)
static const double kInfinity
void InitVoxels(UReduciblePolygon &z, double radius)
void SetAreaAccuracy(double ep)
UVCSGfaceted & operator=(const UVCSGfaceted &source)
int GetSection(double z) const
virtual double Capacity()
virtual double Safety(const UVector3 &p, bool outgoing)=0
void SetBitNumber(unsigned int bitnumber, bool value=true)
double DistanceToIn(const UVector3 &aPoint, const UVector3 &aDirection, double aPstep=UUtils::kInfinity) const
double GetZHalfLength() const
virtual double SurfaceArea()
double SafetyFromInsideSection(int index, const UVector3 &p, UBits &bits) const
virtual double Extent(const UVector3 axis)=0
double DistanceToInNoVoxels(const UVector3 &p, const UVector3 &v) const
std::vector< std::vector< int > > fCandidates
void Set(double dx, double dy, double dz)
virtual UVector3 Normal(const UVector3 &p, double *bestDistance)=0
std::string UGeometryType
double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const
UVCSGfaceted(const std::string &name)
virtual double SurfaceArea()=0
void CopyStuff(const UVCSGfaceted &source)
UVector3 GetPointOnSurfaceGeneric() const
virtual double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const
virtual double DistanceToIn(const UVector3 &p, const UVector3 &v, double aPstep=UUtils::kInfinity) const
double GetCubVolEpsilon() const
VUSolid::EnumInside InsideNoVoxels(const UVector3 &p) const
virtual double DistanceToOut(const UVector3 &p, const UVector3 &v, UVector3 &n, bool &aConvex, double aPstep=UUtils::kInfinity) const
double Random(double min=0.0, double max=1.0)
virtual VUSolid::EnumInside Inside(const UVector3 &p) const
int GetAreaStatistics() const
virtual UGeometryType GetEntityType() const
double GetAreaAccuracy() const
virtual double SafetyFromInside(const UVector3 &aPoint, bool aAccurate=false) const
virtual std::ostream & StreamInfo(std::ostream &os) const