itkShapedFloodFilledFunctionConditionalConstIterator.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkShapedFloodFilledFunctionConditionalConstIterator_h
00018 #define __itkShapedFloodFilledFunctionConditionalConstIterator_h
00019
00020 #include <queue>
00021 #include <vector>
00022
00023 #include "itkIndex.h"
00024 #include "itkSize.h"
00025 #include "itkConditionalConstIterator.h"
00026 #include "itkShapedNeighborhoodIterator.h"
00027 #include "itkConnectedComponentAlgorithm.h"
00028 #include "itkImage.h"
00029
00030 namespace itk
00031 {
00032
00040 template<class TImage, class TFunction>
00041 class ITK_EXPORT ShapedFloodFilledFunctionConditionalConstIterator:
00042 public ConditionalConstIterator<TImage>
00043 {
00044 public:
00045
00047 typedef ShapedFloodFilledFunctionConditionalConstIterator Self;
00048
00050 typedef TFunction FunctionType;
00051
00053 typedef typename TFunction::InputType FunctionInputType;
00054
00056 typedef typename TImage::IndexType IndexType;
00057
00059 typedef typename TImage::OffsetType OffsetType;
00060
00062 typedef typename TImage::SizeType SizeType;
00063
00065 typedef typename TImage::RegionType RegionType;
00066
00068 typedef TImage ImageType;
00069
00071 typedef typename TImage::InternalPixelType InternalPixelType;
00072
00074 typedef typename TImage::PixelType PixelType;
00075
00077 typedef typename itk::ShapedNeighborhoodIterator<ImageType> NeighborhoodIteratorType;
00078
00083 itkStaticConstMacro(NDimensions, unsigned int, TImage::ImageDimension);
00084
00088 ShapedFloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00089 FunctionType *fnPtr,
00090 IndexType startIndex);
00091
00095 ShapedFloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00096 FunctionType *fnPtr,
00097 std::vector<IndexType> & startIndices);
00098
00102 ShapedFloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00103 FunctionType *fnPtr);
00104
00109 void FindSeedPixel();
00110
00112 void FindSeedPixels();
00113
00115 void InitializeIterator();
00116
00118 virtual ~ShapedFloodFilledFunctionConditionalConstIterator() {};
00119
00121 virtual bool IsPixelIncluded(const IndexType & index) const = 0;
00122
00125 Self &operator=(const Self& it)
00126 {
00127 this->m_Image = it.m_Image;
00128 this->m_Region = it.m_Region;
00129 return *this;
00130 }
00131
00133 static unsigned int GetIteratorDimension()
00134 {return TImage::ImageDimension;}
00135
00140 const IndexType GetIndex()
00141 { return m_IndexStack.front();}
00142
00144 const PixelType & Get(void) const
00145 { return this->m_Image->GetPixel(m_IndexStack.front() ); }
00146
00148 bool IsAtEnd()
00149 { return this->m_IsAtEnd; }
00150
00152 void AddSeed ( const IndexType seed )
00153 {
00154 m_StartIndices.push_back ( seed );
00155 }
00156
00158 void ClearSeeds ()
00159 {
00160 m_StartIndices.clear();
00161 }
00162
00165 void GoToBegin()
00166 {
00167
00168 while (!m_IndexStack.empty())
00169 {
00170 m_IndexStack.pop();
00171 }
00172
00173 this->m_IsAtEnd = true;
00174
00175 m_TempPtr->FillBuffer(
00176 NumericTraits<ITK_TYPENAME TTempImage::PixelType>::Zero
00177 );
00178
00179 for ( unsigned int i = 0; i < m_StartIndices.size(); i++ )
00180 {
00181 if( this->m_Image->GetBufferedRegion().IsInside ( m_StartIndices[i] ) &&
00182 this->IsPixelIncluded(m_StartIndices[i]) )
00183 {
00184
00185 m_IndexStack.push(m_StartIndices[i]);
00186
00187
00188 this->m_IsAtEnd = false;
00189
00190
00191
00192 m_TempPtr->SetPixel(m_StartIndices[i], 2);
00193 }
00194 }
00195 }
00196
00198 void operator++()
00199 { this->DoFloodStep(); }
00200
00201 void DoFloodStep();
00202
00203 virtual SmartPointer<FunctionType> GetFunction() const
00204 {
00205 return m_Function;
00206 }
00207
00212 void SetFullyConnected(const bool _arg);
00213 bool GetFullyConnected() const;
00214 itkBooleanMacro(FullyConnected);
00216
00217
00218 protected:
00220 SmartPointer<FunctionType> m_Function;
00221
00227 typedef Image<unsigned char, itkGetStaticConstMacro(NDimensions)> TTempImage;
00228
00229 typename TTempImage::Pointer m_TempPtr;
00230
00232 std::vector<IndexType> m_StartIndices;
00233
00235 typename ImageType::PointType m_ImageOrigin;
00236
00238 typename ImageType::SpacingType m_ImageSpacing;
00239
00241 NeighborhoodIteratorType m_NeighborhoodIterator;
00242
00244 RegionType m_ImageRegion;
00245
00247 std::queue<IndexType> m_IndexStack;
00248
00250 FunctionInputType m_LocationVector;
00251
00254 bool m_FoundUncheckedNeighbor;
00255
00257 bool m_IsValidIndex;
00258
00264 bool m_FullyConnected;
00265 };
00267
00268 }
00269
00270 #ifndef ITK_MANUAL_INSTANTIATION
00271 #include "itkShapedFloodFilledFunctionConditionalConstIterator.txx"
00272 #endif
00273
00274 #endif
00275