Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

mitkNeighborhoodIterator.h

00001 /*=========================================================================
00002 
00003   Program:   3DMed
00004   Date:      $Date: 2014-02-25 18:30:00 +0800 $
00005   Version:   $Version: 4.6.0 $
00006   Copyright: MIPG, Institute of Automation, Chinese Academy of Sciences
00007 
00008 =========================================================================*/
00009 
00010 #ifndef __mitkNeighborhoodIterator_h
00011 #define __mitkNeighborhoodIterator_h
00012 
00013 #include "mitkVolumeIterator.h"
00014 #include "mitkNeighborhood.h"
00015 
00017 // ---------------------- mitkNeighborhoodIterator --------------------------------
00018 //You should first invoke mitkNeumannBoundary to get volume with NeumannBoundary
00019 //which is defined in mitkNeumannBoundary.h
00020 //a example:
00021 //mitkNeumannBoundary *NeumannBoundary = new mitkNeumannBoundary;
00022 //NeumannBoundary->SetInput(vol);
00023 //NeumannBoundary->Run();
00024 //m_NeumannBoundaryVol = NeumannBoundary->GetOutput();
00025 //NeumannBoundary->Delete();
00026 //mitkNeighborhoodIterator<int> it(m_NeumannBoundaryVol);
00027 //  [8/20/2010 Xiuli Li]
00029 
00030 template<class T>
00031 class mitkNeighborhoodIterator : public mitkVolumeIterator<T>
00032 {
00033 public:
00034     mitkNeighborhoodIterator();
00035 
00036     mitkNeighborhoodIterator(mitkVolume* vol, VectorIndexType& radius);
00037 
00038     mitkNeighborhoodIterator(mitkVolume* vol, VectorIndexType& region, VectorIndexType& radius);
00039 
00040     ~mitkNeighborhoodIterator();
00041 
00042     void SetRadius(VectorIndexType& radius);
00043 
00044     virtual ScalarPixelType GetCenterPixel() const
00045     {
00046         return static_cast<ScalarPixelType>( *m_Position );
00047     }
00048 
00049     const VectorIndexType & GetInnerImageRegion();
00050 
00051     // Get Neighborhood values
00052     virtual void GetNeighborhood(const ScalarIndexType* index, ScalarPixelType* value, int ch=0)
00053 
00054     // Get given offset vector point value
00055     virtual ScalarPixelType GetOffsetVal(VectorIndexType& m_Offset);
00056 protected:
00057     mitkNeighborhood* m_Neighborhood;
00058     VectorPixelType   m_NeighborhoodVec;
00059 private:
00060 };
00061 
00062 template<class T>
00063 ScalarPixelType mitkNeighborhoodIterator<T>::GetOffsetVal( VectorIndexType& m_Offset )
00064 {
00065     T* pos = m_DataPointer;
00066     ScalarPixelType OffsetVal;
00067     if(m_Neighborhood->m_Dimension == 2)
00068     {
00069         int inc = m_Offset[0] + m_Offset[1]*m_Increments[1];
00070         OffsetVal = static_cast<ScalarPixelType>( *(pos + inc) );
00071     }
00072     else if(m_Neighborhood->m_Dimension == 3)
00073     {
00074         int inc = m_Offset[0] + m_Offset[1]*m_Increments[1] + m_Offset[2]*m_Increments[2];
00075         OffsetVal = static_cast<ScalarPixelType>( *(pos + inc) );
00076     }
00077 }
00078 template<class T>
00079 void mitkNeighborhoodIterator<T>::GetNeighborhood( const ScalarIndexType* index, VectorPixelType& m_NeighborhoodVec, int ch/*=0*/ )
00080 {
00081     ScalarIndexType offset = this->ComputeOffset(index);
00082     T* pos = m_DataPointer + offset + ch;
00083 
00084     if(m_Neighborhood->m_Dimension == 2)
00085     {
00086         unsigned int len = m_Neighborhood->m_OffsetTable.size();
00087         m_NeighborhoodVec = VectorPixelType(len,0.0);
00088 
00089         unsigned int i; 
00090         for (i=0;i<len;i++)
00091         {
00092             int inc = m_Neighborhood->m_OffsetTable[i][0] + m_Neighborhood->m_OffsetTable[i][1]*m_Increments[1];
00093             m_NeighborhoodVec[i] = static_cast<ScalarPixelType>( *(pos + inc) );
00094         }
00095     }
00096     else if(m_Neighborhood->m_Dimension == 3)
00097     {
00098         unsigned int len = m_Neighborhood->m_OffsetTable.size();
00099         m_NeighborhoodVec = VectorPixelType(len,0.0);
00100 
00101         unsigned int i; 
00102         for (i=0;i<len;i++)
00103         {
00104             int inc = m_Neighborhood->m_OffsetTable[i][0] + m_Neighborhood->m_OffsetTable[i][1]*m_Increments[1]
00105                                         +m_Neighborhood->m_OffsetTable[i][2]*m_Increments[2];
00106             m_NeighborhoodVec[i] = static_cast<ScalarPixelType>( *(pos + inc) );
00107         }
00108     }
00109 }
00110 //-------------------------------------------------------------------------------
00111 template<class T>
00112 const VectorIndexType & mitkNeighborhoodIterator<T>::GetInnerImageRegion()
00113 {
00114     for(unsigned int i=0;i<m_ImageDimension;i++)
00115     {
00116         m_Region[i*2] = 2;
00117         m_Region[i*2+1] = m_Dimensions[i] - 5;      //Notice:width
00118     }
00119 
00120     return m_Region; 
00121 }
00122 //-----------------------------------------------------------------------------
00123 template<class T>
00124 mitkNeighborhoodIterator<T>::~mitkNeighborhoodIterator()
00125 {
00126     delete m_Neighborhood;
00127 }
00128 //-------------------------------------------------------------------------------
00129 template<class T>
00130 void mitkNeighborhoodIterator<T>::SetRadius( VectorIndexType& radius )
00131 {
00132     m_Neighborhood->SetRadius(radius);
00133 }
00134 //-------------------------------------------------------------------------------
00135 template<class T>
00136 mitkNeighborhoodIterator<T>::mitkNeighborhoodIterator()
00137 : mitkVolumeIterator<T>()
00138 {
00139     m_Neighborhood = new mitkNeighborhood;
00140 }
00141 //---------------------------------------------------------------------------------
00142 template<class T>
00143 mitkNeighborhoodIterator<T>::mitkNeighborhoodIterator( mitkVolume* vol, VectorIndexType& region, VectorIndexType& radius )
00144 : mitkVolumeIterator<T>(vol, region)
00145 {
00146     m_Neighborhood = new mitkNeighborhood;
00147     m_Neighborhood->SetRadius(radius);
00148 }
00149 //------------------------------------------------------------------------------------
00150 template<class T>
00151 mitkNeighborhoodIterator<T>::mitkNeighborhoodIterator( mitkVolume* vol, VectorIndexType& radius )
00152 :  mitkVolumeIterator<T>(vol)
00153 {
00154     m_Neighborhood = new mitkNeighborhood;
00155     m_Neighborhood->SetRadius(radius);
00156 }
00157 //-------------------------------------------------------------------------------------------
00158 #endif

Generated on Tue Feb 25 15:00:37 2014 for MITK (Medical Imaging ToolKit) by  doxygen 1.4.3