Import Geant4 5.0.0 source tree
This commit is contained in:
@@ -26,8 +26,8 @@
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4VCSGfaceted.cc,v 1.7 2001/07/11 10:00:17 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-04-01 $
|
||||
// $Id: G4VCSGfaceted.cc,v 1.9 2002/10/30 13:52:24 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-05-00 $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
@@ -54,21 +54,32 @@
|
||||
#include "G4NURBSbox.hh"
|
||||
#include "G4VisExtent.hh"
|
||||
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
G4VCSGfaceted::G4VCSGfaceted( G4String name )
|
||||
: G4VSolid(name),
|
||||
numFace(0), faces(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Destructor
|
||||
//
|
||||
G4VCSGfaceted::~G4VCSGfaceted()
|
||||
{
|
||||
DeleteStuff();
|
||||
DeleteStuff();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Copy constructor
|
||||
//
|
||||
G4VCSGfaceted::G4VCSGfaceted( const G4VCSGfaceted &source ) : G4VSolid( source )
|
||||
G4VCSGfaceted::G4VCSGfaceted( const G4VCSGfaceted &source )
|
||||
: G4VSolid( source )
|
||||
{
|
||||
CopyStuff( source );
|
||||
CopyStuff( source );
|
||||
}
|
||||
|
||||
|
||||
@@ -77,12 +88,12 @@ G4VCSGfaceted::G4VCSGfaceted( const G4VCSGfaceted &source ) : G4VSolid( source )
|
||||
//
|
||||
const G4VCSGfaceted &G4VCSGfaceted::operator=( const G4VCSGfaceted &source )
|
||||
{
|
||||
if (&source == this) return *this;
|
||||
|
||||
DeleteStuff();
|
||||
CopyStuff( source );
|
||||
|
||||
return *this;
|
||||
if (&source == this) return *this;
|
||||
|
||||
DeleteStuff();
|
||||
CopyStuff( source );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,16 +104,16 @@ const G4VCSGfaceted &G4VCSGfaceted::operator=( const G4VCSGfaceted &source )
|
||||
//
|
||||
void G4VCSGfaceted::CopyStuff( const G4VCSGfaceted &source )
|
||||
{
|
||||
numFace = source.numFace;
|
||||
if (numFace == 0) return; // odd, but permissable?
|
||||
|
||||
faces = new G4VCSGface*[numFace];
|
||||
|
||||
G4VCSGface **face = faces,
|
||||
**sourceFace = source.faces;
|
||||
do {
|
||||
*face = (*sourceFace)->Clone();
|
||||
} while( ++sourceFace, ++face < faces+numFace );
|
||||
numFace = source.numFace;
|
||||
if (numFace == 0) return; // odd, but permissable?
|
||||
|
||||
faces = new G4VCSGface*[numFace];
|
||||
|
||||
G4VCSGface **face = faces,
|
||||
**sourceFace = source.faces;
|
||||
do {
|
||||
*face = (*sourceFace)->Clone();
|
||||
} while( ++sourceFace, ++face < faces+numFace );
|
||||
}
|
||||
|
||||
|
||||
@@ -113,14 +124,15 @@ void G4VCSGfaceted::CopyStuff( const G4VCSGfaceted &source )
|
||||
//
|
||||
void G4VCSGfaceted::DeleteStuff()
|
||||
{
|
||||
if (numFace) {
|
||||
G4VCSGface **face = faces;
|
||||
do {
|
||||
delete *face;
|
||||
} while( ++face < faces + numFace );
|
||||
if (numFace)
|
||||
{
|
||||
G4VCSGface **face = faces;
|
||||
do {
|
||||
delete *face;
|
||||
} while( ++face < faces + numFace );
|
||||
|
||||
delete [] faces;
|
||||
}
|
||||
delete [] faces;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,24 +140,25 @@ void G4VCSGfaceted::DeleteStuff()
|
||||
// CalculateExtent
|
||||
//
|
||||
G4bool G4VCSGfaceted::CalculateExtent( const EAxis axis,
|
||||
const G4VoxelLimits &voxelLimit,
|
||||
const G4AffineTransform &transform,
|
||||
G4double &min, G4double &max ) const
|
||||
const G4VoxelLimits &voxelLimit,
|
||||
const G4AffineTransform &transform,
|
||||
G4double &min,
|
||||
G4double &max ) const
|
||||
{
|
||||
G4SolidExtentList extentList( axis, voxelLimit );
|
||||
G4SolidExtentList extentList( axis, voxelLimit );
|
||||
|
||||
//
|
||||
// Loop over all faces, checking min/max extent as we go.
|
||||
//
|
||||
G4VCSGface **face = faces;
|
||||
do {
|
||||
(*face)->CalculateExtent( axis, voxelLimit, transform, extentList );
|
||||
} while( ++face < faces + numFace );
|
||||
|
||||
//
|
||||
// Return min/max value
|
||||
//
|
||||
return extentList.GetExtent( min, max );
|
||||
//
|
||||
// Loop over all faces, checking min/max extent as we go.
|
||||
//
|
||||
G4VCSGface **face = faces;
|
||||
do {
|
||||
(*face)->CalculateExtent( axis, voxelLimit, transform, extentList );
|
||||
} while( ++face < faces + numFace );
|
||||
|
||||
//
|
||||
// Return min/max value
|
||||
//
|
||||
return extentList.GetExtent( min, max );
|
||||
}
|
||||
|
||||
|
||||
@@ -159,78 +172,84 @@ G4bool G4VCSGfaceted::CalculateExtent( const EAxis axis,
|
||||
//
|
||||
EInside G4VCSGfaceted::Inside( const G4ThreeVector &p ) const
|
||||
{
|
||||
EInside answer=kOutside;
|
||||
G4VCSGface **face = faces;
|
||||
G4double best = kInfinity;
|
||||
do {
|
||||
G4double distance;
|
||||
EInside result = (*face)->Inside( p, kCarTolerance/2, &distance );
|
||||
if (result == kSurface) return kSurface;
|
||||
if (distance < best) {
|
||||
best = distance;
|
||||
answer = result;
|
||||
}
|
||||
} while( ++face < faces + numFace );
|
||||
EInside answer=kOutside;
|
||||
G4VCSGface **face = faces;
|
||||
G4double best = kInfinity;
|
||||
do {
|
||||
G4double distance;
|
||||
EInside result = (*face)->Inside( p, kCarTolerance/2, &distance );
|
||||
if (result == kSurface) return kSurface;
|
||||
if (distance < best)
|
||||
{
|
||||
best = distance;
|
||||
answer = result;
|
||||
}
|
||||
} while( ++face < faces + numFace );
|
||||
|
||||
return answer;
|
||||
return answer;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// SurfaceNormal
|
||||
//
|
||||
G4ThreeVector G4VCSGfaceted::SurfaceNormal( const G4ThreeVector& p) const
|
||||
G4ThreeVector G4VCSGfaceted::SurfaceNormal( const G4ThreeVector& p ) const
|
||||
{
|
||||
G4ThreeVector answer;
|
||||
G4VCSGface **face = faces;
|
||||
G4double best = kInfinity;
|
||||
do {
|
||||
G4double distance;
|
||||
G4ThreeVector normal = (*face)->Normal( p, &distance );
|
||||
if (distance < best) {
|
||||
best = distance;
|
||||
answer = normal;
|
||||
}
|
||||
} while( ++face < faces + numFace );
|
||||
G4ThreeVector answer;
|
||||
G4VCSGface **face = faces;
|
||||
G4double best = kInfinity;
|
||||
do {
|
||||
G4double distance;
|
||||
G4ThreeVector normal = (*face)->Normal( p, &distance );
|
||||
if (distance < best)
|
||||
{
|
||||
best = distance;
|
||||
answer = normal;
|
||||
}
|
||||
} while( ++face < faces + numFace );
|
||||
|
||||
return answer;
|
||||
return answer;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// DistanceToIn(p,v)
|
||||
//
|
||||
G4double G4VCSGfaceted::DistanceToIn( const G4ThreeVector &p, const G4ThreeVector &v ) const
|
||||
G4double G4VCSGfaceted::DistanceToIn( const G4ThreeVector &p,
|
||||
const G4ThreeVector &v ) const
|
||||
{
|
||||
G4double distance = kInfinity;
|
||||
G4double distFromSurface = kInfinity;
|
||||
G4VCSGface *bestFace=0;
|
||||
G4VCSGface **face = faces;
|
||||
do {
|
||||
G4double faceDistance,
|
||||
faceDistFromSurface;
|
||||
G4ThreeVector faceNormal;
|
||||
G4bool faceAllBehind;
|
||||
if ((*face)->Intersect( p, v, false, kCarTolerance/2,
|
||||
faceDistance, faceDistFromSurface,
|
||||
faceNormal, faceAllBehind ) ) {
|
||||
//
|
||||
// Intersecting face
|
||||
//
|
||||
if (faceDistance < distance) {
|
||||
distance = faceDistance;
|
||||
distFromSurface = faceDistFromSurface;
|
||||
bestFace = *face;
|
||||
if (distFromSurface <= 0) return 0;
|
||||
}
|
||||
}
|
||||
} while( ++face < faces + numFace );
|
||||
|
||||
if (distance < kInfinity && distFromSurface<kCarTolerance/2) {
|
||||
if (bestFace->Distance(p,false) < kCarTolerance/2) distance = 0;
|
||||
}
|
||||
G4double distance = kInfinity;
|
||||
G4double distFromSurface = kInfinity;
|
||||
G4VCSGface *bestFace=0;
|
||||
G4VCSGface **face = faces;
|
||||
do {
|
||||
G4double faceDistance,
|
||||
faceDistFromSurface;
|
||||
G4ThreeVector faceNormal;
|
||||
G4bool faceAllBehind;
|
||||
if ((*face)->Intersect( p, v, false, kCarTolerance/2,
|
||||
faceDistance, faceDistFromSurface,
|
||||
faceNormal, faceAllBehind ) )
|
||||
{
|
||||
//
|
||||
// Intersecting face
|
||||
//
|
||||
if (faceDistance < distance)
|
||||
{
|
||||
distance = faceDistance;
|
||||
distFromSurface = faceDistFromSurface;
|
||||
bestFace = *face;
|
||||
if (distFromSurface <= 0) return 0;
|
||||
}
|
||||
}
|
||||
} while( ++face < faces + numFace );
|
||||
|
||||
if (distance < kInfinity && distFromSurface<kCarTolerance/2)
|
||||
{
|
||||
if (bestFace->Distance(p,false) < kCarTolerance/2) distance = 0;
|
||||
}
|
||||
|
||||
return distance;
|
||||
return distance;
|
||||
}
|
||||
|
||||
|
||||
@@ -239,63 +258,71 @@ G4double G4VCSGfaceted::DistanceToIn( const G4ThreeVector &p, const G4ThreeVecto
|
||||
//
|
||||
G4double G4VCSGfaceted::DistanceToIn( const G4ThreeVector &p ) const
|
||||
{
|
||||
return DistanceTo( p, false );
|
||||
return DistanceTo( p, false );
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// DistanceToOut(p,v)
|
||||
//
|
||||
G4double G4VCSGfaceted::DistanceToOut( const G4ThreeVector &p, const G4ThreeVector &v,
|
||||
const G4bool calcNorm,
|
||||
G4bool *validNorm, G4ThreeVector *n ) const
|
||||
G4double G4VCSGfaceted::DistanceToOut( const G4ThreeVector &p,
|
||||
const G4ThreeVector &v,
|
||||
const G4bool calcNorm,
|
||||
G4bool *validNorm,
|
||||
G4ThreeVector *n ) const
|
||||
{
|
||||
G4bool allBehind = true;
|
||||
G4double distance = kInfinity;
|
||||
G4double distFromSurface = kInfinity;
|
||||
G4ThreeVector normal;
|
||||
G4VCSGface *bestFace=0;
|
||||
|
||||
G4VCSGface **face = faces;
|
||||
do {
|
||||
G4double faceDistance,
|
||||
faceDistFromSurface;
|
||||
G4ThreeVector faceNormal;
|
||||
G4bool faceAllBehind;
|
||||
if ((*face)->Intersect( p, v, true, kCarTolerance/2,
|
||||
faceDistance, faceDistFromSurface,
|
||||
faceNormal, faceAllBehind ) ) {
|
||||
//
|
||||
// Intersecting face
|
||||
//
|
||||
if ( (distance < kInfinity) || (!faceAllBehind) ) allBehind = false;
|
||||
if (faceDistance < distance) {
|
||||
distance = faceDistance;
|
||||
distFromSurface = faceDistFromSurface;
|
||||
normal = faceNormal;
|
||||
bestFace = *face;
|
||||
if (distFromSurface <= 0) break;
|
||||
}
|
||||
}
|
||||
} while( ++face < faces + numFace );
|
||||
|
||||
if (distance < kInfinity) {
|
||||
if (distFromSurface <= 0)
|
||||
distance = 0;
|
||||
else if (distFromSurface<kCarTolerance/2) {
|
||||
if (bestFace->Distance(p,true) < kCarTolerance/2) distance = 0;
|
||||
}
|
||||
G4bool allBehind = true;
|
||||
G4double distance = kInfinity;
|
||||
G4double distFromSurface = kInfinity;
|
||||
G4ThreeVector normal;
|
||||
G4VCSGface *bestFace=0;
|
||||
|
||||
G4VCSGface **face = faces;
|
||||
do {
|
||||
G4double faceDistance,
|
||||
faceDistFromSurface;
|
||||
G4ThreeVector faceNormal;
|
||||
G4bool faceAllBehind;
|
||||
if ((*face)->Intersect( p, v, true, kCarTolerance/2,
|
||||
faceDistance, faceDistFromSurface,
|
||||
faceNormal, faceAllBehind ) )
|
||||
{
|
||||
//
|
||||
// Intersecting face
|
||||
//
|
||||
if ( (distance < kInfinity) || (!faceAllBehind) ) allBehind = false;
|
||||
if (faceDistance < distance)
|
||||
{
|
||||
distance = faceDistance;
|
||||
distFromSurface = faceDistFromSurface;
|
||||
normal = faceNormal;
|
||||
bestFace = *face;
|
||||
if (distFromSurface <= 0) break;
|
||||
}
|
||||
}
|
||||
} while( ++face < faces + numFace );
|
||||
|
||||
if (distance < kInfinity)
|
||||
{
|
||||
if (distFromSurface <= 0)
|
||||
distance = 0;
|
||||
else if (distFromSurface<kCarTolerance/2)
|
||||
{
|
||||
if (bestFace->Distance(p,true) < kCarTolerance/2) distance = 0;
|
||||
}
|
||||
|
||||
if (calcNorm) {
|
||||
*validNorm = allBehind;
|
||||
*n = normal;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (calcNorm) *validNorm = false;
|
||||
}
|
||||
if (calcNorm)
|
||||
{
|
||||
*validNorm = allBehind;
|
||||
*n = normal;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (calcNorm) *validNorm = false;
|
||||
}
|
||||
|
||||
return distance;
|
||||
return distance;
|
||||
}
|
||||
|
||||
|
||||
@@ -304,7 +331,7 @@ G4double G4VCSGfaceted::DistanceToOut( const G4ThreeVector &p, const G4ThreeVect
|
||||
//
|
||||
G4double G4VCSGfaceted::DistanceToOut( const G4ThreeVector &p ) const
|
||||
{
|
||||
return DistanceTo( p, true );
|
||||
return DistanceTo( p, true );
|
||||
}
|
||||
|
||||
|
||||
@@ -313,16 +340,17 @@ G4double G4VCSGfaceted::DistanceToOut( const G4ThreeVector &p ) const
|
||||
//
|
||||
// Protected routine called by DistanceToIn and DistanceToOut
|
||||
//
|
||||
G4double G4VCSGfaceted::DistanceTo( const G4ThreeVector &p, const G4bool outgoing ) const
|
||||
G4double G4VCSGfaceted::DistanceTo( const G4ThreeVector &p,
|
||||
const G4bool outgoing ) const
|
||||
{
|
||||
G4VCSGface **face = faces;
|
||||
G4double best = kInfinity;
|
||||
do {
|
||||
G4double distance = (*face)->Distance( p, outgoing );
|
||||
if (distance < best) best = distance;
|
||||
} while( ++face < faces + numFace );
|
||||
G4VCSGface **face = faces;
|
||||
G4double best = kInfinity;
|
||||
do {
|
||||
G4double distance = (*face)->Distance( p, outgoing );
|
||||
if (distance < best) best = distance;
|
||||
} while( ++face < faces + numFace );
|
||||
|
||||
return (best < 0.5*kCarTolerance) ? 0 : best;
|
||||
return (best < 0.5*kCarTolerance) ? 0 : best;
|
||||
}
|
||||
|
||||
|
||||
@@ -342,26 +370,54 @@ void G4VCSGfaceted::DescribeYourselfTo( G4VGraphicsScene& scene ) const
|
||||
//
|
||||
G4VisExtent G4VCSGfaceted::GetExtent() const
|
||||
{
|
||||
static const G4ThreeVector xMax(1,0,0), xMin(-1,0,0),
|
||||
yMax(0,1,0), yMin(0,-1,0),
|
||||
zMax(0,0,1), zMin(0,0,-1);
|
||||
static const G4ThreeVector *axes[6] = { &xMin, &xMax, &yMin, &yMax, &zMin, &zMax };
|
||||
|
||||
G4double answers[6] = {-kInfinity, -kInfinity, -kInfinity, -kInfinity, -kInfinity, -kInfinity};
|
||||
|
||||
G4VCSGface **face = faces;
|
||||
do {
|
||||
const G4ThreeVector **axis = axes+5 ;
|
||||
G4double *answer = answers+5;
|
||||
do {
|
||||
G4double testFace = (*face)->Extent( **axis );
|
||||
if (testFace > *answer) *answer = testFace;
|
||||
}
|
||||
while( --axis, --answer >= answers );
|
||||
|
||||
} while( ++face < faces + numFace );
|
||||
static const G4ThreeVector xMax(1,0,0), xMin(-1,0,0),
|
||||
yMax(0,1,0), yMin(0,-1,0),
|
||||
zMax(0,0,1), zMin(0,0,-1);
|
||||
static const G4ThreeVector *axes[6] =
|
||||
{ &xMin, &xMax, &yMin, &yMax, &zMin, &zMax };
|
||||
|
||||
return G4VisExtent( -answers[0], answers[1],
|
||||
-answers[2], answers[3],
|
||||
-answers[4], answers[5] );
|
||||
G4double answers[6] =
|
||||
{-kInfinity, -kInfinity, -kInfinity, -kInfinity, -kInfinity, -kInfinity};
|
||||
|
||||
G4VCSGface **face = faces;
|
||||
do {
|
||||
const G4ThreeVector **axis = axes+5 ;
|
||||
G4double *answer = answers+5;
|
||||
do {
|
||||
G4double testFace = (*face)->Extent( **axis );
|
||||
if (testFace > *answer) *answer = testFace;
|
||||
}
|
||||
while( --axis, --answer >= answers );
|
||||
|
||||
} while( ++face < faces + numFace );
|
||||
|
||||
return G4VisExtent( -answers[0], answers[1],
|
||||
-answers[2], answers[3],
|
||||
-answers[4], answers[5] );
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// GetEntityType
|
||||
//
|
||||
G4GeometryType G4VCSGfaceted::GetEntityType() const
|
||||
{
|
||||
return G4String("G4CSGfaceted");
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Stream object contents to an output stream
|
||||
//
|
||||
G4std::ostream& G4VCSGfaceted::StreamInfo( G4std::ostream& os ) const
|
||||
{
|
||||
os << "-----------------------------------------------------------\n"
|
||||
<< " *** Dump for solid - " << GetName() << " ***\n"
|
||||
<< " ===================================================\n"
|
||||
<< " Solid type: G4VCSGfaceted\n"
|
||||
<< " Parameters: \n"
|
||||
<< " number of faces: " << numFace << "\n"
|
||||
<< "-----------------------------------------------------------\n";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user