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


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