cmtkVoxelMatchingMetric_Type.h

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: 2752 $
00026 //
00027 //  $LastChangedDate: 2011-01-17 11:33:31 -0800 (Mon, 17 Jan 2011) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkVoxelMatchingMetric_Type_h_included_
00034 #define __cmtkVoxelMatchingMetric_Type_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Base/cmtkTypes.h>
00039 #include <Base/cmtkNumericTraits.h>
00040 #include <Base/cmtkInterpolator.h>
00041 #include <Base/cmtkUniformVolume.h>
00042 #include <Base/cmtkTypedArray.h>
00043 
00044 #include <algorithm>
00045 
00046 namespace
00047 cmtk
00048 {
00049 
00052 
00055 template<class T,ScalarDataType DT>
00056 class VoxelMatchingMetric_Type
00057 {
00058 public:
00060   typedef VoxelMatchingMetric_Type<T,DT> Self;
00061 
00063   typedef T Exchange;
00064   
00066   class ImageData 
00067   {
00068   private:
00070     T Padding;
00071 
00072   public:
00074     T padding() const { return this->Padding; }
00075     
00077     T* Data;
00078     
00080     TypedArray::SmartPtr DataArray;
00081 
00083     Types::DataItem BinOffset;
00084     
00086     Types::DataItem BinWidth;
00087     
00089     Types::DataItemRange m_ValueRange;
00090     
00092     DataGrid::IndexType ImageDims;
00093 
00095     size_t NumberOfSamples;
00096 
00098     const Types::DataItemRange GetValueRange() const
00099     {
00100       return this->m_ValueRange;
00101     }
00102 
00104     byte ValueToIndex( const Types::DataItem value )
00105     {
00106       return static_cast<byte>( (std::min( std::max( value, this->m_ValueRange.m_LowerBound ), this->m_ValueRange.m_UpperBound )- this->BinOffset) / BinWidth );
00107     }
00108     
00110     ImageData() : Padding( NumericTraits<T>::DefaultPaddingValue ), Data( NULL ), DataArray( NULL )
00111     {
00112       nextJ = nextK = nextIJ = nextJK = nextIK = nextIJK = 0;
00113     }
00114 
00116     void AllocDataArray( const TypedArray* templateArray );
00117 
00131     size_t Init( const UniformVolume* volume, const size_t defNumBins, const Types::DataItemRange& bounds = Types::DataItemRange( -HUGE_VAL, HUGE_VAL ) );
00132     
00141     void Init( const UniformVolume* volume );
00142     
00144     void PrecomputeIncrements( const UniformVolume* volume );
00145 
00147     unsigned int nextJ;
00148     
00150     unsigned int nextIJ;
00151     
00153     unsigned int nextK;
00154     
00156     unsigned int nextIK;
00157     
00159     unsigned int nextJK;
00160     
00162     unsigned int nextIJK;
00163   };
00164 
00166   ImageData DataX;
00167 
00169   ImageData DataY;
00170 
00172   void SetDataX( const UniformVolume* volume )
00173   { 
00174     DataX.PrecomputeIncrements( volume ); 
00175   }
00176 
00178   void SetDataY( const UniformVolume* volume ) 
00179   { 
00180     DataY.PrecomputeIncrements( volume );
00181   }
00182 
00184   void SetDataXY( const UniformVolume* volumeX, const UniformVolume* volumeY ) 
00185   {
00186     DataX.PrecomputeIncrements( volumeX );
00187     DataY.PrecomputeIncrements( volumeY );
00188   }
00189 };
00190 
00192 
00193 } // namespace cmtk
00194 
00195 #endif // #ifndef __cmtkVoxelMatchingMetric_Type_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines