ITK  6.0.0
Insight Toolkit
itkShapedFloodFilledFunctionConditionalConstIterator.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 itkShapedFloodFilledFunctionConditionalConstIterator_h
19#define itkShapedFloodFilledFunctionConditionalConstIterator_h
20
21#include <queue>
22#include <vector>
23
24#include "itkSize.h"
27
28namespace itk
29{
42template <typename TImage, typename TFunction>
44{
45public:
46
49
51 using FunctionType = TFunction;
52
54 using FunctionInputType = typename TFunction::InputType;
55
57 using IndexType = typename TImage::IndexType;
58
60 using SeedsContainerType = typename std::vector<IndexType>;
61
63 using OffsetType = typename TImage::OffsetType;
64
66 using SizeType = typename TImage::SizeType;
67
70
72 using ImageType = TImage;
73
75 using InternalPixelType = typename TImage::InternalPixelType;
76
78 using PixelType = typename TImage::PixelType;
79
82
87 static constexpr unsigned int NDimensions = TImage::ImageDimension;
88
93 FunctionType * fnPtr,
94 IndexType startIndex);
95
100 FunctionType * fnPtr,
101 std::vector<IndexType> & startIndex);
102
107
112 void
114
116 void
118
120 void
122
125
127 bool
128 IsPixelIncluded(const IndexType & index) const override = 0;
129
132 Self &
133 operator=(const Self & it)
134 {
135 this->m_Image = it.m_Image; // copy the smart pointer
136 this->m_Region = it.m_Region;
137 return *this;
138 }
139
141 static unsigned int
143 {
144 return TImage::ImageDimension;
145 }
146
151 const IndexType
152 GetIndex() override
153 {
154 return m_IndexStack.front();
155 }
156
158 const PixelType
159 Get() const override
160 {
161 return this->m_Image->GetPixel(m_IndexStack.front());
162 }
163
165 bool
166 IsAtEnd() const override
167 {
168 return this->m_IsAtEnd;
169 }
170
172 void
173 AddSeed(const IndexType seed)
174 {
175 m_Seeds.push_back(seed);
176 }
177
179 void
181 {
182 m_Seeds.clear();
183 }
184
187 void
189 {
190 // Clear the queue
191 while (!m_IndexStack.empty())
192 {
193 m_IndexStack.pop();
194 }
195
196 this->m_IsAtEnd = true;
197 // Initialize the temporary image
198 m_TempPtr->FillBuffer(typename TTempImage::PixelType{});
199
200 for (unsigned int i = 0; i < m_Seeds.size(); ++i)
201 {
202 if (this->m_Image->GetBufferedRegion().IsInside(m_Seeds[i]) && this->IsPixelIncluded(m_Seeds[i]))
203 {
204 // Push the seed onto the queue
205 m_IndexStack.push(m_Seeds[i]);
206
207 // Obviously, we're at the beginning
208 this->m_IsAtEnd = false;
209
210 // Mark the start index in the temp image as inside the
211 // function, neighbor check incomplete
212 m_TempPtr->SetPixel(m_Seeds[i], 2);
213 }
214 }
215 }
216
218 void
219 operator++() override
220 {
221 this->DoFloodStep();
222 }
223
224 void
226
229 {
230 return m_Function;
231 }
232
237 void
238 SetFullyConnected(const bool _arg);
239
240 bool
242
243 itkBooleanMacro(FullyConnected);
244
245 virtual const SeedsContainerType &
246 GetSeeds() const
247 {
248 return m_Seeds;
249 }
250
251protected: // made protected so other iterators can access
254
261
262 typename TTempImage::Pointer m_TempPtr{};
263
266
268 typename ImageType::PointType m_ImageOrigin{};
269
271 typename ImageType::SpacingType m_ImageSpacing{};
272
274 NeighborhoodIteratorType m_NeighborhoodIterator{};
275
277 RegionType m_ImageRegion{};
278
280 std::queue<IndexType> m_IndexStack{};
281
283 FunctionInputType m_LocationVector{};
284
287 bool m_FoundUncheckedNeighbor{};
288
290 bool m_IsValidIndex{};
291
297 bool m_FullyConnected{};
298};
299} // end namespace itk
302#ifndef ITK_MANUAL_INSTANTIATION
303# include "itkShapedFloodFilledFunctionConditionalConstIterator.hxx"
304#endif
305
306#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::RegionType RegionType
Templated n-dimensional image class.
Definition: itkImage.h:89
TPixel PixelType
Definition: itkImage.h:108
Iterates over a flood-filled spatial function with read-only access to pixels.
ShapedFloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr, FunctionType *fnPtr)
ShapedFloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr, FunctionType *fnPtr, std::vector< IndexType > &startIndex)
bool IsPixelIncluded(const IndexType &index) const override=0
ShapedFloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr, FunctionType *fnPtr, IndexType startIndex)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....