ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkShapedFloodFilledFunctionConditionalConstIterator.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 __itkShapedFloodFilledFunctionConditionalConstIterator_h
19 #define __itkShapedFloodFilledFunctionConditionalConstIterator_h
20 
21 #include <queue>
22 #include <vector>
23 
24 #include "itkSize.h"
27 
28 namespace itk
29 {
42 template< typename TImage, typename TFunction >
44  public ConditionalConstIterator< TImage >
45 {
46 public:
47 
50 
52  typedef TFunction FunctionType;
53 
55  typedef typename TFunction::InputType FunctionInputType;
56 
58  typedef typename TImage::IndexType IndexType;
59 
61  typedef typename std::vector< IndexType > SeedsContainerType;
62 
64  typedef typename TImage::OffsetType OffsetType;
65 
67  typedef typename TImage::SizeType SizeType;
68 
70  typedef typename TImage::RegionType RegionType;
71 
73  typedef TImage ImageType;
74 
76  typedef typename TImage::InternalPixelType InternalPixelType;
77 
79  typedef typename TImage::PixelType PixelType;
80 
83 
88  itkStaticConstMacro(NDimensions, unsigned int, TImage::ImageDimension);
89 
94  FunctionType *fnPtr,
95  IndexType startIndex);
96 
101  FunctionType *fnPtr,
102  std::vector< IndexType > & startIndices);
103 
108  FunctionType *fnPtr);
109 
114  void FindSeedPixel();
115 
117  void FindSeedPixels();
118 
120  void InitializeIterator();
121 
124 
126  virtual bool IsPixelIncluded(const IndexType & index) const = 0;
127 
130  Self & operator=(const Self & it)
131  {
132  this->m_Image = it.m_Image; // copy the smart pointer
133  this->m_Region = it.m_Region;
134  return *this;
135  }
136 
138  static unsigned int GetIteratorDimension()
139  { return TImage::ImageDimension; }
140 
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  void ClearSeeds()
164  {
165  m_Seeds.clear();
166  }
167 
170  void GoToBegin()
171  {
172  // Clear the queue
173  while ( !m_IndexStack.empty() )
174  {
175  m_IndexStack.pop();
176  }
177 
178  this->m_IsAtEnd = true;
179  // Initialize the temporary image
180  m_TempPtr->FillBuffer(
182  );
183 
184  for ( unsigned int i = 0; i < m_Seeds.size(); i++ )
185  {
186  if ( this->m_Image->GetBufferedRegion().IsInside (m_Seeds[i])
187  && this->IsPixelIncluded(m_Seeds[i]) )
188  {
189  // Push the seed onto the queue
190  m_IndexStack.push(m_Seeds[i]);
191 
192  // Obviously, we're at the beginning
193  this->m_IsAtEnd = false;
194 
195  // Mark the start index in the temp image as inside the
196  // function, neighbor check incomplete
197  m_TempPtr->SetPixel(m_Seeds[i], 2);
198  }
199  }
200  }
201 
203  void operator++()
204  { this->DoFloodStep(); }
205 
206  void DoFloodStep();
207 
209  {
210  return m_Function;
211  }
212 
217  void SetFullyConnected(const bool _arg);
218 
219  bool GetFullyConnected() const;
220 
221  itkBooleanMacro(FullyConnected);
222 
223  virtual const SeedsContainerType &GetSeeds() const
224  {
225  return m_Seeds;
226  }
227 
228 protected: //made protected so other iterators can access
231 
238 
240 
243 
245  typename ImageType::PointType m_ImageOrigin;
246 
248  typename ImageType::SpacingType m_ImageSpacing;
249 
252 
255 
257  std::queue< IndexType > m_IndexStack;
258 
261 
265 
268 
275 };
276 } // end namespace itk
278 
279 #ifndef ITK_MANUAL_INSTANTIATION
280 #include "itkShapedFloodFilledFunctionConditionalConstIterator.hxx"
281 #endif
282 
283 #endif
virtual bool IsPixelIncluded(const IndexType &index) const =0
ShapedFloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr, FunctionType *fnPtr, IndexType startIndex)
Iterates over a flood-filled spatial function with read-only access to pixels.
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