Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/management/src/G4VSolid.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 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/management/src/G4VSolid.cc (Version 11.3.0) and /geometry/management/src/G4VSolid.cc (Version 10.2.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 // G4VSolid implementation for solid base clas << 
 27 //                                                 26 //
 28 // 10.10.18 E.Tcherniaev, more robust Estimate <<  27 // $Id: G4VSolid.cc 72936 2013-08-14 13:17:11Z gcosmo $
 29 // 30.06.95 P.Kent, Created.                   <<  28 //
                                                   >>  29 // class G4VSolid
                                                   >>  30 //
                                                   >>  31 // Implementation for solid base class
                                                   >>  32 //
                                                   >>  33 // History:
                                                   >>  34 //
                                                   >>  35 //  06.12.02 V.Grichine, restored original conditions in ClipPolygon()
                                                   >>  36 //  10.05.02 V.Grichine, ClipPolygon(): clip only other axis and limited voxels
                                                   >>  37 //  15.04.02 V.Grichine, bug fixed in ClipPolygon(): clip only one axis
                                                   >>  38 //  13.03.02 V.Grichine, cosmetics of voxel limit functions  
                                                   >>  39 //  15.11.00 D.Williams, V.Grichine, fix in CalculateClippedPolygonExtent()
                                                   >>  40 //  10.07.95 P.Kent, Added == operator, solid Store entry
                                                   >>  41 //  30.06.95 P.Kent, Created.
 30 // -------------------------------------------     42 // --------------------------------------------------------------------
 31                                                    43 
 32 #include "G4VSolid.hh"                             44 #include "G4VSolid.hh"
 33 #include "G4SolidStore.hh"                         45 #include "G4SolidStore.hh"
 34 #include "globals.hh"                              46 #include "globals.hh"
 35 #include "G4QuickRand.hh"                      <<  47 #include "Randomize.hh"
 36 #include "G4GeometryTolerance.hh"                  48 #include "G4GeometryTolerance.hh"
 37                                                    49 
 38 #include "G4VoxelLimits.hh"                        50 #include "G4VoxelLimits.hh"
 39 #include "G4AffineTransform.hh"                    51 #include "G4AffineTransform.hh"
 40 #include "G4VisExtent.hh"                          52 #include "G4VisExtent.hh"
 41                                                    53 
 42 //////////////////////////////////////////////     54 //////////////////////////////////////////////////////////////////////////
 43 //                                                 55 //
 44 // Streaming operator dumping solid contents   << 
 45                                                << 
 46 std::ostream& operator<< ( std::ostream& os, c << 
 47 {                                              << 
 48     return e.StreamInfo(os);                   << 
 49 }                                              << 
 50                                                << 
 51 ////////////////////////////////////////////// << 
 52 //                                             << 
 53 // Constructor                                     56 // Constructor
 54 //  - Copies name                                  57 //  - Copies name
 55 //  - Add ourselves to solid Store                 58 //  - Add ourselves to solid Store
 56                                                    59 
 57 G4VSolid::G4VSolid(const G4String& name)           60 G4VSolid::G4VSolid(const G4String& name)
 58   : fshapeName(name)                               61   : fshapeName(name)
 59 {                                                  62 {
 60     kCarTolerance = G4GeometryTolerance::GetIn     63     kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
 61                                                    64 
 62     // Register to store                           65     // Register to store
 63     //                                             66     //
 64     G4SolidStore::GetInstance()->Register(this     67     G4SolidStore::GetInstance()->Register(this);
 65 }                                                  68 }
 66                                                    69 
 67 //////////////////////////////////////////////     70 //////////////////////////////////////////////////////////////////////////
 68 //                                                 71 //
 69 // Copy constructor                                72 // Copy constructor
 70 //                                                 73 //
 71                                                    74 
 72 G4VSolid::G4VSolid(const G4VSolid& rhs)            75 G4VSolid::G4VSolid(const G4VSolid& rhs)
 73   : kCarTolerance(rhs.kCarTolerance), fshapeNa     76   : kCarTolerance(rhs.kCarTolerance), fshapeName(rhs.fshapeName)
 74 {                                                  77 {
 75     // Register to store                           78     // Register to store
 76     //                                             79     //
 77     G4SolidStore::GetInstance()->Register(this     80     G4SolidStore::GetInstance()->Register(this);
 78 }                                                  81 }
 79                                                    82 
 80 //////////////////////////////////////////////     83 //////////////////////////////////////////////////////////////////////////
 81 //                                                 84 //
 82 // Fake default constructor - sets only member     85 // Fake default constructor - sets only member data and allocates memory
 83 //                            for usage restri     86 //                            for usage restricted to object persistency.
 84 //                                                 87 //
 85 G4VSolid::G4VSolid( __void__& )                    88 G4VSolid::G4VSolid( __void__& )
 86   : fshapeName("")                                 89   : fshapeName("")
 87 {                                                  90 {
 88     // Register to store                           91     // Register to store
 89     //                                             92     //
 90     G4SolidStore::GetInstance()->Register(this     93     G4SolidStore::GetInstance()->Register(this);
 91 }                                                  94 }
 92                                                    95 
 93 //////////////////////////////////////////////     96 //////////////////////////////////////////////////////////////////////////
 94 //                                                 97 //
 95 // Destructor (virtual)                            98 // Destructor (virtual)
 96 // - Remove ourselves from solid Store             99 // - Remove ourselves from solid Store
 97                                                   100 
 98 G4VSolid::~G4VSolid()                             101 G4VSolid::~G4VSolid()
 99 {                                                 102 {
100     G4SolidStore::GetInstance()->DeRegister(th    103     G4SolidStore::GetInstance()->DeRegister(this);
101 }                                                 104 }
102                                                   105 
103 //////////////////////////////////////////////    106 //////////////////////////////////////////////////////////////////////////
104 //                                                107 //
105 // Assignment operator                            108 // Assignment operator
106                                                   109 
107 G4VSolid& G4VSolid::operator = (const G4VSolid << 110 G4VSolid& G4VSolid::operator = (const G4VSolid& rhs) 
108 {                                                 111 {
109    // Check assignment to self                    112    // Check assignment to self
110    //                                             113    //
111    if (this == &rhs)  { return *this; }           114    if (this == &rhs)  { return *this; }
112                                                   115 
113    // Copy data                                   116    // Copy data
114    //                                             117    //
115    kCarTolerance = rhs.kCarTolerance;             118    kCarTolerance = rhs.kCarTolerance;
116    fshapeName = rhs.fshapeName;                   119    fshapeName = rhs.fshapeName;
117                                                   120 
118    return *this;                                  121    return *this;
119 }                                              << 122 }  
120                                                << 
121                                                << 
122                                                   123 
123 //////////////////////////////////////////////    124 //////////////////////////////////////////////////////////////////////////
124 //                                                125 //
125 // Set solid name and notify store of the chan << 126 // Streaming operator dumping solid contents
126                                                   127 
127 void G4VSolid::SetName(const G4String& name)   << 128 std::ostream& operator<< ( std::ostream& os, const G4VSolid& e )
128 {                                                 129 {
129   fshapeName = name;                           << 130     return e.StreamInfo(os);
130   G4SolidStore::GetInstance()->SetMapValid(fal << 
131 }                                                 131 }
132                                                   132 
133 //////////////////////////////////////////////    133 //////////////////////////////////////////////////////////////////////////
134 //                                                134 //
135 // Throw exception if ComputeDimensions called    135 // Throw exception if ComputeDimensions called for illegal derived class
136                                                   136 
137 void G4VSolid::ComputeDimensions(G4VPVParamete    137 void G4VSolid::ComputeDimensions(G4VPVParameterisation*,
138                                  const G4int,     138                                  const G4int,
139                                  const G4VPhys    139                                  const G4VPhysicalVolume*)
140 {                                                 140 {
141     std::ostringstream message;                   141     std::ostringstream message;
142     message << "Illegal call to G4VSolid::Comp    142     message << "Illegal call to G4VSolid::ComputeDimensions()" << G4endl
143             << "Method not overloaded by deriv    143             << "Method not overloaded by derived class !";
144     G4Exception("G4VSolid::ComputeDimensions()    144     G4Exception("G4VSolid::ComputeDimensions()", "GeomMgt0003",
145                 FatalException, message);         145                 FatalException, message);
146 }                                                 146 }
147                                                   147 
148 //////////////////////////////////////////////    148 //////////////////////////////////////////////////////////////////////////
149 //                                                149 //
150 // Throw exception (warning) for solids not im    150 // Throw exception (warning) for solids not implementing the method
151                                                   151 
152 G4ThreeVector G4VSolid::GetPointOnSurface() co    152 G4ThreeVector G4VSolid::GetPointOnSurface() const
153 {                                                 153 {
154     std::ostringstream message;                   154     std::ostringstream message;
155     message << "Not implemented for solid: "      155     message << "Not implemented for solid: "
156             << GetEntityType() << " !" << G4en << 156             << this->GetEntityType() << " !" << G4endl
157             << "Returning origin.";               157             << "Returning origin.";
158     G4Exception("G4VSolid::GetPointOnSurface()    158     G4Exception("G4VSolid::GetPointOnSurface()", "GeomMgt1001",
159                 JustWarning, message);            159                 JustWarning, message);
160     return {0,0,0};                            << 160     return G4ThreeVector(0,0,0);
161 }                                                 161 }
162                                                   162 
163 //////////////////////////////////////////////    163 //////////////////////////////////////////////////////////////////////////
164 //                                                164 //
165 // Returns total number of constituents that w << 
166 // of the solid. For non-Boolean solids the re << 
167                                                << 
168 G4int G4VSolid::GetNumOfConstituents() const   << 
169 { return 1; }                                  << 
170                                                << 
171 ////////////////////////////////////////////// << 
172 //                                             << 
173 // Returns true if the solid has only planar f << 
174                                                << 
175 G4bool G4VSolid::IsFaceted() const             << 
176 { return false; }                              << 
177                                                << 
178 ////////////////////////////////////////////// << 
179 //                                             << 
180 // Dummy implementations ...                      165 // Dummy implementations ...
181                                                   166 
182 const G4VSolid* G4VSolid::GetConstituentSolid(    167 const G4VSolid* G4VSolid::GetConstituentSolid(G4int) const
183 { return nullptr; }                            << 168 { return 0; } 
184                                                   169 
185 G4VSolid* G4VSolid::GetConstituentSolid(G4int)    170 G4VSolid* G4VSolid::GetConstituentSolid(G4int)
186 { return nullptr; }                            << 171 { return 0; } 
187                                                   172 
188 const G4DisplacedSolid* G4VSolid::GetDisplaced    173 const G4DisplacedSolid* G4VSolid::GetDisplacedSolidPtr() const
189 { return nullptr; }                            << 174 { return 0; } 
190                                                   175 
191 G4DisplacedSolid* G4VSolid::GetDisplacedSolidP << 176 G4DisplacedSolid* G4VSolid::GetDisplacedSolidPtr() 
192 { return nullptr; }                            << 177 { return 0; } 
193                                                   178 
194 //////////////////////////////////////////////    179 ////////////////////////////////////////////////////////////////
195 //                                                180 //
196 // Returns an estimation of the solid volume i    181 // Returns an estimation of the solid volume in internal units.
197 // The number of statistics and error accuracy    182 // The number of statistics and error accuracy is fixed.
198 // This method may be overloaded by derived cl    183 // This method may be overloaded by derived classes to compute the
199 // exact geometrical quantity for solids where    184 // exact geometrical quantity for solids where this is possible.
200 // or anyway to cache the computed value.         185 // or anyway to cache the computed value.
201 // This implementation does NOT cache the comp    186 // This implementation does NOT cache the computed value.
202                                                   187 
203 G4double G4VSolid::GetCubicVolume()               188 G4double G4VSolid::GetCubicVolume()
204 {                                                 189 {
205   G4int cubVolStatistics = 1000000;               190   G4int cubVolStatistics = 1000000;
206   G4double cubVolEpsilon = 0.001;                 191   G4double cubVolEpsilon = 0.001;
207   return EstimateCubicVolume(cubVolStatistics,    192   return EstimateCubicVolume(cubVolStatistics, cubVolEpsilon);
208 }                                                 193 }
209                                                   194 
210 //////////////////////////////////////////////    195 ////////////////////////////////////////////////////////////////
211 //                                                196 //
212 // Calculate cubic volume based on Inside() me    197 // Calculate cubic volume based on Inside() method.
213 // Accuracy is limited by the second argument     198 // Accuracy is limited by the second argument or the statistics
214 // expressed by the first argument.               199 // expressed by the first argument.
215 // Implementation is courtesy of Vasiliki Desp    200 // Implementation is courtesy of Vasiliki Despoina Mitsou,
216 // University of Athens.                          201 // University of Athens.
217                                                   202 
218 G4double G4VSolid::EstimateCubicVolume(G4int n    203 G4double G4VSolid::EstimateCubicVolume(G4int nStat, G4double epsilon) const
219 {                                                 204 {
220   G4int iInside=0;                                205   G4int iInside=0;
221   G4double px,py,pz,minX,maxX,minY,maxY,minZ,m    206   G4double px,py,pz,minX,maxX,minY,maxY,minZ,maxZ,volume,halfepsilon;
222   G4ThreeVector p;                                207   G4ThreeVector p;
223   EInside in;                                     208   EInside in;
224                                                   209 
225   // values needed for CalculateExtent signatu    210   // values needed for CalculateExtent signature
226                                                   211 
227   G4VoxelLimits limit;                // Unlim    212   G4VoxelLimits limit;                // Unlimited
228   G4AffineTransform origin;                       213   G4AffineTransform origin;
229                                                   214 
230   // min max extents of pSolid along X,Y,Z        215   // min max extents of pSolid along X,Y,Z
231                                                   216 
232   CalculateExtent(kXAxis,limit,origin,minX,max << 217   this->CalculateExtent(kXAxis,limit,origin,minX,maxX);
233   CalculateExtent(kYAxis,limit,origin,minY,max << 218   this->CalculateExtent(kYAxis,limit,origin,minY,maxY);
234   CalculateExtent(kZAxis,limit,origin,minZ,max << 219   this->CalculateExtent(kZAxis,limit,origin,minZ,maxZ);
235                                                   220 
236   // limits                                       221   // limits
237                                                   222 
238   if(nStat < 100)    nStat   = 100;               223   if(nStat < 100)    nStat   = 100;
239   if(epsilon > 0.01) epsilon = 0.01;              224   if(epsilon > 0.01) epsilon = 0.01;
240   halfepsilon = 0.5*epsilon;                      225   halfepsilon = 0.5*epsilon;
241                                                   226 
242   for(auto i = 0; i < nStat; ++i )             << 227   for(G4int i = 0; i < nStat; i++ )
243   {                                               228   {
244     px = minX-halfepsilon+(maxX-minX+epsilon)* << 229     px = minX-halfepsilon+(maxX-minX+epsilon)*G4UniformRand();
245     py = minY-halfepsilon+(maxY-minY+epsilon)* << 230     py = minY-halfepsilon+(maxY-minY+epsilon)*G4UniformRand();
246     pz = minZ-halfepsilon+(maxZ-minZ+epsilon)* << 231     pz = minZ-halfepsilon+(maxZ-minZ+epsilon)*G4UniformRand();
247     p  = G4ThreeVector(px,py,pz);                 232     p  = G4ThreeVector(px,py,pz);
248     in = Inside(p);                            << 233     in = this->Inside(p);
249     if(in != kOutside) ++iInside;              << 234     if(in != kOutside) iInside++;    
250   }                                               235   }
251   volume = (maxX-minX+epsilon)*(maxY-minY+epsi    236   volume = (maxX-minX+epsilon)*(maxY-minY+epsilon)
252          * (maxZ-minZ+epsilon)*iInside/nStat;     237          * (maxZ-minZ+epsilon)*iInside/nStat;
253   return volume;                                  238   return volume;
254 }                                                 239 }
255                                                   240 
256 //////////////////////////////////////////////    241 ////////////////////////////////////////////////////////////////
257 //                                                242 //
258 // Returns an estimation of the solid surface     243 // Returns an estimation of the solid surface area in internal units.
259 // The number of statistics and error accuracy    244 // The number of statistics and error accuracy is fixed.
260 // This method may be overloaded by derived cl    245 // This method may be overloaded by derived classes to compute the
261 // exact geometrical quantity for solids where    246 // exact geometrical quantity for solids where this is possible.
262 // or anyway to cache the computed value.         247 // or anyway to cache the computed value.
263 // This implementation does NOT cache the comp    248 // This implementation does NOT cache the computed value.
264                                                   249 
265 G4double G4VSolid::GetSurfaceArea()               250 G4double G4VSolid::GetSurfaceArea()
266 {                                                 251 {
267   G4int stat = 1000000;                           252   G4int stat = 1000000;
268   G4double ell = -1.;                             253   G4double ell = -1.;
269   return EstimateSurfaceArea(stat,ell);           254   return EstimateSurfaceArea(stat,ell);
270 }                                                 255 }
271                                                   256 
272 ////////////////////////////////////////////// << 257 ////////////////////////////////////////////////////////////////
273 //                                                258 //
274 // Calculate surface area by estimating volume << 259 // Estimate surface area based on Inside(), DistanceToIn(), and
275 // surrounding the surface using Monte-Carlo m << 260 // DistanceToOut() methods. Accuracy is limited by the statistics
276 // Input parameters:                           << 261 // defined by the first argument. Implemented by Mikhail Kosov.
277 //    nstat - statistics (number of random poi << 262 
278 //    eps   - shell thinkness                  << 263 G4double G4VSolid::EstimateSurfaceArea(G4int nStat, G4double ell) const
279                                                << 264 {
280 G4double G4VSolid::EstimateSurfaceArea(G4int n << 265   G4int inside=0;
281 {                                              << 266   G4double px,py,pz,minX,maxX,minY,maxY,minZ,maxZ,surf;
282   static const G4double s2 = 1./std::sqrt(2.); << 267   G4ThreeVector p;
283   static const G4double s3 = 1./std::sqrt(3.); << 268   EInside in;
284   static const G4ThreeVector directions[64] =  << 269 
                                                   >> 270   // values needed for CalculateExtent signature
                                                   >> 271 
                                                   >> 272   G4VoxelLimits limit;                // Unlimited
                                                   >> 273   G4AffineTransform origin;
                                                   >> 274 
                                                   >> 275   // min max extents of pSolid along X,Y,Z
                                                   >> 276 
                                                   >> 277   this->CalculateExtent(kXAxis,limit,origin,minX,maxX);
                                                   >> 278   this->CalculateExtent(kYAxis,limit,origin,minY,maxY);
                                                   >> 279   this->CalculateExtent(kZAxis,limit,origin,minZ,maxZ);
                                                   >> 280 
                                                   >> 281   // limits
                                                   >> 282 
                                                   >> 283   if(nStat < 100) { nStat = 100; }
                                                   >> 284 
                                                   >> 285   G4double dX=maxX-minX;
                                                   >> 286   G4double dY=maxY-minY;
                                                   >> 287   G4double dZ=maxZ-minZ;
                                                   >> 288   if(ell<=0.)          // Automatic definition of skin thickness
285   {                                               289   {
286     G4ThreeVector(  0,  0,  0), G4ThreeVector( << 290     G4double minval=dX;
287     G4ThreeVector(  1,  0,  0), G4ThreeVector( << 291     if(dY<dX) { minval=dY; }
288     G4ThreeVector(  0, -1,  0), G4ThreeVector( << 292     if(dZ<minval) { minval=dZ; }
289     G4ThreeVector( s2, -s2, 0), G4ThreeVector( << 293     ell=.01*minval;
290                                                << 294   }
291     G4ThreeVector(  0,  1,  0), G4ThreeVector( << 295 
292     G4ThreeVector( s2, s2,  0), G4ThreeVector( << 296   G4double dd=2*ell;
293     G4ThreeVector(  0, -1,  0), G4ThreeVector( << 297   minX-=ell; minY-=ell; minZ-=ell; dX+=dd; dY+=dd; dZ+=dd;
294     G4ThreeVector(  1,  0,  0), G4ThreeVector( << 298 
295                                                << 299   for(G4int i = 0; i < nStat; i++ )
296     G4ThreeVector(  0,  0, -1), G4ThreeVector( << 
297     G4ThreeVector( s2,  0,-s2), G4ThreeVector( << 
298     G4ThreeVector(  0,-s2,-s2), G4ThreeVector( << 
299     G4ThreeVector( s3,-s3,-s3), G4ThreeVector( << 
300                                                << 
301     G4ThreeVector(  0, s2,-s2), G4ThreeVector( << 
302     G4ThreeVector( s3, s3,-s3), G4ThreeVector( << 
303     G4ThreeVector(  0,  0, -1), G4ThreeVector( << 
304     G4ThreeVector( s2,  0,-s2), G4ThreeVector( << 
305                                                << 
306     G4ThreeVector(  0,  0,  1), G4ThreeVector( << 
307     G4ThreeVector( s2,  0, s2), G4ThreeVector( << 
308     G4ThreeVector(  0,-s2, s2), G4ThreeVector( << 
309     G4ThreeVector( s3,-s3, s3), G4ThreeVector( << 
310                                                << 
311     G4ThreeVector(  0, s2, s2), G4ThreeVector( << 
312     G4ThreeVector( s3, s3, s3), G4ThreeVector( << 
313     G4ThreeVector(  0,  0,  1), G4ThreeVector( << 
314     G4ThreeVector( s2,  0, s2), G4ThreeVector( << 
315                                                << 
316     G4ThreeVector(  0,  0, -1), G4ThreeVector( << 
317     G4ThreeVector(  1,  0,  0), G4ThreeVector( << 
318     G4ThreeVector(  0, -1,  0), G4ThreeVector( << 
319     G4ThreeVector( s2, -s2, 0), G4ThreeVector( << 
320                                                << 
321     G4ThreeVector(  0,  1,  0), G4ThreeVector( << 
322     G4ThreeVector( s2, s2,  0), G4ThreeVector( << 
323     G4ThreeVector(  0, -1,  0), G4ThreeVector( << 
324     G4ThreeVector(  1,  0,  0), G4ThreeVector( << 
325   };                                           << 
326                                                << 
327   G4ThreeVector bmin, bmax;                    << 
328   BoundingLimits(bmin, bmax);                  << 
329                                                << 
330   G4double dX = bmax.x() - bmin.x();           << 
331   G4double dY = bmax.y() - bmin.y();           << 
332   G4double dZ = bmax.z() - bmin.z();           << 
333                                                << 
334   // Define statistics and shell thickness     << 
335   //                                           << 
336   G4int npoints = (nstat < 1000) ? 1000 : nsta << 
337   G4double coeff = 0.5 / std::cbrt(G4double(np << 
338   G4double eps = (ell > 0) ? ell : coeff * std << 
339   G4double del = 1.8 * eps; // shold be more t << 
340                                                << 
341   G4double minX = bmin.x() - eps;              << 
342   G4double minY = bmin.y() - eps;              << 
343   G4double minZ = bmin.z() - eps;              << 
344                                                << 
345   G4double dd = 2. * eps;                      << 
346   dX += dd;                                    << 
347   dY += dd;                                    << 
348   dZ += dd;                                    << 
349                                                << 
350   // Calculate surface area                    << 
351   //                                           << 
352   G4int icount = 0;                            << 
353   for(auto i = 0; i < npoints; ++i)            << 
354   {                                               300   {
355     G4double px = minX + dX*G4QuickRand();     << 301     px = minX+dX*G4UniformRand();
356     G4double py = minY + dY*G4QuickRand();     << 302     py = minY+dY*G4UniformRand();
357     G4double pz = minZ + dZ*G4QuickRand();     << 303     pz = minZ+dZ*G4UniformRand();
358     G4ThreeVector p  = G4ThreeVector(px, py, p << 304     p  = G4ThreeVector(px,py,pz);
359     EInside in = Inside(p);                    << 305     in = this->Inside(p);
360     G4double dist = 0;                         << 306     if(in != kOutside)
361     if (in == kInside)                         << 
362     {                                          << 
363       if (DistanceToOut(p) >= eps) continue;   << 
364       G4int icase = 0;                         << 
365       if (Inside(G4ThreeVector(px-del, py, pz) << 
366       if (Inside(G4ThreeVector(px+del, py, pz) << 
367       if (Inside(G4ThreeVector(px, py-del, pz) << 
368       if (Inside(G4ThreeVector(px, py+del, pz) << 
369       if (Inside(G4ThreeVector(px, py, pz-del) << 
370       if (Inside(G4ThreeVector(px, py, pz+del) << 
371       if (icase == 0) continue;                << 
372       G4ThreeVector v = directions[icase];     << 
373       dist = DistanceToOut(p, v);              << 
374       G4ThreeVector n = SurfaceNormal(p + v*di << 
375       dist *= v.dot(n);                        << 
376     }                                          << 
377     else if (in == kOutside)                   << 
378     {                                             307     {
379       if (DistanceToIn(p) >= eps) continue;    << 308       if  (DistanceToOut(p)<ell) { inside++; }
380       G4int icase = 0;                         << 
381       if (Inside(G4ThreeVector(px-del, py, pz) << 
382       if (Inside(G4ThreeVector(px+del, py, pz) << 
383       if (Inside(G4ThreeVector(px, py-del, pz) << 
384       if (Inside(G4ThreeVector(px, py+del, pz) << 
385       if (Inside(G4ThreeVector(px, py, pz-del) << 
386       if (Inside(G4ThreeVector(px, py, pz+del) << 
387       if (icase == 0) continue;                << 
388       G4ThreeVector v = directions[icase];     << 
389       dist = DistanceToIn(p, v);               << 
390       if (dist == kInfinity) continue;         << 
391       G4ThreeVector n = SurfaceNormal(p + v*di << 
392       dist *= -(v.dot(n));                     << 
393     }                                             309     }
394     if (dist < eps) ++icount;                  << 310     else if(DistanceToIn(p)<ell) { inside++; }
395   }                                               311   }
396   return dX*dY*dZ*icount/npoints/dd;           << 312   // @@ The conformal correction can be upgraded
                                                   >> 313   surf = dX*dY*dZ*inside/dd/nStat;
                                                   >> 314   return surf;
397 }                                                 315 }
398                                                   316 
399 //////////////////////////////////////////////    317 ///////////////////////////////////////////////////////////////////////////
400 //                                             << 318 // 
401 // Returns a pointer of a dynamically allocate    319 // Returns a pointer of a dynamically allocated copy of the solid.
402 // Returns NULL pointer with warning in case t    320 // Returns NULL pointer with warning in case the concrete solid does not
403 // implement this method. The caller has respo    321 // implement this method. The caller has responsibility for ownership.
404 //                                                322 //
405                                                   323 
406 G4VSolid* G4VSolid::Clone() const                 324 G4VSolid* G4VSolid::Clone() const
407 {                                                 325 {
408   std::ostringstream message;                     326   std::ostringstream message;
409   message << "Clone() method not implemented f    327   message << "Clone() method not implemented for type: "
410           << GetEntityType() << "!" << G4endl     328           << GetEntityType() << "!" << G4endl
411           << "Returning NULL pointer!";           329           << "Returning NULL pointer!";
412   G4Exception("G4VSolid::Clone()", "GeomMgt100    330   G4Exception("G4VSolid::Clone()", "GeomMgt1001", JustWarning, message);
413   return nullptr;                              << 331   return 0;
414 }                                                 332 }
415                                                   333 
416 //////////////////////////////////////////////    334 ///////////////////////////////////////////////////////////////////////////
417 //                                             << 335 // 
418 // Calculate the maximum and minimum extents o    336 // Calculate the maximum and minimum extents of the polygon described
419 // by the vertices: pSectionIndex->pSectionInd    337 // by the vertices: pSectionIndex->pSectionIndex+1->
420 //                   pSectionIndex+2->pSection    338 //                   pSectionIndex+2->pSectionIndex+3->pSectionIndex
421 // in the List pVertices                          339 // in the List pVertices
422 //                                                340 //
423 // If the minimum is <pMin pMin is set to the     341 // If the minimum is <pMin pMin is set to the new minimum
424 // If the maximum is >pMax pMax is set to the     342 // If the maximum is >pMax pMax is set to the new maximum
425 //                                                343 //
426 // No modifications are made to pVertices         344 // No modifications are made to pVertices
427 //                                                345 //
428                                                   346 
429 void G4VSolid::ClipCrossSection(       G4Three    347 void G4VSolid::ClipCrossSection(       G4ThreeVectorList* pVertices,
430                                  const G4int p    348                                  const G4int pSectionIndex,
431                                  const G4Voxel    349                                  const G4VoxelLimits& pVoxelLimit,
432                                  const EAxis p << 350                                  const EAxis pAxis, 
433                                        G4doubl    351                                        G4double& pMin, G4double& pMax) const
434 {                                                 352 {
435                                                   353 
436   G4ThreeVectorList polygon;                      354   G4ThreeVectorList polygon;
437   polygon.reserve(4);                             355   polygon.reserve(4);
438   polygon.push_back((*pVertices)[pSectionIndex    356   polygon.push_back((*pVertices)[pSectionIndex]);
439   polygon.push_back((*pVertices)[pSectionIndex    357   polygon.push_back((*pVertices)[pSectionIndex+1]);
440   polygon.push_back((*pVertices)[pSectionIndex    358   polygon.push_back((*pVertices)[pSectionIndex+2]);
441   polygon.push_back((*pVertices)[pSectionIndex    359   polygon.push_back((*pVertices)[pSectionIndex+3]);
                                                   >> 360   //  G4cout<<"ClipCrossSection: 0-1-2-3"<<G4endl;
442   CalculateClippedPolygonExtent(polygon,pVoxel    361   CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
443   return;                                         362   return;
444 }                                                 363 }
445                                                   364 
446 //////////////////////////////////////////////    365 //////////////////////////////////////////////////////////////////////////////////
447 //                                                366 //
448 // Calculate the maximum and minimum extents o    367 // Calculate the maximum and minimum extents of the polygons
449 // joining the CrossSections at pSectionIndex-    368 // joining the CrossSections at pSectionIndex->pSectionIndex+3 and
450 //                              pSectionIndex+    369 //                              pSectionIndex+4->pSectionIndex7
451 //                                                370 //
452 // in the List pVertices, within the boundarie    371 // in the List pVertices, within the boundaries of the voxel limits pVoxelLimit
453 //                                                372 //
454 // If the minimum is <pMin pMin is set to the     373 // If the minimum is <pMin pMin is set to the new minimum
455 // If the maximum is >pMax pMax is set to the     374 // If the maximum is >pMax pMax is set to the new maximum
456 //                                                375 //
457 // No modifications are made to pVertices         376 // No modifications are made to pVertices
458                                                   377 
459 void G4VSolid::ClipBetweenSections(      G4Thr    378 void G4VSolid::ClipBetweenSections(      G4ThreeVectorList* pVertices,
460                                    const G4int    379                                    const G4int pSectionIndex,
461                                    const G4Vox    380                                    const G4VoxelLimits& pVoxelLimit,
462                                    const EAxis << 381                                    const EAxis pAxis, 
463                                          G4dou    382                                          G4double& pMin, G4double& pMax) const
464 {                                                 383 {
465   G4ThreeVectorList polygon;                      384   G4ThreeVectorList polygon;
466   polygon.reserve(4);                             385   polygon.reserve(4);
467   polygon.push_back((*pVertices)[pSectionIndex    386   polygon.push_back((*pVertices)[pSectionIndex]);
468   polygon.push_back((*pVertices)[pSectionIndex    387   polygon.push_back((*pVertices)[pSectionIndex+4]);
469   polygon.push_back((*pVertices)[pSectionIndex    388   polygon.push_back((*pVertices)[pSectionIndex+5]);
470   polygon.push_back((*pVertices)[pSectionIndex    389   polygon.push_back((*pVertices)[pSectionIndex+1]);
                                                   >> 390   // G4cout<<"ClipBetweenSections: 0-4-5-1"<<G4endl;
471   CalculateClippedPolygonExtent(polygon,pVoxel    391   CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
472   polygon.clear();                                392   polygon.clear();
473                                                   393 
474   polygon.push_back((*pVertices)[pSectionIndex    394   polygon.push_back((*pVertices)[pSectionIndex+1]);
475   polygon.push_back((*pVertices)[pSectionIndex    395   polygon.push_back((*pVertices)[pSectionIndex+5]);
476   polygon.push_back((*pVertices)[pSectionIndex    396   polygon.push_back((*pVertices)[pSectionIndex+6]);
477   polygon.push_back((*pVertices)[pSectionIndex    397   polygon.push_back((*pVertices)[pSectionIndex+2]);
                                                   >> 398   // G4cout<<"ClipBetweenSections: 1-5-6-2"<<G4endl;
478   CalculateClippedPolygonExtent(polygon,pVoxel    399   CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
479   polygon.clear();                                400   polygon.clear();
480                                                   401 
481   polygon.push_back((*pVertices)[pSectionIndex    402   polygon.push_back((*pVertices)[pSectionIndex+2]);
482   polygon.push_back((*pVertices)[pSectionIndex    403   polygon.push_back((*pVertices)[pSectionIndex+6]);
483   polygon.push_back((*pVertices)[pSectionIndex    404   polygon.push_back((*pVertices)[pSectionIndex+7]);
484   polygon.push_back((*pVertices)[pSectionIndex    405   polygon.push_back((*pVertices)[pSectionIndex+3]);
                                                   >> 406   //  G4cout<<"ClipBetweenSections: 2-6-7-3"<<G4endl;
485   CalculateClippedPolygonExtent(polygon,pVoxel    407   CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
486   polygon.clear();                                408   polygon.clear();
487                                                   409 
488   polygon.push_back((*pVertices)[pSectionIndex    410   polygon.push_back((*pVertices)[pSectionIndex+3]);
489   polygon.push_back((*pVertices)[pSectionIndex    411   polygon.push_back((*pVertices)[pSectionIndex+7]);
490   polygon.push_back((*pVertices)[pSectionIndex    412   polygon.push_back((*pVertices)[pSectionIndex+4]);
491   polygon.push_back((*pVertices)[pSectionIndex    413   polygon.push_back((*pVertices)[pSectionIndex]);
                                                   >> 414   //  G4cout<<"ClipBetweenSections: 3-7-4-0"<<G4endl;
492   CalculateClippedPolygonExtent(polygon,pVoxel    415   CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
493   return;                                         416   return;
494 }                                                 417 }
495                                                   418 
496                                                   419 
497 //////////////////////////////////////////////    420 ///////////////////////////////////////////////////////////////////////////////
498 //                                                421 //
499 // Calculate the maximum and minimum extents o    422 // Calculate the maximum and minimum extents of the convex polygon pPolygon
500 // along the axis pAxis, within the limits pVo    423 // along the axis pAxis, within the limits pVoxelLimit
501 //                                                424 //
502                                                   425 
503 void                                              426 void
504 G4VSolid::CalculateClippedPolygonExtent(G4Thre    427 G4VSolid::CalculateClippedPolygonExtent(G4ThreeVectorList& pPolygon,
505                                   const G4Voxe    428                                   const G4VoxelLimits& pVoxelLimit,
506                                   const EAxis  << 429                                   const EAxis pAxis, 
507                                         G4doub    430                                         G4double& pMin,
508                                         G4doub    431                                         G4double& pMax) const
509 {                                                 432 {
510   G4int noLeft,i;                                 433   G4int noLeft,i;
511   G4double component;                             434   G4double component;
512                                                << 435   /*  
                                                   >> 436   G4cout<<G4endl;
                                                   >> 437   for(i = 0 ; i < pPolygon.size() ; i++ )
                                                   >> 438   {
                                                   >> 439       G4cout << i << "\t"
                                                   >> 440              << "p.x = " << pPolygon[i].operator()(pAxis) << "\t"
                                                   >> 441         //   << "p.y = " << pPolygon[i].y() << "\t"
                                                   >> 442         //   << "p.z = " << pPolygon[i].z() << "\t"
                                                   >> 443              << G4endl;
                                                   >> 444   }    
                                                   >> 445   G4cout<<G4endl;
                                                   >> 446   */  
513   ClipPolygon(pPolygon,pVoxelLimit,pAxis);        447   ClipPolygon(pPolygon,pVoxelLimit,pAxis);
514   noLeft = (G4int)pPolygon.size();             << 448   noLeft = pPolygon.size();
515                                                   449 
516   if ( noLeft != 0 )                           << 450   if ( noLeft )
517   {                                               451   {
518     for (i=0; i<noLeft; ++i)                   << 452     //  G4cout<<G4endl;
                                                   >> 453     for (i=0;i<noLeft;i++)
519     {                                             454     {
520       component = pPolygon[i].operator()(pAxis    455       component = pPolygon[i].operator()(pAxis);
521                                                << 456       //  G4cout <<i<<"\t"<<component<<G4endl;
522       if (component < pMin)                    << 457  
523       {                                        << 458       if (component < pMin) 
524         pMin = component;                      << 459       { 
                                                   >> 460         //  G4cout <<i<<"\t"<<"Pmin = "<<component<<G4endl;
                                                   >> 461         pMin = component;      
525       }                                           462       }
526       if (component > pMax)                       463       if (component > pMax)
527       {                                        << 464       {  
528         pMax = component;                      << 465         //  G4cout <<i<<"\t"<<"PMax = "<<component<<G4endl;
529       }                                        << 466         pMax = component;  
                                                   >> 467       }    
530     }                                             468     }
                                                   >> 469     //  G4cout<<G4endl;
531   }                                               470   }
                                                   >> 471   // G4cout<<"pMin = "<<pMin<<"\t"<<"pMax = "<<pMax<<G4endl;
532 }                                                 472 }
533                                                   473 
534 //////////////////////////////////////////////    474 /////////////////////////////////////////////////////////////////////////////
535 //                                                475 //
536 // Clip the convex polygon described by the ve    476 // Clip the convex polygon described by the vertices at
537 // pSectionIndex ->pSectionIndex+3 within pVer    477 // pSectionIndex ->pSectionIndex+3 within pVertices to the limits pVoxelLimit
538 //                                                478 //
539 // Set pMin to the smallest                       479 // Set pMin to the smallest
540 //                                                480 //
541 // Calculate the extent of the polygon along p    481 // Calculate the extent of the polygon along pAxis, when clipped to the
542 // limits pVoxelLimit. If the polygon exists a    482 // limits pVoxelLimit. If the polygon exists after clippin, set pMin to
543 // the polygon's minimum extent along the axis    483 // the polygon's minimum extent along the axis if <pMin, and set pMax to
544 // the polygon's maximum extent along the axis    484 // the polygon's maximum extent along the axis if >pMax.
545 //                                                485 //
546 // The polygon is described by a set of vector    486 // The polygon is described by a set of vectors, where each vector represents
547 // a vertex, so that the polygon is described     487 // a vertex, so that the polygon is described by the vertex sequence:
548 //   0th->1st 1st->2nd 2nd->... nth->0th          488 //   0th->1st 1st->2nd 2nd->... nth->0th
549 //                                                489 //
550 // Modifications to the polygon are made          490 // Modifications to the polygon are made
551 //                                                491 //
552 // NOTE: Execessive copying during clipping       492 // NOTE: Execessive copying during clipping
553                                                   493 
554 void G4VSolid::ClipPolygon(      G4ThreeVector    494 void G4VSolid::ClipPolygon(      G4ThreeVectorList& pPolygon,
555                            const G4VoxelLimits    495                            const G4VoxelLimits& pVoxelLimit,
556                            const EAxis            496                            const EAxis                        ) const
557 {                                                 497 {
558   G4ThreeVectorList outputPolygon;                498   G4ThreeVectorList outputPolygon;
559                                                   499 
560   if ( pVoxelLimit.IsLimited() )                  500   if ( pVoxelLimit.IsLimited() )
561   {                                               501   {
562     if (pVoxelLimit.IsXLimited() ) // && pAxis    502     if (pVoxelLimit.IsXLimited() ) // && pAxis != kXAxis)
563     {                                             503     {
564       G4VoxelLimits simpleLimit1;                 504       G4VoxelLimits simpleLimit1;
565       simpleLimit1.AddLimit(kXAxis,pVoxelLimit    505       simpleLimit1.AddLimit(kXAxis,pVoxelLimit.GetMinXExtent(),kInfinity);
                                                   >> 506       //  G4cout<<"MinXExtent()"<<G4endl;
566       ClipPolygonToSimpleLimits(pPolygon,outpu    507       ClipPolygonToSimpleLimits(pPolygon,outputPolygon,simpleLimit1);
567                                                << 508    
568       pPolygon.clear();                           509       pPolygon.clear();
569                                                   510 
570       if ( outputPolygon.empty() )  return;    << 511       if ( !outputPolygon.size() )  return;
571                                                   512 
572       G4VoxelLimits simpleLimit2;                 513       G4VoxelLimits simpleLimit2;
                                                   >> 514       //  G4cout<<"MaxXExtent()"<<G4endl;
573       simpleLimit2.AddLimit(kXAxis,-kInfinity,    515       simpleLimit2.AddLimit(kXAxis,-kInfinity,pVoxelLimit.GetMaxXExtent());
574       ClipPolygonToSimpleLimits(outputPolygon,    516       ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
575                                                   517 
576       if ( pPolygon.empty() )       return;    << 518       if ( !pPolygon.size() )       return;
577       else                          outputPoly    519       else                          outputPolygon.clear();
578     }                                             520     }
579     if ( pVoxelLimit.IsYLimited() ) // && pAxi    521     if ( pVoxelLimit.IsYLimited() ) // && pAxis != kYAxis)
580     {                                             522     {
581       G4VoxelLimits simpleLimit1;                 523       G4VoxelLimits simpleLimit1;
582       simpleLimit1.AddLimit(kYAxis,pVoxelLimit    524       simpleLimit1.AddLimit(kYAxis,pVoxelLimit.GetMinYExtent(),kInfinity);
583       ClipPolygonToSimpleLimits(pPolygon,outpu    525       ClipPolygonToSimpleLimits(pPolygon,outputPolygon,simpleLimit1);
584                                                   526 
585       // Must always clear pPolygon - for clip    527       // Must always clear pPolygon - for clip to simpleLimit2 and in case of
586       // early exit                               528       // early exit
587                                                   529 
588       pPolygon.clear();                           530       pPolygon.clear();
589                                                   531 
590       if ( outputPolygon.empty() )  return;    << 532       if ( !outputPolygon.size() )  return;
591                                                   533 
592       G4VoxelLimits simpleLimit2;                 534       G4VoxelLimits simpleLimit2;
593       simpleLimit2.AddLimit(kYAxis,-kInfinity,    535       simpleLimit2.AddLimit(kYAxis,-kInfinity,pVoxelLimit.GetMaxYExtent());
594       ClipPolygonToSimpleLimits(outputPolygon,    536       ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
595                                                   537 
596       if ( pPolygon.empty() )       return;    << 538       if ( !pPolygon.size() )       return;
597       else                          outputPoly    539       else                          outputPolygon.clear();
598     }                                             540     }
599     if ( pVoxelLimit.IsZLimited() ) // && pAxi    541     if ( pVoxelLimit.IsZLimited() ) // && pAxis != kZAxis)
600     {                                             542     {
601       G4VoxelLimits simpleLimit1;                 543       G4VoxelLimits simpleLimit1;
602       simpleLimit1.AddLimit(kZAxis,pVoxelLimit    544       simpleLimit1.AddLimit(kZAxis,pVoxelLimit.GetMinZExtent(),kInfinity);
603       ClipPolygonToSimpleLimits(pPolygon,outpu    545       ClipPolygonToSimpleLimits(pPolygon,outputPolygon,simpleLimit1);
604                                                   546 
605       // Must always clear pPolygon - for clip    547       // Must always clear pPolygon - for clip to simpleLimit2 and in case of
606       // early exit                               548       // early exit
607                                                   549 
608       pPolygon.clear();                           550       pPolygon.clear();
609                                                   551 
610       if ( outputPolygon.empty() )  return;    << 552       if ( !outputPolygon.size() )  return;
611                                                   553 
612       G4VoxelLimits simpleLimit2;                 554       G4VoxelLimits simpleLimit2;
613       simpleLimit2.AddLimit(kZAxis,-kInfinity,    555       simpleLimit2.AddLimit(kZAxis,-kInfinity,pVoxelLimit.GetMaxZExtent());
614       ClipPolygonToSimpleLimits(outputPolygon,    556       ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
615                                                   557 
616       // Return after final clip - no cleanup     558       // Return after final clip - no cleanup
617     }                                             559     }
618   }                                               560   }
619 }                                                 561 }
620                                                   562 
621 //////////////////////////////////////////////    563 ////////////////////////////////////////////////////////////////////////////
622 //                                                564 //
623 // pVoxelLimits must be only limited along one    565 // pVoxelLimits must be only limited along one axis, and either the maximum
624 // along the axis must be +kInfinity, or the m    566 // along the axis must be +kInfinity, or the minimum -kInfinity
625                                                   567 
626 void                                              568 void
627 G4VSolid::ClipPolygonToSimpleLimits( G4ThreeVe    569 G4VSolid::ClipPolygonToSimpleLimits( G4ThreeVectorList& pPolygon,
628                                      G4ThreeVe    570                                      G4ThreeVectorList& outputPolygon,
629                                const G4VoxelLi    571                                const G4VoxelLimits& pVoxelLimit       ) const
630 {                                                 572 {
631   G4int i;                                        573   G4int i;
632   auto  noVertices = (G4int)pPolygon.size();   << 574   G4int noVertices=pPolygon.size();
633   G4ThreeVector vEnd,vStart;                      575   G4ThreeVector vEnd,vStart;
634                                                   576 
635   for (i = 0 ; i < noVertices ; ++i )          << 577   for (i = 0 ; i < noVertices ; i++ )
636   {                                               578   {
637     vStart = pPolygon[i];                         579     vStart = pPolygon[i];
                                                   >> 580     // G4cout << "i = " << i << G4endl;
638     if ( i == noVertices-1 )    vEnd = pPolygo    581     if ( i == noVertices-1 )    vEnd = pPolygon[0];
639     else                        vEnd = pPolygo    582     else                        vEnd = pPolygon[i+1];
640                                                   583 
641     if ( pVoxelLimit.Inside(vStart) )             584     if ( pVoxelLimit.Inside(vStart) )
642     {                                             585     {
643       if (pVoxelLimit.Inside(vEnd))               586       if (pVoxelLimit.Inside(vEnd))
644       {                                           587       {
645         // vStart and vEnd inside -> output en    588         // vStart and vEnd inside -> output end point
646         //                                        589         //
647         outputPolygon.push_back(vEnd);            590         outputPolygon.push_back(vEnd);
648       }                                           591       }
649       else                                        592       else
650       {                                           593       {
651         // vStart inside, vEnd outside -> outp    594         // vStart inside, vEnd outside -> output crossing point
652         //                                        595         //
                                                   >> 596         // G4cout << "vStart inside, vEnd outside" << G4endl;
653         pVoxelLimit.ClipToLimits(vStart,vEnd);    597         pVoxelLimit.ClipToLimits(vStart,vEnd);
654         outputPolygon.push_back(vEnd);            598         outputPolygon.push_back(vEnd);
655       }                                        << 599       }    
656     }                                             600     }
657     else                                          601     else
658     {                                             602     {
659       if (pVoxelLimit.Inside(vEnd))               603       if (pVoxelLimit.Inside(vEnd))
660       {                                           604       {
661         // vStart outside, vEnd inside -> outp    605         // vStart outside, vEnd inside -> output inside section
662         //                                        606         //
                                                   >> 607         // G4cout << "vStart outside, vEnd inside" << G4endl;
663         pVoxelLimit.ClipToLimits(vStart,vEnd);    608         pVoxelLimit.ClipToLimits(vStart,vEnd);
664         outputPolygon.push_back(vStart);          609         outputPolygon.push_back(vStart);
665         outputPolygon.push_back(vEnd);         << 610         outputPolygon.push_back(vEnd);  
666       }                                           611       }
667       else  // Both point outside -> no output    612       else  // Both point outside -> no output
668       {                                           613       {
669         // outputPolygon.push_back(vStart);       614         // outputPolygon.push_back(vStart);
670         // outputPolygon.push_back(vEnd);      << 615         // outputPolygon.push_back(vEnd);  
671       }                                           616       }
672     }                                             617     }
673   }                                               618   }
674 }                                                 619 }
675                                                   620 
676 ////////////////////////////////////////////// << 621 G4VisExtent G4VSolid::GetExtent () const 
677 //                                             << 
678 // Throw exception (warning) for solids not im << 
679                                                << 
680 void G4VSolid::BoundingLimits(G4ThreeVector& p << 
681 {                                              << 
682   std::ostringstream message;                  << 
683   message << "Not implemented for solid: "     << 
684           << GetEntityType() << " !"           << 
685           << "\nReturning infinite boundinx bo << 
686   G4Exception("G4VSolid::BoundingLimits()", "G << 
687               JustWarning, message);           << 
688                                                << 
689   pMin.set(-kInfinity,-kInfinity,-kInfinity);  << 
690   pMax.set( kInfinity, kInfinity, kInfinity);  << 
691 }                                              << 
692                                                << 
693 ////////////////////////////////////////////// << 
694 //                                             << 
695 // Get G4VisExtent - bounding box for graphics << 
696                                                << 
697 G4VisExtent G4VSolid::GetExtent () const       << 
698 {                                                 622 {
699   G4VisExtent extent;                             623   G4VisExtent extent;
700   G4VoxelLimits voxelLimits;  // Defaults to "    624   G4VoxelLimits voxelLimits;  // Defaults to "infinite" limits.
701   G4AffineTransform affineTransform;              625   G4AffineTransform affineTransform;
702   G4double vmin, vmax;                            626   G4double vmin, vmax;
703   CalculateExtent(kXAxis,voxelLimits,affineTra    627   CalculateExtent(kXAxis,voxelLimits,affineTransform,vmin,vmax);
704   extent.SetXmin (vmin);                          628   extent.SetXmin (vmin);
705   extent.SetXmax (vmax);                          629   extent.SetXmax (vmax);
706   CalculateExtent(kYAxis,voxelLimits,affineTra    630   CalculateExtent(kYAxis,voxelLimits,affineTransform,vmin,vmax);
707   extent.SetYmin (vmin);                          631   extent.SetYmin (vmin);
708   extent.SetYmax (vmax);                          632   extent.SetYmax (vmax);
709   CalculateExtent(kZAxis,voxelLimits,affineTra    633   CalculateExtent(kZAxis,voxelLimits,affineTransform,vmin,vmax);
710   extent.SetZmin (vmin);                          634   extent.SetZmin (vmin);
711   extent.SetZmax (vmax);                          635   extent.SetZmax (vmax);
712   return extent;                                  636   return extent;
713 }                                                 637 }
714                                                   638 
715 G4Polyhedron* G4VSolid::CreatePolyhedron () co    639 G4Polyhedron* G4VSolid::CreatePolyhedron () const
716 {                                                 640 {
717   return nullptr;                              << 641   return 0;
718 }                                                 642 }
719                                                   643 
720 G4Polyhedron* G4VSolid::GetPolyhedron () const    644 G4Polyhedron* G4VSolid::GetPolyhedron () const
721 {                                                 645 {
722   return nullptr;                              << 646   return 0;
723 }                                                 647 }
724                                                   648