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