ITK  5.1.0
Insight Toolkit
itkImageRandomNonRepeatingConstIteratorWithIndex.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 
26 namespace itk
27 {
41 {
42 public:
45  double m_Value;
46 
48  {
49  m_Priority = 0;
50  m_Index = 0;
51  m_Value = 0.0;
52  }
53 
54  bool
55  operator<(const NodeOfPermutation & b) const
56  {
57  if (m_Priority == b.m_Priority)
58  {
59  return m_Value < b.m_Value;
60  }
61  else
62  {
63  return m_Priority < b.m_Priority;
64  }
65  }
66 };
67 
73 {
74 public:
79 
81  {
82  m_Size = sz;
85  this->Shuffle();
86  }
87 
90  {
91  delete[] m_Permutation;
92  m_Size = it.m_Size;
95  return *this;
96  }
97 
98  void
100  {
101  if (i > m_Size)
102  {
103  std::ostringstream ostrm;
104  ostrm << "Error: RandomPermuation does not have " << i << " elements" << std::endl;
105  throw std::runtime_error(ostrm.str());
106  }
107  else
108  {
109  m_Permutation[i].m_Priority = priority;
110  }
111  }
112 
113  void
115  {
116  for (SizeValueType i = 0; i < m_Size; i++)
117  {
118  m_Permutation[i].m_Value = m_Generator->GetVariateWithClosedRange(1.0);
119  m_Permutation[i].m_Index = i;
120  }
121  std::sort(m_Permutation, m_Permutation + m_Size);
122  }
123 
125 
127 
129  void
131  {
132  m_Generator->Initialize();
133  }
134 
135  void
136  ReinitializeSeed(unsigned int seed)
137  {
138  m_Generator->SetSeed(seed);
139  }
140 };
141 
213 template <typename TImage>
215 {
216 public:
220 
223  using SizeType = typename Superclass::SizeType;
235 
238  ~ImageRandomNonRepeatingConstIteratorWithIndex() override { delete m_Permutation; }
240 
243  ImageRandomNonRepeatingConstIteratorWithIndex(const ImageType * ptr, const RegionType & region);
244 
252  {
254 
255  m_Permutation = nullptr;
256  }
257 
259  Self &
260  operator=(const Self & it);
261 
263  void
265  {
266  m_NumberOfSamplesDone = 0L;
267  this->UpdatePosition();
268  }
270 
272  void
274  {
275  m_NumberOfSamplesDone = m_NumberOfSamplesRequested;
276  this->UpdatePosition();
277  }
279 
281  bool
282  IsAtBegin() const
283  {
284  return (m_NumberOfSamplesDone == 0L);
285  }
286 
288  bool
289  IsAtEnd() const
290  {
291  return (m_NumberOfSamplesDone >= m_NumberOfSamplesRequested);
292  }
293 
295  static constexpr unsigned int ImageDimension = TImage::ImageDimension;
296 
299 
305  void
306  SetPriorityImage(const PriorityImageType * priorityImage);
307 
310  Self &
312  {
313  m_NumberOfSamplesDone++;
314  this->UpdatePosition();
315  return *this;
316  }
318 
321  Self &
323  {
324  m_NumberOfSamplesDone--;
325  this->UpdatePosition();
326  return *this;
327  }
329 
331  void
332  SetNumberOfSamples(SizeValueType number);
333 
335  GetNumberOfSamples() const;
336 
338  void
339  ReinitializeSeed();
340 
343  void
344  ReinitializeSeed(int);
345 
346 private:
347  void
348  UpdatePosition();
349 
354 };
355 } // end namespace itk
356 
357 #ifndef ITK_MANUAL_INSTANTIATION
358 # include "itkImageRandomNonRepeatingConstIteratorWithIndex.hxx"
359 #endif
360 
361 #endif
itk::ImageRandomNonRepeatingConstIteratorWithIndex::~ImageRandomNonRepeatingConstIteratorWithIndex
~ImageRandomNonRepeatingConstIteratorWithIndex() override
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:238
itk::RandomPermutation::m_Size
SizeValueType m_Size
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:78
itk::ImageConstIteratorWithIndex::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkImageConstIteratorWithIndex.h:106
itk::ImageConstIteratorWithIndex::SizeType
typename TImage::SizeType SizeType
Definition: itkImageConstIteratorWithIndex.h:109
itk::RandomPermutation::Shuffle
void Shuffle()
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:114
itk::RandomPermutation
Produce a random permutation of a collection.
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:72
itk::RandomPermutation::GeneratorPointer
typename Statistics::MersenneTwisterRandomVariateGenerator::Pointer GeneratorPointer
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:75
itk::ImageRandomNonRepeatingConstIteratorWithIndex::operator++
Self & operator++()
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:311
itk::NodeOfPermutation::m_Priority
SizeValueType m_Priority
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:43
itk::RandomPermutation::operator[]
SizeValueType operator[](SizeValueType i)
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:124
itk::ImageConstIteratorWithIndex::PixelContainerPointer
typename PixelContainer::Pointer PixelContainerPointer
Definition: itkImageConstIteratorWithIndex.h:122
itk::ImageRandomNonRepeatingConstIteratorWithIndex::m_NumberOfSamplesRequested
SizeValueType m_NumberOfSamplesRequested
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:350
itk::ImageRandomNonRepeatingConstIteratorWithIndex::IsAtBegin
bool IsAtBegin() const
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:282
itk::RandomPermutation::ReinitializeSeed
void ReinitializeSeed()
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:130
itk::ImageConstIteratorWithIndex::OffsetValueType
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkImageConstIteratorWithIndex.h:137
itkImageConstIteratorWithIndex.h
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::ImageConstIteratorWithIndex::PixelType
typename TImage::PixelType PixelType
Definition: itkImageConstIteratorWithIndex.h:128
itk::ImageRandomNonRepeatingConstIteratorWithIndex::m_Permutation
RandomPermutation * m_Permutation
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:353
itk::ImageConstIteratorWithIndex::IndexType
typename TImage::IndexType IndexType
Definition: itkImageConstIteratorWithIndex.h:105
itk::ImageConstIteratorWithIndex::InternalPixelType
typename TImage::InternalPixelType InternalPixelType
Definition: itkImageConstIteratorWithIndex.h:125
itk::NodeOfPermutation::NodeOfPermutation
NodeOfPermutation()
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:47
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::RandomPermutation::ReinitializeSeed
void ReinitializeSeed(unsigned int seed)
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:136
itk::ImageRandomNonRepeatingConstIteratorWithIndex::m_NumberOfSamplesDone
SizeValueType m_NumberOfSamplesDone
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:351
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::NodeOfPermutation
A node to be used when computing permutations.
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:40
itk::NodeOfPermutation::m_Index
SizeValueType m_Index
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:44
itk::ImageConstIteratorWithIndex::AccessorType
typename TImage::AccessorType AccessorType
Definition: itkImageConstIteratorWithIndex.h:132
itk::Statistics::MersenneTwisterRandomVariateGenerator::New
static Pointer New()
Method for creation through the object factory.
itk::ImageRandomNonRepeatingConstIteratorWithIndex::operator--
Self & operator--()
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:322
itk::NodeOfPermutation::operator<
bool operator<(const NodeOfPermutation &b) const
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:55
itk::RandomPermutation::~RandomPermutation
~RandomPermutation()
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:126
itk::ImageConstIteratorWithIndex
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
Definition: itkImageConstIteratorWithIndex.h:92
itk::RandomPermutation::operator=
RandomPermutation & operator=(const RandomPermutation &it)
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:89
itk::RandomPermutation::m_Permutation
NodeOfPermutation * m_Permutation
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:76
itkMersenneTwisterRandomVariateGenerator.h
itk::RandomPermutation::SetPriority
void SetPriority(SizeValueType i, SizeValueType priority)
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:99
itk::ImageRandomNonRepeatingConstIteratorWithIndex::GoToEnd
void GoToEnd()
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:273
itk::Statistics::MersenneTwisterRandomVariateGenerator::Pointer
SmartPointer< Self > Pointer
Definition: itkMersenneTwisterRandomVariateGenerator.h:133
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
itk::RandomPermutation::m_Generator
GeneratorPointer m_Generator
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:77
itk::ImageConstIteratorWithIndex::RegionType
typename TImage::RegionType RegionType
Definition: itkImageConstIteratorWithIndex.h:113
itk::ImageRandomNonRepeatingConstIteratorWithIndex
A multi-dimensional image iterator that visits a random set of pixels within an image region....
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:214
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::ImageRandomNonRepeatingConstIteratorWithIndex::IsAtEnd
bool IsAtEnd() const
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:289
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
itk::ImageConstIteratorWithIndex::ImageType
TImage ImageType
Definition: itkImageConstIteratorWithIndex.h:116
itk::ImageConstIteratorWithIndex::PixelContainer
typename TImage::PixelContainer PixelContainer
Definition: itkImageConstIteratorWithIndex.h:121
itk::ImageConstIteratorWithIndex::SizeValueType
typename SizeType::SizeValueType SizeValueType
Definition: itkImageConstIteratorWithIndex.h:110
itk::ImageConstIteratorWithIndex::operator=
Self & operator=(const Self &it)
itk::ImageRandomNonRepeatingConstIteratorWithIndex::GoToBegin
void GoToBegin()
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:264
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::RandomPermutation::RandomPermutation
RandomPermutation(SizeValueType sz)
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:80
itk::ImageRandomNonRepeatingConstIteratorWithIndex::m_NumberOfPixelsInRegion
SizeValueType m_NumberOfPixelsInRegion
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:352
itk::NodeOfPermutation::m_Value
double m_Value
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:45
itk::ImageConstIteratorWithIndex::OffsetType
typename TImage::OffsetType OffsetType
Definition: itkImageConstIteratorWithIndex.h:136
itk::ImageRandomNonRepeatingConstIteratorWithIndex::ImageRandomNonRepeatingConstIteratorWithIndex
ImageRandomNonRepeatingConstIteratorWithIndex(const ImageConstIteratorWithIndex< TImage > &it)
Definition: itkImageRandomNonRepeatingConstIteratorWithIndex.h:251