ITK  6.0.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 * https://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
28namespace itk
29{
38template <typename TImage, typename TFunction>
40{
41public:
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
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
83
88 FunctionType * fnPtr,
89 std::vector<IndexType> & startIndex);
90
95
100 void
102
104 void
106
108 void
110
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 }
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(typename TTempImage::PixelType{});
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
235
238 {
239 return m_Function;
240 }
241
242protected: // made protected so other iterators can access
245
252 typename TTempImage::Pointer m_TemporaryPointer{};
253
256
258 typename ImageType::PointType m_ImageOrigin{};
259
261 typename ImageType::SpacingType m_ImageSpacing{};
262
264 RegionType m_ImageRegion{};
265
267 std::queue<IndexType> m_IndexStack{};
268
270 FunctionInputType m_LocationVector{};
271
274 bool m_FoundUncheckedNeighbor{};
275
277 bool m_IsValidIndex{};
278};
279} // end namespace itk
280
281#ifndef ITK_MANUAL_INSTANTIATION
282# include "itkFloodFilledFunctionConditionalConstIterator.hxx"
283#endif
284
285#endif
A base class for other iterators where membership in the set of output pixels is conditional upon som...
typename TImage::PixelType PixelType
typename TImage::InternalPixelType InternalPixelType
typename TImage::RegionType RegionType
FloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr, FunctionType *fnPtr, std::vector< IndexType > &startIndex)
FloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr, FunctionType *fnPtr)
FloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr, FunctionType *fnPtr, IndexType startIndex)
~FloodFilledFunctionConditionalConstIterator() override=default
bool IsPixelIncluded(const IndexType &index) const override=0
Templated n-dimensional image class.
Definition: itkImage.h:89
TPixel PixelType
Definition: itkImage.h:108
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....