ITK  5.2.0
Insight Toolkit
itkFloodFilledFunctionConditionalConstIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 {
41 public:
42 
45 
47  using FunctionType = TFunction;
48 
50  using FunctionInputType = typename TFunction::InputType;
51 
53  using IndexType = typename TImage::IndexType;
54 
56  using SeedsContainerType = typename std::vector<IndexType>;
57 
59  using SizeType = typename TImage::SizeType;
60 
62  using RegionType = typename TImage::RegionType;
63 
65  using ImageType = TImage;
66 
68  using InternalPixelType = typename TImage::InternalPixelType;
69 
71  using PixelType = typename TImage::PixelType;
72 
77  static constexpr unsigned int NDimensions = TImage::ImageDimension;
78 
82  FloodFilledFunctionConditionalConstIterator(const ImageType * imagePtr, FunctionType * fnPtr, IndexType startIndex);
83 
88  FunctionType * fnPtr,
89  std::vector<IndexType> & startIndex);
90 
95 
100  void
101  FindSeedPixel();
102 
104  void
105  FindSeedPixels();
106 
108  void
109  InitializeIterator();
110 
112  ~FloodFilledFunctionConditionalConstIterator() override = default;
113 
115  bool
116  IsPixelIncluded(const IndexType & index) const override = 0;
117 
120  Self &
121  operator=(const Self & it)
122  {
123  if (this != &it)
124  {
125  this->m_Image = it.m_Image; // copy the smart pointer
126  this->m_Region = it.m_Region;
127  this->m_Function = it.m_Function;
128  this->m_TemporaryPointer = it.m_TemporaryPointer;
129  this->m_Seeds = it.m_Seeds;
130  this->m_ImageOrigin = it.m_ImageOrigin;
131  this->m_ImageSpacing = it.m_ImageSpacing;
132  this->m_ImageRegion = it.m_ImageRegion;
133  this->m_IndexStack = it.m_IndexStack;
134  this->m_LocationVector = it.m_LocationVector;
135  this->m_FoundUncheckedNeighbor = it.m_FoundUncheckedNeighbor;
136  this->m_IsValidIndex = it.m_IsValidIndex;
137  }
138  return *this;
139  }
141 
143  static unsigned int
145  {
146  return TImage::ImageDimension;
147  }
148 
153  const IndexType
154  GetIndex() override
155  {
156  return m_IndexStack.front();
157  }
158 
160  const PixelType
161  Get() const override
162  {
163  return this->m_Image->GetPixel(m_IndexStack.front());
164  }
165 
167  bool
168  IsAtEnd() const override
169  {
170  return this->m_IsAtEnd;
171  }
172 
174  void
175  AddSeed(const IndexType & seed)
176  {
177  m_Seeds.push_back(seed);
178  }
179 
181  virtual const SeedsContainerType &
182  GetSeeds() const
183  {
184  return m_Seeds;
185  }
186 
188  void
190  {
191  m_Seeds.clear();
192  }
193 
196  void
198  {
199  // Clear the queue
200  while (!m_IndexStack.empty())
201  {
202  m_IndexStack.pop();
203  }
204 
205  this->m_IsAtEnd = true;
206  // Initialize the temporary image
207  m_TemporaryPointer->FillBuffer(NumericTraits<typename TTempImage::PixelType>::ZeroValue());
208 
209  for (unsigned int i = 0; i < m_Seeds.size(); i++)
210  {
211  if (this->m_Image->GetBufferedRegion().IsInside(m_Seeds[i]) && this->IsPixelIncluded(m_Seeds[i]))
212  {
213  // Push the seed onto the queue
214  m_IndexStack.push(m_Seeds[i]);
215 
216  // Obviously, we're at the beginning
217  this->m_IsAtEnd = false;
218 
219  // Mark the start index in the temp image as inside the
220  // function, neighbor check incomplete
221  m_TemporaryPointer->SetPixel(m_Seeds[i], 2);
222  }
223  }
224  }
225 
227  void
228  operator++() override
229  {
230  this->DoFloodStep();
231  }
232 
233  void
234  DoFloodStep();
235 
237  GetFunction() const
238  {
239  return m_Function;
240  }
241 
242 protected: // made protected so other iterators can access
245 
253 
256 
259 
261  typename ImageType::SpacingType m_ImageSpacing;
262 
265 
267  std::queue<IndexType> m_IndexStack;
268 
271 
275 
278 };
279 } // end namespace itk
280 
281 #ifndef ITK_MANUAL_INSTANTIATION
282 # include "itkFloodFilledFunctionConditionalConstIterator.hxx"
283 #endif
284 
285 #endif
itk::ConditionalConstIterator::m_Region
RegionType m_Region
Definition: itkConditionalConstIterator.h:118
itk::FloodFilledFunctionConditionalConstIterator::m_ImageOrigin
ImageType::PointType m_ImageOrigin
Definition: itkFloodFilledFunctionConditionalConstIterator.h:258
itk::ConditionalConstIterator::ImageType
TImage ImageType
Definition: itkConditionalConstIterator.h:60
itk::FloodFilledFunctionConditionalConstIterator::m_FoundUncheckedNeighbor
bool m_FoundUncheckedNeighbor
Definition: itkFloodFilledFunctionConditionalConstIterator.h:274
itk::FloodFilledFunctionConditionalConstIterator::m_IsValidIndex
bool m_IsValidIndex
Definition: itkFloodFilledFunctionConditionalConstIterator.h:277
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::ConditionalConstIterator::InternalPixelType
typename TImage::InternalPixelType InternalPixelType
Definition: itkConditionalConstIterator.h:63
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::FloodFilledFunctionConditionalConstIterator::ClearSeeds
void ClearSeeds()
Definition: itkFloodFilledFunctionConditionalConstIterator.h:189
itkImage.h
itk::FloodFilledFunctionConditionalConstIterator::FunctionType
TFunction FunctionType
Definition: itkFloodFilledFunctionConditionalConstIterator.h:47
itk::SmartPointer< FunctionType >
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::FloodFilledFunctionConditionalConstIterator::Get
const PixelType Get() const override
Definition: itkFloodFilledFunctionConditionalConstIterator.h:161
itk::FloodFilledFunctionConditionalConstIterator::m_TemporaryPointer
TTempImage::Pointer m_TemporaryPointer
Definition: itkFloodFilledFunctionConditionalConstIterator.h:252
itk::FloodFilledFunctionConditionalConstIterator::AddSeed
void AddSeed(const IndexType &seed)
Definition: itkFloodFilledFunctionConditionalConstIterator.h:175
itk::ConditionalConstIterator::m_Image
ImageType::ConstWeakPointer m_Image
Definition: itkConditionalConstIterator.h:115
itk::FloodFilledFunctionConditionalConstIterator::m_Function
SmartPointer< FunctionType > m_Function
Definition: itkFloodFilledFunctionConditionalConstIterator.h:244
itk::FloodFilledFunctionConditionalConstIterator::m_IndexStack
std::queue< IndexType > m_IndexStack
Definition: itkFloodFilledFunctionConditionalConstIterator.h:267
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::FloodFilledFunctionConditionalConstIterator::IsAtEnd
bool IsAtEnd() const override
Definition: itkFloodFilledFunctionConditionalConstIterator.h:168
itk::ConditionalConstIterator::RegionType
typename TImage::RegionType RegionType
Definition: itkConditionalConstIterator.h:57
itk::FloodFilledFunctionConditionalConstIterator::GetIteratorDimension
static unsigned int GetIteratorDimension()
Definition: itkFloodFilledFunctionConditionalConstIterator.h:144
itk::FloodFilledFunctionConditionalConstIterator::GetIndex
const IndexType GetIndex() override
Definition: itkFloodFilledFunctionConditionalConstIterator.h:154
itk::FloodFilledFunctionConditionalConstIterator::m_ImageSpacing
ImageType::SpacingType m_ImageSpacing
Definition: itkFloodFilledFunctionConditionalConstIterator.h:261
itk::FloodFilledFunctionConditionalConstIterator::FunctionInputType
typename TFunction::InputType FunctionInputType
Definition: itkFloodFilledFunctionConditionalConstIterator.h:50
itk::FloodFilledFunctionConditionalConstIterator::GetSeeds
virtual const SeedsContainerType & GetSeeds() const
Definition: itkFloodFilledFunctionConditionalConstIterator.h:182
itk::FloodFilledFunctionConditionalConstIterator::GetFunction
virtual SmartPointer< FunctionType > GetFunction() const
Definition: itkFloodFilledFunctionConditionalConstIterator.h:237
itk::FloodFilledFunctionConditionalConstIterator::SeedsContainerType
typename std::vector< IndexType > SeedsContainerType
Definition: itkFloodFilledFunctionConditionalConstIterator.h:56
itk::ConditionalConstIterator::SizeType
typename TImage::SizeType SizeType
Definition: itkConditionalConstIterator.h:54
itk::FloodFilledFunctionConditionalConstIterator::m_LocationVector
FunctionInputType m_LocationVector
Definition: itkFloodFilledFunctionConditionalConstIterator.h:270
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::FloodFilledFunctionConditionalConstIterator::GoToBegin
void GoToBegin()
Definition: itkFloodFilledFunctionConditionalConstIterator.h:197
itk::ConditionalConstIterator
A base class for other iterators where membership in the set of output pixels is conditional upon som...
Definition: itkConditionalConstIterator.h:38
itk::FloodFilledFunctionConditionalConstIterator
Iterates over a flood-filled spatial function.
Definition: itkFloodFilledFunctionConditionalConstIterator.h:39
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::FloodFilledFunctionConditionalConstIterator::operator=
Self & operator=(const Self &it)
Definition: itkFloodFilledFunctionConditionalConstIterator.h:121
itkConditionalConstIterator.h
itk::FloodFilledFunctionConditionalConstIterator::m_ImageRegion
RegionType m_ImageRegion
Definition: itkFloodFilledFunctionConditionalConstIterator.h:264
itk::FloodFilledFunctionConditionalConstIterator::IndexType
typename TImage::IndexType IndexType
Definition: itkFloodFilledFunctionConditionalConstIterator.h:53
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
itk::FloodFilledFunctionConditionalConstIterator::m_Seeds
SeedsContainerType m_Seeds
Definition: itkFloodFilledFunctionConditionalConstIterator.h:255
itk::FloodFilledFunctionConditionalConstIterator::operator++
void operator++() override
Definition: itkFloodFilledFunctionConditionalConstIterator.h:228
itk::ConditionalConstIterator::PixelType
typename TImage::PixelType PixelType
Definition: itkConditionalConstIterator.h:66
itkSize.h