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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /geometry/solids/CSG/src/G4UOrb.cc (Version 11.3.0) and /geometry/solids/CSG/src/G4UOrb.cc (Version 10.4.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // Implementation for G4UOrb wrapper class     <<  26 // $Id:$
 27 //                                                 27 //
 28 // 30.10.13 G.Cosmo, CERN/PH                   <<  28 // 
                                                   >>  29 // Implementation for G4UOrb wrapper class
 29 // -------------------------------------------     30 // --------------------------------------------------------------------
 30                                                    31 
 31 #include "G4Orb.hh"                                32 #include "G4Orb.hh"
 32 #include "G4UOrb.hh"                               33 #include "G4UOrb.hh"
 33                                                    34 
 34 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G     35 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
 35                                                    36 
 36 #include "G4TwoVector.hh"                          37 #include "G4TwoVector.hh"
 37 #include "G4AffineTransform.hh"                    38 #include "G4AffineTransform.hh"
 38 #include "G4GeometryTolerance.hh"                  39 #include "G4GeometryTolerance.hh"
 39 #include "G4BoundingEnvelope.hh"                   40 #include "G4BoundingEnvelope.hh"
 40                                                    41 
 41 #include "G4VPVParameterisation.hh"                42 #include "G4VPVParameterisation.hh"
 42 #include "G4PhysicalConstants.hh"                  43 #include "G4PhysicalConstants.hh"
 43                                                    44 
 44 using namespace CLHEP;                             45 using namespace CLHEP;
 45                                                    46 
 46 //////////////////////////////////////////////     47 ////////////////////////////////////////////////////////////////////////
 47 //                                                 48 //
 48 // constructor - check positive radius             49 // constructor - check positive radius
 49 //                                                 50 //             
 50                                                    51 
 51 G4UOrb::G4UOrb( const G4String& pName, G4doubl     52 G4UOrb::G4UOrb( const G4String& pName, G4double pRmax )
 52   : Base_t(pName, pRmax)                           53   : Base_t(pName, pRmax)
 53 {                                                  54 {
 54 }                                                  55 }
 55                                                    56 
 56 //////////////////////////////////////////////     57 ///////////////////////////////////////////////////////////////////////
 57 //                                                 58 //
 58 // Fake default constructor - sets only member     59 // Fake default constructor - sets only member data and allocates memory
 59 //                            for usage restri     60 //                            for usage restricted to object persistency.
 60 //                                                 61 //
 61 G4UOrb::G4UOrb( __void__& a )                      62 G4UOrb::G4UOrb( __void__& a )
 62   : Base_t(a)                                      63   : Base_t(a)
 63 {                                                  64 {
 64 }                                                  65 }
 65                                                    66 
 66 //////////////////////////////////////////////     67 /////////////////////////////////////////////////////////////////////
 67 //                                                 68 //
 68 // Destructor                                      69 // Destructor
 69                                                    70 
 70 G4UOrb::~G4UOrb() = default;                   <<  71 G4UOrb::~G4UOrb()
                                                   >>  72 {
                                                   >>  73 }
 71                                                    74 
 72 //////////////////////////////////////////////     75 //////////////////////////////////////////////////////////////////////////
 73 //                                                 76 //
 74 // Copy constructor                                77 // Copy constructor
 75                                                    78 
 76 G4UOrb::G4UOrb(const G4UOrb& rhs)                  79 G4UOrb::G4UOrb(const G4UOrb& rhs)
 77   : Base_t(rhs)                                    80   : Base_t(rhs)
 78 {                                                  81 {
 79 }                                                  82 }
 80                                                    83 
 81 //////////////////////////////////////////////     84 //////////////////////////////////////////////////////////////////////////
 82 //                                                 85 //
 83 // Assignment operator                             86 // Assignment operator
 84                                                    87 
 85 G4UOrb& G4UOrb::operator = (const G4UOrb& rhs)     88 G4UOrb& G4UOrb::operator = (const G4UOrb& rhs) 
 86 {                                                  89 {
 87    // Check assignment to self                     90    // Check assignment to self
 88    //                                              91    //
 89    if (this == &rhs)  { return *this; }            92    if (this == &rhs)  { return *this; }
 90                                                    93 
 91    // Copy base class data                         94    // Copy base class data
 92    //                                              95    //
 93    Base_t::operator=(rhs);                         96    Base_t::operator=(rhs);
 94                                                    97 
 95    return *this;                                   98    return *this;
 96 }                                                  99 }
 97                                                   100 
 98 //////////////////////////////////////////////    101 //////////////////////////////////////////////////////////////////////////
 99 //                                                102 //
100 // Accessors & modifiers                          103 // Accessors & modifiers
101                                                   104 
102 G4double G4UOrb::GetRadius() const                105 G4double G4UOrb::GetRadius() const
103 {                                                 106 {
104   return Base_t::GetRadius();                     107   return Base_t::GetRadius();
105 }                                                 108 }
106                                                   109 
107 void G4UOrb::SetRadius(G4double newRmax)          110 void G4UOrb::SetRadius(G4double newRmax)
108 {                                                 111 {
109   Base_t::SetRadius(newRmax);                     112   Base_t::SetRadius(newRmax);
110   fRebuildPolyhedron = true;                      113   fRebuildPolyhedron = true;
111 }                                                 114 }
112                                                   115 
113 G4double G4UOrb::GetRadialTolerance() const       116 G4double G4UOrb::GetRadialTolerance() const
114 {                                                 117 {
115   return Base_t::GetRadialTolerance();            118   return Base_t::GetRadialTolerance();
116 }                                                 119 }
117                                                   120 
118 //////////////////////////////////////////////    121 //////////////////////////////////////////////////////////////////////////
119 //                                                122 //
120 // Dispatch to parameterisation for replicatio    123 // Dispatch to parameterisation for replication mechanism dimension
121 // computation & modification.                    124 // computation & modification.
122                                                   125 
123 void G4UOrb::ComputeDimensions(       G4VPVPar    126 void G4UOrb::ComputeDimensions(       G4VPVParameterisation* p,
124                                const G4int n,     127                                const G4int n,
125                                const G4VPhysic    128                                const G4VPhysicalVolume* pRep )
126 {                                                 129 {
127   p->ComputeDimensions(*(G4Orb*)this,n,pRep);     130   p->ComputeDimensions(*(G4Orb*)this,n,pRep);
128 }                                                 131 }
129                                                   132 
130 //////////////////////////////////////////////    133 //////////////////////////////////////////////////////////////////////////
131 //                                                134 //
132 // Make a clone of the object                     135 // Make a clone of the object
133                                                   136 
134 G4VSolid* G4UOrb::Clone() const                   137 G4VSolid* G4UOrb::Clone() const
135 {                                                 138 {
136   return new G4UOrb(*this);                       139   return new G4UOrb(*this);
137 }                                                 140 }
138                                                   141 
139 //////////////////////////////////////////////    142 //////////////////////////////////////////////////////////////////////////
140 //                                                143 //
141 // Get bounding box                               144 // Get bounding box
142                                                   145 
143 void G4UOrb::BoundingLimits(G4ThreeVector& pMi    146 void G4UOrb::BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const
144 {                                                 147 {
145   G4double radius = GetRadius();                  148   G4double radius = GetRadius();
146   pMin.set(-radius,-radius,-radius);              149   pMin.set(-radius,-radius,-radius);
147   pMax.set( radius, radius, radius);              150   pMax.set( radius, radius, radius);
148                                                   151 
149   // Check correctness of the bounding box        152   // Check correctness of the bounding box
150   //                                              153   //
151   if (pMin.x() >= pMax.x() || pMin.y() >= pMax    154   if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
152   {                                               155   {
153     std::ostringstream message;                   156     std::ostringstream message;
154     message << "Bad bounding box (min >= max)     157     message << "Bad bounding box (min >= max) for solid: "
155             << GetName() << " !"                  158             << GetName() << " !"
156             << "\npMin = " << pMin                159             << "\npMin = " << pMin
157             << "\npMax = " << pMax;               160             << "\npMax = " << pMax;
158     G4Exception("G4UOrb::BoundingLimits()", "G    161     G4Exception("G4UOrb::BoundingLimits()", "GeomMgt0001",
159                 JustWarning, message);            162                 JustWarning, message);
160     StreamInfo(G4cout);                           163     StreamInfo(G4cout);
161   }                                               164   }
162 }                                                 165 }
163                                                   166 
164 //////////////////////////////////////////////    167 //////////////////////////////////////////////////////////////////////////
165 //                                                168 //
166 // Calculate extent under transform and specif    169 // Calculate extent under transform and specified limit
167                                                   170 
168 G4bool                                            171 G4bool
169 G4UOrb::CalculateExtent(const EAxis pAxis,        172 G4UOrb::CalculateExtent(const EAxis pAxis,
170                         const G4VoxelLimits& p    173                         const G4VoxelLimits& pVoxelLimit,
171                         const G4AffineTransfor    174                         const G4AffineTransform& pTransform,
172                         G4double& pMin, G4doub    175                         G4double& pMin, G4double& pMax) const
173 {                                                 176 {
174   G4ThreeVector bmin, bmax;                       177   G4ThreeVector bmin, bmax;
175   G4bool exist;                                   178   G4bool exist;
176                                                   179 
177   // Get bounding box                             180   // Get bounding box
178   BoundingLimits(bmin,bmax);                      181   BoundingLimits(bmin,bmax);
179                                                   182 
180   // Check bounding box                           183   // Check bounding box
181   G4BoundingEnvelope bbox(bmin,bmax);             184   G4BoundingEnvelope bbox(bmin,bmax);
182 #ifdef G4BBOX_EXTENT                              185 #ifdef G4BBOX_EXTENT
183   if (true) return bbox.CalculateExtent(pAxis,    186   if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
184 #endif                                            187 #endif
185   if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVox    188   if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
186   {                                               189   {
187     return exist = pMin < pMax;                << 190     return exist = (pMin < pMax) ? true : false;
188   }                                               191   }
189                                                   192 
190   // Find bounding envelope and calculate exte    193   // Find bounding envelope and calculate extent
191   //                                              194   //
192   static const G4int NTHETA = 8;  // number of    195   static const G4int NTHETA = 8;  // number of steps along Theta
193   static const G4int NPHI   = 16; // number of    196   static const G4int NPHI   = 16; // number of steps along Phi
194   static const G4double sinHalfTheta = std::si    197   static const G4double sinHalfTheta = std::sin(halfpi/NTHETA);
195   static const G4double cosHalfTheta = std::co    198   static const G4double cosHalfTheta = std::cos(halfpi/NTHETA);
196   static const G4double sinHalfPhi   = std::si    199   static const G4double sinHalfPhi   = std::sin(pi/NPHI);
197   static const G4double cosHalfPhi   = std::co    200   static const G4double cosHalfPhi   = std::cos(pi/NPHI);
198   static const G4double sinStepTheta = 2.*sinH    201   static const G4double sinStepTheta = 2.*sinHalfTheta*cosHalfTheta;
199   static const G4double cosStepTheta = 1. - 2.    202   static const G4double cosStepTheta = 1. - 2.*sinHalfTheta*sinHalfTheta;
200   static const G4double sinStepPhi   = 2.*sinH    203   static const G4double sinStepPhi   = 2.*sinHalfPhi*cosHalfPhi;
201   static const G4double cosStepPhi   = 1. - 2.    204   static const G4double cosStepPhi   = 1. - 2.*sinHalfPhi*sinHalfPhi;
202                                                   205 
203   G4double radius = GetRadius();                  206   G4double radius = GetRadius();
204   G4double rtheta = radius/cosHalfTheta;          207   G4double rtheta = radius/cosHalfTheta;
205   G4double rphi   = rtheta/cosHalfPhi;            208   G4double rphi   = rtheta/cosHalfPhi;
206                                                   209 
207   // set reference circle                         210   // set reference circle
208   G4TwoVector xy[NPHI];                           211   G4TwoVector xy[NPHI];
209   G4double sinCurPhi = sinHalfPhi;                212   G4double sinCurPhi = sinHalfPhi;
210   G4double cosCurPhi = cosHalfPhi;                213   G4double cosCurPhi = cosHalfPhi;
211   for (auto & k : xy)                          << 214   for (G4int k=0; k<NPHI; ++k)
212   {                                               215   {
213     k.set(cosCurPhi,sinCurPhi);                << 216     xy[k].set(cosCurPhi,sinCurPhi);
214     G4double sinTmpPhi = sinCurPhi;               217     G4double sinTmpPhi = sinCurPhi;
215     sinCurPhi = sinCurPhi*cosStepPhi + cosCurP    218     sinCurPhi = sinCurPhi*cosStepPhi + cosCurPhi*sinStepPhi;
216     cosCurPhi = cosCurPhi*cosStepPhi - sinTmpP    219     cosCurPhi = cosCurPhi*cosStepPhi - sinTmpPhi*sinStepPhi;
217   }                                               220   }
218                                                   221   
219   // set bounding circles                         222   // set bounding circles
220   G4ThreeVectorList circles[NTHETA];              223   G4ThreeVectorList circles[NTHETA];
221   for (auto & circle : circles) circle.resize( << 224   for (G4int i=0; i<NTHETA; ++i) circles[i].resize(NPHI);
222                                                   225 
223   G4double sinCurTheta = sinHalfTheta;            226   G4double sinCurTheta = sinHalfTheta;
224   G4double cosCurTheta = cosHalfTheta;            227   G4double cosCurTheta = cosHalfTheta;
225   for (auto & circle : circles)                << 228   for (G4int i=0; i<NTHETA; ++i)
226   {                                               229   {
227     G4double z = rtheta*cosCurTheta;              230     G4double z = rtheta*cosCurTheta;
228     G4double rho = rphi*sinCurTheta;              231     G4double rho = rphi*sinCurTheta;
229     for (G4int k=0; k<NPHI; ++k)                  232     for (G4int k=0; k<NPHI; ++k)
230     {                                             233     {
231       circle[k].set(rho*xy[k].x(),rho*xy[k].y( << 234       circles[i][k].set(rho*xy[k].x(),rho*xy[k].y(),z);
232     }                                             235     }
233     G4double sinTmpTheta = sinCurTheta;           236     G4double sinTmpTheta = sinCurTheta;
234     sinCurTheta = sinCurTheta*cosStepTheta + c    237     sinCurTheta = sinCurTheta*cosStepTheta + cosCurTheta*sinStepTheta;
235     cosCurTheta = cosCurTheta*cosStepTheta - s    238     cosCurTheta = cosCurTheta*cosStepTheta - sinTmpTheta*sinStepTheta;
236   }                                               239   }
237                                                   240 
238   // set envelope and calculate extent            241   // set envelope and calculate extent
239   std::vector<const G4ThreeVectorList *> polyg    242   std::vector<const G4ThreeVectorList *> polygons;
240   polygons.resize(NTHETA);                        243   polygons.resize(NTHETA);
241   for (G4int i=0; i<NTHETA; ++i) polygons[i] =    244   for (G4int i=0; i<NTHETA; ++i) polygons[i] = &circles[i];
242                                                   245 
243   G4BoundingEnvelope benv(bmin,bmax,polygons);    246   G4BoundingEnvelope benv(bmin,bmax,polygons);
244   exist = benv.CalculateExtent(pAxis,pVoxelLim    247   exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
245   return exist;                                   248   return exist;
246 }                                                 249 }
247                                                   250 
248 //////////////////////////////////////////////    251 //////////////////////////////////////////////////////////////////////////
249 //                                                252 //
250 // Create polyhedron for visualization            253 // Create polyhedron for visualization
251                                                   254 
252 G4Polyhedron* G4UOrb::CreatePolyhedron() const    255 G4Polyhedron* G4UOrb::CreatePolyhedron() const
253 {                                                 256 {
254   return new G4PolyhedronSphere(0., GetRadius(    257   return new G4PolyhedronSphere(0., GetRadius(), 0., twopi, 0., pi);
255 }                                                 258 }
256                                                   259 
257 #endif  // G4GEOM_USE_USOLIDS                     260 #endif  // G4GEOM_USE_USOLIDS
258                                                   261