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.0)


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