00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#ifndef __itkFloodFilledFunctionConditionalConstIterator_h
00018
#define __itkFloodFilledFunctionConditionalConstIterator_h
00019
00020
#include <queue>
00021
#include <vector>
00022
00023
#include "itkIndex.h"
00024
#include "itkSize.h"
00025
#include "itkConditionalConstIterator.h"
00026
#include "itkImage.h"
00027
00028
namespace itk
00029 {
00030
00038
template<
class TImage,
class TFunction>
00039 class ITK_EXPORT FloodFilledFunctionConditionalConstIterator:
public ConditionalConstIterator<TImage>
00040 {
00041
public:
00043
typedef FloodFilledFunctionConditionalConstIterator
Self;
00044
00046
typedef TFunction
FunctionType;
00047
00049
typedef typename TFunction::InputType
FunctionInputType;
00050
00052
typedef typename TImage::IndexType
IndexType;
00053
00055
typedef typename TImage::SizeType
SizeType;
00056
00058
typedef typename TImage::RegionType
RegionType;
00059
00061
typedef TImage
ImageType;
00062
00064
typedef typename TImage::InternalPixelType
InternalPixelType;
00065
00067
typedef typename TImage::PixelType
PixelType;
00068
00073
itkStaticConstMacro(NDimensions,
unsigned int, TImage::ImageDimension);
00074
00078 FloodFilledFunctionConditionalConstIterator(
const ImageType *imagePtr,
00079
FunctionType *fnPtr,
00080
IndexType startIndex);
00081
00085 FloodFilledFunctionConditionalConstIterator(
const ImageType *imagePtr,
00086
FunctionType *fnPtr,
00087 std::vector<IndexType> & startIndices);
00088
00092 FloodFilledFunctionConditionalConstIterator(
const ImageType *imagePtr,
00093
FunctionType *fnPtr);
00094
00099
void FindSeedPixel();
00100
00102
void FindSeedPixels();
00103
00105
void InitializeIterator();
00106
00108
virtual ~FloodFilledFunctionConditionalConstIterator() {};
00109
00111
virtual bool IsPixelIncluded(
const IndexType & index)
const = 0;
00112
00115
Self &operator=(
const Self& it)
00116 {
00117 m_Image = it.
m_Image;
00118 m_Region = it.
m_Region;
00119 }
00120
00122
static unsigned int GetIteratorDimension()
00123 {
return TImage::ImageDimension;}
00124
00129
const IndexType GetIndex()
00130 {
return m_IndexStack.front();}
00131
00133
const PixelType & Get(
void)
const
00134 {
return m_Image->GetPixel(m_IndexStack.front() ); }
00135
00137
bool IsAtEnd()
00138 {
return m_IsAtEnd; };
00139
00141
void AddSeed (
const IndexType seed )
00142 {
00143 m_StartIndices.push_back ( seed );
00144 };
00145
00147
void ClearSeeds ()
00148 {
00149 m_StartIndices.clear();
00150 };
00151
00154
void GoToBegin()
00155 {
00156
00157 while (!m_IndexStack.empty())
00158 {
00159 m_IndexStack.pop();
00160 }
00161
00162 m_IsAtEnd =
true;
00163
00164 tempPtr->FillBuffer(
NumericTraits<ITK_TYPENAME TTempImage::PixelType>::Zero);
00165
00166
for (
unsigned int i = 0; i < m_StartIndices.size(); i++ )
00167 {
00168
if( m_Image->GetBufferedRegion().IsInside ( m_StartIndices[i] ) &&
00169 this->IsPixelIncluded(m_StartIndices[i]) )
00170 {
00171
00172 m_IndexStack.push(m_StartIndices[i]);
00173
00174
00175 m_IsAtEnd =
false;
00176
00177
00178 tempPtr->SetPixel(m_StartIndices[i], 2);
00179 }
00180 }
00181 };
00182
00184
void operator++()
00185 { this->DoFloodStep(); }
00186
00187 void DoFloodStep();
00188
00189
protected:
00191
SmartPointer<FunctionType> m_Function;
00192
00198
typedef Image<unsigned char, itkGetStaticConstMacro(NDimensions)> TTempImage;
00199
typename TTempImage::Pointer tempPtr;
00200
00202 std::vector<IndexType> m_StartIndices;
00203
00205 typename ImageType::PointType m_ImageOrigin;
00206
00208 typename ImageType::SpacingType m_ImageSpacing;
00209
00211 RegionType m_ImageRegion;
00212
00214 std::queue<IndexType> m_IndexStack;
00215
00217 FunctionInputType m_LocationVector;
00218
00220 bool m_FoundUncheckedNeighbor;
00221
00223 bool m_IsValidIndex;
00224 };
00225
00226 }
00227
00228
#ifndef ITK_MANUAL_INSTANTIATION
00229
#include "itkFloodFilledFunctionConditionalConstIterator.txx"
00230
#endif
00231
00232
#endif