ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkImageRandomNonRepeatingConstIteratorWithIndex.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 itkImageRandomNonRepeatingConstIteratorWithIndex_h
19#define itkImageRandomNonRepeatingConstIteratorWithIndex_h
20
22#include <algorithm>
23#include <iostream>
24#include <type_traits> // For remove_const_t.
26
27namespace itk
28{
42{
43public:
46 double m_Value{ 0.0 };
47
48 NodeOfPermutation() = default;
49
50 bool
51 operator<(const NodeOfPermutation & b) const
52 {
53 if (m_Priority == b.m_Priority)
54 {
55 return m_Value < b.m_Value;
56 }
57
58 return m_Priority < b.m_Priority;
59 }
60};
61
67{
68public:
73
81
84 {
85 delete[] m_Permutation;
86 m_Size = it.m_Size;
89 return *this;
90 }
91
92 void
94 {
95 if (i > m_Size)
96 {
97 std::ostringstream ostrm;
98 ostrm << "Error: RandomPermuation does not have " << i << " elements" << std::endl;
99 throw std::runtime_error(ostrm.str());
100 }
101
102 m_Permutation[i].m_Priority = priority;
103 }
104
105 void
106 Shuffle() const
107 {
108 for (SizeValueType i = 0; i < m_Size; ++i)
109 {
110 m_Permutation[i].m_Value = m_Generator->GetVariateWithClosedRange(1.0);
111 m_Permutation[i].m_Index = i;
112 }
113 std::sort(m_Permutation, m_Permutation + m_Size);
114 }
115
118 {
119 return m_Permutation[i].m_Index;
120 }
121
123
125 void
127 {
128 m_Generator->SetSeed();
129 }
130
131 void
132 ReinitializeSeed(unsigned int seed) const
133 {
134 m_Generator->SetSeed(seed);
135 }
136};
137
209template <typename TImage>
211{
212public:
216
218 using typename Superclass::IndexType;
219 using typename Superclass::SizeType;
220 using typename Superclass::OffsetType;
221 using typename Superclass::RegionType;
222 using typename Superclass::ImageType;
223 using typename Superclass::PixelContainer;
225 using typename Superclass::InternalPixelType;
226 using typename Superclass::PixelType;
227 using typename Superclass::AccessorType;
228 using typename Superclass::IndexValueType;
229 using typename Superclass::OffsetValueType;
230 using typename Superclass::SizeValueType;
231
234
236
240
252
254 Self &
255 operator=(const Self & it);
256
258 void
260 {
262 this->UpdatePosition();
263 }
264
266 void
272
274 [[nodiscard]] bool
275 IsAtBegin() const
276 {
277 return m_NumberOfSamplesDone == 0L;
278 }
279
281 [[nodiscard]] bool
282 IsAtEnd() const
283 {
285 }
286
288 static constexpr unsigned int ImageDimension = TImage::ImageDimension;
289
292
298 void
299 SetPriorityImage(const PriorityImageType * priorityImage);
300
303 Self &
305 {
307 this->UpdatePosition();
308 return *this;
309 }
310
313 Self &
315 {
317 this->UpdatePosition();
318 return *this;
319 }
320
323 void
332 [[nodiscard]] SizeValueType
334 {
336 }
337
338
340 void
342
345 void
347
348private:
350 void
352
357};
358
359// Deduction guide for class template argument deduction (CTAD).
360template <typename TImage>
363
364} // end namespace itk
365
366#ifndef ITK_MANUAL_INSTANTIATION
367# include "itkImageRandomNonRepeatingConstIteratorWithIndex.hxx"
368#endif
369
370#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....
void SetPriorityImage(const PriorityImageType *priorityImage)
ImageRandomNonRepeatingConstIteratorWithIndex(const TImage *ptr, const RegionType &region)
ImageRandomNonRepeatingConstIteratorWithIndex(const ImageConstIteratorWithIndex< TImage > &it)
Templated n-dimensional image class.
Definition itkImage.h:89
A node to be used when computing permutations.
bool operator<(const NodeOfPermutation &b) const
Produce a random permutation of a collection.
RandomPermutation & operator=(const RandomPermutation &it)
Statistics::MersenneTwisterRandomVariateGenerator::Pointer GeneratorPointer
void SetPriority(SizeValueType i, SizeValueType priority) const
Implements transparent reference counting.
static Pointer New()
Method for creation through the object factory.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86
ImageRandomNonRepeatingConstIteratorWithIndex(SmartPointer< TImage >, const typename TImage::RegionType &) -> ImageRandomNonRepeatingConstIteratorWithIndex< std::remove_const_t< TImage > >