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 9.2)


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