ITK
4.3.0
Insight Segmentation and Registration Toolkit
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
ITK
Modules
Core
Common
include
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
21
#include "
itkImageConstIteratorWithIndex.h
"
22
#include <algorithm>
23
#include <iostream>
24
#include "
itkMersenneTwisterRandomVariateGenerator.h
"
25
26
namespace
itk
27
{
40
class
NodeOfPermutation
41
{
42
public
:
43
SizeValueType
m_Priority
;
44
SizeValueType
m_Index
;
45
double
m_Value
;
46
47
NodeOfPermutation
()
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
71
class
RandomPermutation
72
{
73
public
:
74
typedef
Statistics::MersenneTwisterRandomVariateGenerator::Pointer
GeneratorPointer
;
75
NodeOfPermutation
*
m_Permutation
;
76
GeneratorPointer
m_Generator
;
77
SizeValueType
m_Size
;
78
79
RandomPermutation
(
SizeValueType
sz)
80
{
81
m_Size
= sz;
82
m_Permutation
=
new
NodeOfPermutation
[
m_Size
];
83
m_Generator
=
Statistics::MersenneTwisterRandomVariateGenerator::GetInstance
();
84
this->
Shuffle
();
85
}
86
87
void
Dump
()
88
{
89
for
(
SizeValueType
i = 0; i <
m_Size
; i++ )
90
{
91
std::cout <<
m_Permutation
[i].
m_Value
<<
" "
<<
m_Permutation
[i].
m_Priority
92
<<
" "
<<
m_Permutation
[i].
m_Index
<<
";"
;
93
std::cout << std::endl;
94
}
95
}
96
97
void
SetPriority
(
SizeValueType
i,
SizeValueType
priority)
98
{
99
if
( i >
m_Size
)
100
{
101
std::cerr <<
"Error - i dont have "
<< i <<
" elements"
<< std::endl;
102
}
103
else
104
{
105
m_Permutation
[i].
m_Priority
= priority;
106
}
107
}
108
109
void
Shuffle
()
110
{
111
for
(
SizeValueType
i = 0; i <
m_Size
; i++ )
112
{
113
m_Permutation
[i].
m_Value
=
m_Generator
->GetVariateWithClosedRange (1.0);
114
m_Permutation
[i].
m_Index
= i;
115
}
116
std::sort(
m_Permutation
,
m_Permutation
+ m_Size);
117
}
118
119
SizeValueType
operator[]
(
SizeValueType
i)
120
{
121
return
m_Permutation
[i].
m_Index
;
122
}
123
124
~RandomPermutation
()
125
{
126
delete
[]
m_Permutation
;
127
}
128
130
void
ReinitializeSeed
()
131
{
132
m_Generator
->Initialize();
133
}
134
135
void
ReinitializeSeed
(
int
seed)
136
{
137
m_Generator
->SetSeed (seed);
138
}
139
};
140
213
template
<
typename
TImage >
214
class
ITK_EXPORT
ImageRandomNonRepeatingConstIteratorWithIndex
:
public
ImageConstIteratorWithIndex
< TImage >
215
{
216
public
:
218
typedef
ImageRandomNonRepeatingConstIteratorWithIndex
Self
;
219
typedef
ImageConstIteratorWithIndex< TImage >
Superclass
;
220
222
typedef
typename
Superclass::IndexType
IndexType
;
223
typedef
typename
Superclass::SizeType
SizeType
;
224
typedef
typename
Superclass::OffsetType
OffsetType
;
225
typedef
typename
Superclass::RegionType
RegionType
;
226
typedef
typename
Superclass::ImageType
ImageType
;
227
typedef
typename
Superclass::PixelContainer
PixelContainer
;
228
typedef
typename
Superclass::PixelContainerPointer
PixelContainerPointer
;
229
typedef
typename
Superclass::InternalPixelType
InternalPixelType
;
230
typedef
typename
Superclass::PixelType
PixelType
;
231
typedef
typename
Superclass::AccessorType
AccessorType
;
232
typedef
typename
Superclass::IndexValueType
IndexValueType
;
233
typedef
typename
Superclass::OffsetValueType
OffsetValueType
;
234
typedef
typename
Superclass::SizeValueType
SizeValueType
;
235
237
ImageRandomNonRepeatingConstIteratorWithIndex
();
238
~
ImageRandomNonRepeatingConstIteratorWithIndex
()
239
{
240
if
( m_Permutation )
241
{
242
delete
m_Permutation;
243
}
244
}
246
249
ImageRandomNonRepeatingConstIteratorWithIndex
(
const
ImageType *ptr,
const
RegionType & region);
250
257
ImageRandomNonRepeatingConstIteratorWithIndex
(
const
ImageConstIteratorWithIndex< TImage >
& it)
258
{
259
this->
ImageConstIteratorWithIndex< TImage >::operator=
(it);
260
261
m_Permutation =
NULL
;
262
}
263
265
Self & operator=(
const
Self & it);
266
268
void
GoToBegin(
void
)
269
{
270
m_NumberOfSamplesDone = 0L;
271
this->UpdatePosition();
272
}
274
276
void
GoToEnd(
void
)
277
{
278
m_NumberOfSamplesDone = m_NumberOfSamplesRequested;
279
this->UpdatePosition();
280
}
282
284
bool
IsAtBegin(
void
)
const
285
{
286
return
( m_NumberOfSamplesDone == 0L );
287
}
288
290
bool
IsAtEnd(
void
)
const
291
{
292
return
( m_NumberOfSamplesDone >= m_NumberOfSamplesRequested );
293
}
294
296
itkStaticConstMacro(ImageDimension,
unsigned
int
, TImage::ImageDimension);
297
299
typedef
itk::Image< SizeValueType, itkGetStaticConstMacro(ImageDimension) >
PriorityImageType
;
300
306
void
SetPriorityImage(
const
PriorityImageType
*priorityImage);
307
310
Self
& operator++()
311
{
312
m_NumberOfSamplesDone++;
313
this->UpdatePosition();
314
return
*
this
;
315
}
317
320
Self
& operator--()
321
{
322
m_NumberOfSamplesDone--;
323
this->UpdatePosition();
324
return
*
this
;
325
}
327
329
void
SetNumberOfSamples(
SizeValueType
number);
330
331
SizeValueType
GetNumberOfSamples(
void
)
const
;
332
334
void
ReinitializeSeed();
335
338
void
ReinitializeSeed(
int
);
339
340
private
:
341
void
UpdatePosition();
342
343
SizeValueType
m_NumberOfSamplesRequested
;
344
SizeValueType
m_NumberOfSamplesDone
;
345
SizeValueType
m_NumberOfPixelsInRegion
;
346
RandomPermutation
*
m_Permutation
;
347
};
348
}
// end namespace itk
349
350
#ifndef ITK_MANUAL_INSTANTIATION
351
#include "itkImageRandomNonRepeatingConstIteratorWithIndex.hxx"
352
#endif
353
354
#endif
355
Generated on Sun Dec 9 2012 01:07:50 for ITK by
1.8.2