G4SolidExtentList.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4SolidExtentList.cc 67011 2013-01-29 16:17:41Z gcosmo $
00028 //
00029 // 
00030 // --------------------------------------------------------------------
00031 // GEANT 4 class source file
00032 //
00033 //
00034 // G4SolidExtentList.cc
00035 //
00036 // Implementation of a list of (voxel) extents along one axis
00037 //
00038 // --------------------------------------------------------------------
00039 
00040 #include "G4SolidExtentList.hh"
00041 #include "G4VoxelLimits.hh"
00042 #include "G4GeometryTolerance.hh"
00043 
00044 
00045 //
00046 // Constructor (default)
00047 //
00048 G4SolidExtentList::G4SolidExtentList() 
00049 {
00050   axis = kZAxis;
00051   limited = false;
00052   minLimit = -INT_MAX/2;
00053   maxLimit =  INT_MAX/2;
00054 }
00055 
00056 
00057 //
00058 // Constructor (limited case)
00059 //
00060 G4SolidExtentList::G4SolidExtentList( const EAxis targetAxis,
00061                                       const G4VoxelLimits &voxelLimits )
00062 {
00063   axis = targetAxis;
00064   
00065   limited = voxelLimits.IsLimited( axis );
00066   if (limited)
00067   {
00068     minLimit = voxelLimits.GetMinExtent( axis );
00069     maxLimit = voxelLimits.GetMaxExtent( axis );
00070   }
00071   else
00072   {
00073     minLimit = -INT_MAX/2;
00074     maxLimit =  INT_MAX/2;
00075   }
00076 }
00077 
00078 
00079 //
00080 // Destructor
00081 //
00082 G4SolidExtentList::~G4SolidExtentList()
00083 {
00084 }
00085 
00086 
00087 //
00088 // AddSurface
00089 //
00090 //
00091 void G4SolidExtentList::AddSurface( const G4ClippablePolygon &surface )
00092 {
00093   //
00094   // Keep track of four surfaces
00095   //
00096   G4double min, max;
00097   
00098   surface.GetExtent( axis, min, max );
00099   
00100   if (min > maxLimit)
00101   {
00102     //
00103     // Nearest surface beyond maximum limit
00104     //
00105     if (surface.InFrontOf(minAbove,axis)) minAbove = surface;
00106   }
00107   else if (max < minLimit)
00108   {
00109     //
00110     // Nearest surface below minimum limit
00111     //
00112     if (surface.BehindOf(maxBelow,axis)) maxBelow = surface;
00113   }
00114   else
00115   {
00116     //
00117     // Max and min surfaces inside
00118     //
00119     if (surface.BehindOf(maxSurface,axis)) maxSurface = surface;
00120     if (surface.InFrontOf(minSurface,axis)) minSurface = surface;
00121   }
00122 }
00123 
00124 
00125 
00126 //
00127 // GetExtent
00128 //
00129 // Return extent after processing all surfaces
00130 //
00131 G4bool G4SolidExtentList::GetExtent( G4double &min, G4double &max ) const
00132 {
00133   G4double kCarTolerance = G4GeometryTolerance::GetInstance()
00134                            ->GetSurfaceTolerance();
00135   //
00136   // Did we have any surfaces within the limits?
00137   //
00138   if (minSurface.Empty())
00139   {
00140     //
00141     // Nothing! Do we have anything above?
00142     //
00143     if (minAbove.Empty()) return false;
00144     
00145     //
00146     // Yup. Is it facing inwards?
00147     //
00148     if (minAbove.GetNormal().operator()(axis) < 0) return false;
00149     
00150     //
00151     // No. We must be entirely within the solid
00152     //
00153     max = maxLimit + kCarTolerance;
00154     min = minLimit - kCarTolerance;
00155     return true;
00156   }
00157   
00158   //
00159   // Check max surface
00160   //
00161   if (maxSurface.GetNormal().operator()(axis) < 0)
00162   {
00163     //
00164     // Inward facing: max limit must be embedded within solid
00165     //
00166     max = maxLimit + kCarTolerance;
00167   }
00168   else
00169   {
00170     G4double sMin, sMax;
00171     maxSurface.GetExtent( axis, sMin, sMax );
00172     max = ( (sMax > maxLimit) ? maxLimit : sMax ) + kCarTolerance;
00173   }
00174   
00175   //
00176   // Check min surface
00177   //
00178   if (minSurface.GetNormal().operator()(axis) > 0)
00179   {
00180     //
00181     // Inward facing: max limit must be embedded within solid
00182     //
00183     min = minLimit - kCarTolerance;
00184   }
00185   else
00186   {
00187     G4double sMin, sMax;
00188     minSurface.GetExtent( axis, sMin, sMax );
00189     min = ( (sMin < minLimit) ? minLimit : sMin ) - kCarTolerance;
00190   }
00191   
00192   return true;
00193 }
00194 

Generated on Mon May 27 17:49:52 2013 for Geant4 by  doxygen 1.4.7