// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // $Id: G4VoxelLimits.cc,v 1.11 2006/06/29 18:34:11 gunter Exp $ // GEANT4 tag $Name: geant4-09-04-beta-01 $ // // class G4VoxelLimits // // Implementation // // History: // // 14.03.02 V. Grichine, cosmetics // 13.07.95 P.Kent Initial version // -------------------------------------------------------------------- #include "G4VoxelLimits.hh" #include "G4ios.hh" /////////////////////////////////////////////////////////////////////////// // // Empty constructor and destructor // G4VoxelLimits::G4VoxelLimits() : fxAxisMin(-kInfinity),fxAxisMax(kInfinity), fyAxisMin(-kInfinity),fyAxisMax(kInfinity), fzAxisMin(-kInfinity),fzAxisMax(kInfinity) { } G4VoxelLimits::~G4VoxelLimits() { } /////////////////////////////////////////////////////////////////////////// // // Further restrict limits // No checks for illegal restrictions // void G4VoxelLimits::AddLimit( const EAxis pAxis, const G4double pMin, const G4double pMax ) { if ( pAxis == kXAxis ) { if ( pMin > fxAxisMin ) fxAxisMin = pMin ; if ( pMax < fxAxisMax ) fxAxisMax = pMax ; } else if ( pAxis == kYAxis ) { if ( pMin > fyAxisMin ) fyAxisMin = pMin ; if ( pMax < fyAxisMax ) fyAxisMax = pMax ; } else { assert( pAxis == kZAxis ) ; if ( pMin > fzAxisMin ) fzAxisMin = pMin ; if ( pMax < fzAxisMax ) fzAxisMax = pMax ; } } /////////////////////////////////////////////////////////////////////////// // // ClipToLimits // // Clip the line segment pStart->pEnd to the volume described by the // current limits. Return true if the line remains after clipping, // else false, and leave the vectors in an undefined state. // // Process: // // Use Cohen-Sutherland clipping in 3D // [Fundamentals of Interactive Computer Graphics,Foley & Van Dam] // G4bool G4VoxelLimits::ClipToLimits( G4ThreeVector& pStart, G4ThreeVector& pEnd ) const { G4int sCode, eCode ; G4bool remainsAfterClip ; // Determine if line is trivially inside (both outcodes==0) or outside // (logical AND of outcodes !=0) sCode = OutCode(pStart) ; eCode = OutCode(pEnd) ; if ( sCode & eCode ) { // Trivially outside, no intersection with region remainsAfterClip = false; } else if ( sCode == 0 && eCode == 0 ) { // Trivially inside, no intersections remainsAfterClip = true ; } else { // Line segment *may* cut volume boundaries // At most, one end point is inside G4double x1, y1, z1, x2, y2, z2 ; x1 = pStart.x() ; y1 = pStart.y() ; z1 = pStart.z() ; x2 = pEnd.x() ; y2 = pEnd.y() ; z2 = pEnd.z() ; /* if( std::abs(x1-x2) < kCarTolerance*kCarTolerance) { G4cout<<"x1 = "<