ITK  4.6.0
Insight Segmentation and Registration 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 operator<(const NodeOfPermutation & b) const
55  {
56  if ( m_Priority == b.m_Priority )
57  {
58  return m_Value < b.m_Value;
59  }
60  else
61  {
62  return m_Priority < b.m_Priority;
63  }
64  }
65 };
66 
72 {
73 public:
78 
80  {
81  m_Size = sz;
84  this->Shuffle();
85  }
86 
88  {
89  delete[] m_Permutation;
90  m_Size = it.m_Size;
93  return *this;
94  }
95 
96  void Dump()
97  {
98  for ( SizeValueType i = 0; i < m_Size; i++ )
99  {
100  std::cout << m_Permutation[i].m_Value << " " << m_Permutation[i].m_Priority
101  << " " << m_Permutation[i].m_Index << ";";
102  std::cout << std::endl;
103  }
104  }
105 
107  {
108  if ( i > m_Size )
109  {
110  std::cerr << "Error - i dont have " << i << " elements" << std::endl;
111  }
112  else
113  {
114  m_Permutation[i].m_Priority = priority;
115  }
116  }
117 
118  void Shuffle()
119  {
120  for ( SizeValueType i = 0; i < m_Size; i++ )
121  {
122  m_Permutation[i].m_Value = m_Generator->GetVariateWithClosedRange (1.0);
123  m_Permutation[i].m_Index = i;
124  }
125  std::sort(m_Permutation, m_Permutation + m_Size);
126  }
127 
129  {
130  return m_Permutation[i].m_Index;
131  }
132 
134  {
135  delete[] m_Permutation;
136  }
137 
140  {
141  m_Generator->Initialize();
142  }
143 
144  void ReinitializeSeed(unsigned int seed)
145  {
146  m_Generator->SetSeed (seed);
147  }
148 };
149 
222 template< typename TImage >
224 {
225 public:
229 
232  typedef typename Superclass::SizeType SizeType;
244 
248  {
249  delete m_Permutation;
250  }
252 
256 
264  {
266 
268  }
269 
271  Self & operator=(const Self & it);
272 
274  void GoToBegin(void)
275  {
277  this->UpdatePosition();
278  }
280 
282  void GoToEnd(void)
283  {
285  this->UpdatePosition();
286  }
288 
290  bool IsAtBegin(void) const
291  {
292  return ( m_NumberOfSamplesDone == 0L );
293  }
294 
296  bool IsAtEnd(void) const
297  {
299  }
300 
302  itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
303 
306 
312  void SetPriorityImage(const PriorityImageType *priorityImage);
313 
317  {
319  this->UpdatePosition();
320  return *this;
321  }
323 
327  {
329  this->UpdatePosition();
330  return *this;
331  }
333 
335  void SetNumberOfSamples(SizeValueType number);
336 
337  SizeValueType GetNumberOfSamples(void) const;
338 
340  void ReinitializeSeed();
341 
344  void ReinitializeSeed(int);
345 
346 private:
347  void UpdatePosition();
348 
353 };
354 } // end namespace itk
355 
356 #ifndef ITK_MANUAL_INSTANTIATION
357 #include "itkImageRandomNonRepeatingConstIteratorWithIndex.hxx"
358 #endif
359 
360 #endif
void SetPriority(SizeValueType i, SizeValueType priority)
itk::Image< SizeValueType, itkGetStaticConstMacro(ImageDimension) > PriorityImageType
A multi-dimensional image iterator that visits a random set of pixels within an image region...
Statistics::MersenneTwisterRandomVariateGenerator::Pointer GeneratorPointer
ImageRandomNonRepeatingConstIteratorWithIndex(const ImageConstIteratorWithIndex< TImage > &it)
A node to be used when computing permutations.
void SetPriorityImage(const PriorityImageType *priorityImage)
unsigned long SizeValueType
Definition: itkIntTypes.h:143
bool operator<(const NodeOfPermutation &b) const
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
Produce a random permutation of a collection.
RandomPermutation & operator=(const RandomPermutation &it)
#define NULL
Self & operator=(const Self &it)
Templated n-dimensional image class.
Definition: itkImage.h:75