00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkConstShapedNeighborhoodIterator_h
00018 #define __itkConstShapedNeighborhoodIterator_h
00019
00020 #include <vector>
00021 #include <list>
00022 #include "itkNeighborhoodIterator.h"
00023
00024 namespace itk {
00025
00040 template<class TImage, class TBoundaryCondition
00041 = ZeroFluxNeumannBoundaryCondition<TImage> >
00042 class ITK_EXPORT ConstShapedNeighborhoodIterator
00043 : private NeighborhoodIterator<TImage, TBoundaryCondition>
00044 {
00045 public:
00047 typedef typename TImage::InternalPixelType InternalPixelType;
00048 typedef typename TImage::PixelType PixelType;
00049
00051 itkStaticConstMacro(Dimension, unsigned int, TImage::ImageDimension);
00052
00054 typedef ConstShapedNeighborhoodIterator Self;
00055 typedef NeighborhoodIterator<TImage, TBoundaryCondition> Superclass;
00056
00058 typedef typename Superclass::OffsetType OffsetType;
00059 typedef typename OffsetType::OffsetValueType OffsetValueType;
00060 typedef typename Superclass::RadiusType RadiusType;
00061 typedef typename Superclass::SizeType SizeType;
00062 typedef typename Superclass::SizeValueType SizeValueType;
00063
00065 typedef TImage ImageType;
00066 typedef typename TImage::RegionType RegionType;
00067 typedef Index<itkGetStaticConstMacro(Dimension)> IndexType;
00068 typedef typename IndexType::IndexValueType IndexValueType;
00069 typedef Neighborhood<PixelType, itkGetStaticConstMacro(Dimension)> NeighborhoodType;
00070
00073 typedef std::list<unsigned int> IndexListType;
00074
00076 typedef TBoundaryCondition BoundaryConditionType;
00077
00079 typedef ImageBoundaryCondition<ImageType> *ImageBoundaryConditionPointerType;
00080
00082 struct ConstIterator
00083 {
00084 ConstIterator() { m_NeighborhoodIterator = 0; }
00085 ConstIterator(Self *s)
00086 {
00087 m_NeighborhoodIterator = s;
00088 this->GoToBegin();
00089 }
00090 ~ConstIterator() {}
00091 const ConstIterator &operator=(const ConstIterator &o)
00092 {
00093 m_NeighborhoodIterator = o.m_NeighborhoodIterator;
00094 m_ListIterator = o.m_ListIterator;
00095 return *this;
00096 }
00097
00098 ConstIterator(const ConstIterator &o)
00099 {
00100 m_NeighborhoodIterator = o.m_NeighborhoodIterator;
00101 m_ListIterator = o.m_ListIterator;
00102 }
00103
00104 void operator++(int)
00105 { m_ListIterator++; }
00106
00107 void operator--(int)
00108 { m_ListIterator--; }
00109
00110 const ConstIterator &operator++()
00111 {
00112 m_ListIterator++;
00113 return *this;
00114 }
00115 const ConstIterator &operator--()
00116 {
00117 m_ListIterator--;
00118 return *this;
00119 }
00120
00121 bool operator!=(const ConstIterator &o) const
00122 { return m_ListIterator.operator!=(o.m_ListIterator); }
00123 bool operator==(const ConstIterator &o) const
00124 { return m_ListIterator.operator==(o.m_ListIterator); }
00125
00126 bool IsAtEnd() const
00127 {
00128 if (m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end())
00129 { return true; }
00130 else { return false; }
00131 }
00132
00133 void GoToBegin()
00134 {
00135 m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
00136 }
00137
00138 void GoToEnd()
00139 {
00140 m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
00141 }
00142
00143 PixelType Get() const
00144 { return m_NeighborhoodIterator->GetPixel(*m_ListIterator); }
00145
00146 OffsetType GetNeighborhoodOffset() const
00147 { return m_NeighborhoodIterator->GetOffset(*m_ListIterator); }
00148
00149 typename IndexListType::value_type GetNeighborhoodIndex() const
00150 { return *m_ListIterator; }
00151
00152 protected:
00153 Self *m_NeighborhoodIterator;
00154 typename IndexListType::const_iterator m_ListIterator;
00155
00156 void ProtectedSet(const PixelType &v) const
00157 { m_NeighborhoodIterator->SetPixel(*m_ListIterator, v); }
00158 };
00159
00162 const ConstIterator &Begin() const
00163 { return m_ConstBeginIterator; }
00164
00167 const ConstIterator &End() const
00168 { return m_ConstEndIterator; }
00169
00171 ConstShapedNeighborhoodIterator()
00172 {
00173 m_ConstBeginIterator = ConstIterator(this);
00174 m_ConstEndIterator = ConstIterator(this);
00175 m_ConstEndIterator.GoToEnd();
00176 m_CenterIsActive = false;
00177 }
00178
00180 virtual ~ConstShapedNeighborhoodIterator() { }
00181
00183 ConstShapedNeighborhoodIterator( const ConstShapedNeighborhoodIterator & );
00184
00187 ConstShapedNeighborhoodIterator(const SizeType &radius,
00188 const ImageType * ptr,
00189 const RegionType ®ion
00190 ) : Superclass (radius, const_cast<ImageType*>(ptr),
00191 region)
00192 {
00193 m_ConstBeginIterator = ConstIterator(this);
00194 m_ConstEndIterator = ConstIterator(this);
00195 m_ConstEndIterator.GoToEnd();
00196 m_CenterIsActive = false;
00197 }
00198
00199
00200
00201 Superclass::GetImagePointer;
00202 Superclass::GetRadius;
00203 Superclass::GetIndex;
00204 Superclass::GetNeighborhoodIndex;
00205 Superclass::GetRegion;
00206 Superclass::GetBeginIndex;
00207 Superclass::GoToBegin;
00208 Superclass::GoToEnd;
00209 Superclass::IsAtBegin;
00210 Superclass::IsAtEnd;
00211 Superclass::GetOffset;
00212 Superclass::operator==;
00213 Superclass::operator!=;
00214 Superclass::operator<;
00215 Superclass::operator>;
00216 Superclass::operator>=;
00217 Superclass::operator<=;
00218 Superclass::operator[];
00219 Superclass::GetElement;
00220 Superclass::SetLocation;
00221 Superclass::OverrideBoundaryCondition;
00222 Superclass::ResetBoundaryCondition;
00223 Superclass::GetBoundaryCondition;
00224 Superclass::Print;
00225
00226 Superclass::operator-;
00227
00228 Superclass::GetPixel;
00229
00231 Self &operator=(const Self& orig)
00232 { return Superclass::operator=(orig); }
00233
00235 virtual void PrintSelf(std::ostream &, Indent) const;
00236
00240 virtual void ActivateOffset(const OffsetType& off)
00241 { this->ActivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
00242 virtual void DeactivateOffset(const OffsetType& off)
00243 { this->DeactivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
00244
00246 virtual void ClearActiveList()
00247 {
00248 m_ActiveIndexList.clear();
00249 m_ConstBeginIterator.GoToBegin();
00250 m_ConstEndIterator.GoToEnd();
00251 m_CenterIsActive = false;
00252 }
00253
00255 const IndexListType &GetActiveIndexList() const
00256 { return m_ActiveIndexList; }
00257
00259 typename IndexListType::size_type GetActiveIndexListSize() const
00260 { return m_ActiveIndexList.size(); }
00261
00264 Self &operator++();
00265
00268 Self &operator--();
00269
00273 Self &operator+=(const OffsetType &);
00274
00278 Self &operator-=(const OffsetType &);
00279
00280
00281
00282 Superclass::SetPixel;
00283 protected:
00284 friend struct ConstIterator;
00285
00288
00289
00295 virtual void ActivateIndex(const unsigned int);
00296 virtual void DeactivateIndex(const unsigned int);
00297
00298 bool m_CenterIsActive;
00299 IndexListType m_ActiveIndexList;
00300 ConstIterator m_ConstEndIterator;
00301 ConstIterator m_ConstBeginIterator;
00302 };
00303
00304
00305 }
00306
00307
00308 #ifndef ITK_MANUAL_INSTANTIATION
00309 #include "itkConstShapedNeighborhoodIterator.txx"
00310 #endif
00311
00312 #endif
00313