Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/solids/specific/src/G4VCSGfaceted.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/solids/specific/src/G4VCSGfaceted.cc (Version 11.3.0) and /geometry/solids/specific/src/G4VCSGfaceted.cc (Version 10.0.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 // G4VCSGfaceted implementation; a virtual cla <<  26 // the GEANT4 collaboration.
 27 // that is built entirely out of G4VCSGface fa <<  27 //
                                                   >>  28 // By copying, distributing or modifying the Program (or any work
                                                   >>  29 // based on the Program) you indicate your acceptance of this statement,
                                                   >>  30 // and all its terms.
                                                   >>  31 //
                                                   >>  32 // $Id: G4VCSGfaceted.cc 84624 2014-10-17 09:56:00Z gcosmo $
                                                   >>  33 //
                                                   >>  34 // 
                                                   >>  35 // --------------------------------------------------------------------
                                                   >>  36 // GEANT 4 class source file
                                                   >>  37 //
                                                   >>  38 //
                                                   >>  39 // G4VCSGfaceted.cc
                                                   >>  40 //
                                                   >>  41 // Implementation of the virtual class of a CSG type shape that is built
                                                   >>  42 // entirely out of G4VCSGface faces.
 28 //                                                 43 //
 29 // Author: David C. Williams (davidw@scipp.ucs << 
 30 // -------------------------------------------     44 // --------------------------------------------------------------------
 31                                                    45 
 32 #include "G4VCSGfaceted.hh"                        46 #include "G4VCSGfaceted.hh"
 33 #include "G4VCSGface.hh"                           47 #include "G4VCSGface.hh"
 34 #include "G4SolidExtentList.hh"                    48 #include "G4SolidExtentList.hh"
 35                                                    49 
 36 #include "G4VoxelLimits.hh"                        50 #include "G4VoxelLimits.hh"
 37 #include "G4AffineTransform.hh"                    51 #include "G4AffineTransform.hh"
 38                                                    52 
 39 #include "Randomize.hh"                            53 #include "Randomize.hh"
 40                                                    54 
 41 #include "G4Polyhedron.hh"                         55 #include "G4Polyhedron.hh"   
 42 #include "G4VGraphicsScene.hh"                     56 #include "G4VGraphicsScene.hh"
 43 #include "G4VisExtent.hh"                          57 #include "G4VisExtent.hh"
 44                                                    58 
 45 #include "G4AutoLock.hh"                           59 #include "G4AutoLock.hh"
 46                                                    60 
 47 namespace                                          61 namespace
 48 {                                                  62 {
 49   G4Mutex polyhedronMutex = G4MUTEX_INITIALIZE     63   G4Mutex polyhedronMutex = G4MUTEX_INITIALIZER;
 50 }                                                  64 }
 51                                                    65 
 52 //                                                 66 //
 53 // Constructor                                     67 // Constructor
 54 //                                                 68 //
 55 G4VCSGfaceted::G4VCSGfaceted( const G4String&      69 G4VCSGfaceted::G4VCSGfaceted( const G4String& name )
 56   : G4VSolid(name),                                70   : G4VSolid(name),
                                                   >>  71     numFace(0), faces(0), fCubicVolume(0.), fSurfaceArea(0.),
                                                   >>  72     fRebuildPolyhedron(false), fpPolyhedron(0),
 57     fStatistics(1000000), fCubVolEpsilon(0.001     73     fStatistics(1000000), fCubVolEpsilon(0.001), fAreaAccuracy(-1.)
 58 {                                                  74 {
 59 }                                                  75 }
 60                                                    76 
 61                                                    77 
 62 //                                                 78 //
 63 // Fake default constructor - sets only member     79 // Fake default constructor - sets only member data and allocates memory
 64 //                            for usage restri     80 //                            for usage restricted to object persistency.
 65 //                                                 81 //
 66 G4VCSGfaceted::G4VCSGfaceted( __void__& a )        82 G4VCSGfaceted::G4VCSGfaceted( __void__& a )
 67   : G4VSolid(a),                                   83   : G4VSolid(a),
                                                   >>  84     numFace(0), faces(0), fCubicVolume(0.), fSurfaceArea(0.),
                                                   >>  85     fRebuildPolyhedron(false), fpPolyhedron(0),
 68     fStatistics(1000000), fCubVolEpsilon(0.001     86     fStatistics(1000000), fCubVolEpsilon(0.001), fAreaAccuracy(-1.)
 69 {                                                  87 {
 70 }                                                  88 }
 71                                                    89 
 72 //                                                 90 //
 73 // Destructor                                      91 // Destructor
 74 //                                                 92 //
 75 G4VCSGfaceted::~G4VCSGfaceted()                    93 G4VCSGfaceted::~G4VCSGfaceted()
 76 {                                                  94 {
 77   DeleteStuff();                                   95   DeleteStuff();
 78   delete fpPolyhedron; fpPolyhedron = nullptr; <<  96   delete fpPolyhedron; fpPolyhedron = 0;
 79 }                                                  97 }
 80                                                    98 
 81                                                    99 
 82 //                                                100 //
 83 // Copy constructor                               101 // Copy constructor
 84 //                                                102 //
 85 G4VCSGfaceted::G4VCSGfaceted( const G4VCSGface << 103 G4VCSGfaceted::G4VCSGfaceted( const G4VCSGfaceted &source )
 86   : G4VSolid( source )                            104   : G4VSolid( source )
 87 {                                                 105 {
 88   fStatistics = source.fStatistics;               106   fStatistics = source.fStatistics;
 89   fCubVolEpsilon = source.fCubVolEpsilon;         107   fCubVolEpsilon = source.fCubVolEpsilon;
 90   fAreaAccuracy = source.fAreaAccuracy;           108   fAreaAccuracy = source.fAreaAccuracy;
 91                                                   109 
 92   CopyStuff( source );                            110   CopyStuff( source );
 93 }                                                 111 }
 94                                                   112 
 95                                                   113 
 96 //                                                114 //
 97 // Assignment operator                            115 // Assignment operator
 98 //                                                116 //
 99 G4VCSGfaceted& G4VCSGfaceted::operator=( const << 117 G4VCSGfaceted &G4VCSGfaceted::operator=( const G4VCSGfaceted &source )
100 {                                                 118 {
101   if (&source == this) { return *this; }          119   if (&source == this) { return *this; }
102                                                   120   
103   // Copy base class data                         121   // Copy base class data
104   //                                              122   //
105   G4VSolid::operator=(source);                    123   G4VSolid::operator=(source);
106                                                   124 
107   // Copy data                                    125   // Copy data
108   //                                              126   //
109   fStatistics = source.fStatistics;               127   fStatistics = source.fStatistics;
110   fCubVolEpsilon = source.fCubVolEpsilon;         128   fCubVolEpsilon = source.fCubVolEpsilon;
111   fAreaAccuracy = source.fAreaAccuracy;           129   fAreaAccuracy = source.fAreaAccuracy;
112                                                   130 
113   DeleteStuff();                                  131   DeleteStuff();
114   CopyStuff( source );                            132   CopyStuff( source );
115                                                   133   
116   return *this;                                   134   return *this;
117 }                                                 135 }
118                                                   136 
119                                                   137 
120 //                                                138 //
121 // CopyStuff (protected)                          139 // CopyStuff (protected)
122 //                                                140 //
123 // Copy the contents of source                    141 // Copy the contents of source
124 //                                                142 //
125 void G4VCSGfaceted::CopyStuff( const G4VCSGfac << 143 void G4VCSGfaceted::CopyStuff( const G4VCSGfaceted &source )
126 {                                                 144 {
127   numFace = source.numFace;                       145   numFace = source.numFace;
128   if (numFace == 0) { return; }    // odd, but    146   if (numFace == 0) { return; }    // odd, but permissable?
129                                                   147   
130   faces = new G4VCSGface*[numFace];               148   faces = new G4VCSGface*[numFace];
131                                                   149   
132   G4VCSGface **face = faces,                      150   G4VCSGface **face = faces,
133        **sourceFace = source.faces;               151        **sourceFace = source.faces;
134   do    // Loop checking, 13.08.2015, G.Cosmo  << 152   do
135   {                                               153   {
136     *face = (*sourceFace)->Clone();               154     *face = (*sourceFace)->Clone();
137   } while( ++sourceFace, ++face < faces+numFac    155   } while( ++sourceFace, ++face < faces+numFace );
138   fCubicVolume = source.fCubicVolume;             156   fCubicVolume = source.fCubicVolume;
139   fSurfaceArea = source.fSurfaceArea;             157   fSurfaceArea = source.fSurfaceArea;
140   fRebuildPolyhedron = false;                     158   fRebuildPolyhedron = false;
141   fpPolyhedron = nullptr;                      << 159   fpPolyhedron = 0;
142 }                                                 160 }
143                                                   161 
144                                                   162 
145 //                                                163 //
146 // DeleteStuff (protected)                        164 // DeleteStuff (protected)
147 //                                                165 //
148 // Delete all allocated objects                   166 // Delete all allocated objects
149 //                                                167 //
150 void G4VCSGfaceted::DeleteStuff()                 168 void G4VCSGfaceted::DeleteStuff()
151 {                                                 169 {
152   if (numFace != 0)                            << 170   if (numFace)
153   {                                               171   {
154     G4VCSGface **face = faces;                    172     G4VCSGface **face = faces;
155     do    // Loop checking, 13.08.2015, G.Cosm << 173     do
156     {                                             174     {
157       delete *face;                               175       delete *face;
158     } while( ++face < faces + numFace );          176     } while( ++face < faces + numFace );
159                                                   177 
160     delete [] faces;                              178     delete [] faces;
161   }                                               179   }
162   delete fpPolyhedron; fpPolyhedron = nullptr; << 180   delete fpPolyhedron; fpPolyhedron = 0;
163 }                                                 181 }
164                                                   182 
165                                                   183 
166 //                                                184 //
167 // CalculateExtent                                185 // CalculateExtent
168 //                                                186 //
169 G4bool G4VCSGfaceted::CalculateExtent( const E    187 G4bool G4VCSGfaceted::CalculateExtent( const EAxis axis,
170                                        const G << 188                                        const G4VoxelLimits &voxelLimit,
171                                        const G << 189                                        const G4AffineTransform &transform,
172                                              G << 190                                              G4double &min,
173                                              G << 191                                              G4double &max ) const
174 {                                                 192 {
175   G4SolidExtentList  extentList( axis, voxelLi    193   G4SolidExtentList  extentList( axis, voxelLimit );
176                                                   194 
177   //                                              195   //
178   // Loop over all faces, checking min/max ext    196   // Loop over all faces, checking min/max extent as we go.
179   //                                              197   //
180   G4VCSGface **face = faces;                      198   G4VCSGface **face = faces;
181   do    // Loop checking, 13.08.2015, G.Cosmo  << 199   do
182   {                                               200   {
183     (*face)->CalculateExtent( axis, voxelLimit    201     (*face)->CalculateExtent( axis, voxelLimit, transform, extentList );
184   } while( ++face < faces + numFace );            202   } while( ++face < faces + numFace );
185                                                   203   
186   //                                              204   //
187   // Return min/max value                         205   // Return min/max value
188   //                                              206   //
189   return extentList.GetExtent( min, max );        207   return extentList.GetExtent( min, max );
190 }                                                 208 }
191                                                   209 
192                                                   210 
193 //                                                211 //
194 // Inside                                         212 // Inside
195 //                                                213 //
196 // It could be a good idea to override this vi    214 // It could be a good idea to override this virtual
197 // member to add first a simple test (such as     215 // member to add first a simple test (such as spherical
198 // test or whatnot) and to call this version o    216 // test or whatnot) and to call this version only if
199 // the simplier test fails.                       217 // the simplier test fails.
200 //                                                218 //
201 EInside G4VCSGfaceted::Inside( const G4ThreeVe << 219 EInside G4VCSGfaceted::Inside( const G4ThreeVector &p ) const
202 {                                                 220 {
203   EInside answer=kOutside;                        221   EInside answer=kOutside;
204   G4VCSGface **face = faces;                      222   G4VCSGface **face = faces;
205   G4double best = kInfinity;                      223   G4double best = kInfinity;
206   do    // Loop checking, 13.08.2015, G.Cosmo  << 224   do
207   {                                               225   {
208     G4double distance;                            226     G4double distance;
209     EInside result = (*face)->Inside( p, kCarT    227     EInside result = (*face)->Inside( p, kCarTolerance/2, &distance );
210     if (result == kSurface) { return kSurface;    228     if (result == kSurface) { return kSurface; }
211     if (distance < best)                          229     if (distance < best)
212     {                                             230     {
213       best = distance;                            231       best = distance;
214       answer = result;                            232       answer = result;
215     }                                             233     }
216   } while( ++face < faces + numFace );            234   } while( ++face < faces + numFace );
217                                                   235 
218   return answer;                                  236   return answer;
219 }                                                 237 }
220                                                   238 
221                                                   239 
222 //                                                240 //
223 // SurfaceNormal                                  241 // SurfaceNormal
224 //                                                242 //
225 G4ThreeVector G4VCSGfaceted::SurfaceNormal( co    243 G4ThreeVector G4VCSGfaceted::SurfaceNormal( const G4ThreeVector& p ) const
226 {                                                 244 {
227   G4ThreeVector answer;                           245   G4ThreeVector answer;
228   G4VCSGface **face = faces;                      246   G4VCSGface **face = faces;
229   G4double best = kInfinity;                      247   G4double best = kInfinity;
230   do    // Loop checking, 13.08.2015, G.Cosmo  << 248   do
231   {                                               249   {
232     G4double distance = kInfinity;             << 250     G4double distance;
233     G4ThreeVector normal = (*face)->Normal( p,    251     G4ThreeVector normal = (*face)->Normal( p, &distance );
234     if (distance < best)                          252     if (distance < best)
235     {                                             253     {
236       best = distance;                            254       best = distance;
237       answer = normal;                            255       answer = normal;
238     }                                             256     }
239   } while( ++face < faces + numFace );            257   } while( ++face < faces + numFace );
240                                                   258 
241   return answer;                                  259   return answer;
242 }                                                 260 }
243                                                   261 
244                                                   262 
245 //                                                263 //
246 // DistanceToIn(p,v)                              264 // DistanceToIn(p,v)
247 //                                                265 //
248 G4double G4VCSGfaceted::DistanceToIn( const G4 << 266 G4double G4VCSGfaceted::DistanceToIn( const G4ThreeVector &p,
249                                       const G4 << 267                                       const G4ThreeVector &v ) const
250 {                                                 268 {
251   G4double distance = kInfinity;                  269   G4double distance = kInfinity;
252   G4double distFromSurface = kInfinity;           270   G4double distFromSurface = kInfinity;
253   G4VCSGface **face = faces;                      271   G4VCSGface **face = faces;
254   G4VCSGface *bestFace = *face;                   272   G4VCSGface *bestFace = *face;
255   do    // Loop checking, 13.08.2015, G.Cosmo  << 273   do
256   {                                               274   {
257     G4double   faceDistance,                      275     G4double   faceDistance,
258                faceDistFromSurface;               276                faceDistFromSurface;
259     G4ThreeVector   faceNormal;                   277     G4ThreeVector   faceNormal;
260     G4bool    faceAllBehind;                      278     G4bool    faceAllBehind;
261     if ((*face)->Intersect( p, v, false, kCarT    279     if ((*face)->Intersect( p, v, false, kCarTolerance/2,
262                 faceDistance, faceDistFromSurf    280                 faceDistance, faceDistFromSurface,
263                 faceNormal, faceAllBehind ) )     281                 faceNormal, faceAllBehind ) )
264     {                                             282     {
265       //                                          283       //
266       // Intersecting face                        284       // Intersecting face
267       //                                          285       //
268       if (faceDistance < distance)                286       if (faceDistance < distance)
269       {                                           287       {
270         distance = faceDistance;                  288         distance = faceDistance;
271         distFromSurface = faceDistFromSurface;    289         distFromSurface = faceDistFromSurface;
272         bestFace = *face;                         290         bestFace = *face;
273         if (distFromSurface <= 0) { return 0;     291         if (distFromSurface <= 0) { return 0; }
274       }                                           292       }
275     }                                             293     }
276   } while( ++face < faces + numFace );            294   } while( ++face < faces + numFace );
277                                                   295   
278   if (distance < kInfinity && distFromSurface<    296   if (distance < kInfinity && distFromSurface<kCarTolerance/2)
279   {                                               297   {
280     if (bestFace->Distance(p,false) < kCarTole    298     if (bestFace->Distance(p,false) < kCarTolerance/2)  { distance = 0; }
281   }                                               299   }
282                                                   300 
283   return distance;                                301   return distance;
284 }                                                 302 }
285                                                   303 
286                                                   304 
287 //                                                305 //
288 // DistanceToIn(p)                                306 // DistanceToIn(p)
289 //                                                307 //
290 G4double G4VCSGfaceted::DistanceToIn( const G4 << 308 G4double G4VCSGfaceted::DistanceToIn( const G4ThreeVector &p ) const
291 {                                                 309 {
292   return DistanceTo( p, false );                  310   return DistanceTo( p, false );
293 }                                                 311 }
294                                                   312 
295                                                   313 
296 //                                                314 //
297 // DistanceToOut(p,v)                             315 // DistanceToOut(p,v)
298 //                                                316 //
299 G4double G4VCSGfaceted::DistanceToOut( const G << 317 G4double G4VCSGfaceted::DistanceToOut( const G4ThreeVector &p,
300                                        const G << 318                                        const G4ThreeVector &v,
301                                        const G    319                                        const G4bool calcNorm,
302                                              G << 320                                              G4bool *validNorm,
303                                              G << 321                                              G4ThreeVector *n ) const
304 {                                                 322 {
305   G4bool allBehind = true;                        323   G4bool allBehind = true;
306   G4double distance = kInfinity;                  324   G4double distance = kInfinity;
307   G4double distFromSurface = kInfinity;           325   G4double distFromSurface = kInfinity;
308   G4ThreeVector normal;                           326   G4ThreeVector normal;
309                                                   327   
310   G4VCSGface **face = faces;                      328   G4VCSGface **face = faces;
311   G4VCSGface *bestFace = *face;                   329   G4VCSGface *bestFace = *face;
312   do    // Loop checking, 13.08.2015, G.Cosmo  << 330   do
313   {                                               331   {
314     G4double  faceDistance,                       332     G4double  faceDistance,
315               faceDistFromSurface;                333               faceDistFromSurface;
316     G4ThreeVector  faceNormal;                    334     G4ThreeVector  faceNormal;
317     G4bool    faceAllBehind;                      335     G4bool    faceAllBehind;
318     if ((*face)->Intersect( p, v, true, kCarTo    336     if ((*face)->Intersect( p, v, true, kCarTolerance/2,
319                 faceDistance, faceDistFromSurf    337                 faceDistance, faceDistFromSurface,
320                 faceNormal, faceAllBehind ) )     338                 faceNormal, faceAllBehind ) )
321     {                                             339     {
322       //                                          340       //
323       // Intersecting face                        341       // Intersecting face
324       //                                          342       //
325       if ( (distance < kInfinity) || (!faceAll    343       if ( (distance < kInfinity) || (!faceAllBehind) )  { allBehind = false; }
326       if (faceDistance < distance)                344       if (faceDistance < distance)
327       {                                           345       {
328         distance = faceDistance;                  346         distance = faceDistance;
329         distFromSurface = faceDistFromSurface;    347         distFromSurface = faceDistFromSurface;
330         normal = faceNormal;                      348         normal = faceNormal;
331         bestFace = *face;                         349         bestFace = *face;
332         if (distFromSurface <= 0.)  { break; } << 350         if (distFromSurface <= 0)  { break; }
333       }                                           351       }
334     }                                             352     }
335   } while( ++face < faces + numFace );            353   } while( ++face < faces + numFace );
336                                                   354   
337   if (distance < kInfinity)                       355   if (distance < kInfinity)
338   {                                               356   {
339     if (distFromSurface <= 0.)                 << 357     if (distFromSurface <= 0)
340     {                                             358     {
341       distance = 0.;                           << 359       distance = 0;
342     }                                             360     }
343     else if (distFromSurface<kCarTolerance/2)     361     else if (distFromSurface<kCarTolerance/2)
344     {                                             362     {
345       if (bestFace->Distance(p,true) < kCarTol << 363       if (bestFace->Distance(p,true) < kCarTolerance/2)  { distance = 0; }
346     }                                             364     }
347                                                   365 
348     if (calcNorm)                                 366     if (calcNorm)
349     {                                             367     {
350       *validNorm = allBehind;                     368       *validNorm = allBehind;
351       *n = normal;                                369       *n = normal;
352     }                                             370     }
353   }                                               371   }
354   else                                            372   else
355   {                                               373   { 
356     if (Inside(p) == kSurface)  { distance = 0 << 374     if (Inside(p) == kSurface)  { distance = 0; }
357     if (calcNorm)  { *validNorm = false; }        375     if (calcNorm)  { *validNorm = false; }
358   }                                               376   }
359                                                   377 
360   return distance;                                378   return distance;
361 }                                                 379 }
362                                                   380 
363                                                   381 
364 //                                                382 //
365 // DistanceToOut(p)                               383 // DistanceToOut(p)
366 //                                                384 //
367 G4double G4VCSGfaceted::DistanceToOut( const G << 385 G4double G4VCSGfaceted::DistanceToOut( const G4ThreeVector &p ) const
368 {                                                 386 {
369   return DistanceTo( p, true );                   387   return DistanceTo( p, true );
370 }                                                 388 }
371                                                   389 
372                                                   390 
373 //                                                391 //
374 // DistanceTo                                     392 // DistanceTo
375 //                                                393 //
376 // Protected routine called by DistanceToIn an    394 // Protected routine called by DistanceToIn and DistanceToOut
377 //                                                395 //
378 G4double G4VCSGfaceted::DistanceTo( const G4Th << 396 G4double G4VCSGfaceted::DistanceTo( const G4ThreeVector &p,
379                                     const G4bo    397                                     const G4bool outgoing ) const
380 {                                                 398 {
381   G4VCSGface **face = faces;                      399   G4VCSGface **face = faces;
382   G4double best = kInfinity;                      400   G4double best = kInfinity;
383   do    // Loop checking, 13.08.2015, G.Cosmo  << 401   do
384   {                                               402   {
385     G4double distance = (*face)->Distance( p,     403     G4double distance = (*face)->Distance( p, outgoing );
386     if (distance < best)  { best = distance; }    404     if (distance < best)  { best = distance; }
387   } while( ++face < faces + numFace );            405   } while( ++face < faces + numFace );
388                                                   406 
389   return (best < 0.5*kCarTolerance) ? 0. : bes << 407   return (best < 0.5*kCarTolerance) ? 0 : best;
390 }                                                 408 }
391                                                   409 
392                                                   410 
393 //                                                411 //
394 // DescribeYourselfTo                             412 // DescribeYourselfTo
395 //                                                413 //
396 void G4VCSGfaceted::DescribeYourselfTo( G4VGra    414 void G4VCSGfaceted::DescribeYourselfTo( G4VGraphicsScene& scene ) const
397 {                                                 415 {
398    scene.AddSolid( *this );                       416    scene.AddSolid( *this );
399 }                                                 417 }
400                                                   418 
401                                                   419 
402 //                                                420 //
403 // GetExtent                                      421 // GetExtent
404 //                                                422 //
405 // Define the sides of the box into which our     423 // Define the sides of the box into which our solid instance would fit.
406 //                                                424 //
407 G4VisExtent G4VCSGfaceted::GetExtent() const      425 G4VisExtent G4VCSGfaceted::GetExtent() const 
408 {                                                 426 {
409   static const G4ThreeVector xMax(1,0,0), xMin    427   static const G4ThreeVector xMax(1,0,0), xMin(-1,0,0),
410                              yMax(0,1,0), yMin    428                              yMax(0,1,0), yMin(0,-1,0),
411                              zMax(0,0,1), zMin    429                              zMax(0,0,1), zMin(0,0,-1);
412   static const G4ThreeVector *axes[6] =           430   static const G4ThreeVector *axes[6] =
413      { &xMin, &xMax, &yMin, &yMax, &zMin, &zMa    431      { &xMin, &xMax, &yMin, &yMax, &zMin, &zMax };
414                                                   432   
415   G4double answers[6] =                           433   G4double answers[6] =
416      {-kInfinity, -kInfinity, -kInfinity, -kIn    434      {-kInfinity, -kInfinity, -kInfinity, -kInfinity, -kInfinity, -kInfinity};
417                                                   435 
418   G4VCSGface **face = faces;                      436   G4VCSGface **face = faces;
419   do    // Loop checking, 13.08.2015, G.Cosmo  << 437   do
420   {                                               438   {    
421     const G4ThreeVector **axis = axes+5 ;         439     const G4ThreeVector **axis = axes+5 ;
422     G4double* answer = answers+5;              << 440     G4double *answer = answers+5;
423     do    // Loop checking, 13.08.2015, G.Cosm << 441     do
424     {                                             442     {
425       G4double testFace = (*face)->Extent( **a    443       G4double testFace = (*face)->Extent( **axis );
426       if (testFace > *answer)  { *answer = tes    444       if (testFace > *answer)  { *answer = testFace; }
427     }                                             445     }
428     while( --axis, --answer >= answers );         446     while( --axis, --answer >= answers );
429                                                   447     
430   } while( ++face < faces + numFace );            448   } while( ++face < faces + numFace );
431                                                   449   
432   return { -answers[0], answers[1],            << 450     return G4VisExtent( -answers[0], answers[1], 
433            -answers[2], answers[3],            << 451                         -answers[2], answers[3],
434            -answers[4], answers[5]  };         << 452                         -answers[4], answers[5]  );
435 }                                                 453 }
436                                                   454 
437                                                   455 
438 //                                                456 //
439 // GetEntityType                                  457 // GetEntityType
440 //                                                458 //
441 G4GeometryType G4VCSGfaceted::GetEntityType()     459 G4GeometryType G4VCSGfaceted::GetEntityType() const
442 {                                                 460 {
443   return {"G4CSGfaceted"};                     << 461   return G4String("G4CSGfaceted");
444 }                                                 462 }
445                                                   463 
446                                                   464 
447 //                                                465 //
448 // Stream object contents to an output stream     466 // Stream object contents to an output stream
449 //                                                467 //
450 std::ostream& G4VCSGfaceted::StreamInfo( std::    468 std::ostream& G4VCSGfaceted::StreamInfo( std::ostream& os ) const
451 {                                                 469 {
452   os << "-------------------------------------    470   os << "-----------------------------------------------------------\n"
453      << "    *** Dump for solid - " << GetName    471      << "    *** Dump for solid - " << GetName() << " ***\n"
454      << "    =================================    472      << "    ===================================================\n"
455      << " Solid type: G4VCSGfaceted\n"            473      << " Solid type: G4VCSGfaceted\n"
456      << " Parameters: \n"                         474      << " Parameters: \n"
457      << "    number of faces: " << numFace <<     475      << "    number of faces: " << numFace << "\n"
458      << "-------------------------------------    476      << "-----------------------------------------------------------\n";
459                                                   477 
460   return os;                                      478   return os;
461 }                                                 479 }
462                                                   480 
463                                                   481 
464 //                                                482 //
465 // GetCubVolStatistics                            483 // GetCubVolStatistics
466 //                                                484 //
467 G4int G4VCSGfaceted::GetCubVolStatistics() con    485 G4int G4VCSGfaceted::GetCubVolStatistics() const
468 {                                                 486 {
469   return fStatistics;                             487   return fStatistics;
470 }                                                 488 }
471                                                   489 
472                                                   490 
473 //                                                491 //
474 // GetCubVolEpsilon                               492 // GetCubVolEpsilon
475 //                                                493 //
476 G4double G4VCSGfaceted::GetCubVolEpsilon() con    494 G4double G4VCSGfaceted::GetCubVolEpsilon() const
477 {                                                 495 {
478   return fCubVolEpsilon;                          496   return fCubVolEpsilon;
479 }                                                 497 }
480                                                   498 
481                                                   499 
482 //                                                500 //
483 // SetCubVolStatistics                            501 // SetCubVolStatistics
484 //                                                502 //
485 void G4VCSGfaceted::SetCubVolStatistics(G4int     503 void G4VCSGfaceted::SetCubVolStatistics(G4int st)
486 {                                                 504 {
487   fCubicVolume=0.;                                505   fCubicVolume=0.;
488   fStatistics=st;                                 506   fStatistics=st;
489 }                                                 507 }
490                                                   508 
491                                                   509 
492 //                                                510 //
493 // SetCubVolEpsilon                               511 // SetCubVolEpsilon
494 //                                                512 //
495 void G4VCSGfaceted::SetCubVolEpsilon(G4double     513 void G4VCSGfaceted::SetCubVolEpsilon(G4double ep)
496 {                                                 514 {
497   fCubicVolume=0.;                                515   fCubicVolume=0.;
498   fCubVolEpsilon=ep;                              516   fCubVolEpsilon=ep;
499 }                                                 517 }
500                                                   518 
501                                                   519 
502 //                                                520 //
503 // GetAreaStatistics                              521 // GetAreaStatistics
504 //                                                522 //
505 G4int G4VCSGfaceted::GetAreaStatistics() const    523 G4int G4VCSGfaceted::GetAreaStatistics() const
506 {                                                 524 {
507   return fStatistics;                             525   return fStatistics;
508 }                                                 526 }
509                                                   527 
510                                                   528 
511 //                                                529 //
512 // GetAreaAccuracy                                530 // GetAreaAccuracy
513 //                                                531 //
514 G4double G4VCSGfaceted::GetAreaAccuracy() cons    532 G4double G4VCSGfaceted::GetAreaAccuracy() const
515 {                                                 533 {
516   return fAreaAccuracy;                           534   return fAreaAccuracy;
517 }                                                 535 }
518                                                   536 
519                                                   537 
520 //                                                538 //
521 // SetAreaStatistics                              539 // SetAreaStatistics
522 //                                                540 //
523 void G4VCSGfaceted::SetAreaStatistics(G4int st    541 void G4VCSGfaceted::SetAreaStatistics(G4int st)
524 {                                                 542 {
525   fSurfaceArea=0.;                                543   fSurfaceArea=0.;
526   fStatistics=st;                                 544   fStatistics=st;
527 }                                                 545 }
528                                                   546 
529                                                   547 
530 //                                                548 //
531 // SetAreaAccuracy                                549 // SetAreaAccuracy
532 //                                                550 //
533 void G4VCSGfaceted::SetAreaAccuracy(G4double e    551 void G4VCSGfaceted::SetAreaAccuracy(G4double ep)
534 {                                                 552 {
535   fSurfaceArea=0.;                                553   fSurfaceArea=0.;
536   fAreaAccuracy=ep;                               554   fAreaAccuracy=ep;
537 }                                                 555 }
538                                                   556 
539                                                   557 
540 //                                                558 //
541 // GetCubicVolume                                 559 // GetCubicVolume
542 //                                                560 //
543 G4double G4VCSGfaceted::GetCubicVolume()          561 G4double G4VCSGfaceted::GetCubicVolume()
544 {                                                 562 {
545   if(fCubicVolume != 0.) {;}                      563   if(fCubicVolume != 0.) {;}
546   else   { fCubicVolume = EstimateCubicVolume(    564   else   { fCubicVolume = EstimateCubicVolume(fStatistics,fCubVolEpsilon); }
547   return fCubicVolume;                            565   return fCubicVolume;
548 }                                                 566 }
549                                                   567 
550                                                   568 
551 //                                                569 //
552 // GetSurfaceArea                                 570 // GetSurfaceArea
553 //                                                571 //
554 G4double G4VCSGfaceted::GetSurfaceArea()          572 G4double G4VCSGfaceted::GetSurfaceArea()
555 {                                                 573 {
556   if(fSurfaceArea != 0.) {;}                      574   if(fSurfaceArea != 0.) {;}
557   else   { fSurfaceArea = EstimateSurfaceArea(    575   else   { fSurfaceArea = EstimateSurfaceArea(fStatistics,fAreaAccuracy); }
558   return fSurfaceArea;                            576   return fSurfaceArea;
559 }                                                 577 }
560                                                   578 
561                                                   579 
562 //                                                580 //
563 // GetPolyhedron                                  581 // GetPolyhedron
564 //                                                582 //
565 G4Polyhedron* G4VCSGfaceted::GetPolyhedron ()     583 G4Polyhedron* G4VCSGfaceted::GetPolyhedron () const
566 {                                                 584 {
567   if (fpPolyhedron == nullptr ||               << 585   if (!fpPolyhedron ||
568       fRebuildPolyhedron ||                       586       fRebuildPolyhedron ||
569       fpPolyhedron->GetNumberOfRotationStepsAt    587       fpPolyhedron->GetNumberOfRotationStepsAtTimeOfCreation() !=
570       fpPolyhedron->GetNumberOfRotationSteps()    588       fpPolyhedron->GetNumberOfRotationSteps())
571   {                                               589   {
572     G4AutoLock l(&polyhedronMutex);               590     G4AutoLock l(&polyhedronMutex);
573     delete fpPolyhedron;                          591     delete fpPolyhedron;
574     fpPolyhedron = CreatePolyhedron();            592     fpPolyhedron = CreatePolyhedron();
575     fRebuildPolyhedron = false;                   593     fRebuildPolyhedron = false;
576     l.unlock();                                   594     l.unlock();
577   }                                               595   }
578   return fpPolyhedron;                            596   return fpPolyhedron;
579 }                                                 597 }
580                                                   598 
581                                                   599 
582 //                                                600 //
583 // GetPointOnSurfaceGeneric proportional to Ar    601 // GetPointOnSurfaceGeneric proportional to Areas of faces
584 // in case of GenericPolycone or GenericPolyhe    602 // in case of GenericPolycone or GenericPolyhedra
585 //                                                603 //
586 G4ThreeVector G4VCSGfaceted::GetPointOnSurface    604 G4ThreeVector G4VCSGfaceted::GetPointOnSurfaceGeneric( ) const
587 {                                                 605 {
588   // Preparing variables                          606   // Preparing variables
589   //                                              607   //
590   G4ThreeVector answer=G4ThreeVector(0.,0.,0.)    608   G4ThreeVector answer=G4ThreeVector(0.,0.,0.);
591   G4VCSGface **face = faces;                      609   G4VCSGface **face = faces;
592   G4double area = 0.;                          << 610   G4double area = 0;
593   G4int i;                                        611   G4int i;
594   std::vector<G4double> areas;                    612   std::vector<G4double> areas; 
595                                                   613 
596   // First step: calculate surface areas          614   // First step: calculate surface areas
597   //                                              615   //
598   do    // Loop checking, 13.08.2015, G.Cosmo  << 616   do
599   {                                               617   {
600     G4double result = (*face)->SurfaceArea( );    618     G4double result = (*face)->SurfaceArea( );
601     areas.push_back(result);                      619     areas.push_back(result);
602     area=area+result;                             620     area=area+result;
603   } while( ++face < faces + numFace );            621   } while( ++face < faces + numFace );
604                                                   622 
605   // Second Step: choose randomly one surface     623   // Second Step: choose randomly one surface
606   //                                              624   //
607   G4VCSGface **face1 = faces;                     625   G4VCSGface **face1 = faces;
608   G4double chose = area*G4UniformRand();          626   G4double chose = area*G4UniformRand();
609   G4double Achose1, Achose2;                      627   G4double Achose1, Achose2;
610   Achose1=0.; Achose2=0.;                      << 628   Achose1=0; Achose2=0.; 
611   i=0;                                            629   i=0;
612                                                   630 
613   do                                              631   do
614   {                                               632   {
615     Achose2+=areas[i];                            633     Achose2+=areas[i];
616     if(chose>=Achose1 && chose<Achose2)           634     if(chose>=Achose1 && chose<Achose2)
617     {                                             635     {
618       G4ThreeVector point;                        636       G4ThreeVector point;
619       point= (*face1)->GetPointOnFace();          637       point= (*face1)->GetPointOnFace();
620       return point;                               638       return point;
621     }                                             639     }
622     ++i;                                       << 640     i++;
623     Achose1=Achose2;                              641     Achose1=Achose2;
624   } while( ++face1 < faces + numFace );           642   } while( ++face1 < faces + numFace );
625                                                   643 
626   return answer;                                  644   return answer;
627 }                                                 645 }
628                                                   646