ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkImageRandomConstIteratorWithIndex.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 itkImageRandomConstIteratorWithIndex_h
19#define itkImageRandomConstIteratorWithIndex_h
20
23#include <type_traits> // For remove_const_t.
24
25namespace itk
26{
27namespace detail
28{
29// Draws a uniform random index in region, as ImageRandomConstIteratorWithIndex does, without an image.
30template <unsigned int VDimension>
33 const ImageRegion<VDimension> & region)
34{
35 auto position = static_cast<IndexValueType>(
36 generator.GetVariateWithOpenRange(static_cast<double>(region.GetNumberOfPixels()) - 0.5));
37
39 for (unsigned int dim = 0; dim < VDimension; ++dim)
40 {
41 const SizeValueType sizeInThisDimension = region.GetSize(dim);
42 const IndexValueType residual = position % sizeInThisDimension;
43 index[dim] = residual + region.GetIndex(dim);
44 position -= residual;
45 position /= sizeInThisDimension;
46 }
47 return index;
48}
49} // namespace detail
50
140template <typename TImage>
141class ITK_TEMPLATE_EXPORT ImageRandomConstIteratorWithIndex : public ImageConstIteratorWithIndex<TImage>
142{
143public:
147
149 using typename Superclass::IndexType;
150 using typename Superclass::SizeType;
151 using typename Superclass::OffsetType;
152 using typename Superclass::RegionType;
153 using typename Superclass::ImageType;
154 using typename Superclass::PixelContainer;
156 using typename Superclass::InternalPixelType;
157 using typename Superclass::PixelType;
158 using typename Superclass::AccessorType;
159 using typename Superclass::IndexValueType;
160 using typename Superclass::OffsetValueType;
161 using typename Superclass::SizeValueType;
162
165
167
170 ImageRandomConstIteratorWithIndex(const TImage * ptr, const RegionType & region);
171
182
184 void
186 {
187 this->RandomJump();
189 }
190
192 void
198
200 [[nodiscard]] bool
201 IsAtBegin() const
202 {
203 return m_NumberOfSamplesDone == 0L;
204 }
205
207 [[nodiscard]] bool
208 IsAtEnd() const
209 {
211 }
212
215 Self &
217 {
218 this->RandomJump();
220 return *this;
221 }
222
225 Self &
227 {
228 this->RandomJump();
230 return *this;
231 }
232
234 void
239
240 [[nodiscard]] SizeValueType
242 {
244 }
245
247 void
249
250 void
252
253private:
255 void
257
263};
264
265// Deduction guide for class template argument deduction (CTAD).
266template <typename TImage>
267ImageRandomConstIteratorWithIndex(SmartPointer<TImage>, const typename TImage::RegionType &)
269
270} // end namespace itk
271
272#ifndef ITK_MANUAL_INSTANTIATION
273# include "itkImageRandomConstIteratorWithIndex.hxx"
274#endif
275
276#endif
typename OffsetType::OffsetValueType OffsetValueType
Self & operator=(const Self &it)
typename SizeType::SizeValueType SizeValueType
typename IndexType::IndexValueType IndexValueType
typename PixelContainer::Pointer PixelContainerPointer
typename TImage::InternalPixelType InternalPixelType
typename TImage::PixelContainer PixelContainer
A multi-dimensional image iterator that visits a random set of pixels within an image region.
~ImageRandomConstIteratorWithIndex() override=default
Statistics::MersenneTwisterRandomVariateGenerator::Pointer GeneratorPointer
ImageRandomConstIteratorWithIndex(const TImage *ptr, const RegionType &region)
ImageRandomConstIteratorWithIndex(const ImageConstIteratorWithIndex< TImage > &it)
An image region represents a structured region of data.
SizeValueType GetNumberOfPixels() const
const IndexType & GetIndex() const
const SizeType & GetSize() const
Implements transparent reference counting.
static Pointer New()
Method for creation through the object factory.
Index< VDimension > RandomIndexInRegion(Statistics::MersenneTwisterRandomVariateGenerator &generator, const ImageRegion< VDimension > &region)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:82
ImageRandomConstIteratorWithIndex(SmartPointer< TImage >, const typename TImage::RegionType &) -> ImageRandomConstIteratorWithIndex< std::remove_const_t< TImage > >
long IndexValueType
Definition itkIntTypes.h:85
Represent a n-dimensional index in a n-dimensional image.
Definition itkIndex.h:69