ITK
4.4.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
RandomPermutation
&
operator=
(
const
RandomPermutation
&it)
88
{
89
delete
[]
m_Permutation
;
90
m_Size
= it.
m_Size
;
91
m_Permutation
=
new
NodeOfPermutation
[
m_Size
];
92
m_Generator
= it.
m_Generator
;
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
106
void
SetPriority
(
SizeValueType
i,
SizeValueType
priority)
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
128
SizeValueType
operator[]
(
SizeValueType
i)
129
{
130
return
m_Permutation
[i].
m_Index
;
131
}
132
133
~RandomPermutation
()
134
{
135
delete
[]
m_Permutation
;
136
}
137
139
void
ReinitializeSeed
()
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 >
223
class
ITK_EXPORT
ImageRandomNonRepeatingConstIteratorWithIndex
:
public
ImageConstIteratorWithIndex
< TImage >
224
{
225
public
:
227
typedef
ImageRandomNonRepeatingConstIteratorWithIndex
Self
;
228
typedef
ImageConstIteratorWithIndex< TImage >
Superclass
;
229
231
typedef
typename
Superclass::IndexType
IndexType
;
232
typedef
typename
Superclass::SizeType
SizeType
;
233
typedef
typename
Superclass::OffsetType
OffsetType
;
234
typedef
typename
Superclass::RegionType
RegionType
;
235
typedef
typename
Superclass::ImageType
ImageType
;
236
typedef
typename
Superclass::PixelContainer
PixelContainer
;
237
typedef
typename
Superclass::PixelContainerPointer
PixelContainerPointer
;
238
typedef
typename
Superclass::InternalPixelType
InternalPixelType
;
239
typedef
typename
Superclass::PixelType
PixelType
;
240
typedef
typename
Superclass::AccessorType
AccessorType
;
241
typedef
typename
Superclass::IndexValueType
IndexValueType
;
242
typedef
typename
Superclass::OffsetValueType
OffsetValueType
;
243
typedef
typename
Superclass::SizeValueType
SizeValueType
;
244
246
ImageRandomNonRepeatingConstIteratorWithIndex
();
247
~
ImageRandomNonRepeatingConstIteratorWithIndex
()
248
{
249
if
( m_Permutation )
250
{
251
delete
m_Permutation;
252
}
253
}
255
258
ImageRandomNonRepeatingConstIteratorWithIndex
(
const
ImageType *ptr,
const
RegionType & region);
259
266
ImageRandomNonRepeatingConstIteratorWithIndex
(
const
ImageConstIteratorWithIndex< TImage >
& it)
267
{
268
this->
ImageConstIteratorWithIndex< TImage >::operator=
(it);
269
270
m_Permutation =
NULL
;
271
}
272
274
Self & operator=(
const
Self & it);
275
277
void
GoToBegin(
void
)
278
{
279
m_NumberOfSamplesDone = 0L;
280
this->UpdatePosition();
281
}
283
285
void
GoToEnd(
void
)
286
{
287
m_NumberOfSamplesDone = m_NumberOfSamplesRequested;
288
this->UpdatePosition();
289
}
291
293
bool
IsAtBegin(
void
)
const
294
{
295
return
( m_NumberOfSamplesDone == 0L );
296
}
297
299
bool
IsAtEnd(
void
)
const
300
{
301
return
( m_NumberOfSamplesDone >= m_NumberOfSamplesRequested );
302
}
303
305
itkStaticConstMacro(ImageDimension,
unsigned
int
, TImage::ImageDimension);
306
308
typedef
itk::Image< SizeValueType, itkGetStaticConstMacro(ImageDimension) >
PriorityImageType
;
309
315
void
SetPriorityImage(
const
PriorityImageType
*priorityImage);
316
319
Self
& operator++()
320
{
321
m_NumberOfSamplesDone++;
322
this->UpdatePosition();
323
return
*
this
;
324
}
326
329
Self
& operator--()
330
{
331
m_NumberOfSamplesDone--;
332
this->UpdatePosition();
333
return
*
this
;
334
}
336
338
void
SetNumberOfSamples(
SizeValueType
number);
339
340
SizeValueType
GetNumberOfSamples(
void
)
const
;
341
343
void
ReinitializeSeed();
344
347
void
ReinitializeSeed(
int
);
348
349
private
:
350
void
UpdatePosition();
351
352
SizeValueType
m_NumberOfSamplesRequested
;
353
SizeValueType
m_NumberOfSamplesDone
;
354
SizeValueType
m_NumberOfPixelsInRegion
;
355
RandomPermutation
*
m_Permutation
;
356
};
357
}
// end namespace itk
358
359
#ifndef ITK_MANUAL_INSTANTIATION
360
#include "itkImageRandomNonRepeatingConstIteratorWithIndex.hxx"
361
#endif
362
363
#endif
364
Generated on Mon May 13 2013 00:54:11 for ITK by
1.8.3.1