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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/G4UTrd.cc (Version 11.3.0) and /geometry/solids/CSG/src/G4UTrd.cc (Version 10.7.p2)


  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 G4UTrd wrapper class         26 // Implementation for G4UTrd wrapper class
 27 //                                                 27 //
 28 // 13.09.13 G.Cosmo, CERN/PH                       28 // 13.09.13 G.Cosmo, CERN/PH
 29 // -------------------------------------------     29 // --------------------------------------------------------------------
 30                                                    30 
 31 #include "G4Trd.hh"                                31 #include "G4Trd.hh"
 32 #include "G4UTrd.hh"                               32 #include "G4UTrd.hh"
 33                                                    33 
 34 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G     34 #if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
 35                                                    35 
 36 #include "G4AffineTransform.hh"                    36 #include "G4AffineTransform.hh"
 37 #include "G4VPVParameterisation.hh"                37 #include "G4VPVParameterisation.hh"
 38 #include "G4BoundingEnvelope.hh"                   38 #include "G4BoundingEnvelope.hh"
 39                                                    39 
 40 using namespace CLHEP;                             40 using namespace CLHEP;
 41                                                    41 
 42 //////////////////////////////////////////////     42 /////////////////////////////////////////////////////////////////////////
 43 //                                                 43 //
 44 // Constructor - check & set half widths           44 // Constructor - check & set half widths
 45 //                                                 45 //
 46 G4UTrd::G4UTrd(const G4String& pName,              46 G4UTrd::G4UTrd(const G4String& pName,
 47                      G4double pdx1,  G4double      47                      G4double pdx1,  G4double pdx2,
 48                      G4double pdy1,  G4double      48                      G4double pdy1,  G4double pdy2,
 49                      G4double pdz)                 49                      G4double pdz)
 50   : Base_t(pName, pdx1, pdx2, pdy1, pdy2, pdz)     50   : Base_t(pName, pdx1, pdx2, pdy1, pdy2, pdz)
 51 {                                                  51 {
 52 }                                                  52 }
 53                                                    53 
 54 //////////////////////////////////////////////     54 ///////////////////////////////////////////////////////////////////////
 55 //                                                 55 //
 56 // Fake default constructor - sets only member     56 // Fake default constructor - sets only member data and allocates memory
 57 //                            for usage restri     57 //                            for usage restricted to object persistency.
 58 //                                                 58 //
 59 G4UTrd::G4UTrd( __void__& a )                      59 G4UTrd::G4UTrd( __void__& a )
 60   : Base_t(a)                                      60   : Base_t(a)
 61 {                                                  61 {
 62 }                                                  62 }
 63                                                    63 
 64 //////////////////////////////////////////////     64 //////////////////////////////////////////////////////////////////////////
 65 //                                                 65 //
 66 // Destructor                                      66 // Destructor
 67 //                                                 67 //
 68 G4UTrd::~G4UTrd() = default;                   <<  68 G4UTrd::~G4UTrd()
                                                   >>  69 {
                                                   >>  70 }
 69                                                    71 
 70 //////////////////////////////////////////////     72 //////////////////////////////////////////////////////////////////////////
 71 //                                                 73 //
 72 // Copy constructor                                74 // Copy constructor
 73 //                                                 75 //
 74 G4UTrd::G4UTrd(const G4UTrd& rhs)                  76 G4UTrd::G4UTrd(const G4UTrd& rhs)
 75   : Base_t(rhs)                                    77   : Base_t(rhs)
 76 {                                                  78 {
 77 }                                                  79 }
 78                                                    80 
 79 //////////////////////////////////////////////     81 //////////////////////////////////////////////////////////////////////////
 80 //                                                 82 //
 81 // Assignment operator                             83 // Assignment operator
 82 //                                                 84 //
 83 G4UTrd& G4UTrd::operator = (const G4UTrd& rhs)     85 G4UTrd& G4UTrd::operator = (const G4UTrd& rhs) 
 84 {                                                  86 {
 85    // Check assignment to self                     87    // Check assignment to self
 86    //                                              88    //
 87    if (this == &rhs)  { return *this; }            89    if (this == &rhs)  { return *this; }
 88                                                    90 
 89    // Copy base class data                         91    // Copy base class data
 90    //                                              92    //
 91    Base_t::operator=(rhs);                         93    Base_t::operator=(rhs);
 92                                                    94 
 93    return *this;                                   95    return *this;
 94 }                                                  96 }
 95                                                    97 
 96 //////////////////////////////////////////////     98 //////////////////////////////////////////////////////////////////////////
 97 //                                                 99 //
 98 // Accessors & modifiers                          100 // Accessors & modifiers
 99                                                   101 
100 G4double G4UTrd::GetXHalfLength1() const          102 G4double G4UTrd::GetXHalfLength1() const
101 {                                                 103 {
102   return dx1();                                   104   return dx1();
103 }                                                 105 }
104 G4double G4UTrd::GetXHalfLength2() const          106 G4double G4UTrd::GetXHalfLength2() const
105 {                                                 107 {
106   return dx2();                                   108   return dx2();
107 }                                                 109 }
108 G4double G4UTrd::GetYHalfLength1() const          110 G4double G4UTrd::GetYHalfLength1() const
109 {                                                 111 {
110   return dy1();                                   112   return dy1();
111 }                                                 113 }
112 G4double G4UTrd::GetYHalfLength2() const          114 G4double G4UTrd::GetYHalfLength2() const
113 {                                                 115 {
114   return dy2();                                   116   return dy2();
115 }                                                 117 }
116 G4double G4UTrd::GetZHalfLength()  const          118 G4double G4UTrd::GetZHalfLength()  const
117 {                                                 119 {
118   return dz();                                    120   return dz();
119 }                                                 121 }
120                                                   122 
121 void G4UTrd::SetXHalfLength1(G4double val)        123 void G4UTrd::SetXHalfLength1(G4double val)
122 {                                                 124 {
123   Base_t::SetXHalfLength1(val);                   125   Base_t::SetXHalfLength1(val);
124   fRebuildPolyhedron = true;                      126   fRebuildPolyhedron = true;
125 }                                                 127 }
126 void G4UTrd::SetXHalfLength2(G4double val)        128 void G4UTrd::SetXHalfLength2(G4double val)
127 {                                                 129 {
128   Base_t::SetXHalfLength2(val);                   130   Base_t::SetXHalfLength2(val);
129   fRebuildPolyhedron = true;                      131   fRebuildPolyhedron = true;
130 }                                                 132 }
131 void G4UTrd::SetYHalfLength1(G4double val)        133 void G4UTrd::SetYHalfLength1(G4double val)
132 {                                                 134 {
133   Base_t::SetYHalfLength1(val);                   135   Base_t::SetYHalfLength1(val);
134   fRebuildPolyhedron = true;                      136   fRebuildPolyhedron = true;
135 }                                                 137 }
136 void G4UTrd::SetYHalfLength2(G4double val)        138 void G4UTrd::SetYHalfLength2(G4double val)
137 {                                                 139 {
138   Base_t::SetYHalfLength2(val);                   140   Base_t::SetYHalfLength2(val);
139   fRebuildPolyhedron = true;                      141   fRebuildPolyhedron = true;
140 }                                                 142 }
141 void G4UTrd::SetZHalfLength(G4double val)         143 void G4UTrd::SetZHalfLength(G4double val)
142 {                                                 144 {
143   Base_t::SetZHalfLength(val);                    145   Base_t::SetZHalfLength(val);
144   fRebuildPolyhedron = true;                      146   fRebuildPolyhedron = true;
145 }                                                 147 }
146 void G4UTrd::SetAllParameters(G4double pdx1, G    148 void G4UTrd::SetAllParameters(G4double pdx1, G4double pdx2,
147                               G4double pdy1, G    149                               G4double pdy1, G4double pdy2, G4double pdz)
148 {                                                 150 {
149   Base_t::SetAllParameters(pdx1, pdx2, pdy1, p    151   Base_t::SetAllParameters(pdx1, pdx2, pdy1, pdy2, pdz);
150   fRebuildPolyhedron = true;                      152   fRebuildPolyhedron = true;
151 }                                                 153 }
152                                                   154 
153 //////////////////////////////////////////////    155 /////////////////////////////////////////////////////////////////////////
154 //                                                156 //
155 // Dispatch to parameterisation for replicatio    157 // Dispatch to parameterisation for replication mechanism dimension
156 // computation & modification.                    158 // computation & modification.
157 //                                                159 //
158 void G4UTrd::ComputeDimensions(      G4VPVPara    160 void G4UTrd::ComputeDimensions(      G4VPVParameterisation* p,
159                                const G4int n,     161                                const G4int n,
160                                const G4VPhysic    162                                const G4VPhysicalVolume* pRep)
161 {                                                 163 {
162   p->ComputeDimensions(*(G4Trd*)this,n,pRep);     164   p->ComputeDimensions(*(G4Trd*)this,n,pRep);
163 }                                                 165 }
164                                                   166 
165 //////////////////////////////////////////////    167 //////////////////////////////////////////////////////////////////////////
166 //                                                168 //
167 // Make a clone of the object                     169 // Make a clone of the object
168                                                   170 
169 G4VSolid* G4UTrd::Clone() const                   171 G4VSolid* G4UTrd::Clone() const
170 {                                                 172 {
171   return new G4UTrd(*this);                       173   return new G4UTrd(*this);
172 }                                                 174 }
173                                                   175 
174 //////////////////////////////////////////////    176 //////////////////////////////////////////////////////////////////////////
175 //                                                177 //
176 // Get bounding box                               178 // Get bounding box
177                                                   179 
178 void G4UTrd::BoundingLimits(G4ThreeVector& pMi    180 void G4UTrd::BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const
179 {                                                 181 {
180   static G4bool checkBBox = true;                 182   static G4bool checkBBox = true;
181                                                   183 
182   G4double dx1 = GetXHalfLength1();               184   G4double dx1 = GetXHalfLength1();
183   G4double dx2 = GetXHalfLength2();               185   G4double dx2 = GetXHalfLength2();
184   G4double dy1 = GetYHalfLength1();               186   G4double dy1 = GetYHalfLength1();
185   G4double dy2 = GetYHalfLength2();               187   G4double dy2 = GetYHalfLength2();
186   G4double dz  = GetZHalfLength();                188   G4double dz  = GetZHalfLength();
187                                                   189 
188   G4double xmax = std::max(dx1,dx2);              190   G4double xmax = std::max(dx1,dx2);
189   G4double ymax = std::max(dy1,dy2);              191   G4double ymax = std::max(dy1,dy2);
190   pMin.set(-xmax,-ymax,-dz);                      192   pMin.set(-xmax,-ymax,-dz);
191   pMax.set( xmax, ymax, dz);                      193   pMax.set( xmax, ymax, dz);
192                                                   194 
193   // Check correctness of the bounding box        195   // Check correctness of the bounding box
194   //                                              196   //
195   if (pMin.x() >= pMax.x() || pMin.y() >= pMax    197   if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
196   {                                               198   {
197     std::ostringstream message;                   199     std::ostringstream message;
198     message << "Bad bounding box (min >= max)     200     message << "Bad bounding box (min >= max) for solid: "
199             << GetName() << " !"                  201             << GetName() << " !"
200             << "\npMin = " << pMin                202             << "\npMin = " << pMin
201             << "\npMax = " << pMax;               203             << "\npMax = " << pMax;
202     G4Exception("G4UTrd::BoundingLimits()", "G    204     G4Exception("G4UTrd::BoundingLimits()", "GeomMgt0001",
203                 JustWarning, message);            205                 JustWarning, message);
204     StreamInfo(G4cout);                           206     StreamInfo(G4cout);
205   }                                               207   }
206                                                   208 
207   // Check consistency of bounding boxes          209   // Check consistency of bounding boxes
208   //                                              210   //
209   if (checkBBox)                                  211   if (checkBBox)
210   {                                               212   {
211     U3Vector vmin, vmax;                          213     U3Vector vmin, vmax;
212     Extent(vmin,vmax);                            214     Extent(vmin,vmax);
213     if (std::abs(pMin.x()-vmin.x()) > kCarTole    215     if (std::abs(pMin.x()-vmin.x()) > kCarTolerance ||
214         std::abs(pMin.y()-vmin.y()) > kCarTole    216         std::abs(pMin.y()-vmin.y()) > kCarTolerance ||
215         std::abs(pMin.z()-vmin.z()) > kCarTole    217         std::abs(pMin.z()-vmin.z()) > kCarTolerance ||
216         std::abs(pMax.x()-vmax.x()) > kCarTole    218         std::abs(pMax.x()-vmax.x()) > kCarTolerance ||
217         std::abs(pMax.y()-vmax.y()) > kCarTole    219         std::abs(pMax.y()-vmax.y()) > kCarTolerance ||
218         std::abs(pMax.z()-vmax.z()) > kCarTole    220         std::abs(pMax.z()-vmax.z()) > kCarTolerance)
219     {                                             221     {
220       std::ostringstream message;                 222       std::ostringstream message;
221       message << "Inconsistency in bounding bo    223       message << "Inconsistency in bounding boxes for solid: "
222               << GetName() << " !"                224               << GetName() << " !"
223               << "\nBBox min: wrapper = " << p    225               << "\nBBox min: wrapper = " << pMin << " solid = " << vmin
224               << "\nBBox max: wrapper = " << p    226               << "\nBBox max: wrapper = " << pMax << " solid = " << vmax;
225       G4Exception("G4UTrd::BoundingLimits()",     227       G4Exception("G4UTrd::BoundingLimits()", "GeomMgt0001",
226                   JustWarning, message);          228                   JustWarning, message);
227       checkBBox = false;                          229       checkBBox = false;
228     }                                             230     }
229   }                                               231   }
230 }                                                 232 }
231                                                   233 
232 //////////////////////////////////////////////    234 //////////////////////////////////////////////////////////////////////////
233 //                                                235 //
234 // Calculate extent under transform and specif    236 // Calculate extent under transform and specified limit
235                                                   237 
236 G4bool                                            238 G4bool
237 G4UTrd::CalculateExtent(const EAxis pAxis,        239 G4UTrd::CalculateExtent(const EAxis pAxis,
238                         const G4VoxelLimits& p    240                         const G4VoxelLimits& pVoxelLimit,
239                         const G4AffineTransfor    241                         const G4AffineTransform& pTransform,
240                               G4double& pMin,     242                               G4double& pMin, G4double& pMax) const
241 {                                                 243 {
242   G4ThreeVector bmin, bmax;                       244   G4ThreeVector bmin, bmax;
243   G4bool exist;                                   245   G4bool exist;
244                                                   246 
245   // Check bounding box (bbox)                    247   // Check bounding box (bbox)
246   //                                              248   //
247   BoundingLimits(bmin,bmax);                      249   BoundingLimits(bmin,bmax);
248   G4BoundingEnvelope bbox(bmin,bmax);             250   G4BoundingEnvelope bbox(bmin,bmax);
249 #ifdef G4BBOX_EXTENT                              251 #ifdef G4BBOX_EXTENT
250   if (true) return bbox.CalculateExtent(pAxis,    252   if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
251 #endif                                            253 #endif
252   if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVox    254   if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
253   {                                               255   {
254     return exist = pMin < pMax;                << 256     return exist = (pMin < pMax) ? true : false;
255   }                                               257   }
256                                                   258 
257   // Set bounding envelope (benv) and calculat    259   // Set bounding envelope (benv) and calculate extent
258   //                                              260   //
259   G4double dx1 = GetXHalfLength1();               261   G4double dx1 = GetXHalfLength1();
260   G4double dx2 = GetXHalfLength2();               262   G4double dx2 = GetXHalfLength2();
261   G4double dy1 = GetYHalfLength1();               263   G4double dy1 = GetYHalfLength1();
262   G4double dy2 = GetYHalfLength2();               264   G4double dy2 = GetYHalfLength2();
263   G4double dz  = GetZHalfLength();                265   G4double dz  = GetZHalfLength();
264                                                   266 
265   G4ThreeVectorList baseA(4), baseB(4);           267   G4ThreeVectorList baseA(4), baseB(4);
266   baseA[0].set(-dx1,-dy1,-dz);                    268   baseA[0].set(-dx1,-dy1,-dz);
267   baseA[1].set( dx1,-dy1,-dz);                    269   baseA[1].set( dx1,-dy1,-dz);
268   baseA[2].set( dx1, dy1,-dz);                    270   baseA[2].set( dx1, dy1,-dz);
269   baseA[3].set(-dx1, dy1,-dz);                    271   baseA[3].set(-dx1, dy1,-dz);
270   baseB[0].set(-dx2,-dy2, dz);                    272   baseB[0].set(-dx2,-dy2, dz);
271   baseB[1].set( dx2,-dy2, dz);                    273   baseB[1].set( dx2,-dy2, dz);
272   baseB[2].set( dx2, dy2, dz);                    274   baseB[2].set( dx2, dy2, dz);
273   baseB[3].set(-dx2, dy2, dz);                    275   baseB[3].set(-dx2, dy2, dz);
274                                                   276 
275   std::vector<const G4ThreeVectorList *> polyg    277   std::vector<const G4ThreeVectorList *> polygons(2);
276   polygons[0] = &baseA;                           278   polygons[0] = &baseA;
277   polygons[1] = &baseB;                           279   polygons[1] = &baseB;
278                                                   280 
279   G4BoundingEnvelope benv(bmin,bmax,polygons);    281   G4BoundingEnvelope benv(bmin,bmax,polygons);
280   exist = benv.CalculateExtent(pAxis,pVoxelLim    282   exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
281   return exist;                                   283   return exist;
282 }                                                 284 }
283                                                   285 
284 //////////////////////////////////////////////    286 //////////////////////////////////////////////////////////////////////////
285 //                                                287 //
286 // Create polyhedron for visualization            288 // Create polyhedron for visualization
287 //                                                289 //
288 G4Polyhedron* G4UTrd::CreatePolyhedron() const    290 G4Polyhedron* G4UTrd::CreatePolyhedron() const
289 {                                                 291 {
290   return new G4PolyhedronTrd2(GetXHalfLength1(    292   return new G4PolyhedronTrd2(GetXHalfLength1(),
291                               GetXHalfLength2(    293                               GetXHalfLength2(),
292                               GetYHalfLength1(    294                               GetYHalfLength1(),
293                               GetYHalfLength2(    295                               GetYHalfLength2(),
294                               GetZHalfLength()    296                               GetZHalfLength());
295 }                                                 297 }
296                                                   298 
297 #endif  // G4GEOM_USE_USOLIDS                     299 #endif  // G4GEOM_USE_USOLIDS
298                                                   300