00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __mitkNeighborhoodIterator_h
00011 #define __mitkNeighborhoodIterator_h
00012
00013 #include "mitkVolumeIterator.h"
00014 #include "mitkNeighborhood.h"
00015
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00052 virtual void GetNeighborhood(const ScalarIndexType* index, ScalarPixelType* value, int ch=0)
00053
00054
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 )
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;
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