Import Geant4 8.3.0 source tree
This commit is contained in:
@@ -0,0 +1,675 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4ExtrudedSolid.cc,v 1.7 2007/05/02 14:59:31 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-08-03 $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class source file
|
||||
//
|
||||
// G4ExtrudedSolid.cc
|
||||
//
|
||||
// Author: Ivana Hrivnacova, IPN Orsay
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "G4ExtrudedSolid.hh"
|
||||
#include "G4TriangularFacet.hh"
|
||||
#include "G4QuadrangularFacet.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4ExtrudedSolid::G4ExtrudedSolid( const G4String& pName,
|
||||
std::vector<G4TwoVector> polygon,
|
||||
std::vector<ZSection> zsections)
|
||||
: G4TessellatedSolid(pName),
|
||||
fNv(polygon.size()),
|
||||
fNz(zsections.size()),
|
||||
fPolygon(),
|
||||
fZSections(),
|
||||
fTriangles(),
|
||||
fIsConvex(false),
|
||||
fGeometryType("G4ExtrudedSolid")
|
||||
|
||||
{
|
||||
// General constructor
|
||||
|
||||
// First check input parameters
|
||||
|
||||
if ( fNv < 3 ) {
|
||||
G4Exception(
|
||||
"G4ExtrudedSolid::G4ExtrudedSolid()", "InvalidSetup",
|
||||
FatalException, "Number of polygon vertices < 3");
|
||||
}
|
||||
|
||||
if ( fNz < 2 ) {
|
||||
G4Exception(
|
||||
"G4ExtrudedSolid::G4ExtrudedSolid()", "InvalidSetup",
|
||||
FatalException, "Number of z-sides < 2");
|
||||
}
|
||||
|
||||
for ( G4int i=0; i<fNz-1; ++i )
|
||||
{
|
||||
if ( zsections[i].fZ > zsections[i+1].fZ )
|
||||
{
|
||||
G4Exception(
|
||||
"G4ExtrudedSolid::G4ExtrudedSolid()", "InvalidSetup",
|
||||
FatalException,
|
||||
"Z-sections have to be ordered by z value (z0 < z1 < z2 ...)");
|
||||
}
|
||||
if ( std::fabs( zsections[i+1].fZ - zsections[i].fZ ) < kCarTolerance )
|
||||
{
|
||||
G4Exception(
|
||||
"G4ExtrudedSolid::G4ExtrudedSolid()", "InvalidSetup",
|
||||
FatalException,
|
||||
"Z-sections with the same z position are not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
// Copy polygon
|
||||
//
|
||||
for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[i]); }
|
||||
|
||||
// Copy z-sections
|
||||
//
|
||||
for ( G4int i=0; i<fNz; ++i ) { fZSections.push_back(zsections[i]); }
|
||||
|
||||
|
||||
G4bool result = MakeFacets();
|
||||
if (!result)
|
||||
{
|
||||
G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "InvalidSetup",
|
||||
FatalException, "Making facets failed.");
|
||||
}
|
||||
fIsConvex = IsConvex();
|
||||
|
||||
|
||||
ComputeProjectionParameters();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4ExtrudedSolid::G4ExtrudedSolid( const G4String& pName,
|
||||
std::vector<G4TwoVector> polygon,
|
||||
G4double dz,
|
||||
G4TwoVector off1, G4double scale1,
|
||||
G4TwoVector off2, G4double scale2 )
|
||||
: G4TessellatedSolid(pName),
|
||||
fNv(polygon.size()),
|
||||
fNz(2),
|
||||
fPolygon(),
|
||||
fZSections(),
|
||||
fTriangles(),
|
||||
fIsConvex(false),
|
||||
fGeometryType("G4ExtrudedSolid")
|
||||
|
||||
{
|
||||
// Special constructor for solid with 2 z-sections
|
||||
|
||||
// First check input parameters
|
||||
//
|
||||
if ( fNv < 3 )
|
||||
{
|
||||
G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "InvalidSetup",
|
||||
FatalException, "Number of polygon vertices < 3");
|
||||
}
|
||||
|
||||
// Copy polygon
|
||||
//
|
||||
for ( G4int i=0; i<fNv; ++i ) { fPolygon.push_back(polygon[i]); }
|
||||
|
||||
// Copy z-sections
|
||||
//
|
||||
fZSections.push_back(ZSection(-dz, off1, scale1));
|
||||
fZSections.push_back(ZSection( dz, off2, scale2));
|
||||
|
||||
G4bool result = MakeFacets();
|
||||
if (!result)
|
||||
{
|
||||
G4Exception("G4ExtrudedSolid::G4ExtrudedSolid()", "InvalidSetup",
|
||||
FatalException, "Making facets failed.");
|
||||
}
|
||||
fIsConvex = IsConvex();
|
||||
|
||||
ComputeProjectionParameters();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4ExtrudedSolid::G4ExtrudedSolid( __void__& a )
|
||||
: G4TessellatedSolid(a)
|
||||
{
|
||||
// Fake default constructor - sets only member data and allocates memory
|
||||
// for usage restricted to object persistency.
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4ExtrudedSolid::~G4ExtrudedSolid()
|
||||
{
|
||||
// Destructor
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
void G4ExtrudedSolid::ComputeProjectionParameters()
|
||||
{
|
||||
// Compute parameters for point projections p(z)
|
||||
// to the polygon scale & offset:
|
||||
// scale(z) = k*z + scale0
|
||||
// offset(z) = l*z + offset0
|
||||
// p(z) = scale(z)*p0 + offset(z)
|
||||
// p0 = (p(z) - offset(z))/scale(z);
|
||||
//
|
||||
|
||||
for ( G4int iz=0; iz<fNz-1; ++iz)
|
||||
{
|
||||
G4double z1 = fZSections[iz].fZ;
|
||||
G4double z2 = fZSections[iz+1].fZ;
|
||||
G4double scale1 = fZSections[iz].fScale;
|
||||
G4double scale2 = fZSections[iz+1].fScale;
|
||||
G4TwoVector off1 = fZSections[iz].fOffset;
|
||||
G4TwoVector off2 = fZSections[iz+1].fOffset;
|
||||
|
||||
G4double kscale = (scale2 - scale1)/(z2 - z1);
|
||||
G4double scale0 = scale2 - kscale*(z2 - z1)/2.0;
|
||||
G4TwoVector koff = (off2 - off1)/(z2 - z1);
|
||||
G4TwoVector off0 = off2 - koff*(z2 - z1)/2.0;
|
||||
|
||||
fKScales.push_back(kscale);
|
||||
fScale0s.push_back(scale0);
|
||||
fKOffsets.push_back(koff);
|
||||
fOffset0s.push_back(off0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4ThreeVector G4ExtrudedSolid::GetVertex(G4int iz, G4int ind) const
|
||||
{
|
||||
// Shift and scale vertices
|
||||
|
||||
return G4ThreeVector( fPolygon[ind].x() * fZSections[iz].fScale
|
||||
+ fZSections[iz].fOffset.x(),
|
||||
fPolygon[ind].y() * fZSections[iz].fScale
|
||||
+ fZSections[iz].fOffset.y(), fZSections[iz].fZ);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
|
||||
G4TwoVector G4ExtrudedSolid::ProjectPoint(const G4ThreeVector& point) const
|
||||
{
|
||||
// Project point in the polygon scale
|
||||
// scale(z) = k*z + scale0
|
||||
// offset(z) = l*z + offset0
|
||||
// p(z) = scale(z)*p0 + offset(z)
|
||||
// p0 = (p(z) - offset(z))/scale(z);
|
||||
|
||||
// Select projection (z-segment of the solid) according to p.z()
|
||||
//
|
||||
G4int iz = 0;
|
||||
while ( point.z() > fZSections[iz+1].fZ && iz < fNz-2 ) { ++iz; }
|
||||
|
||||
G4double z0 = ( fZSections[iz+1].fZ + fZSections[iz].fZ )/2.0;
|
||||
G4TwoVector p2(point.x(), point.y());
|
||||
G4double pscale = fKScales[iz]*(point.z()-z0) + fScale0s[iz];
|
||||
G4TwoVector poffset = fKOffsets[iz]*(point.z()-z0) + fOffset0s[iz];
|
||||
|
||||
// G4cout << point << " projected to "
|
||||
// << iz << "-th z-segment polygon as "
|
||||
// << (p2 - poffset)/pscale << G4endl;
|
||||
|
||||
// pscale is always >0 as it is an interpolation between two
|
||||
// positive scale values
|
||||
//
|
||||
return (p2 - poffset)/pscale;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4bool G4ExtrudedSolid::IsSameLine(G4TwoVector p,
|
||||
G4TwoVector l1, G4TwoVector l2) const
|
||||
{
|
||||
// Return true if p is on the line through l1, l2
|
||||
|
||||
if ( l1.x() == l2.x() )
|
||||
{
|
||||
return std::fabs(p.x() - l1.x()) < kCarTolerance;
|
||||
}
|
||||
return std::fabs (p.y() - l1.y() - ((l2.y() - l1.y())/(l2.x() - l1.x()))
|
||||
*(p.x() - l1.x())) < kCarTolerance;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4bool G4ExtrudedSolid::IsSameSide(G4TwoVector p1, G4TwoVector p2,
|
||||
G4TwoVector l1, G4TwoVector l2) const
|
||||
{
|
||||
// Return true if p1 and p2 are on the same side of the line through l1, l2
|
||||
|
||||
return ( (p1.x() - l1.x()) * (l2.y() - l1.y())
|
||||
- (l2.x() - l1.x()) * (p1.y() - l1.y()) )
|
||||
* ( (p2.x() - l1.x()) * (l2.y() - l1.y())
|
||||
- (l2.x() - l1.x()) * (p2.y() - l1.y()) ) > 0;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4bool G4ExtrudedSolid::IsPointInside(G4TwoVector a, G4TwoVector b,
|
||||
G4TwoVector c, G4TwoVector p) const
|
||||
{
|
||||
// Return true if p is inside of triangle abc, else returns false
|
||||
|
||||
// Check extent first
|
||||
//
|
||||
if ( ( p.x() < a.x() && p.x() < b.x() && p.x() < c.x() ) ||
|
||||
( p.x() > a.x() && p.x() > b.x() && p.x() > c.x() ) ||
|
||||
( p.y() < a.y() && p.y() < b.y() && p.y() < c.y() ) ||
|
||||
( p.y() > a.y() && p.y() > b.y() && p.y() > c.y() ) ) return false;
|
||||
|
||||
return IsSameSide(p, a, b, c)
|
||||
&& IsSameSide(p, b, a, c)
|
||||
&& IsSameSide(p, c, a, b);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4VFacet*
|
||||
G4ExtrudedSolid::MakeDownFacet(G4int ind1, G4int ind2, G4int ind3) const
|
||||
{
|
||||
// Create a triangular facet from the polygon points given by indices
|
||||
// forming the down side ( the normal goes in -z)
|
||||
|
||||
std::vector<G4ThreeVector> vertices;
|
||||
vertices.push_back(GetVertex(0, ind1));
|
||||
vertices.push_back(GetVertex(0, ind2));
|
||||
vertices.push_back(GetVertex(0, ind3));
|
||||
|
||||
// first vertex most left
|
||||
//
|
||||
G4ThreeVector cross
|
||||
= (vertices[1]-vertices[0]).cross(vertices[2]-vertices[1]);
|
||||
|
||||
if ( cross.z() > 0.0 )
|
||||
{
|
||||
// vertices ardered clock wise has to be reordered
|
||||
|
||||
// G4cout << "G4ExtrudedSolid::MakeDownFacet: reordering vertices "
|
||||
// << ind1 << ", " << ind2 << ", " << ind3 << G4endl;
|
||||
|
||||
G4ThreeVector tmp = vertices[1];
|
||||
vertices[1] = vertices[2];
|
||||
vertices[2] = tmp;
|
||||
}
|
||||
|
||||
return new G4TriangularFacet(vertices[0], vertices[1],
|
||||
vertices[2], ABSOLUTE);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4VFacet*
|
||||
G4ExtrudedSolid::MakeUpFacet(G4int ind1, G4int ind2, G4int ind3) const
|
||||
{
|
||||
// Creates a triangular facet from the polygon points given by indices
|
||||
// forming the upper side ( z>0 )
|
||||
|
||||
std::vector<G4ThreeVector> vertices;
|
||||
vertices.push_back(GetVertex(fNz-1, ind1));
|
||||
vertices.push_back(GetVertex(fNz-1, ind2));
|
||||
vertices.push_back(GetVertex(fNz-1, ind3));
|
||||
|
||||
// first vertex most left
|
||||
//
|
||||
G4ThreeVector cross
|
||||
= (vertices[1]-vertices[0]).cross(vertices[2]-vertices[1]);
|
||||
|
||||
if ( cross.z() < 0.0 )
|
||||
{
|
||||
// vertices ordered clock wise has to be reordered
|
||||
|
||||
// G4cout << "G4ExtrudedSolid::MakeUpFacet: reordering vertices "
|
||||
// << ind1 << ", " << ind2 << ", " << ind3 << G4endl;
|
||||
|
||||
G4ThreeVector tmp = vertices[1];
|
||||
vertices[1] = vertices[2];
|
||||
vertices[2] = tmp;
|
||||
}
|
||||
|
||||
return new G4TriangularFacet(vertices[0], vertices[1],
|
||||
vertices[2], ABSOLUTE);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4bool G4ExtrudedSolid::AddGeneralPolygonFacets()
|
||||
{
|
||||
// Decompose polygonal sides in triangular facets
|
||||
|
||||
typedef std::pair < G4TwoVector, G4int > Vertex;
|
||||
|
||||
// Fill one more vector
|
||||
//
|
||||
std::vector< Vertex > verticesToBeDone;
|
||||
for ( G4int i=0; i<fNv; ++i )
|
||||
{
|
||||
verticesToBeDone.push_back(Vertex(fPolygon[i], i));
|
||||
}
|
||||
std::vector< Vertex > ears;
|
||||
|
||||
std::vector< Vertex >::iterator c1 = verticesToBeDone.begin();
|
||||
std::vector< Vertex >::iterator c2 = c1+1;
|
||||
std::vector< Vertex >::iterator c3 = c1+2;
|
||||
while ( verticesToBeDone.size()>2 )
|
||||
{
|
||||
|
||||
// G4cout << "Looking at triangle : "
|
||||
// << c1->second << " " << c2->second
|
||||
// << " " << c3->second << G4endl;
|
||||
|
||||
G4bool good = true;
|
||||
std::vector< Vertex >::iterator it;
|
||||
for ( it=verticesToBeDone.begin(); it != verticesToBeDone.end(); ++it )
|
||||
{
|
||||
// skip vertices of tested triangle
|
||||
//
|
||||
if ( it == c1 || it == c2 || it == c3 ) { continue; }
|
||||
if ( IsPointInside(c1->first, c2->first, c3->first, it->first) )
|
||||
{
|
||||
// G4cout << "Point " << it->second << " is inside" << G4endl;
|
||||
good = false;
|
||||
|
||||
// try next three consecutive vertices
|
||||
//
|
||||
c1 = c2;
|
||||
c2 = c3;
|
||||
++c3;
|
||||
if ( c3 == verticesToBeDone.end() ) { c3 = verticesToBeDone.begin(); }
|
||||
break;
|
||||
}
|
||||
// else
|
||||
// { G4cout << "Point " << it->second << " is outside" << G4endl; }
|
||||
}
|
||||
if ( good )
|
||||
{
|
||||
// all points are outside triangle, we can make a facet
|
||||
|
||||
// G4cout << "Found triangle : "
|
||||
// << c1->second << " " << c2->second
|
||||
// << " " << c3->second << G4endl;
|
||||
|
||||
G4bool result;
|
||||
result = AddFacet( MakeDownFacet(c1->second, c2->second, c3->second) );
|
||||
if ( ! result ) { return false; }
|
||||
|
||||
result = AddFacet( MakeUpFacet(c1->second, c2->second, c3->second) );
|
||||
if ( ! result ) { return false; }
|
||||
|
||||
std::vector<G4int> triangle(3);
|
||||
triangle[0] = c1->second;
|
||||
triangle[1] = c2->second;
|
||||
triangle[2] = c3->second;
|
||||
fTriangles.push_back(triangle);
|
||||
|
||||
// remove the ear point from verticesToBeDone
|
||||
//
|
||||
verticesToBeDone.erase(c2);
|
||||
c1 = verticesToBeDone.begin();
|
||||
c2 = c1+1;
|
||||
c3 = c1+2;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4bool G4ExtrudedSolid::MakeFacets()
|
||||
{
|
||||
// Define facets
|
||||
|
||||
G4bool good;
|
||||
|
||||
// The quadrangular sides
|
||||
//
|
||||
for ( G4int iz = 0; iz < fNz-1; ++iz )
|
||||
{
|
||||
for ( G4int i = 0; i < fNv; ++i )
|
||||
{
|
||||
G4int j = (i+1) % fNv;
|
||||
good = AddFacet( new G4QuadrangularFacet
|
||||
( GetVertex(iz, j), GetVertex(iz, i),
|
||||
GetVertex(iz+1, i), GetVertex(iz+1, j), ABSOLUTE) );
|
||||
if ( ! good ) { return false; }
|
||||
}
|
||||
}
|
||||
|
||||
// Decomposition of polygonal sides in the facets
|
||||
//
|
||||
if ( fNv == 3 )
|
||||
{
|
||||
good = AddFacet( new G4TriangularFacet( GetVertex(0, 0), GetVertex(0, 1),
|
||||
GetVertex(0, 2), ABSOLUTE) );
|
||||
if ( ! good ) { return false; }
|
||||
|
||||
good = AddFacet( new G4TriangularFacet( GetVertex(fNz-1, 2), GetVertex(fNz-1, 1),
|
||||
GetVertex(fNz-1, 0), ABSOLUTE) );
|
||||
if ( ! good ) { return false; }
|
||||
}
|
||||
|
||||
else if ( fNv == 4 )
|
||||
{
|
||||
good = AddFacet( new G4QuadrangularFacet( GetVertex(0, 0),GetVertex(0, 1),
|
||||
GetVertex(0, 2),GetVertex(0, 3),
|
||||
ABSOLUTE) );
|
||||
if ( ! good ) { return false; }
|
||||
|
||||
good = AddFacet( new G4QuadrangularFacet( GetVertex(fNz-1, 3), GetVertex(fNz-1, 2),
|
||||
GetVertex(fNz-1, 1), GetVertex(1, 0),
|
||||
ABSOLUTE) );
|
||||
if ( ! good ) { return false; }
|
||||
}
|
||||
else
|
||||
{
|
||||
good = AddGeneralPolygonFacets();
|
||||
if ( ! good ) { return false; }
|
||||
}
|
||||
|
||||
SetSolidClosed(true);
|
||||
|
||||
return good;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4bool G4ExtrudedSolid::IsConvex() const
|
||||
{
|
||||
// Get polygon convexity (polygon is convex if all vertex angles are < pi )
|
||||
|
||||
for ( G4int i=0; i< fNv; ++i )
|
||||
{
|
||||
G4int j = ( i + 1 ) % fNv;
|
||||
G4int k = ( i + 2 ) % fNv;
|
||||
G4TwoVector v1 = fPolygon[i]-fPolygon[j];
|
||||
G4TwoVector v2 = fPolygon[k]-fPolygon[j];
|
||||
G4double dphi = v2.phi() - v1.phi();
|
||||
if ( dphi < 0. ) { dphi += 2.*pi; }
|
||||
|
||||
if ( dphi >= pi ) { return false; }
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4GeometryType G4ExtrudedSolid::GetEntityType () const
|
||||
{
|
||||
// Return entity type
|
||||
|
||||
return fGeometryType;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
EInside G4ExtrudedSolid::Inside (const G4ThreeVector &p) const
|
||||
{
|
||||
// Override the base class function as it fails in case of concave polygon.
|
||||
// Project the point in the original polygon scale and check if it is inside
|
||||
// for each triangle.
|
||||
|
||||
// Check first if outside extent
|
||||
//
|
||||
if ( p.x() < GetMinXExtent() - kCarTolerance ||
|
||||
p.x() > GetMaxXExtent() + kCarTolerance ||
|
||||
p.y() < GetMinYExtent() - kCarTolerance ||
|
||||
p.y() > GetMaxYExtent() + kCarTolerance ||
|
||||
p.z() < GetMinZExtent() - kCarTolerance ||
|
||||
p.z() > GetMaxZExtent() + kCarTolerance )
|
||||
{
|
||||
// G4cout << "G4ExtrudedSolid::Outside extent: " << p << G4endl;
|
||||
return kOutside;
|
||||
}
|
||||
|
||||
// Project point p(z) to the polygon scale p0
|
||||
//
|
||||
G4TwoVector pscaled = ProjectPoint(p);
|
||||
|
||||
// Check if on surface of polygon
|
||||
//
|
||||
for ( G4int i=0; i<fNv; ++i )
|
||||
{
|
||||
G4int j = (i+1) % fNv;
|
||||
if ( IsSameLine(pscaled, fPolygon[i], fPolygon[j]) )
|
||||
{
|
||||
// G4cout << "G4ExtrudedSolid::Inside return Surface (on polygon) "
|
||||
// << G4endl;
|
||||
|
||||
return kSurface;
|
||||
}
|
||||
}
|
||||
|
||||
// Now check if inside triangles
|
||||
//
|
||||
std::vector< std::vector<G4int> >::const_iterator it = fTriangles.begin();
|
||||
G4bool inside = false;
|
||||
do
|
||||
{
|
||||
if ( IsPointInside(fPolygon[(*it)[0]], fPolygon[(*it)[1]],
|
||||
fPolygon[(*it)[2]], pscaled) ) { inside = true; }
|
||||
++it;
|
||||
} while ( (inside == false) && (it != fTriangles.end()) );
|
||||
|
||||
if ( inside )
|
||||
{
|
||||
// Check if on surface of z sides
|
||||
//
|
||||
if ( std::fabs( p.z() - fZSections[0].fZ ) < kCarTolerance ||
|
||||
std::fabs( p.z() - fZSections[fNz-1].fZ ) < kCarTolerance )
|
||||
{
|
||||
// G4cout << "G4ExtrudedSolid::Inside return Surface (on z side)"
|
||||
// << G4endl;
|
||||
|
||||
return kSurface;
|
||||
}
|
||||
|
||||
// G4cout << "G4ExtrudedSolid::Inside return Inside" << G4endl;
|
||||
|
||||
return kInside;
|
||||
}
|
||||
|
||||
// G4cout << "G4ExtrudedSolid::Inside return Outside " << G4endl;
|
||||
|
||||
return kOutside;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4double G4ExtrudedSolid::DistanceToOut (const G4ThreeVector &p,
|
||||
const G4ThreeVector &v,
|
||||
const G4bool calcNorm,
|
||||
G4bool *validNorm,
|
||||
G4ThreeVector *n) const
|
||||
{
|
||||
// Override the base class function to redefine validNorm
|
||||
// (the solid can be concave)
|
||||
|
||||
G4double distOut =
|
||||
G4TessellatedSolid::DistanceToOut(p, v, calcNorm, validNorm, n);
|
||||
if (validNorm) { *validNorm = fIsConvex; }
|
||||
|
||||
return distOut;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
G4double G4ExtrudedSolid::DistanceToOut (const G4ThreeVector &p) const
|
||||
{
|
||||
// Override the overloaded base class function
|
||||
|
||||
return G4TessellatedSolid::DistanceToOut(p);
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
std::ostream& G4ExtrudedSolid::StreamInfo(std::ostream &os) const
|
||||
{
|
||||
os << "-----------------------------------------------------------\n"
|
||||
<< " *** Dump for solid - " << GetName() << " ***\n"
|
||||
<< " ===================================================\n"
|
||||
<< " Solid geometry type: " << fGeometryType << G4endl;
|
||||
|
||||
if ( fIsConvex)
|
||||
{ os << " Convex polygon; list of vertices:" << G4endl; }
|
||||
else
|
||||
{ os << " Concave polygon; list of vertices:" << G4endl; }
|
||||
|
||||
for ( G4int i=0; i<fNv; ++i )
|
||||
{
|
||||
os << " vx = " << fPolygon[i].x()/mm << " mm"
|
||||
<< " vy = " << fPolygon[i].y()/mm << " mm" << G4endl;
|
||||
}
|
||||
|
||||
os << " Sections:" << G4endl;
|
||||
for ( G4int iz=0; iz<fNz; ++iz )
|
||||
{
|
||||
os << " z = " << fZSections[iz].fZ/mm << " mm "
|
||||
<< " x0= " << fZSections[iz].fOffset.x()/mm << " mm "
|
||||
<< " y0= " << fZSections[iz].fOffset.y()/mm << " mm "
|
||||
<< " scale= " << fZSections[iz].fScale << G4endl;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
@@ -24,8 +24,8 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4Polycone.cc,v 1.34 2006/11/15 10:40:38 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-08-02 $
|
||||
// $Id: G4Polycone.cc,v 1.37 2007/04/26 13:34:04 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-08-03 $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
@@ -411,7 +411,7 @@ G4bool G4Polycone::Reset()
|
||||
if (genericPcon)
|
||||
{
|
||||
G4cerr << "Solid " << GetName() << " built using generic construct."
|
||||
<< G4endl << "Specify original parameters first !" << G4endl;
|
||||
<< G4endl << "Not applicable to the generic construct !" << G4endl;
|
||||
G4Exception("G4Polycone::Reset()", "NotApplicableConstruct",
|
||||
JustWarning, "Parameters NOT resetted.");
|
||||
return 1;
|
||||
@@ -567,7 +567,7 @@ G4ThreeVector G4Polycone::GetPointOnCone(G4double fRmin1, G4double fRmax1,
|
||||
G4double fRmin2, G4double fRmax2,
|
||||
G4double zOne, G4double zTwo,
|
||||
G4double& totArea) const
|
||||
{
|
||||
{
|
||||
// declare working variables
|
||||
//
|
||||
G4double Aone, Atwo, Afive, phi, zRand, fDPhi, fSPhi, cosu, sinu;
|
||||
@@ -576,12 +576,16 @@ G4ThreeVector G4Polycone::GetPointOnCone(G4double fRmin1, G4double fRmax1,
|
||||
G4ThreeVector point, offset;
|
||||
offset = G4ThreeVector(0.,0.,0.5*(zTwo+zOne));
|
||||
fSPhi = startPhi; fDPhi = endPhi - startPhi;
|
||||
|
||||
rone = (fRmax1-fRmax2)/(2.*fDz);
|
||||
rtwo = (fRmin1-fRmin2)/(2.*fDz);
|
||||
qone = fDz*(fRmax1+fRmax2)/(fRmax1-fRmax2);
|
||||
qtwo = fDz*(fRmin1+fRmin2)/(fRmin1-fRmin2);
|
||||
|
||||
if(fRmax1==fRmax2){qone=0.;}
|
||||
else{
|
||||
qone = fDz*(fRmax1+fRmax2)/(fRmax1-fRmax2);
|
||||
}
|
||||
if(fRmin1==fRmin2){qtwo=0.;}
|
||||
else{
|
||||
qtwo = fDz*(fRmin1+fRmin2)/(fRmin1-fRmin2);
|
||||
}
|
||||
Aone = 0.5*fDPhi*(fRmax2 + fRmax1)*(sqr(fRmin1-fRmin2)+sqr(zTwo-zOne));
|
||||
Atwo = 0.5*fDPhi*(fRmin2 + fRmin1)*(sqr(fRmax1-fRmax2)+sqr(zTwo-zOne));
|
||||
Afive = fDz*(fRmax1-fRmin1+fRmax2-fRmin2);
|
||||
@@ -590,10 +594,10 @@ G4ThreeVector G4Polycone::GetPointOnCone(G4double fRmin1, G4double fRmax1,
|
||||
phi = RandFlat::shoot(startPhi,endPhi);
|
||||
cosu = std::cos(phi);
|
||||
sinu = std::sin(phi);
|
||||
|
||||
|
||||
|
||||
if( (startPhi == 0) && (endPhi == twopi) ) { Afive = 0; }
|
||||
chose = RandFlat::shoot(0.,Aone+Atwo+2.*Afive);
|
||||
|
||||
if( (chose >= 0) && (chose < Aone) )
|
||||
{
|
||||
if(fRmax1 != fRmax2)
|
||||
@@ -601,25 +605,30 @@ G4ThreeVector G4Polycone::GetPointOnCone(G4double fRmin1, G4double fRmax1,
|
||||
zRand = RandFlat::shoot(-1.*fDz,fDz);
|
||||
point = G4ThreeVector (rone*cosu*(qone-zRand),
|
||||
rone*sinu*(qone-zRand), zRand);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
point = G4ThreeVector(fRmax1*cosu, fRmax1*sinu,
|
||||
RandFlat::shoot(-1.*fDz,fDz));
|
||||
|
||||
}
|
||||
}
|
||||
else if(chose >= Aone && chose < Aone + Atwo)
|
||||
{
|
||||
if(fRmin1 != fRmin2)
|
||||
{
|
||||
{
|
||||
zRand = RandFlat::shoot(-1.*fDz,fDz);
|
||||
point = G4ThreeVector (rtwo*cosu*(qtwo-zRand),
|
||||
rtwo*sinu*(qtwo-zRand), zRand);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
point = G4ThreeVector(fRmin1*cosu, fRmin1*sinu,
|
||||
RandFlat::shoot(-1.*fDz,fDz));
|
||||
|
||||
}
|
||||
}
|
||||
else if( (chose >= Aone + Atwo + Afive) && (chose < Aone + Atwo + 2.*Afive) )
|
||||
@@ -629,6 +638,7 @@ G4ThreeVector G4Polycone::GetPointOnCone(G4double fRmin1, G4double fRmax1,
|
||||
fRmax2-((zRand-fDz)/(2.*fDz))*(fRmax1-fRmax2));
|
||||
point = G4ThreeVector (rRand1*std::cos(startPhi),
|
||||
rRand1*std::sin(startPhi), zRand);
|
||||
G4cout<<"Point3="<<point<<G4endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -637,6 +647,7 @@ G4ThreeVector G4Polycone::GetPointOnCone(G4double fRmin1, G4double fRmax1,
|
||||
fRmax2-((zRand-fDz)/(2.*fDz))*(fRmax1-fRmax2));
|
||||
point = G4ThreeVector (rRand1*std::cos(endPhi),
|
||||
rRand1*std::sin(endPhi), zRand);
|
||||
|
||||
}
|
||||
return point+offset;
|
||||
}
|
||||
@@ -650,7 +661,7 @@ G4ThreeVector G4Polycone::GetPointOnCone(G4double fRmin1, G4double fRmax1,
|
||||
G4ThreeVector G4Polycone::GetPointOnTubs(G4double fRMin, G4double fRMax,
|
||||
G4double zOne, G4double zTwo,
|
||||
G4double& totArea) const
|
||||
{
|
||||
{
|
||||
G4double xRand,yRand,zRand,phi,cosphi,sinphi,chose,
|
||||
aOne,aTwo,aFou,rRand,fDz,fSPhi,fDPhi;
|
||||
fDz = std::fabs(0.5*(zTwo-zOne));
|
||||
@@ -661,7 +672,6 @@ G4ThreeVector G4Polycone::GetPointOnTubs(G4double fRMin, G4double fRMax,
|
||||
aTwo = 2.*fDz*fDPhi*fRMin;
|
||||
aFou = 2.*fDz*(fRMax-fRMin);
|
||||
totArea = aOne+aTwo+2.*aFou;
|
||||
|
||||
phi = RandFlat::shoot(startPhi,endPhi);
|
||||
cosphi = std::cos(phi);
|
||||
sinphi = std::sin(phi);
|
||||
@@ -702,6 +712,50 @@ G4ThreeVector G4Polycone::GetPointOnTubs(G4double fRMin, G4double fRMax,
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// GetPointOnRing
|
||||
//
|
||||
// Auxiliary method for GetPoint On Surface
|
||||
//
|
||||
G4ThreeVector G4Polycone::GetPointOnRing(G4double fRMin1, G4double fRMax1,
|
||||
G4double fRMin2,G4double fRMax2,
|
||||
G4double zOne) const
|
||||
{
|
||||
G4double xRand,yRand,phi,cosphi,sinphi,rRand1,rRand2,A1,Atot,rCh;
|
||||
|
||||
phi = RandFlat::shoot(startPhi,endPhi);
|
||||
cosphi = std::cos(phi);
|
||||
sinphi = std::sin(phi);
|
||||
|
||||
if(fRMin1==fRMin2)
|
||||
{
|
||||
rRand1 = fRMin1; A1=0.;
|
||||
}
|
||||
else
|
||||
{
|
||||
rRand1 = RandFlat::shoot(fRMin1,fRMin2);
|
||||
A1=std::abs(fRMin2*fRMin2-fRMin1*fRMin1);
|
||||
}
|
||||
if(fRMax1==fRMax2)
|
||||
{
|
||||
rRand2=fRMax1; Atot=A1;
|
||||
}
|
||||
else
|
||||
{
|
||||
rRand2 = RandFlat::shoot(fRMax1,fRMax2);
|
||||
Atot = A1+std::abs(fRMax2*fRMax2-fRMax1*fRMax1);
|
||||
}
|
||||
rCh = RandFlat::shoot(0.,Atot);
|
||||
|
||||
if(rCh>A1) { rRand1=rRand2; }
|
||||
|
||||
xRand = rRand1*cosphi;
|
||||
yRand = rRand1*sinphi;
|
||||
|
||||
return G4ThreeVector(xRand, yRand, zOne);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// GetPointOnCut
|
||||
//
|
||||
@@ -711,12 +765,15 @@ G4ThreeVector G4Polycone::GetPointOnCut(G4double fRMin1, G4double fRMax1,
|
||||
G4double fRMin2, G4double fRMax2,
|
||||
G4double zOne, G4double zTwo,
|
||||
G4double& totArea) const
|
||||
{
|
||||
if( (fRMin1 == fRMin2) && (fRMax1 == fRMax2) )
|
||||
{
|
||||
return GetPointOnTubs(fRMin1, fRMax1,zOne,zTwo,totArea);
|
||||
}
|
||||
return GetPointOnCone(fRMin1,fRMax1,fRMin2,fRMax2,zOne,zTwo,totArea);
|
||||
{ if(zOne==zTwo)
|
||||
{
|
||||
return GetPointOnRing(fRMin1, fRMax1,fRMin2,fRMax2,zOne);
|
||||
}
|
||||
if( (fRMin1 == fRMin2) && (fRMax1 == fRMax2) )
|
||||
{
|
||||
return GetPointOnTubs(fRMin1, fRMax1,zOne,zTwo,totArea);
|
||||
}
|
||||
return GetPointOnCone(fRMin1,fRMax1,fRMin2,fRMax2,zOne,zTwo,totArea);
|
||||
}
|
||||
|
||||
|
||||
@@ -724,7 +781,7 @@ G4ThreeVector G4Polycone::GetPointOnCut(G4double fRMin1, G4double fRMax1,
|
||||
// GetPointOnSurface
|
||||
//
|
||||
G4ThreeVector G4Polycone::GetPointOnSurface() const
|
||||
{
|
||||
{
|
||||
G4double Area=0,totArea=0,Achose1=0,Achose2=0,phi,cosphi,sinphi,rRand;
|
||||
G4int i=0;
|
||||
G4int numPlanes = original_parameters->Num_z_planes;
|
||||
@@ -788,7 +845,7 @@ G4ThreeVector G4Polycone::GetPointOnSurface() const
|
||||
Achose1 += areas[i];
|
||||
Achose2 = (Achose1+areas[i+1]);
|
||||
if(chose>=Achose1 && chose<Achose2)
|
||||
{
|
||||
{// G4cout<<"will return Point On Cut"<<G4endl;
|
||||
return GetPointOnCut(original_parameters->Rmin[i],
|
||||
original_parameters->Rmax[i],
|
||||
original_parameters->Rmin[i+1],
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4PolyconeSide.cc,v 1.13 2006/06/29 18:48:44 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-08-02 $
|
||||
// $Id: G4PolyconeSide.cc,v 1.14 2007/02/01 09:20:33 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-08-03 $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
@@ -930,7 +930,10 @@ G4double G4PolyconeSide::DistanceAway( const G4ThreeVector &p,
|
||||
G4double dist = d1*rx;
|
||||
|
||||
distOutside2 += dist*dist;
|
||||
if (edgeRZnorm) *edgeRZnorm = std::max(*edgeRZnorm,std::fabs(dist));
|
||||
if (edgeRZnorm)
|
||||
{
|
||||
*edgeRZnorm = std::max(std::fabs(*edgeRZnorm),std::fabs(dist));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4Polyhedra.cc,v 1.32 2006/11/08 09:49:51 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-08-02 $
|
||||
// $Id: G4Polyhedra.cc,v 1.33 2007/01/22 12:58:53 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-08-03 $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
@@ -100,7 +100,7 @@ G4Polyhedra::G4Polyhedra( const G4String& name,
|
||||
//
|
||||
G4double phiTotal = thePhiTotal;
|
||||
if ( (phiTotal <=0) || (phiTotal >= twopi*(1-DBL_EPSILON)) )
|
||||
phiTotal = twopi;
|
||||
{ phiTotal = twopi; }
|
||||
G4double convertRad = std::cos(0.5*phiTotal/theNumSide);
|
||||
|
||||
//
|
||||
@@ -176,7 +176,7 @@ G4Polyhedra::G4Polyhedra( const G4String& name,
|
||||
|
||||
// Set original_parameters struct for consistency
|
||||
//
|
||||
SetOriginalParameters(); // In .icc; looks dodgy to me (J.Allison). Ignore.
|
||||
SetOriginalParameters();
|
||||
|
||||
delete rz;
|
||||
}
|
||||
@@ -459,17 +459,17 @@ void G4Polyhedra::CopyStuff( const G4Polyhedra &source )
|
||||
//
|
||||
// Reset
|
||||
//
|
||||
// Recalculates and reshapes the solid, given pre-assigned
|
||||
// Recalculates and reshapes the solid, given pre-assigned scaled
|
||||
// original_parameters.
|
||||
//
|
||||
G4bool G4Polyhedra::Reset()
|
||||
{
|
||||
if (genericPgon)
|
||||
{
|
||||
G4cerr << "Solid " << GetName() << " built using generic construct."
|
||||
<< G4endl << "Not applicable to the generic construct !" << G4endl;
|
||||
G4Exception("G4Polyhedra::Reset()", "NotApplicableConstruct",
|
||||
JustWarning, "Parameters NOT resetted.");
|
||||
G4cerr << "Solid " << GetName() << " built using generic construct."
|
||||
<< G4endl << "Specify original parameters first !" << G4endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -488,16 +488,8 @@ G4bool G4Polyhedra::Reset()
|
||||
original_parameters->Rmax,
|
||||
original_parameters->Z_values,
|
||||
original_parameters->Num_z_planes );
|
||||
//
|
||||
// Calculate conversion factor
|
||||
//
|
||||
G4double phiTotal = original_parameters->Opening_angle;
|
||||
if ( (phiTotal <=0) || (phiTotal >= twopi*(1-DBL_EPSILON)) )
|
||||
phiTotal = twopi;
|
||||
G4double convertRad = std::cos(0.5*phiTotal/original_parameters->numSide);
|
||||
rz->ScaleA( 1/convertRad );
|
||||
|
||||
Create( original_parameters->Start_angle, phiTotal,
|
||||
Create( original_parameters->Start_angle,
|
||||
original_parameters->Opening_angle,
|
||||
original_parameters->numSide, rz );
|
||||
delete rz;
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4QuadrangularFacet.cc,v 1.3 2006/06/29 18:48:51 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-08-02 $
|
||||
// $Id: G4QuadrangularFacet.cc,v 1.5 2007/02/15 17:04:10 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-08-03 $
|
||||
//
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
//
|
||||
@@ -48,6 +48,7 @@
|
||||
|
||||
#include "G4QuadrangularFacet.hh"
|
||||
#include "globals.hh"
|
||||
#include "Randomize.hh"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -255,8 +256,9 @@ G4bool G4QuadrangularFacet::Intersect (const G4ThreeVector &p,
|
||||
G4bool intersect =
|
||||
facet1->Intersect(p,v,outgoing,distance,distFromSurface,normal);
|
||||
if (!intersect)
|
||||
intersect =
|
||||
facet2->Intersect(p,v,outgoing,distance,distFromSurface,normal);
|
||||
{
|
||||
intersect = facet2->Intersect(p,v,outgoing,distance,distFromSurface,normal);
|
||||
}
|
||||
|
||||
if (!intersect)
|
||||
{
|
||||
@@ -267,3 +269,38 @@ G4bool G4QuadrangularFacet::Intersect (const G4ThreeVector &p,
|
||||
|
||||
return intersect;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GetPointOnFace
|
||||
//
|
||||
// Auxiliary method for get a random point on surface
|
||||
|
||||
G4ThreeVector G4QuadrangularFacet::GetPointOnFace() const
|
||||
{
|
||||
G4ThreeVector pr;
|
||||
|
||||
if ( G4UniformRand() < 0.5 )
|
||||
{
|
||||
pr = facet1->GetPointOnFace();
|
||||
}
|
||||
else
|
||||
{
|
||||
pr = facet2->GetPointOnFace();
|
||||
}
|
||||
|
||||
return pr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GetArea
|
||||
//
|
||||
// Auxiliary method for returning the surface area
|
||||
|
||||
G4double G4QuadrangularFacet::GetArea()
|
||||
{
|
||||
if (!area) { area = facet1->GetArea() + facet2->GetArea(); }
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4TessellatedSolid.cc,v 1.5 2006/10/20 13:45:21 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-08-02 $
|
||||
// $Id: G4TessellatedSolid.cc,v 1.9 2007/02/12 12:08:33 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-08-03 $
|
||||
//
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
//
|
||||
@@ -54,6 +54,7 @@
|
||||
#include "G4TessellatedSolid.hh"
|
||||
#include "G4PolyhedronArbitrary.hh"
|
||||
#include "globals.hh"
|
||||
#include "Randomize.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -123,14 +124,26 @@ G4TessellatedSolid::~G4TessellatedSolid ()
|
||||
DeleteObjects ();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Define copy constructor.
|
||||
//
|
||||
G4TessellatedSolid::G4TessellatedSolid (const G4TessellatedSolid &s)
|
||||
: G4VSolid(s)
|
||||
{
|
||||
if (&s == this) { return; }
|
||||
|
||||
CopyObjects (s);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Define assignment operator.
|
||||
//
|
||||
const G4TessellatedSolid &G4TessellatedSolid::operator=
|
||||
(const G4TessellatedSolid &s)
|
||||
const G4TessellatedSolid &
|
||||
G4TessellatedSolid::operator= (const G4TessellatedSolid &s)
|
||||
{
|
||||
if (&s == this) return *this;
|
||||
if (&s == this) { return *this; }
|
||||
|
||||
DeleteObjects ();
|
||||
CopyObjects (s);
|
||||
@@ -142,8 +155,10 @@ const G4TessellatedSolid &G4TessellatedSolid::operator=
|
||||
//
|
||||
void G4TessellatedSolid::DeleteObjects ()
|
||||
{
|
||||
for (std::vector<G4VFacet *>::iterator f=facets.begin();
|
||||
f!=facets.end(); f++) delete *f;
|
||||
for (std::vector<G4VFacet *>::iterator f=facets.begin(); f!=facets.end(); f++)
|
||||
{
|
||||
delete *f;
|
||||
}
|
||||
facets.clear();
|
||||
}
|
||||
|
||||
@@ -321,6 +336,16 @@ size_t G4TessellatedSolid::GetNumberOfFacets () const
|
||||
//
|
||||
EInside G4TessellatedSolid::Inside (const G4ThreeVector &p) const
|
||||
{
|
||||
if ( p.x() < xMinExtent - kCarTolerance ||
|
||||
p.x() > xMaxExtent + kCarTolerance ||
|
||||
p.y() < yMinExtent - kCarTolerance ||
|
||||
p.y() > yMaxExtent + kCarTolerance ||
|
||||
p.z() < zMinExtent - kCarTolerance ||
|
||||
p.z() > zMaxExtent + kCarTolerance )
|
||||
{
|
||||
return kOutside;
|
||||
}
|
||||
|
||||
G4double minDist = kInfinity;
|
||||
G4double dist = 0.0;
|
||||
typedef std::multimap< G4double, FacetCI, std::less<G4double> > DistMapType;
|
||||
@@ -372,6 +397,7 @@ G4ThreeVector G4TessellatedSolid::SurfaceNormal (const G4ThreeVector &p) const
|
||||
FacetCI minFacet;
|
||||
G4double minDist = kInfinity;
|
||||
G4double dist = 0.0;
|
||||
G4ThreeVector normal;
|
||||
|
||||
for (FacetCI f=facets.begin(); f!=facets.end(); f++)
|
||||
{
|
||||
@@ -383,7 +409,23 @@ G4ThreeVector G4TessellatedSolid::SurfaceNormal (const G4ThreeVector &p) const
|
||||
}
|
||||
}
|
||||
|
||||
return (*minFacet)->GetSurfaceNormal();
|
||||
if (minDist != kInfinity)
|
||||
{
|
||||
normal = (*minFacet)->GetSurfaceNormal();
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
G4cout << "WARNING - G4TessellatedSolid::SurfaceNormal(p)" << G4endl
|
||||
<< " No facets found for point: " << p << " !" << G4endl
|
||||
<< " Returning approximated value for normal." << G4endl;
|
||||
G4Exception("G4TessellatedSolid::SurfaceNormal(p)", "Notification",
|
||||
JustWarning, "Point p is not on surface !?" );
|
||||
#endif
|
||||
normal = (p.z()>0 ? G4ThreeVector(0,0,1) : G4ThreeVector(0,0,-1));
|
||||
}
|
||||
|
||||
return normal;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -747,7 +789,21 @@ G4double G4TessellatedSolid::GetCubicVolume ()
|
||||
//
|
||||
G4double G4TessellatedSolid::GetSurfaceArea ()
|
||||
{
|
||||
if(surfaceArea != 0.) {;}
|
||||
else { surfaceArea = G4VSolid::GetSurfaceArea(); }
|
||||
if(surfaceArea != 0.) { return surfaceArea; }
|
||||
|
||||
for (FacetI f=facets.begin(); f!=facets.end(); f++)
|
||||
{
|
||||
surfaceArea += (*f)->GetArea();
|
||||
}
|
||||
return surfaceArea;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
G4ThreeVector G4TessellatedSolid::GetPointOnSurface() const
|
||||
{
|
||||
// Select randomly a facet and return a random point on it
|
||||
|
||||
G4int i = CLHEP::RandFlat::shootInt(facets.size());
|
||||
return facets[i]->GetPointOnFace();
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4TriangularFacet.cc,v 1.5 2006/06/29 18:49:02 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-08-02 $
|
||||
// $Id: G4TriangularFacet.cc,v 1.7 2007/02/15 17:03:49 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-08-03 $
|
||||
//
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
//
|
||||
@@ -48,6 +48,7 @@
|
||||
|
||||
#include "G4TriangularFacet.hh"
|
||||
#include "globals.hh"
|
||||
#include "Randomize.hh"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -451,8 +452,8 @@ G4bool G4TriangularFacet::Intersect (const G4ThreeVector &p,
|
||||
|
||||
if (intersect)
|
||||
{
|
||||
if (dist > kCarTolerance * 0.5) distance = dist;
|
||||
else dist = 0.0;
|
||||
if (dist < kCarTolerance * 0.5) { dist = 0.0; }
|
||||
distance = dist;
|
||||
distFromSurface = dist * normalComp;
|
||||
normal = surfaceNormal;
|
||||
}
|
||||
@@ -465,3 +466,42 @@ G4bool G4TriangularFacet::Intersect (const G4ThreeVector &p,
|
||||
|
||||
return intersect;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GetPointOnFace
|
||||
//
|
||||
// Auxiliary method for get a random point on surface
|
||||
|
||||
G4ThreeVector G4TriangularFacet::GetPointOnFace() const
|
||||
{
|
||||
G4double lambda1,lambda2;
|
||||
G4ThreeVector v, w;
|
||||
|
||||
v = P[1] - P[0];
|
||||
w = P[0] - P0;
|
||||
|
||||
lambda1 = CLHEP::RandFlat::shoot(0.,1.);
|
||||
lambda2 = CLHEP::RandFlat::shoot(0.,lambda1);
|
||||
|
||||
return (P0 + lambda1*w + lambda2*v);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GetArea
|
||||
//
|
||||
// Auxiliary method for returning the surface area
|
||||
|
||||
G4double G4TriangularFacet::GetArea()
|
||||
{
|
||||
if (area) { return area; }
|
||||
|
||||
G4ThreeVector v, w;
|
||||
|
||||
v = P[1] - P[0];
|
||||
w = P[0] - P0;
|
||||
area = 0.5*(v.cross(w)).mag();
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4VFacet.cc,v 1.3 2006/06/29 18:49:31 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-08-02 $
|
||||
// $Id: G4VFacet.cc,v 1.4 2007/02/12 09:34:45 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-08-03 $
|
||||
//
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
//
|
||||
@@ -49,6 +49,67 @@
|
||||
#include "G4VFacet.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
G4VFacet::G4VFacet ()
|
||||
{
|
||||
dirTolerance = 1.0E-14;
|
||||
|
||||
P.clear();
|
||||
E.clear();
|
||||
|
||||
centroid = G4ThreeVector(0.0,0.0,0.0);
|
||||
radius = 0.0;
|
||||
radiusSqr = 0.0;
|
||||
area = 0.0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
G4VFacet::~G4VFacet ()
|
||||
{
|
||||
P.clear();
|
||||
E.clear();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
G4bool G4VFacet::operator== (const G4VFacet &right) const
|
||||
{
|
||||
G4double tolerance = kCarTolerance*kCarTolerance/4.0;
|
||||
if (nVertices != right.GetNumberOfVertices())
|
||||
{ return false; }
|
||||
else if ((centroid-right.GetCentroid()).mag2() > tolerance)
|
||||
{ return false; }
|
||||
else if (std::fabs((right.GetSurfaceNormal()).dot(surfaceNormal)) < 0.9999999999)
|
||||
{ return false; }
|
||||
|
||||
G4bool coincident = true;
|
||||
size_t i = 0;
|
||||
do
|
||||
{
|
||||
coincident = false;
|
||||
size_t j = 0;
|
||||
do
|
||||
{
|
||||
coincident = (GetVertex(i)-right.GetVertex(j)).mag2() < tolerance;
|
||||
} while (!coincident && j++ < nVertices);
|
||||
} while (coincident && i++ < nVertices);
|
||||
|
||||
return coincident;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
void G4VFacet::ApplyTranslation(const G4ThreeVector v)
|
||||
{
|
||||
P0 += v;
|
||||
for (G4ThreeVectorList::iterator it=P.begin(); it!=P.end(); it++)
|
||||
{
|
||||
(*it) += v;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
std::ostream &G4VFacet::StreamInfo(std::ostream &os) const
|
||||
@@ -71,3 +132,31 @@ std::ostream &G4VFacet::StreamInfo(std::ostream &os) const
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
G4VFacet* G4VFacet::GetClone ()
|
||||
{return 0;}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
G4double G4VFacet::Distance (const G4ThreeVector&, const G4double)
|
||||
{return kInfinity;}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
G4double G4VFacet::Distance (const G4ThreeVector&, const G4double,
|
||||
const G4bool)
|
||||
{return kInfinity;}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
G4double G4VFacet::Extent (const G4ThreeVector)
|
||||
{return 0.0;}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
G4bool G4VFacet::Intersect (const G4ThreeVector&, const G4ThreeVector &,
|
||||
const G4bool , G4double &, G4double &,
|
||||
G4ThreeVector &)
|
||||
{return false;}
|
||||
|
||||
Reference in New Issue
Block a user