ITK  4.6.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< typename TImage, typename 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  if(this != &it)
123  {
124  this->m_Image = it.m_Image; // copy the smart pointer
125  this->m_Region = it.m_Region;
126  this->m_Function = it.m_Function;
127  this->m_TemporaryPointer = it.m_TemporaryPointer;
128  this->m_Seeds = it.m_Seeds;
129  this->m_ImageOrigin = it.m_ImageOrigin;
130  this->m_ImageSpacing = it.m_ImageSpacing;
131  this->m_ImageRegion = it.m_ImageRegion;
132  this->m_IndexStack = it.m_IndexStack;
133  this->m_LocationVector = it.m_LocationVector;
134  this->m_FoundUncheckedNeighbor = it.m_FoundUncheckedNeighbor;
135  this->m_IsValidIndex = it.m_IsValidIndex;
136  }
137  return *this;
138  }
140 
142  static unsigned int GetIteratorDimension()
143  { return TImage::ImageDimension; }
144 
150  { return m_IndexStack.front(); }
151 
153  const PixelType Get(void) const
154  { return this->m_Image->GetPixel( m_IndexStack.front() ); }
155 
157  bool IsAtEnd()
158  { return this->m_IsAtEnd; }
159 
161  void AddSeed(const IndexType &seed)
162  {
163  m_Seeds.push_back (seed);
164  }
165 
167  virtual const SeedsContainerType &GetSeeds() const
168  {
169  return m_Seeds;
170  }
171 
173  void ClearSeeds()
174  {
175  m_Seeds.clear();
176  }
177 
180  void GoToBegin()
181  {
182  // Clear the queue
183  while ( !m_IndexStack.empty() )
184  {
185  m_IndexStack.pop();
186  }
187 
188  this->m_IsAtEnd = true;
189  // Initialize the temporary image
190  m_TemporaryPointer->FillBuffer(
192  );
193 
194  for ( unsigned int i = 0; i < m_Seeds.size(); i++ )
195  {
196  if ( this->m_Image->GetBufferedRegion().IsInside (m_Seeds[i])
197  && this->IsPixelIncluded(m_Seeds[i]) )
198  {
199  // Push the seed onto the queue
200  m_IndexStack.push(m_Seeds[i]);
201 
202  // Obviously, we're at the beginning
203  this->m_IsAtEnd = false;
204 
205  // Mark the start index in the temp image as inside the
206  // function, neighbor check incomplete
207  m_TemporaryPointer->SetPixel(m_Seeds[i], 2);
208  }
209  }
210  }
211 
213  void operator++()
214  { this->DoFloodStep(); }
215 
216  void DoFloodStep();
217 
219  {
220  return m_Function;
221  }
222 
223 protected: //made protected so other iterators can access
226 
234 
237 
239  typename ImageType::PointType m_ImageOrigin;
240 
242  typename ImageType::SpacingType m_ImageSpacing;
243 
246 
248  std::queue< IndexType > m_IndexStack;
249 
252 
256 
259 };
260 } // end namespace itk
261 
262 #ifndef ITK_MANUAL_INSTANTIATION
263 #include "itkFloodFilledFunctionConditionalConstIterator.hxx"
264 #endif
265 
266 #endif
virtual bool IsPixelIncluded(const IndexType &index) const =0
Image< unsigned char, itkGetStaticConstMacro(NDimensions) > TTempImage
FloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr, FunctionType *fnPtr, IndexType startIndex)
Define additional traits for native types such as int or float.
A base class for other iterators where membership in the set of output pixels is conditional upon som...
Templated n-dimensional image class.
Definition: itkImage.h:75