33 fTransformObjs.clear();
46 fSolids.push_back(&solid);
47 fTransformObjs.push_back(trans);
59 :
VUSolid(rhs),fCubicVolume (rhs.fCubicVolume),
60 fSurfaceArea (rhs.fSurfaceArea)
78 VUSolid::operator=(rhs);
96 UVector3 extentMin, extentMax, d, p, point;
97 int inside = 0, generated;
98 Extent(extentMin, extentMax);
99 d = (extentMax - extentMin) / 2.;
100 p = (extentMax + extentMin) / 2.;
103 for (generated = 0; generated < 10000; generated++)
105 UVector3 random(rand(), rand(), rand());
109 double vbox = (2 * d.x()) * (2 * d.y()) * (2 * d.z());
119 cout <<
"ComputeBBox - Not implemented" << endl;
127 UVector3 localPoint, localDirection;
131 for (
int i = 0 ; i < numNodes ; ++i)
139 double distance = solid.
DistanceToIn(localPoint, localDirection, aPstep);
140 if (minDistance > distance) minDistance = distance;
148 int candidatesCount = candidates.size();
149 UVector3 localPoint, localDirection;
152 for (
int i = 0 ; i < candidatesCount; ++i)
154 int candidate = candidates[i];
160 double distance = solid.
DistanceToIn(localPoint, localDirection, aPstep);
161 if (minDistance > distance) minDistance = distance;
163 if (minDistance == 0)
break;
179 const UVector3& aDirection,
double aPstep)
const
193 if (shift) currentPoint += direction * shift;
198 vector<int> candidates, curVoxel(3);
208 if (minDistance > distance) minDistance = distance;
209 if (distance < shift)
break;
214 while (minDistance > shift);
220 minDistance = distanceToInNoVoxels;
242 UVector3 localPoint, localDirection;
243 int ignoredSolid = -1;
244 double resultDistToOut = 0;
248 for (
int i = 0; i < numNodes; ++i)
250 if (i != ignoredSolid)
254 localPoint = transform.
LocalPoint(currentPoint);
259 double distance = solid.
DistanceToOut(localPoint, localDirection, aNormal, convex);
265 currentPoint = transform.
GlobalPoint(localPoint + distance * localDirection);
266 resultDistToOut += distance;
274 return resultDistToOut;
289 double distanceToOutVoxels =
DistanceToOutVoxels(aPoint, aDirection, aNormal, convex, aPstep);
299 return distanceToOutVoxels;
322 vector<int> candidates;
324 int numNodes = 2*
fSolids.size();
330 UVector3 localPoint, localDirection, localNormal;
341 int maxCandidate = 0;
344 int limit = candidates.size();
345 for (
int i = 0 ; i < limit ; ++i)
347 int candidate = candidates[i];
354 localPoint = transform.
LocalPoint(currentPoint);
366 double shift = solid.
DistanceToOut(localPoint, localDirection, localNormal, convex);
374 if (maxDistance < shift)
377 maxCandidate = candidate;
378 maxNormal = localNormal;
392 distance += maxDistance;
394 currentPoint += maxDistance * direction;
395 if(maxDistance == 0.)count++;
397 exclusion.SetBitNumber(maxCandidate);
414 exclusion.ResetBitNumber(maxCandidate);
417 while ((notOutside) && (count < numNodes));
450 vector<int> candidates;
451 vector<USurface> surfaces;
462 for (
int i = 0 ; i < limit ; ++i)
464 int candidate = candidates[i];
470 location = solid.
Inside(localPoint);
475 surface.
point = localPoint;
476 surface.
solid = &solid;
477 surfaces.push_back(surface);
486 int size = surfaces.size();
487 for (
int i = 0; i < size - 1; ++i)
490 for (
int j = i + 1; j < size; ++j)
593 if (location != insideNoVoxels)
594 location = insideNoVoxels;
604 int countSurface = 0;
607 for (
int i = 0 ; i < numNodes ; ++i)
615 location = solid.
Inside(localPoint);
622 if (countSurface != 0)
return eSurface;
633 for (
int i = 0 ; i < numNodes ; ++i)
705 vector<int> candidates;
709 double normalTolerance = 1E-5;
718 int limit = candidates.size();
719 for (
int i = 0 ; i < limit ; ++i)
721 int candidate = candidates[i];
731 solid.
Normal(localPoint, localNormal);
733 aNormal = normal.
Unit();
752 solid.
Normal(localPoint, localNormal);
754 aNormal = normal.
Unit();
755 if (safety > normalTolerance)
return false;
770 solid.
Normal(localPoint, localNormal);
775 aNormal = normal.
Unit();
776 if (safety > normalTolerance)
return false;
789 vector<int> candidates;
797 int limit = candidates.size();
798 for (
int i = 0; i < limit; ++i)
800 int candidate = candidates[i];
808 if (safetyMin > safety) safetyMin = safety;
830 for (
int j = 0; j < numNodes; j++)
836 const UVector3& hlen = boxes[j].hlen;
837 for (
int i = 0; i <= 2; ++i)
839 if ((dxyz[i] = std::abs(point[i] - pos[i]) - hlen[i]) > safetyMin)
843 for (
int i = 0; i <= 2; ++i)
844 if (dxyz[i] > 0) d2xyz += dxyz[i] * dxyz[i];
847 if (d2xyz >= safetyMin * safetyMin)
854 if (safetyMin > safety)
865 if (safety <= 0)
return safety;
866 if (safetyMin > safety) safetyMin = safety;
904 for (
int i = 0; i < numNodes; ++i)
907 double dxyz0 = std::abs(aPoint.
x() - boxes[i].pos.x()) - boxes[i].hlen.x();
908 if (dxyz0 > safetyMin)
continue;
909 double dxyz1 = std::abs(aPoint.
y() - boxes[i].pos.y()) - boxes[i].hlen.y();
910 if (dxyz1 > safetyMin)
continue;
911 double dxyz2 = std::abs(aPoint.
z() - boxes[i].pos.z()) - boxes[i].hlen.z();
912 if (dxyz2 > safetyMin)
continue;
914 if (dxyz0 > 0) d2xyz += dxyz0 * dxyz0;
915 if (dxyz1 > 0) d2xyz += dxyz1 * dxyz1;
916 if (dxyz2 > 0) d2xyz += dxyz2 * dxyz2;
917 if (d2xyz >= safetyMin * safetyMin)
continue;
923 if (safetyMin > safety)
936 int oldprc = os.precision(16);
937 os <<
"-----------------------------------------------------------\n"
938 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
939 <<
" ===================================================\n"
940 <<
" Solid type: UMultiUnion\n"
941 <<
" Parameters: \n";
943 for (
int i = 0 ; i < numNodes ; ++i)
948 os<<
" Translation is " <<transform.
fTr<<
" \n";
949 os<<
" Rotation is :"<<
" \n";
950 for(
int j = 0; j < 3; j++ )
951 os<<
" "<<transform.
fRot[j*3]<<
" "<<transform.
fRot[1+j*3]<<
" "<<transform.
fRot[2+j*3]<<
"\n";
955 <<
"-----------------------------------------------------------\n";
956 os.precision(oldprc);
virtual UVector3 GetPointOnSurface() const =0
double DistanceToOutVoxels(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const
static double frTolerance
double DistanceToNext(const UVector3 &point, const UVector3 &direction, std::vector< int > &curVoxel) const
const std::string & GetName() const
std::ostream & StreamInfo(std::ostream &os) const
void Voxelize(std::vector< VUSolid * > &solids, std::vector< UTransform3D > &transforms)
double SafetyFromInside(const UVector3 &aPoint, bool aAccurate=false) const
UMultiUnion & operator=(const UMultiUnion &rhs)
virtual bool Normal(const UVector3 &aPoint, UVector3 &aNormal) const =0
bool Normal(const UVector3 &aPoint, UVector3 &aNormal) const
virtual EnumInside Inside(const UVector3 &aPoint) const =0
double DistanceToIn(const UVector3 &aPoint, const UVector3 &aDirection, double aPstep) const
double EstimateSurfaceArea(int nStat, double ell) const
EnumInside Inside(const UVector3 &aPoint) const
void GetVoxel(std::vector< int > &curVoxel, const UVector3 &point) const
static double Tolerance()
int SafetyFromOutsideNumberNode(const UVector3 &aPoint, bool aAccurate, double &safety) const
double DistanceToInNoVoxels(const UVector3 &aPoint, const UVector3 &aDirection, double aPstep=UUtils::kInfinity) const
EnumInside InsideWithExclusion(const UVector3 &aPoint, UBits *bits=NULL) const
static double normal(HepRandomEngine *eptr)
double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const
virtual std::ostream & StreamInfo(std::ostream &os) const =0
double DistanceToFirst(const UVector3 &point, const UVector3 &direction) const
const UTransform3D & GetTransformation(int index) const
static const double kInfinity
virtual double DistanceToIn(const UVector3 &aPoint, const UVector3 &aDirection, double aPstep=UUtils::kInfinity) const =0
std::vector< UTransform3D > fTransformObjs
int GetCandidatesVoxelArray(const UVector3 &point, std::vector< int > &list, UBits *crossed=NULL) const
void SetBitNumber(unsigned int bitnumber, bool value=true)
EnumInside InsideNoVoxels(const UVector3 &aPoint) const
void ComputeBBox(UBBox *aBox, bool aStore=false)
virtual double SafetyFromInside(const UVector3 &aPoint, bool aAccurate=false) const =0
T max(const T t1, const T t2)
brief Return the largest of the two arguments
UVector3 GetPointOnSurface() const
virtual double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const =0
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
int GetBitsPerSlice() const
double DistanceToOut(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const
virtual double DistanceToOut(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const =0
virtual void Extent(UVector3 &aMin, UVector3 &aMax) const =0
void AddNode(VUSolid &solid, UTransform3D &trans)
const std::vector< UVoxelBox > & GetBoxes() const
double SafetyToBoundingBox(const UVector3 &point) const
std::vector< VUSolid * > fSolids
double Random(double min=0.0, double max=1.0)
double DistanceToOutNoVoxels(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const
static const G4double pos
void TransformLimits(UVector3 &min, UVector3 &max, const UTransform3D &transformation)
void Extent(EAxisType aAxis, double &aMin, double &aMax) const
double DistanceToInCandidates(const UVector3 &aPoint, const UVector3 &aDirection, double aPstep, std::vector< int > &candidates, UBits &bits) const
UVector3 & MultiplyByComponents(const UVector3 &p)