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.4.p1)


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