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