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


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