Orfeo Toolbox  4.0
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  }
251 
255 
263  {
265 
267  }
268 
270  Self & operator=(const Self & it);
271 
273  void GoToBegin(void)
274  {
276  this->UpdatePosition();
277  }
278 
280  void GoToEnd(void)
281  {
283  this->UpdatePosition();
284  }
285 
287  bool IsAtBegin(void) const
288  {
289  return ( m_NumberOfSamplesDone == 0L );
290  }
291 
293  bool IsAtEnd(void) const
294  {
296  }
297 
299  itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
300 
303 
309  void SetPriorityImage(const PriorityImageType *priorityImage);
310 
314  {
316  this->UpdatePosition();
317  return *this;
318  }
319 
323  {
325  this->UpdatePosition();
326  return *this;
327  }
328 
330  void SetNumberOfSamples(SizeValueType number);
331 
332  SizeValueType GetNumberOfSamples(void) const;
333 
335  void ReinitializeSeed();
336 
339  void ReinitializeSeed(int);
340 
341 private:
342  void UpdatePosition();
343 
348 };
349 } // end namespace itk
350 
351 #ifndef ITK_MANUAL_INSTANTIATION
353 #endif
354 
355 #endif

Generated at Sat Mar 8 2014 14:51:40 for Orfeo Toolbox with doxygen 1.8.3.1