ITK  6.0.0
Insight Toolkit
itkImageRegionConstIterator.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 itkImageRegionConstIterator_h
19#define itkImageRegionConstIterator_h
20
21#include "itkImageIterator.h"
22
23namespace itk
24{
108template <typename TImage>
109class ITK_TEMPLATE_EXPORT ImageRegionConstIterator : public ImageConstIterator<TImage>
110{
111public:
115
120 static constexpr unsigned int ImageIteratorDimension = Superclass::ImageIteratorDimension;
121
128 using typename Superclass::IndexType;
129 using typename Superclass::SizeType;
130 using typename Superclass::OffsetType;
131 using typename Superclass::RegionType;
132 using typename Superclass::ImageType;
133 using typename Superclass::PixelContainer;
135 using typename Superclass::InternalPixelType;
136 using typename Superclass::PixelType;
137 using typename Superclass::AccessorType;
138
140 itkOverrideGetNameOfClassMacro(ImageRegionConstIterator);
141
144 : ImageConstIterator<TImage>()
145 {
146 m_SpanBeginOffset = 0;
147 m_SpanEndOffset = 0;
148 }
153 ImageRegionConstIterator(const ImageType * ptr, const RegionType & region)
154 : ImageConstIterator<TImage>(ptr, region)
155 {
156 m_SpanBeginOffset = this->m_BeginOffset;
157 m_SpanEndOffset = this->m_BeginOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
158 }
168 {
170
171 IndexType ind = this->GetIndex();
172 m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
173 (ind[0] - this->m_Region.GetIndex()[0]);
174 m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
175 }
176
184 {
186
187 IndexType ind = this->GetIndex();
188 m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
189 (ind[0] - this->m_Region.GetIndex()[0]);
190 m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
191 }
192
195 void
197 {
198 Superclass::GoToBegin();
199
200 // reset the span offsets
201 m_SpanBeginOffset = this->m_BeginOffset;
202 m_SpanEndOffset = this->m_BeginOffset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
203 }
204
207 void
209 {
210 Superclass::GoToEnd();
211
212 // reset the span offsets
213 m_SpanEndOffset = this->m_EndOffset;
214 m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
215 }
216
220 void
221 SetIndex(const IndexType & ind) override
222 {
223 Superclass::SetIndex(ind);
224 m_SpanEndOffset = this->m_Offset + static_cast<OffsetValueType>(this->m_Region.GetSize()[0]) -
225 (ind[0] - this->m_Region.GetIndex()[0]);
226 m_SpanBeginOffset = m_SpanEndOffset - static_cast<OffsetValueType>(this->m_Region.GetSize()[0]);
227 }
237 Self &
239 {
240 if (++this->m_Offset >= m_SpanEndOffset)
241 {
242 this->Increment();
243 }
244 return *this;
245 }
255 Self &
257 {
258 if (--this->m_Offset < m_SpanBeginOffset)
259 {
260 this->Decrement();
261 }
262 return *this;
263 }
266protected:
267 OffsetValueType m_SpanBeginOffset{}; // one pixel before the beginning of the span
268 // (row)
269 OffsetValueType m_SpanEndOffset{}; // one pixel past the end of the span (row)
270
271private:
272 void
273 Increment(); // advance in a direction other than the fastest moving
274
275 void
276 Decrement(); // go back in a direction other than the fastest moving
277};
278} // end namespace itk
279
280#ifndef ITK_MANUAL_INSTANTIATION
281# include "itkImageRegionConstIterator.hxx"
282#endif
283
284#endif
Pixel-wise addition of two images.
A multi-dimensional image iterator templated over image type.
typename TImage::IndexType IndexType
typename TImage::PixelContainer PixelContainer
typename TImage::OffsetType OffsetType
typename TImage::InternalPixelType InternalPixelType
typename PixelContainer::Pointer PixelContainerPointer
typename TImage::AccessorType AccessorType
typename TImage::RegionType RegionType
Self & operator=(const Self &it)
typename TImage::PixelType PixelType
A multi-dimensional iterator templated over image type.
A multi-dimensional iterator templated over image type that walks a region of pixels.
ImageRegionConstIterator(const ImageConstIterator< TImage > &it)
void SetIndex(const IndexType &ind) override
ImageRegionConstIterator(const ImageType *ptr, const RegionType &region)
ImageRegionConstIterator(const ImageIterator< TImage > &it)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long OffsetValueType
Definition: itkIntTypes.h:97