Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/solids/specific/src/G4ClippablePolygon.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/G4ClippablePolygon.cc (Version 11.3.0) and /geometry/solids/specific/src/G4ClippablePolygon.cc (Version 9.2.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4ClippablePolygon implementation           <<  26 //
                                                   >>  27 // $Id: G4ClippablePolygon.cc,v 1.12 2007/05/11 13:54:28 gcosmo Exp $
                                                   >>  28 // GEANT4 tag $Name: geant4-09-02 $
                                                   >>  29 //
                                                   >>  30 // 
                                                   >>  31 // --------------------------------------------------------------------
                                                   >>  32 // GEANT 4 class source file
                                                   >>  33 //
                                                   >>  34 //
                                                   >>  35 // G4ClippablePolygon.cc
 27 //                                                 36 //
 28 // Includes code from G4VSolid (P.Kent, V.Gric     37 // Includes code from G4VSolid (P.Kent, V.Grichine, J.Allison)
                                                   >>  38 //
 29 // -------------------------------------------     39 // --------------------------------------------------------------------
 30                                                    40 
 31 #include "G4ClippablePolygon.hh"                   41 #include "G4ClippablePolygon.hh"
 32                                                    42 
 33 #include "G4VoxelLimits.hh"                        43 #include "G4VoxelLimits.hh"
 34 #include "G4GeometryTolerance.hh"                  44 #include "G4GeometryTolerance.hh"
 35                                                    45 
                                                   >>  46 //
 36 // Constructor                                     47 // Constructor
 37 //                                                 48 //
 38 G4ClippablePolygon::G4ClippablePolygon()           49 G4ClippablePolygon::G4ClippablePolygon()
 39   : normal(0.,0.,0.)                               50   : normal(0.,0.,0.)
 40 {                                                  51 {
 41   kCarTolerance = G4GeometryTolerance::GetInst     52   kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
 42 }                                                  53 }
 43                                                    54 
                                                   >>  55 
                                                   >>  56 //
 44 // Destructor                                      57 // Destructor
 45 //                                                 58 //
 46 G4ClippablePolygon::~G4ClippablePolygon() = de <<  59 G4ClippablePolygon::~G4ClippablePolygon()
                                                   >>  60 {
                                                   >>  61 }
 47                                                    62 
                                                   >>  63 
                                                   >>  64 //
 48 // AddVertexInOrder                                65 // AddVertexInOrder
 49 //                                                 66 //
 50 void G4ClippablePolygon::AddVertexInOrder( con     67 void G4ClippablePolygon::AddVertexInOrder( const G4ThreeVector vertex )
 51 {                                                  68 {
 52   vertices.push_back( vertex );                    69   vertices.push_back( vertex );
 53 }                                                  70 }
 54                                                    71 
                                                   >>  72 
                                                   >>  73 //
 55 // ClearAllVertices                                74 // ClearAllVertices
 56 //                                                 75 //
 57 void G4ClippablePolygon::ClearAllVertices()        76 void G4ClippablePolygon::ClearAllVertices()
 58 {                                                  77 {
 59   vertices.clear();                                78   vertices.clear();
 60 }                                                  79 }
 61                                                    80 
                                                   >>  81 
                                                   >>  82 //
 62 // Clip                                            83 // Clip
 63 //                                                 84 //
 64 G4bool G4ClippablePolygon::Clip( const G4Voxel <<  85 G4bool G4ClippablePolygon::Clip( const G4VoxelLimits &voxelLimit )
 65 {                                                  86 {
 66   if (voxelLimit.IsLimited())                  <<  87   if (voxelLimit.IsLimited()) {
 67   {                                            << 
 68     ClipAlongOneAxis( voxelLimit, kXAxis );        88     ClipAlongOneAxis( voxelLimit, kXAxis );
 69     ClipAlongOneAxis( voxelLimit, kYAxis );        89     ClipAlongOneAxis( voxelLimit, kYAxis );
 70     ClipAlongOneAxis( voxelLimit, kZAxis );        90     ClipAlongOneAxis( voxelLimit, kZAxis );
 71   }                                                91   }
 72                                                    92   
 73   return (!vertices.empty());                  <<  93   return (vertices.size() > 0);
 74 }                                                  94 }
 75                                                    95 
                                                   >>  96 
                                                   >>  97 //
 76 // PartialClip                                     98 // PartialClip
 77 //                                                 99 //
 78 // Clip, while ignoring the indicated axis        100 // Clip, while ignoring the indicated axis
 79 //                                                101 //
 80 G4bool G4ClippablePolygon::PartialClip( const  << 102 G4bool G4ClippablePolygon::PartialClip( const G4VoxelLimits &voxelLimit,
 81                                         const     103                                         const EAxis IgnoreMe )
 82 {                                                 104 {
 83   if (voxelLimit.IsLimited())                  << 105   if (voxelLimit.IsLimited()) {
 84   {                                            << 
 85     if (IgnoreMe != kXAxis) ClipAlongOneAxis(     106     if (IgnoreMe != kXAxis) ClipAlongOneAxis( voxelLimit, kXAxis );
 86     if (IgnoreMe != kYAxis) ClipAlongOneAxis(     107     if (IgnoreMe != kYAxis) ClipAlongOneAxis( voxelLimit, kYAxis );
 87     if (IgnoreMe != kZAxis) ClipAlongOneAxis(     108     if (IgnoreMe != kZAxis) ClipAlongOneAxis( voxelLimit, kZAxis );
 88   }                                               109   }
 89                                                   110   
 90   return (!vertices.empty());                  << 111   return (vertices.size() > 0);
 91 }                                                 112 }
 92                                                   113 
                                                   >> 114 
                                                   >> 115 //
 93 // GetExtent                                      116 // GetExtent
 94 //                                                117 //
 95 G4bool G4ClippablePolygon::GetExtent( const EA    118 G4bool G4ClippablePolygon::GetExtent( const EAxis axis, 
 96                                             G4 << 119                                             G4double &min,
 97                                             G4 << 120                                             G4double &max ) const
 98 {                                                 121 {
 99   //                                              122   //
100   // Okay, how many entries do we have?           123   // Okay, how many entries do we have?
101   //                                              124   //
102   std::size_t noLeft = vertices.size();        << 125   G4int noLeft = vertices.size();
103                                                   126   
104   //                                              127   //
105   // Return false if nothing is left              128   // Return false if nothing is left
106   //                                              129   //
107   if (noLeft == 0) return false;                  130   if (noLeft == 0) return false;
108                                                   131   
109   //                                              132   //
110   // Initialize min and max to our first verte    133   // Initialize min and max to our first vertex
111   //                                              134   //
112   min = max = vertices[0].operator()( axis );     135   min = max = vertices[0].operator()( axis );
113                                                   136   
114   //                                              137   //
115   // Compare to the rest                          138   // Compare to the rest
116   //                                              139   //
117   for( std::size_t i=1; i<noLeft; ++i )        << 140   G4int i;
                                                   >> 141   for( i=1; i<noLeft; i++ )
118   {                                               142   {
119     G4double component = vertices[i].operator(    143     G4double component = vertices[i].operator()( axis );
120     if (component < min )                         144     if (component < min )
121       min = component;                            145       min = component;
122     else if (component > max )                    146     else if (component > max )
123       max = component;                            147       max = component;
124   }                                               148   }
125                                                   149   
126   return true;                                    150   return true;
127 }                                                 151 }
128                                                   152 
                                                   >> 153 
                                                   >> 154 //
129 // GetMinPoint                                    155 // GetMinPoint
130 //                                                156 //
131 // Returns pointer to minimum point along the     157 // Returns pointer to minimum point along the specified axis.
132 // Take care! Do not use pointer after destroy    158 // Take care! Do not use pointer after destroying parent polygon.
133 //                                                159 //
134 const G4ThreeVector* G4ClippablePolygon::GetMi << 160 const G4ThreeVector *G4ClippablePolygon::GetMinPoint( const EAxis axis ) const
135 {                                                 161 {
136   std::size_t noLeft = vertices.size();        << 162   G4int noLeft = vertices.size();
137   if (noLeft==0)                                  163   if (noLeft==0)
138   {                                            << 
139     G4Exception("G4ClippablePolygon::GetMinPoi    164     G4Exception("G4ClippablePolygon::GetMinPoint()",
140                 "GeomSolids0002", FatalExcepti << 165                 "InvalidSetup", FatalException, "Empty polygon.");
141   }                                            << 166   
142                                                << 
143   const G4ThreeVector *answer = &(vertices[0])    167   const G4ThreeVector *answer = &(vertices[0]);
144   G4double min = answer->operator()(axis);        168   G4double min = answer->operator()(axis);
145                                                   169 
146   for( std::size_t i=1; i<noLeft; ++i )        << 170   G4int i;
                                                   >> 171   for( i=1; i<noLeft; i++ )
147   {                                               172   {
148     G4double component = vertices[i].operator(    173     G4double component = vertices[i].operator()( axis );
149     if (component < min)                          174     if (component < min)
150     {                                             175     {
151       answer = &(vertices[i]);                    176       answer = &(vertices[i]);
152       min = component;                            177       min = component;
153     }                                             178     }
154   }                                               179   }
155                                                   180   
156   return answer;                                  181   return answer;
157 }                                                 182 }
158                                                   183 
                                                   >> 184 
                                                   >> 185 //
159 // GetMaxPoint                                    186 // GetMaxPoint
160 //                                                187 //
161 // Returns pointer to maximum point along the     188 // Returns pointer to maximum point along the specified axis.
162 // Take care! Do not use pointer after destroy    189 // Take care! Do not use pointer after destroying parent polygon.
163 //                                                190 //
164 const G4ThreeVector* G4ClippablePolygon::GetMa << 191 const G4ThreeVector *G4ClippablePolygon::GetMaxPoint( const EAxis axis ) const
165 {                                                 192 {
166   std::size_t noLeft = vertices.size();        << 193   G4int noLeft = vertices.size();
167   if (noLeft==0)                                  194   if (noLeft==0)
168   {                                            << 
169     G4Exception("G4ClippablePolygon::GetMaxPoi    195     G4Exception("G4ClippablePolygon::GetMaxPoint()",
170                 "GeomSolids0002", FatalExcepti << 196                 "InvalidSetup", FatalException, "Empty polygon.");
171   }                                            << 197   
172                                                << 
173   const G4ThreeVector *answer = &(vertices[0])    198   const G4ThreeVector *answer = &(vertices[0]);
174   G4double max = answer->operator()(axis);        199   G4double max = answer->operator()(axis);
175                                                   200 
176   for( std::size_t i=1; i<noLeft; ++i )        << 201   G4int i;
                                                   >> 202   for( i=1; i<noLeft; i++ )
177   {                                               203   {
178     G4double component = vertices[i].operator(    204     G4double component = vertices[i].operator()( axis );
179     if (component > max)                          205     if (component > max)
180     {                                             206     {
181       answer = &(vertices[i]);                    207       answer = &(vertices[i]);
182       max = component;                            208       max = component;
183     }                                             209     }
184   }                                               210   }
185                                                   211   
186   return answer;                                  212   return answer;
187 }                                                 213 }
                                                   >> 214     
188                                                   215 
                                                   >> 216 //
189 // InFrontOf                                      217 // InFrontOf
190 //                                                218 //
191 // Decide if this polygon is in "front" of ano    219 // Decide if this polygon is in "front" of another when
192 // viewed along the specified axis. For our pu    220 // viewed along the specified axis. For our purposes here,
193 // it is sufficient to use the minimum extent     221 // it is sufficient to use the minimum extent of the
194 // polygon along the axis to determine this.      222 // polygon along the axis to determine this.
195 //                                                223 //
196 // In case the minima of the two polygons are     224 // In case the minima of the two polygons are equal,
197 // we use a more sophisticated test.              225 // we use a more sophisticated test.
198 //                                                226 //
199 // Note that it is possible for the two follow    227 // Note that it is possible for the two following
200 // statements to both return true or both retu    228 // statements to both return true or both return false:
201 //         polygon1.InFrontOf(polygon2)           229 //         polygon1.InFrontOf(polygon2)
202 //         polygon2.BehindOf(polygon1)            230 //         polygon2.BehindOf(polygon1)
203 //                                                231 //
204 G4bool G4ClippablePolygon::InFrontOf( const G4 << 232 G4bool G4ClippablePolygon::InFrontOf( const G4ClippablePolygon &other,
205                                             EA    233                                             EAxis axis ) const
206 {                                                 234 {
207   //                                              235   //
208   // If things are empty, do something semi-se    236   // If things are empty, do something semi-sensible
209   //                                              237   //
210   std::size_t noLeft = vertices.size();        << 238   G4int noLeft = vertices.size();
211   if (noLeft==0) return false;                    239   if (noLeft==0) return false;
212                                                   240   
213   if (other.Empty()) return true;                 241   if (other.Empty()) return true;
214                                                   242 
215   //                                              243   //
216   // Get minimum of other polygon                 244   // Get minimum of other polygon
217   //                                              245   //
218   const G4ThreeVector *minPointOther = other.G    246   const G4ThreeVector *minPointOther = other.GetMinPoint( axis );
219   const G4double minOther = minPointOther->ope    247   const G4double minOther = minPointOther->operator()(axis);
220                                                   248   
221   //                                              249   //
222   // Get minimum of this polygon                  250   // Get minimum of this polygon
223   //                                              251   //
224   const G4ThreeVector *minPoint = GetMinPoint(    252   const G4ThreeVector *minPoint = GetMinPoint( axis );
225   const G4double min = minPoint->operator()(ax    253   const G4double min = minPoint->operator()(axis);
226                                                   254   
227   //                                              255   //
228   // Easy decision                                256   // Easy decision
229   //                                              257   //
230   if (min < minOther-kCarTolerance) return tru    258   if (min < minOther-kCarTolerance) return true;    // Clear winner
231                                                   259   
232   if (minOther < min-kCarTolerance) return fal    260   if (minOther < min-kCarTolerance) return false;    // Clear loser
233                                                   261   
234   //                                              262   //
235   // We have a tie (this will not be all that     263   // We have a tie (this will not be all that rare since our
236   // polygons are connected)                      264   // polygons are connected)
237   //                                              265   //
238   // Check to see if there is a vertex in the     266   // Check to see if there is a vertex in the other polygon
239   // that is behind this one (or vice versa)      267   // that is behind this one (or vice versa)
240   //                                              268   //
241   G4bool answer;                                  269   G4bool answer;
242   G4ThreeVector normalOther = other.GetNormal(    270   G4ThreeVector normalOther = other.GetNormal();
243                                                   271   
244   if (std::fabs(normalOther(axis)) > std::fabs    272   if (std::fabs(normalOther(axis)) > std::fabs(normal(axis)))
245   {                                               273   {
246     G4double minP, maxP;                          274     G4double minP, maxP;
247     GetPlanerExtent( *minPointOther, normalOth    275     GetPlanerExtent( *minPointOther, normalOther, minP, maxP );
248                                                   276     
249     answer = (normalOther(axis) > 0) ? (minP <    277     answer = (normalOther(axis) > 0) ? (minP < -kCarTolerance)
250                                      : (maxP >    278                                      : (maxP > +kCarTolerance);
251   }                                               279   }
252   else                                            280   else
253   {                                               281   {
254     G4double minP, maxP;                          282     G4double minP, maxP;
255     other.GetPlanerExtent( *minPoint, normal,     283     other.GetPlanerExtent( *minPoint, normal, minP, maxP );
256                                                   284     
257     answer = (normal(axis) > 0) ? (maxP > +kCa    285     answer = (normal(axis) > 0) ? (maxP > +kCarTolerance)
258                                 : (minP < -kCa    286                                 : (minP < -kCarTolerance);
259   }                                               287   }
260   return answer;                                  288   return answer;
261 }                                                 289 }
262                                                   290 
                                                   >> 291 //
263 // BehindOf                                       292 // BehindOf
264 //                                                293 //
265 // Decide if this polygon is behind another.      294 // Decide if this polygon is behind another.
266 // See notes in method "InFrontOf"                295 // See notes in method "InFrontOf"
267 //                                                296 //
268 G4bool G4ClippablePolygon::BehindOf( const G4C << 297 G4bool G4ClippablePolygon::BehindOf( const G4ClippablePolygon &other,
269                                            EAx    298                                            EAxis axis ) const
270 {                                                 299 {
271   //                                              300   //
272   // If things are empty, do something semi-se    301   // If things are empty, do something semi-sensible
273   //                                              302   //
274   std::size_t noLeft = vertices.size();        << 303   G4int noLeft = vertices.size();
275   if (noLeft==0) return false;                    304   if (noLeft==0) return false;
276                                                   305   
277   if (other.Empty()) return true;                 306   if (other.Empty()) return true;
278                                                   307 
279   //                                              308   //
280   // Get minimum of other polygon                 309   // Get minimum of other polygon
281   //                                              310   //
282   const G4ThreeVector *maxPointOther = other.G    311   const G4ThreeVector *maxPointOther = other.GetMaxPoint( axis );
283   const G4double maxOther = maxPointOther->ope    312   const G4double maxOther = maxPointOther->operator()(axis);
284                                                   313   
285   //                                              314   //
286   // Get minimum of this polygon                  315   // Get minimum of this polygon
287   //                                              316   //
288   const G4ThreeVector *maxPoint = GetMaxPoint(    317   const G4ThreeVector *maxPoint = GetMaxPoint( axis );
289   const G4double max = maxPoint->operator()(ax    318   const G4double max = maxPoint->operator()(axis);
290                                                   319   
291   //                                              320   //
292   // Easy decision                                321   // Easy decision
293   //                                              322   //
294   if (max > maxOther+kCarTolerance) return tru    323   if (max > maxOther+kCarTolerance) return true;    // Clear winner
295                                                   324   
296   if (maxOther > max+kCarTolerance) return fal    325   if (maxOther > max+kCarTolerance) return false;    // Clear loser
297                                                   326   
298   //                                              327   //
299   // We have a tie (this will not be all that     328   // We have a tie (this will not be all that rare since our
300   // polygons are connected)                      329   // polygons are connected)
301   //                                              330   //
302   // Check to see if there is a vertex in the     331   // Check to see if there is a vertex in the other polygon
303   // that is in front of this one (or vice ver    332   // that is in front of this one (or vice versa)
304   //                                              333   //
305   G4bool answer;                                  334   G4bool answer;
306   G4ThreeVector normalOther = other.GetNormal(    335   G4ThreeVector normalOther = other.GetNormal();
307                                                   336   
308   if (std::fabs(normalOther(axis)) > std::fabs    337   if (std::fabs(normalOther(axis)) > std::fabs(normal(axis)))
309   {                                               338   {
310     G4double minP, maxP;                          339     G4double minP, maxP;
311     GetPlanerExtent( *maxPointOther, normalOth    340     GetPlanerExtent( *maxPointOther, normalOther, minP, maxP );
312                                                   341     
313     answer = (normalOther(axis) > 0) ? (maxP >    342     answer = (normalOther(axis) > 0) ? (maxP > +kCarTolerance)
314                                      : (minP <    343                                      : (minP < -kCarTolerance);
315   }                                               344   }
316   else                                            345   else
317   {                                               346   {
318     G4double minP, maxP;                          347     G4double minP, maxP;
319     other.GetPlanerExtent( *maxPoint, normal,     348     other.GetPlanerExtent( *maxPoint, normal, minP, maxP );
320                                                   349     
321     answer = (normal(axis) > 0) ? (minP < -kCa    350     answer = (normal(axis) > 0) ? (minP < -kCarTolerance)
322                                 : (maxP > +kCa    351                                 : (maxP > +kCarTolerance);
323   }                                               352   }
324   return answer;                                  353   return answer;
325 }                                                 354 }
326                                                   355 
                                                   >> 356 
                                                   >> 357 //
327 // GetPlanerExtent                                358 // GetPlanerExtent
328 //                                                359 //
329 // Get min/max distance in or out of a plane      360 // Get min/max distance in or out of a plane
330 //                                                361 //
331 G4bool G4ClippablePolygon::GetPlanerExtent( co << 362 G4bool G4ClippablePolygon::GetPlanerExtent( const G4ThreeVector &pointOnPlane, 
332                                             co << 363                                             const G4ThreeVector &planeNormal,
333                                                << 364                                                   G4double &min,
334                                                << 365                                                   G4double &max ) const
335 {                                                 366 {
336   //                                              367   //
337   // Okay, how many entries do we have?           368   // Okay, how many entries do we have?
338   //                                              369   //
339   std::size_t noLeft = vertices.size();        << 370   G4int noLeft = vertices.size();
340                                                   371   
341   //                                              372   //
342   // Return false if nothing is left              373   // Return false if nothing is left
343   //                                              374   //
344   if (noLeft == 0) return false;                  375   if (noLeft == 0) return false;
345                                                   376   
346   //                                              377   //
347   // Initialize min and max to our first verte    378   // Initialize min and max to our first vertex
348   //                                              379   //
349   min = max = planeNormal.dot(vertices[0]-poin    380   min = max = planeNormal.dot(vertices[0]-pointOnPlane);
350                                                   381   
351   //                                              382   //
352   // Compare to the rest                          383   // Compare to the rest
353   //                                              384   //
354   for( std::size_t i=1; i<noLeft; ++i )        << 385   G4int i;
                                                   >> 386   for( i=1; i<noLeft; i++ )
355   {                                               387   {
356     G4double component = planeNormal.dot(verti    388     G4double component = planeNormal.dot(vertices[i] - pointOnPlane);
357     if (component < min )                         389     if (component < min )
358       min = component;                            390       min = component;
359     else if (component > max )                    391     else if (component > max )
360       max = component;                            392       max = component;
361   }                                               393   }
362                                                   394   
363   return true;                                    395   return true;
364 }                                                 396 }
365                                                   397 
366 // ClipAlongOneAxis                            << 398 
367 //                                                399 //
368 // Clip along just one axis, as specified in v    400 // Clip along just one axis, as specified in voxelLimit
369 //                                                401 //
370 void G4ClippablePolygon::ClipAlongOneAxis( con << 402 void G4ClippablePolygon::ClipAlongOneAxis( const G4VoxelLimits &voxelLimit,
371                                            con    403                                            const EAxis axis )
372 {                                                 404 {    
373   if (!voxelLimit.IsLimited(axis)) return;        405   if (!voxelLimit.IsLimited(axis)) return;
374                                                   406   
375   G4ThreeVectorList tempPolygon;                  407   G4ThreeVectorList tempPolygon;
376                                                   408 
377   //                                              409   //
378   // Build a "simple" voxelLimit that includes    410   // Build a "simple" voxelLimit that includes only the min extent
379   // and apply this to our vertices, producing    411   // and apply this to our vertices, producing result in tempPolygon
380   //                                              412   //
381   G4VoxelLimits simpleLimit1;                     413   G4VoxelLimits simpleLimit1;
382   simpleLimit1.AddLimit( axis, voxelLimit.GetM    414   simpleLimit1.AddLimit( axis, voxelLimit.GetMinExtent(axis), kInfinity );
383   ClipToSimpleLimits( vertices, tempPolygon, s    415   ClipToSimpleLimits( vertices, tempPolygon, simpleLimit1 );
384                                                   416 
385   //                                              417   //
386   // If nothing is left from the above clip, w    418   // If nothing is left from the above clip, we might as well return now
387   // (but with an empty vertices)                 419   // (but with an empty vertices)
388   //                                              420   //
389   if (tempPolygon.empty())                     << 421   if (tempPolygon.size() == 0)
390   {                                               422   {
391     vertices.clear();                             423     vertices.clear();
392     return;                                       424     return;
393   }                                               425   }
394                                                   426 
395   //                                              427   //
396   // Now do the same, but using a "simple" lim    428   // Now do the same, but using a "simple" limit that includes only the max
397   // extent. Apply this to out tempPolygon, pr    429   // extent. Apply this to out tempPolygon, producing result in vertices.
398   //                                              430   //
399   G4VoxelLimits simpleLimit2;                     431   G4VoxelLimits simpleLimit2;
400   simpleLimit2.AddLimit( axis, -kInfinity, vox    432   simpleLimit2.AddLimit( axis, -kInfinity, voxelLimit.GetMaxExtent(axis) );
401   ClipToSimpleLimits( tempPolygon, vertices, s    433   ClipToSimpleLimits( tempPolygon, vertices, simpleLimit2 );
402                                                   434 
403   //                                              435   //
404   // If nothing is left, return now               436   // If nothing is left, return now
405   //                                              437   //
406   if (vertices.empty()) return;                << 438   if (vertices.size() == 0) return;
407 }                                                 439 }
408                                                   440 
409 // ClipToSimpleLimits                          << 441 
410 //                                                442 //
411 // pVoxelLimits must be only limited along one    443 // pVoxelLimits must be only limited along one axis, and either the maximum
412 // along the axis must be +kInfinity, or the m    444 // along the axis must be +kInfinity, or the minimum -kInfinity
413 //                                                445 //
414 void G4ClippablePolygon::ClipToSimpleLimits( G    446 void G4ClippablePolygon::ClipToSimpleLimits( G4ThreeVectorList& pPolygon,
415                                              G    447                                              G4ThreeVectorList& outputPolygon,
416                                        const G    448                                        const G4VoxelLimits& pVoxelLimit   )
417 {                                                 449 {
418   std::size_t noVertices = pPolygon.size();    << 450   G4int i;
                                                   >> 451   G4int noVertices=pPolygon.size();
419   G4ThreeVector vEnd,vStart;                      452   G4ThreeVector vEnd,vStart;
420                                                   453 
421   outputPolygon.clear();                          454   outputPolygon.clear();
422                                                   455     
423   for (std::size_t i=0; i<noVertices; ++i)     << 456   for (i=0;i<noVertices;i++)
424   {                                               457   {
425     vStart=pPolygon[i];                           458     vStart=pPolygon[i];
426     if (i==noVertices-1)                          459     if (i==noVertices-1)
427     {                                             460     {
428       vEnd=pPolygon[0];                           461       vEnd=pPolygon[0];
429     }                                             462     }
430     else                                          463     else
431     {                                             464     {
432       vEnd=pPolygon[i+1];                         465       vEnd=pPolygon[i+1];
433     }                                             466     }
434                                                   467 
435     if (pVoxelLimit.Inside(vStart))               468     if (pVoxelLimit.Inside(vStart))
436     {                                             469     {
437       if (pVoxelLimit.Inside(vEnd))               470       if (pVoxelLimit.Inside(vEnd))
438       {                                           471       {
439         // vStart and vEnd inside -> output en    472         // vStart and vEnd inside -> output end point
440         //                                        473         //
441         outputPolygon.push_back(vEnd);            474         outputPolygon.push_back(vEnd);
442       }                                           475       }
443       else                                        476       else
444       {                                           477       {
445         // vStart inside, vEnd outside -> outp    478         // vStart inside, vEnd outside -> output crossing point
446         //                                        479         //
447         pVoxelLimit.ClipToLimits(vStart,vEnd);    480         pVoxelLimit.ClipToLimits(vStart,vEnd);
448         outputPolygon.push_back(vEnd);            481         outputPolygon.push_back(vEnd);
449       }                                           482       }
450     }                                             483     }
451     else                                          484     else
452     {                                             485     {
453       if (pVoxelLimit.Inside(vEnd))               486       if (pVoxelLimit.Inside(vEnd))
454       {                                           487       {
455         // vStart outside, vEnd inside -> outp    488         // vStart outside, vEnd inside -> output inside section
456         //                                        489         //
457         pVoxelLimit.ClipToLimits(vStart,vEnd);    490         pVoxelLimit.ClipToLimits(vStart,vEnd);
458         outputPolygon.push_back(vStart);          491         outputPolygon.push_back(vStart);
459         outputPolygon.push_back(vEnd);            492         outputPolygon.push_back(vEnd);
460       }                                           493       }
461       else    // Both point outside -> no outp    494       else    // Both point outside -> no output
462       {                                           495       {
463       }                                           496       }
464     }                                             497     }
465   }                                               498   }
466 }                                                 499 }
467                                                   500