ITK  5.0.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  using FunctionType = TFunction;
53 
55  using FunctionInputType = typename TFunction::InputType;
56 
58  using IndexType = typename TImage::IndexType;
59 
61  using SeedsContainerType = typename std::vector< IndexType >;
62 
64  using OffsetType = typename TImage::OffsetType;
65 
67  using SizeType = typename TImage::SizeType;
68 
70  using RegionType = typename TImage::RegionType;
71 
73  using ImageType = TImage;
74 
76  using InternalPixelType = typename TImage::InternalPixelType;
77 
79  using PixelType = typename TImage::PixelType;
80 
83 
88  static constexpr unsigned int NDimensions = 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  bool IsPixelIncluded(const IndexType & index) const override = 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 
145  const IndexType GetIndex() override
146  { return m_IndexStack.front(); }
147 
149  const PixelType Get() const override
150  { return this->m_Image->GetPixel( m_IndexStack.front() ); }
151 
153  bool IsAtEnd() const override
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++() override
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 
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
typename TImage::PixelType PixelType
Define numeric traits for std::vector.
Iterates over a flood-filled spatial function with read-only access to pixels.
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