Geant4 Cross Reference |
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.8 2002/10/30 13:52:22 gcosmo Exp $ >> 25 // GEANT4 tag $Name: geant4-05-02-patch-01 $ >> 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 { << 158 G4Exception("G4ClippablePolygon::GetMinPoint() - empty polygon"); 139 G4Exception("G4ClippablePolygon::GetMinPoi << 159 140 "GeomSolids0002", FatalExcepti << 141 } << 142 << 143 const G4ThreeVector *answer = &(vertices[0]) 160 const G4ThreeVector *answer = &(vertices[0]); 144 G4double min = answer->operator()(axis); 161 G4double min = answer->operator()(axis); 145 162 146 for( std::size_t i=1; i<noLeft; ++i ) << 163 G4int i; >> 164 for( i=1; i<noLeft; i++ ) 147 { 165 { 148 G4double component = vertices[i].operator( 166 G4double component = vertices[i].operator()( axis ); 149 if (component < min) 167 if (component < min) 150 { 168 { 151 answer = &(vertices[i]); 169 answer = &(vertices[i]); 152 min = component; 170 min = component; 153 } 171 } 154 } 172 } 155 173 156 return answer; 174 return answer; 157 } 175 } 158 176 >> 177 >> 178 // 159 // GetMaxPoint 179 // GetMaxPoint 160 // 180 // 161 // Returns pointer to maximum point along the 181 // Returns pointer to maximum point along the specified axis. 162 // Take care! Do not use pointer after destroy 182 // Take care! Do not use pointer after destroying parent polygon. 163 // 183 // 164 const G4ThreeVector* G4ClippablePolygon::GetMa << 184 const G4ThreeVector *G4ClippablePolygon::GetMaxPoint( const EAxis axis ) const 165 { 185 { 166 std::size_t noLeft = vertices.size(); << 186 G4int noLeft = vertices.size(); 167 if (noLeft==0) 187 if (noLeft==0) 168 { << 188 G4Exception("G4ClippablePolygon::GetMaxPoint() - empty polygon"); 169 G4Exception("G4ClippablePolygon::GetMaxPoi << 189 170 "GeomSolids0002", FatalExcepti << 171 } << 172 << 173 const G4ThreeVector *answer = &(vertices[0]) 190 const G4ThreeVector *answer = &(vertices[0]); 174 G4double max = answer->operator()(axis); 191 G4double max = answer->operator()(axis); 175 192 176 for( std::size_t i=1; i<noLeft; ++i ) << 193 G4int i; >> 194 for( i=1; i<noLeft; i++ ) 177 { 195 { 178 G4double component = vertices[i].operator( 196 G4double component = vertices[i].operator()( axis ); 179 if (component > max) 197 if (component > max) 180 { 198 { 181 answer = &(vertices[i]); 199 answer = &(vertices[i]); 182 max = component; 200 max = component; 183 } 201 } 184 } 202 } 185 203 186 return answer; 204 return answer; 187 } 205 } >> 206 188 207 >> 208 // 189 // InFrontOf 209 // InFrontOf 190 // 210 // 191 // Decide if this polygon is in "front" of ano 211 // Decide if this polygon is in "front" of another when 192 // viewed along the specified axis. For our pu 212 // viewed along the specified axis. For our purposes here, 193 // it is sufficient to use the minimum extent 213 // it is sufficient to use the minimum extent of the 194 // polygon along the axis to determine this. 214 // polygon along the axis to determine this. 195 // 215 // 196 // In case the minima of the two polygons are 216 // In case the minima of the two polygons are equal, 197 // we use a more sophisticated test. 217 // we use a more sophisticated test. 198 // 218 // 199 // Note that it is possible for the two follow 219 // Note that it is possible for the two following 200 // statements to both return true or both retu 220 // statements to both return true or both return false: 201 // polygon1.InFrontOf(polygon2) 221 // polygon1.InFrontOf(polygon2) 202 // polygon2.BehindOf(polygon1) 222 // polygon2.BehindOf(polygon1) 203 // 223 // 204 G4bool G4ClippablePolygon::InFrontOf( const G4 << 224 G4bool G4ClippablePolygon::InFrontOf( const G4ClippablePolygon &other, 205 EA 225 EAxis axis ) const 206 { 226 { 207 // 227 // 208 // If things are empty, do something semi-se 228 // If things are empty, do something semi-sensible 209 // 229 // 210 std::size_t noLeft = vertices.size(); << 230 G4int noLeft = vertices.size(); 211 if (noLeft==0) return false; 231 if (noLeft==0) return false; 212 232 213 if (other.Empty()) return true; 233 if (other.Empty()) return true; 214 234 215 // 235 // 216 // Get minimum of other polygon 236 // Get minimum of other polygon 217 // 237 // 218 const G4ThreeVector *minPointOther = other.G 238 const G4ThreeVector *minPointOther = other.GetMinPoint( axis ); 219 const G4double minOther = minPointOther->ope 239 const G4double minOther = minPointOther->operator()(axis); 220 240 221 // 241 // 222 // Get minimum of this polygon 242 // Get minimum of this polygon 223 // 243 // 224 const G4ThreeVector *minPoint = GetMinPoint( 244 const G4ThreeVector *minPoint = GetMinPoint( axis ); 225 const G4double min = minPoint->operator()(ax 245 const G4double min = minPoint->operator()(axis); 226 246 227 // 247 // 228 // Easy decision 248 // Easy decision 229 // 249 // 230 if (min < minOther-kCarTolerance) return tru 250 if (min < minOther-kCarTolerance) return true; // Clear winner 231 251 232 if (minOther < min-kCarTolerance) return fal 252 if (minOther < min-kCarTolerance) return false; // Clear loser 233 253 234 // 254 // 235 // We have a tie (this will not be all that 255 // We have a tie (this will not be all that rare since our 236 // polygons are connected) 256 // polygons are connected) 237 // 257 // 238 // Check to see if there is a vertex in the 258 // Check to see if there is a vertex in the other polygon 239 // that is behind this one (or vice versa) 259 // that is behind this one (or vice versa) 240 // 260 // 241 G4bool answer; 261 G4bool answer; 242 G4ThreeVector normalOther = other.GetNormal( 262 G4ThreeVector normalOther = other.GetNormal(); 243 263 244 if (std::fabs(normalOther(axis)) > std::fabs << 264 if (fabs(normalOther(axis)) > fabs(normal(axis))) 245 { 265 { 246 G4double minP, maxP; 266 G4double minP, maxP; 247 GetPlanerExtent( *minPointOther, normalOth 267 GetPlanerExtent( *minPointOther, normalOther, minP, maxP ); 248 268 249 answer = (normalOther(axis) > 0) ? (minP < 269 answer = (normalOther(axis) > 0) ? (minP < -kCarTolerance) 250 : (maxP > 270 : (maxP > +kCarTolerance); 251 } 271 } 252 else 272 else 253 { 273 { 254 G4double minP, maxP; 274 G4double minP, maxP; 255 other.GetPlanerExtent( *minPoint, normal, 275 other.GetPlanerExtent( *minPoint, normal, minP, maxP ); 256 276 257 answer = (normal(axis) > 0) ? (maxP > +kCa 277 answer = (normal(axis) > 0) ? (maxP > +kCarTolerance) 258 : (minP < -kCa 278 : (minP < -kCarTolerance); 259 } 279 } 260 return answer; 280 return answer; 261 } 281 } 262 282 >> 283 // 263 // BehindOf 284 // BehindOf 264 // 285 // 265 // Decide if this polygon is behind another. 286 // Decide if this polygon is behind another. 266 // See notes in method "InFrontOf" 287 // See notes in method "InFrontOf" 267 // 288 // 268 G4bool G4ClippablePolygon::BehindOf( const G4C << 289 G4bool G4ClippablePolygon::BehindOf( const G4ClippablePolygon &other, 269 EAx 290 EAxis axis ) const 270 { 291 { 271 // 292 // 272 // If things are empty, do something semi-se 293 // If things are empty, do something semi-sensible 273 // 294 // 274 std::size_t noLeft = vertices.size(); << 295 G4int noLeft = vertices.size(); 275 if (noLeft==0) return false; 296 if (noLeft==0) return false; 276 297 277 if (other.Empty()) return true; 298 if (other.Empty()) return true; 278 299 279 // 300 // 280 // Get minimum of other polygon 301 // Get minimum of other polygon 281 // 302 // 282 const G4ThreeVector *maxPointOther = other.G 303 const G4ThreeVector *maxPointOther = other.GetMaxPoint( axis ); 283 const G4double maxOther = maxPointOther->ope 304 const G4double maxOther = maxPointOther->operator()(axis); 284 305 285 // 306 // 286 // Get minimum of this polygon 307 // Get minimum of this polygon 287 // 308 // 288 const G4ThreeVector *maxPoint = GetMaxPoint( 309 const G4ThreeVector *maxPoint = GetMaxPoint( axis ); 289 const G4double max = maxPoint->operator()(ax 310 const G4double max = maxPoint->operator()(axis); 290 311 291 // 312 // 292 // Easy decision 313 // Easy decision 293 // 314 // 294 if (max > maxOther+kCarTolerance) return tru 315 if (max > maxOther+kCarTolerance) return true; // Clear winner 295 316 296 if (maxOther > max+kCarTolerance) return fal 317 if (maxOther > max+kCarTolerance) return false; // Clear loser 297 318 298 // 319 // 299 // We have a tie (this will not be all that 320 // We have a tie (this will not be all that rare since our 300 // polygons are connected) 321 // polygons are connected) 301 // 322 // 302 // Check to see if there is a vertex in the 323 // Check to see if there is a vertex in the other polygon 303 // that is in front of this one (or vice ver 324 // that is in front of this one (or vice versa) 304 // 325 // 305 G4bool answer; 326 G4bool answer; 306 G4ThreeVector normalOther = other.GetNormal( 327 G4ThreeVector normalOther = other.GetNormal(); 307 328 308 if (std::fabs(normalOther(axis)) > std::fabs << 329 if (fabs(normalOther(axis)) > fabs(normal(axis))) 309 { 330 { 310 G4double minP, maxP; 331 G4double minP, maxP; 311 GetPlanerExtent( *maxPointOther, normalOth 332 GetPlanerExtent( *maxPointOther, normalOther, minP, maxP ); 312 333 313 answer = (normalOther(axis) > 0) ? (maxP > 334 answer = (normalOther(axis) > 0) ? (maxP > +kCarTolerance) 314 : (minP < 335 : (minP < -kCarTolerance); 315 } 336 } 316 else 337 else 317 { 338 { 318 G4double minP, maxP; 339 G4double minP, maxP; 319 other.GetPlanerExtent( *maxPoint, normal, 340 other.GetPlanerExtent( *maxPoint, normal, minP, maxP ); 320 341 321 answer = (normal(axis) > 0) ? (minP < -kCa 342 answer = (normal(axis) > 0) ? (minP < -kCarTolerance) 322 : (maxP > +kCa 343 : (maxP > +kCarTolerance); 323 } 344 } 324 return answer; 345 return answer; 325 } 346 } 326 347 >> 348 >> 349 // 327 // GetPlanerExtent 350 // GetPlanerExtent 328 // 351 // 329 // Get min/max distance in or out of a plane 352 // Get min/max distance in or out of a plane 330 // 353 // 331 G4bool G4ClippablePolygon::GetPlanerExtent( co << 354 G4bool G4ClippablePolygon::GetPlanerExtent( const G4ThreeVector &pointOnPlane, 332 co << 355 const G4ThreeVector &planeNormal, 333 << 356 G4double &min, 334 << 357 G4double &max ) const 335 { 358 { 336 // 359 // 337 // Okay, how many entries do we have? 360 // Okay, how many entries do we have? 338 // 361 // 339 std::size_t noLeft = vertices.size(); << 362 G4int noLeft = vertices.size(); 340 363 341 // 364 // 342 // Return false if nothing is left 365 // Return false if nothing is left 343 // 366 // 344 if (noLeft == 0) return false; 367 if (noLeft == 0) return false; 345 368 346 // 369 // 347 // Initialize min and max to our first verte 370 // Initialize min and max to our first vertex 348 // 371 // 349 min = max = planeNormal.dot(vertices[0]-poin 372 min = max = planeNormal.dot(vertices[0]-pointOnPlane); 350 373 351 // 374 // 352 // Compare to the rest 375 // Compare to the rest 353 // 376 // 354 for( std::size_t i=1; i<noLeft; ++i ) << 377 G4int i; >> 378 for( i=1; i<noLeft; i++ ) 355 { 379 { 356 G4double component = planeNormal.dot(verti 380 G4double component = planeNormal.dot(vertices[i] - pointOnPlane); 357 if (component < min ) 381 if (component < min ) 358 min = component; 382 min = component; 359 else if (component > max ) 383 else if (component > max ) 360 max = component; 384 max = component; 361 } 385 } 362 386 363 return true; 387 return true; 364 } 388 } 365 389 366 // ClipAlongOneAxis << 390 367 // 391 // 368 // Clip along just one axis, as specified in v 392 // Clip along just one axis, as specified in voxelLimit 369 // 393 // 370 void G4ClippablePolygon::ClipAlongOneAxis( con << 394 void G4ClippablePolygon::ClipAlongOneAxis( const G4VoxelLimits &voxelLimit, 371 con 395 const EAxis axis ) 372 { 396 { 373 if (!voxelLimit.IsLimited(axis)) return; 397 if (!voxelLimit.IsLimited(axis)) return; 374 398 375 G4ThreeVectorList tempPolygon; 399 G4ThreeVectorList tempPolygon; 376 400 377 // 401 // 378 // Build a "simple" voxelLimit that includes 402 // Build a "simple" voxelLimit that includes only the min extent 379 // and apply this to our vertices, producing 403 // and apply this to our vertices, producing result in tempPolygon 380 // 404 // 381 G4VoxelLimits simpleLimit1; 405 G4VoxelLimits simpleLimit1; 382 simpleLimit1.AddLimit( axis, voxelLimit.GetM 406 simpleLimit1.AddLimit( axis, voxelLimit.GetMinExtent(axis), kInfinity ); 383 ClipToSimpleLimits( vertices, tempPolygon, s 407 ClipToSimpleLimits( vertices, tempPolygon, simpleLimit1 ); 384 408 385 // 409 // 386 // If nothing is left from the above clip, w 410 // If nothing is left from the above clip, we might as well return now 387 // (but with an empty vertices) 411 // (but with an empty vertices) 388 // 412 // 389 if (tempPolygon.empty()) << 413 if (tempPolygon.size() == 0) 390 { 414 { 391 vertices.clear(); 415 vertices.clear(); 392 return; 416 return; 393 } 417 } 394 418 395 // 419 // 396 // Now do the same, but using a "simple" lim 420 // Now do the same, but using a "simple" limit that includes only the max 397 // extent. Apply this to out tempPolygon, pr 421 // extent. Apply this to out tempPolygon, producing result in vertices. 398 // 422 // 399 G4VoxelLimits simpleLimit2; 423 G4VoxelLimits simpleLimit2; 400 simpleLimit2.AddLimit( axis, -kInfinity, vox 424 simpleLimit2.AddLimit( axis, -kInfinity, voxelLimit.GetMaxExtent(axis) ); 401 ClipToSimpleLimits( tempPolygon, vertices, s 425 ClipToSimpleLimits( tempPolygon, vertices, simpleLimit2 ); 402 426 403 // 427 // 404 // If nothing is left, return now 428 // If nothing is left, return now 405 // 429 // 406 if (vertices.empty()) return; << 430 if (vertices.size() == 0) return; 407 } 431 } 408 432 409 // ClipToSimpleLimits << 433 410 // 434 // 411 // pVoxelLimits must be only limited along one 435 // pVoxelLimits must be only limited along one axis, and either the maximum 412 // along the axis must be +kInfinity, or the m 436 // along the axis must be +kInfinity, or the minimum -kInfinity 413 // 437 // 414 void G4ClippablePolygon::ClipToSimpleLimits( G 438 void G4ClippablePolygon::ClipToSimpleLimits( G4ThreeVectorList& pPolygon, 415 G 439 G4ThreeVectorList& outputPolygon, 416 const G 440 const G4VoxelLimits& pVoxelLimit ) 417 { 441 { 418 std::size_t noVertices = pPolygon.size(); << 442 G4int i; >> 443 G4int noVertices=pPolygon.size(); 419 G4ThreeVector vEnd,vStart; 444 G4ThreeVector vEnd,vStart; 420 445 421 outputPolygon.clear(); 446 outputPolygon.clear(); 422 447 423 for (std::size_t i=0; i<noVertices; ++i) << 448 for (i=0;i<noVertices;i++) 424 { 449 { 425 vStart=pPolygon[i]; 450 vStart=pPolygon[i]; 426 if (i==noVertices-1) 451 if (i==noVertices-1) 427 { 452 { 428 vEnd=pPolygon[0]; 453 vEnd=pPolygon[0]; 429 } 454 } 430 else 455 else 431 { 456 { 432 vEnd=pPolygon[i+1]; 457 vEnd=pPolygon[i+1]; 433 } 458 } 434 459 435 if (pVoxelLimit.Inside(vStart)) 460 if (pVoxelLimit.Inside(vStart)) 436 { 461 { 437 if (pVoxelLimit.Inside(vEnd)) 462 if (pVoxelLimit.Inside(vEnd)) 438 { 463 { 439 // vStart and vEnd inside -> output en 464 // vStart and vEnd inside -> output end point 440 // 465 // 441 outputPolygon.push_back(vEnd); 466 outputPolygon.push_back(vEnd); 442 } 467 } 443 else 468 else 444 { 469 { 445 // vStart inside, vEnd outside -> outp 470 // vStart inside, vEnd outside -> output crossing point 446 // 471 // 447 pVoxelLimit.ClipToLimits(vStart,vEnd); 472 pVoxelLimit.ClipToLimits(vStart,vEnd); 448 outputPolygon.push_back(vEnd); 473 outputPolygon.push_back(vEnd); 449 } 474 } 450 } 475 } 451 else 476 else 452 { 477 { 453 if (pVoxelLimit.Inside(vEnd)) 478 if (pVoxelLimit.Inside(vEnd)) 454 { 479 { 455 // vStart outside, vEnd inside -> outp 480 // vStart outside, vEnd inside -> output inside section 456 // 481 // 457 pVoxelLimit.ClipToLimits(vStart,vEnd); 482 pVoxelLimit.ClipToLimits(vStart,vEnd); 458 outputPolygon.push_back(vStart); 483 outputPolygon.push_back(vStart); 459 outputPolygon.push_back(vEnd); 484 outputPolygon.push_back(vEnd); 460 } 485 } 461 else // Both point outside -> no outp 486 else // Both point outside -> no output 462 { 487 { 463 } 488 } 464 } 489 } 465 } 490 } 466 } 491 } 467 492