ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkFloodFilledFunctionConditionalConstIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkFloodFilledFunctionConditionalConstIterator_h
19 #define __itkFloodFilledFunctionConditionalConstIterator_h
20 
21 #include <queue>
22 #include <vector>
23 
24 #include "itkSize.h"
26 #include "itkImage.h"
27 
28 namespace itk
29 {
38 template< class TImage, class TFunction >
40  public ConditionalConstIterator< TImage >
41 {
42 public:
43 
46 
48  typedef TFunction FunctionType;
49 
51  typedef typename TFunction::InputType FunctionInputType;
52 
54  typedef typename TImage::IndexType IndexType;
55 
57  typedef typename std::vector<IndexType> SeedsContainerType;
58 
60  typedef typename TImage::SizeType SizeType;
61 
63  typedef typename TImage::RegionType RegionType;
64 
66  typedef TImage ImageType;
67 
69  typedef typename TImage::InternalPixelType InternalPixelType;
70 
72  typedef typename TImage::PixelType PixelType;
73 
78  itkStaticConstMacro(NDimensions, unsigned int, TImage::ImageDimension);
79 
84  FunctionType *fnPtr,
85  IndexType startIndex);
86 
91  FunctionType *fnPtr,
92  std::vector< IndexType > & startIndices);
93 
98  FunctionType *fnPtr);
99 
104  void FindSeedPixel();
105 
107  void FindSeedPixels();
108 
110  void InitializeIterator();
111 
114 
116  virtual bool IsPixelIncluded(const IndexType & index) const = 0;
117 
120  Self & operator=(const Self & it)
121  {
122  this->m_Image = it.m_Image; // copy the smart pointer
123  this->m_Region = it.m_Region;
124  this->m_Function = it.m_Function;
125  this->m_TemporaryPointer = it.m_TemporaryPointer;
126  this->m_Seeds = it.m_Seeds;
127  this->m_ImageOrigin = it.m_ImageOrigin;
128  this->m_ImageSpacing = it.m_ImageSpacing;
129  this->m_ImageRegion = it.m_ImageRegion;
130  this->m_IndexStack = it.m_IndexStack;
131  this->m_LocationVector = it.m_LocationVector;
132  this->m_FoundUncheckedNeighbor = it.m_FoundUncheckedNeighbor;
133  this->m_IsValidIndex = it.m_IsValidIndex;
134  return *this;
135  }
136 
138  static unsigned int GetIteratorDimension()
139  { return TImage::ImageDimension; }
140 
145  const IndexType GetIndex()
146  { return m_IndexStack.front(); }
147 
149  const PixelType Get(void) const
150  { return this->m_Image->GetPixel( m_IndexStack.front() ); }
151 
153  bool IsAtEnd()
154  { return this->m_IsAtEnd; }
155 
157  void AddSeed(const IndexType &seed)
158  {
159  m_Seeds.push_back (seed);
160  }
161 
163  virtual const SeedsContainerType &GetSeeds() const
164  {
165  return m_Seeds;
166  }
167 
169  void ClearSeeds()
170  {
171  m_Seeds.clear();
172  }
173 
176  void GoToBegin()
177  {
178  // Clear the queue
179  while ( !m_IndexStack.empty() )
180  {
181  m_IndexStack.pop();
182  }
183 
184  this->m_IsAtEnd = true;
185  // Initialize the temporary image
186  m_TemporaryPointer->FillBuffer(
188  );
189 
190  for ( unsigned int i = 0; i < m_Seeds.size(); i++ )
191  {
192  if ( this->m_Image->GetBufferedRegion().IsInside (m_Seeds[i])
193  && this->IsPixelIncluded(m_Seeds[i]) )
194  {
195  // Push the seed onto the queue
196  m_IndexStack.push(m_Seeds[i]);
197 
198  // Obviously, we're at the beginning
199  this->m_IsAtEnd = false;
200 
201  // Mark the start index in the temp image as inside the
202  // function, neighbor check incomplete
203  m_TemporaryPointer->SetPixel(m_Seeds[i], 2);
204  }
205  }
206  }
207 
209  void operator++()
210  { this->DoFloodStep(); }
211 
212  void DoFloodStep();
213 
214  virtual SmartPointer< FunctionType > GetFunction() const
215  {
216  return m_Function;
217  }
218 
219 protected: //made protected so other iterators can access
222 
230 
233 
235  typename ImageType::PointType m_ImageOrigin;
236 
238  typename ImageType::SpacingType m_ImageSpacing;
239 
242 
244  std::queue< IndexType > m_IndexStack;
245 
248 
252 
255 };
256 } // end namespace itk
257 
258 #ifndef ITK_MANUAL_INSTANTIATION
259 #include "itkFloodFilledFunctionConditionalConstIterator.hxx"
260 #endif
261 
262 #endif
263