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>
25
26namespace itk
27{
41{
42public:
45 double m_Value{ 0.0 };
46
47 NodeOfPermutation() = default;
48
49 bool
50 operator<(const NodeOfPermutation & b) const
51 {
52 if (m_Priority == b.m_Priority)
53 {
54 return m_Value < b.m_Value;
55 }
56
57 return m_Priority < b.m_Priority;
58 }
59};
60
66{
67public:
72
80
83 {
84 delete[] m_Permutation;
85 m_Size = it.m_Size;
88 return *this;
89 }
90
91 void
93 {
94 if (i > m_Size)
95 {
96 std::ostringstream ostrm;
97 ostrm << "Error: RandomPermuation does not have " << i << " elements" << std::endl;
98 throw std::runtime_error(ostrm.str());
99 }
100
101 m_Permutation[i].m_Priority = priority;
102 }
103
104 void
105 Shuffle() const
106 {
107 for (SizeValueType i = 0; i < m_Size; ++i)
108 {
109 m_Permutation[i].m_Value = m_Generator->GetVariateWithClosedRange(1.0);
110 m_Permutation[i].m_Index = i;
111 }
112 std::sort(m_Permutation, m_Permutation + m_Size);
113 }
114
117 {
118 return m_Permutation[i].m_Index;
119 }
120
122
124 void
126 {
127 m_Generator->SetSeed();
128 }
129
130 void
131 ReinitializeSeed(unsigned int seed) const
132 {
133 m_Generator->SetSeed(seed);
134 }
135};
136
208template <typename TImage>
210{
211public:
215
217 using typename Superclass::IndexType;
218 using typename Superclass::SizeType;
219 using typename Superclass::OffsetType;
220 using typename Superclass::RegionType;
221 using typename Superclass::ImageType;
222 using typename Superclass::PixelContainer;
224 using typename Superclass::InternalPixelType;
225 using typename Superclass::PixelType;
226 using typename Superclass::AccessorType;
227 using typename Superclass::IndexValueType;
228 using typename Superclass::OffsetValueType;
229 using typename Superclass::SizeValueType;
230
233
235
239
251
253 Self &
254 operator=(const Self & it);
255
257 void
259 {
261 this->UpdatePosition();
262 }
263
265 void
271
273 [[nodiscard]] bool
274 IsAtBegin() const
275 {
276 return (m_NumberOfSamplesDone == 0L);
277 }
278
280 [[nodiscard]] bool
281 IsAtEnd() const
282 {
284 }
285
287 static constexpr unsigned int ImageDimension = TImage::ImageDimension;
288
291
297 void
298 SetPriorityImage(const PriorityImageType * priorityImage);
299
302 Self &
304 {
306 this->UpdatePosition();
307 return *this;
308 }
309
312 Self &
314 {
316 this->UpdatePosition();
317 return *this;
318 }
319
322 void
331 [[nodiscard]] SizeValueType
333 {
335 }
336
337
339 void
341
344 void
346
347private:
349 void
351
356};
357} // end namespace itk
358
359#ifndef ITK_MANUAL_INSTANTIATION
360# include "itkImageRandomNonRepeatingConstIteratorWithIndex.hxx"
361#endif
362
363#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
void SetPriorityImage(const PriorityImageType *priorityImage)
ImageRandomNonRepeatingConstIteratorWithIndex(const ImageType *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)
void SetPriority(SizeValueType i, SizeValueType priority) const
typename Statistics::MersenneTwisterRandomVariateGenerator::Pointer GeneratorPointer
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