cmtkUniformVolume.txx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2011 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2751 $
00026 //
00027 //  $LastChangedDate: 2011-01-14 15:48:39 -0800 (Fri, 14 Jan 2011) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #include <math.h>
00034 
00035 namespace
00036 cmtk
00037 {
00038 
00041 
00042 template<class TData> 
00043 inline bool
00044 UniformVolume::ProbeData 
00045 ( TData& result, const TData* dataPtr, const Self::CoordinateVectorType& location ) const
00046 {
00047   result=0;
00048   
00049   Self::CoordinateVectorType l( location );
00050   l -= this->m_Offset;
00051 
00052   if ( (l[0] < 0) || (l[1] < 0) || (l[2] < 0) )
00053     return false;
00054   
00055   const int idxX=(int) (l[0]/this->m_Delta[0]);
00056   if ( idxX>=this->m_Dims[0]-1 )
00057     return false;
00058   
00059   const int idxY=(int) (l[1]/this->m_Delta[1]);
00060   if ( idxY>=this->m_Dims[1]-1 )
00061     return false;
00062 
00063   const int idxZ=(int) (l[2]/this->m_Delta[2]);
00064   if ( idxZ>=this->m_Dims[2]-1 )
00065     return false;
00066   
00067   const Types::Coordinate from[3] = { idxX*this->m_Delta[0], idxY*this->m_Delta[1], idxZ*this->m_Delta[2] };
00068   const Types::Coordinate to[3] = { from[0]+this->m_Delta[0], from[1]+this->m_Delta[1], from[2]+this->m_Delta[2] };
00069   result = this->TrilinearInterpolation( dataPtr, idxX, idxY, idxZ, l, from, to );
00070   return true;
00071 }
00072 
00073 inline bool
00074 UniformVolume::ProbeNoXform
00075 ( ProbeInfo& probeInfo, const Self::CoordinateVectorType& location ) const
00076 {
00077   Self::CoordinateVectorType l( location );
00078   l -= this->m_Offset;
00079 
00080   if ( (l[0] < 0) || (l[1] < 0) || (l[2] < 0) )
00081     return false;
00082   
00083   const int idxX=(int) (l[0]/this->m_Delta[0]);
00084   if ( idxX>=this->m_Dims[0]-1 )
00085     return false;
00086 
00087   const int idxY=(int) (l[1]/this->m_Delta[1]);
00088   if ( idxY>=this->m_Dims[1]-1 )
00089     return false;
00090 
00091   const int idxZ=(int) (l[2]/this->m_Delta[2]);
00092   if ( idxZ>=this->m_Dims[2]-1 )
00093     return false;
00094 
00095   const Types::Coordinate from[3] = { idxX*this->m_Delta[0], idxY*this->m_Delta[1], idxZ*this->m_Delta[2] };
00096   const Types::Coordinate to[3] = { from[0]+this->m_Delta[0], from[1]+this->m_Delta[1], from[2]+this->m_Delta[2] };
00097 
00098   return this->GetTrilinear( probeInfo, idxX, idxY, idxZ, l, from, to );
00099 }
00100 
00101 inline bool
00102 UniformVolume::FindVoxel
00103 ( const Self::CoordinateVectorType& location, int *const idx, Types::Coordinate *const from, Types::Coordinate *const to ) const
00104 {
00105   Self::CoordinateVectorType l( location );
00106   l -= this->m_Offset;
00107 
00108   if ( (l[0] < 0) || (l[1] < 0) || (l[2] < 0) )
00109     return false;
00110   
00111   for ( int dim = 0; dim < 3; ++dim ) 
00112     {
00113     idx[dim] = static_cast<int>( l[dim] / this->m_Delta[dim] );
00114     if ( idx[dim]>=(this->m_Dims[dim]-1) ) 
00115       return false;
00116     (to[dim] = (from[dim] = this->m_Offset[dim] + (idx[dim] * this->m_Delta[dim]))) += this->m_Delta[dim];
00117     }
00118   
00119   return true;
00120 }
00121 
00122 inline bool
00123 UniformVolume::FindVoxel
00124 ( const Self::CoordinateVectorType& location, int *const idx ) const
00125 {
00126   Self::CoordinateVectorType l( location );
00127   l -= this->m_Offset;
00128   
00129   if ( (l[0] < 0) || (l[1] < 0) || (l[2] < 0) )
00130     return false;
00131   
00132   for ( int dim = 0; dim < 3; ++dim ) 
00133     {
00134     idx[dim] = static_cast<int>( l[dim] / this->m_Delta[dim] );
00135     if ( idx[dim]>=(this->m_Dims[dim]-1) ) 
00136       return false;
00137     }
00138   return true;
00139 }
00140 
00141 inline void
00142 UniformVolume::GetVoxelIndexNoBounds
00143 ( const Self::CoordinateVectorType& location, int *const idx ) const
00144 {
00145   for ( int dim = 0; dim < 3; ++dim ) 
00146     {
00147     idx[dim] = static_cast<int>( floor( (location[dim]-this->m_Offset[dim]) / this->m_Delta[dim]) );
00148     }
00149 }
00150 
00151 inline bool
00152 UniformVolume::FindVoxelByIndex
00153 ( const Self::CoordinateVectorType& fracIndex, int *const idx, Types::Coordinate *const frac ) const
00154 {
00155   if ( (fracIndex[0]<0) || (fracIndex[1]<0) || (fracIndex[2]<0) )
00156     return false;
00157   
00158   for ( int dim = 0; dim < 3; ++dim ) 
00159     {
00160     idx[dim] = static_cast<int>( fracIndex[dim] );
00161     if ( (idx[dim] >= (this->m_Dims[dim]-1)) ) 
00162       return false;
00163     frac[dim] = fracIndex[dim] - idx[dim];
00164   }
00165   
00166   return true;
00167 }
00168 
00169 template<class TAccumulator>
00170 ScalarImage*
00171 UniformVolume::ComputeProjection( const int axis ) const
00172 {
00173   ScalarImage* projectImage = DataGrid::ComputeProjection<TAccumulator>( axis );
00174   switch ( axis ) 
00175     {
00176     case AXIS_X:
00177       projectImage->SetPixelSize( this->GetDelta( AXIS_Y ), this->GetDelta( AXIS_Z ) );
00178       break;
00179     case AXIS_Y:
00180       projectImage->SetPixelSize( this->GetDelta( AXIS_X ), this->GetDelta( AXIS_Z ) );
00181       break;
00182     case AXIS_Z:
00183       projectImage->SetPixelSize( this->GetDelta( AXIS_X ), this->GetDelta( AXIS_Y ) );
00184       break;
00185     }
00186   return projectImage;
00187 }
00188 
00189 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines