G4SurfaceVoxelizer.icc

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 // $Id: G4SurfaceVoxelizer.icc 67011 2013-01-29 16:17:41Z gcosmo $
00027 //
00028 // --------------------------------------------------------------------
00029 // GEANT 4 class header file
00030 //
00031 // G4SurfaceVoxelizer inline methods
00032 //
00033 // History:
00034 // 19.10.12 Marek Gayer, created
00035 // --------------------------------------------------------------------
00036 
00037 
00038 template <typename T> inline
00039 G4int G4SurfaceVoxelizer::BinarySearch(const std::vector<T> &vec, T value)
00040 {
00041   typename std::vector<T>::const_iterator begin=vec.begin(), end=vec.end();
00042   G4int res = std::upper_bound(begin, end, value) - begin - 1;
00043   return res;
00044 }
00045 
00046 inline
00047 const std::vector<G4VoxelBox> &G4SurfaceVoxelizer::GetBoxes() const
00048 {
00049   return fBoxes;
00050 }
00051   
00052 inline
00053 const std::vector<G4double> &G4SurfaceVoxelizer::GetBoundary(G4int index) const
00054 {
00055   return fBoundaries[index];
00056 }
00057 
00058 inline
00059 void G4SurfaceVoxelizer::GetVoxel(std::vector<G4int> &curVoxel,
00060                                   const G4ThreeVector &point) const
00061 {
00062   for (G4int i=0; i<=2; ++i)
00063   {
00064     curVoxel[i] = BinarySearch(GetBoundary(i), point[i]);
00065   }
00066 }
00067 
00068 inline
00069 G4int G4SurfaceVoxelizer::GetBitsPerSlice () const
00070 {
00071   return fNPerSlice*8*sizeof(unsigned int);
00072 }
00073 
00074 inline
00075 G4int G4SurfaceVoxelizer::GetVoxelsIndex(G4int x, G4int y, G4int z) const
00076 {
00077   if (x < 0 || y < 0 || z < 0) { return -1; }
00078   G4int maxX = fBoundaries[0].size();
00079   G4int maxY = fBoundaries[1].size();
00080   G4int index = x + y*maxX + z*maxX*maxY;
00081 
00082   return index;
00083 }
00084 
00085 inline
00086 G4int G4SurfaceVoxelizer::GetVoxelsIndex(const std::vector<G4int> &voxels) const
00087 {
00088   return GetVoxelsIndex(voxels[0], voxels[1], voxels[2]);
00089 }
00090 
00091 inline
00092 G4int G4SurfaceVoxelizer::GetPointIndex(const G4ThreeVector &p) const
00093 {
00094   G4int maxX = fBoundaries[0].size();
00095   G4int maxY = fBoundaries[1].size();
00096   G4int x = BinarySearch(fBoundaries[0], p[0]);
00097   G4int y = BinarySearch(fBoundaries[1], p[1]);
00098   G4int z = BinarySearch(fBoundaries[2], p[2]);
00099   G4int index = x + y*maxX + z*maxX*maxY;
00100 
00101   return index;
00102 }
00103 
00104 inline
00105 const G4SurfBits &G4SurfaceVoxelizer::Empty() const
00106 {
00107   return fEmpty;
00108 }
00109 
00110 inline
00111 G4bool G4SurfaceVoxelizer::IsEmpty(G4int index) const
00112 {
00113   return fEmpty[index];
00114 }
00115 
00116 inline
00117 G4int G4SurfaceVoxelizer::GetMaxVoxels(G4ThreeVector &ratioOfReduction)
00118 {
00119   ratioOfReduction = fReductionRatio;
00120   return fMaxVoxels;
00121 }
00122 
00123 inline
00124 long long G4SurfaceVoxelizer::GetCountOfVoxels() const
00125 {
00126   return fCountOfVoxels;
00127 }
00128 
00129 inline
00130 long long G4SurfaceVoxelizer::CountVoxels(std::vector<G4double> boundaries[]) const
00131 {
00132   long long sx = boundaries[0].size() - 1;
00133   long long sy = boundaries[1].size() - 1;
00134   long long sz = boundaries[2].size() - 1;
00135 
00136   return  sx * sy *sz;
00137 }
00138 
00139 inline
00140 const std::vector<G4int>&
00141 G4SurfaceVoxelizer::GetCandidates(std::vector<G4int> &curVoxel) const
00142 {
00143   G4int voxelsIndex = GetVoxelsIndex(curVoxel);
00144 
00145   if (voxelsIndex >= 0 && !fEmpty[voxelsIndex])
00146   {      
00147     return fCandidates[voxelsIndex];
00148   }
00149   return fNoCandidates;
00150 }
00151 
00152 inline
00153 G4int G4SurfaceVoxelizer::GetVoxelBoxesSize() const
00154 {
00155   return fVoxelBoxes.size();
00156 }
00157 
00158 inline
00159 const G4VoxelBox &G4SurfaceVoxelizer::GetVoxelBox(G4int i) const
00160 {
00161   return fVoxelBoxes[i];
00162 }
00163 
00164 inline
00165 const std::vector<G4int>&
00166 G4SurfaceVoxelizer::GetVoxelBoxCandidates(G4int i) const
00167 {
00168   return fVoxelBoxesCandidates[i];
00169 }

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