ITK
4.2.0
Insight Segmentation and Registration Toolkit
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
ITK
Modules
Core
Common
include
itkFixedArray.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 __itkFixedArray_h
19
#define __itkFixedArray_h
20
21
#include "
itkMacro.h
"
22
23
namespace
itk
24
{
25
//HACK: Need to remove this function.
26
#if 1
27
33
template
<
typename
TVector >
34
struct
GetVectorDimension
{
35
itkStaticConstMacro(
VectorDimension
,
unsigned
int
, TVector::Dimension);
36
};
37
#endif
38
62
template
<
typename
TValueType,
unsigned
int
VLength = 3 >
63
class
FixedArray
64
{
65
public
:
67
itkStaticConstMacro(
Length
,
unsigned
int
, VLength);
68
70
itkStaticConstMacro(
Dimension
,
unsigned
int
, VLength);
71
73
typedef
TValueType
ValueType
;
74
76
typedef
ValueType
CArray
[VLength];
77
79
typedef
ValueType
*
Iterator
;
80
82
typedef
const
ValueType
*
ConstIterator
;
83
84
class
ConstReverseIterator;
85
90
class
ReverseIterator
91
{
92
public
:
93
explicit
ReverseIterator
(
Iterator
i):
m_Iterator
(i) {}
94
Iterator
operator++
() {
return
--
m_Iterator
; }
95
Iterator
operator++
(
int
) {
return
m_Iterator
--; }
96
Iterator
operator--
() {
return
++
m_Iterator
; }
97
Iterator
operator--
(
int
) {
return
m_Iterator
++; }
98
Iterator
operator->
()
const
{
return
(
m_Iterator
- 1 ); }
99
ValueType
&
operator*
()
const
{
return
*(
m_Iterator
- 1 ); }
100
bool
operator!=
(
const
ReverseIterator
& rit)
const
{
return
m_Iterator
!= rit.
m_Iterator
; }
101
bool
operator==
(
const
ReverseIterator
& rit)
const
{
return
m_Iterator
== rit.
m_Iterator
; }
102
private
:
103
Iterator
m_Iterator
;
104
friend
class
ConstReverseIterator
;
105
};
106
111
class
ConstReverseIterator
112
{
113
public
:
114
explicit
ConstReverseIterator
(
ConstIterator
i):
m_Iterator
(i) {}
115
ConstReverseIterator
(
const
ReverseIterator
& rit) {
m_Iterator
= rit.
m_Iterator
; }
116
ConstIterator
operator++
() {
return
--
m_Iterator
; }
117
ConstIterator
operator++
(
int
) {
return
m_Iterator
--; }
118
ConstIterator
operator--
() {
return
++
m_Iterator
; }
119
ConstIterator
operator--
(
int
) {
return
m_Iterator
++; }
120
ConstIterator
operator->
()
const
{
return
(
m_Iterator
- 1 ); }
121
const
ValueType
&
operator*
()
const
{
return
*(
m_Iterator
- 1 ); }
122
bool
operator!=
(
const
ConstReverseIterator
& rit)
const
{
return
m_Iterator
!= rit.
m_Iterator
; }
123
bool
operator==
(
const
ConstReverseIterator
& rit)
const
{
return
m_Iterator
== rit.
m_Iterator
; }
124
private
:
125
ConstIterator
m_Iterator
;
126
};
127
129
typedef
ValueType
*
pointer
;
130
132
typedef
const
ValueType
*
const_pointer
;
133
135
typedef
ValueType
&
reference
;
136
138
typedef
const
ValueType
&
const_reference
;
139
140
typedef
unsigned
int
SizeType
;
141
public
:
143
FixedArray
();
144
FixedArray
(
const
ValueType
r[VLength]);
145
FixedArray
(
const
ValueType
& r);
147
149
template
<
class
TFixedArrayValueType >
150
FixedArray
(
const
FixedArray< TFixedArrayValueType, VLength >
& r)
151
{
152
typename
FixedArray< TFixedArrayValueType, VLength >::ConstIterator
input = r.
Begin
();
153
Iterator
i = this->
Begin
();
154
while
( i != this->
End
() )
155
{
156
*i++ =
static_cast<
TValueType
>
( *input++ );
157
}
158
}
160
175
template
<
class
TFixedArrayValueType >
176
FixedArray
&
operator=
(
const
FixedArray< TFixedArrayValueType, VLength >
& r)
177
{
178
if
( (
void
*)r.
Begin
() == (
void
*)
m_InternalArray
) {
return
*
this
; }
179
typename
FixedArray< TFixedArrayValueType, VLength >::ConstIterator
input = r.
Begin
();
180
Iterator
i = this->
Begin
();
181
while
( i != this->
End
() )
182
{
183
*i++ =
static_cast<
TValueType
>
( *input++ );
184
}
185
return
*
this
;
186
}
188
189
FixedArray
&
operator=
(
const
ValueType
r[VLength]);
190
194
bool
operator==
(
const
FixedArray
& r)
const
;
195
196
bool
operator!=
(
const
FixedArray
& r)
const
197
{
return
!
operator==
(r); }
198
202
reference
operator[]
(
short
index) {
return
m_InternalArray
[index]; }
203
const_reference
operator[]
(
short
index)
const
{
return
m_InternalArray
[index]; }
204
reference
operator[]
(
unsigned
short
index) {
return
m_InternalArray
[index]; }
205
const_reference
operator[]
(
unsigned
short
index)
const
{
return
m_InternalArray
[index]; }
206
reference
operator[]
(
int
index) {
return
m_InternalArray
[index]; }
207
const_reference
operator[]
(
int
index)
const
{
return
m_InternalArray
[index]; }
208
reference
operator[]
(
unsigned
int
index) {
return
m_InternalArray
[index]; }
209
const_reference
operator[]
(
unsigned
int
index)
const
{
return
m_InternalArray
[index]; }
210
reference
operator[]
(
long
index) {
return
m_InternalArray
[index]; }
211
const_reference
operator[]
(
long
index)
const
{
return
m_InternalArray
[index]; }
212
reference
operator[]
(
unsigned
long
index) {
return
m_InternalArray
[index]; }
213
const_reference
operator[]
(
unsigned
long
index)
const
{
return
m_InternalArray
[index]; }
214
reference
operator[]
(
long
long
index) {
return
m_InternalArray
[index]; }
215
const_reference
operator[]
(
long
long
index)
const
{
return
m_InternalArray
[index]; }
216
reference
operator[]
(
unsigned
long
long
index) {
return
m_InternalArray
[index]; }
217
const_reference
operator[]
(
unsigned
long
long
index)
const
{
return
m_InternalArray
[index]; }
219
221
void
SetElement
(
unsigned
short
index,
const_reference
value)
222
{
m_InternalArray
[index] = value; }
223
const_reference
GetElement
(
unsigned
short
index)
const
{
return
m_InternalArray
[index]; }
225
227
ValueType
*
GetDataPointer
()
228
{
229
return
m_InternalArray
; \
230
}
231
232
const
ValueType
*
GetDataPointer
()
const
233
{
234
return
m_InternalArray
; \
235
}
236
238
Iterator
Begin
();
239
240
ConstIterator
Begin
()
const
;
241
242
Iterator
End
();
243
244
ConstIterator
End
()
const
;
245
246
ReverseIterator
rBegin
();
247
248
ConstReverseIterator
rBegin
()
const
;
249
250
ReverseIterator
rEnd
();
251
252
ConstReverseIterator
rEnd
()
const
;
253
254
SizeType
Size
()
const
;
255
256
void
Fill
(
const
ValueType
&);
257
258
private
:
260
CArray
m_InternalArray
;
261
public
:
262
263
static
FixedArray
Filled
(
const
ValueType
&);
264
};
265
266
template
<
typename
TValueType,
unsigned
int
VLength >
267
std::ostream & operator<<(std::ostream & os, const FixedArray< TValueType, VLength > & arr);
268
}
// namespace itk
269
270
// Define instantiation macro for this template.
271
#define ITK_TEMPLATE_FixedArray(_, EXPORT, TypeX, TypeY) \
272
namespace itk \
273
{ \
274
_( 2 ( class EXPORT FixedArray< ITK_TEMPLATE_2 TypeX > ) ) \
275
_( 1 ( EXPORT std::ostream & operator<<(std::ostream &, \
276
const FixedArray< ITK_TEMPLATE_2 TypeX > &) ) ) \
277
namespace Templates \
278
{ \
279
typedef FixedArray< ITK_TEMPLATE_2 TypeX > FixedArray##TypeY; \
280
} \
281
}
282
283
#if ITK_TEMPLATE_EXPLICIT
284
#include "Templates/itkFixedArray+-.h"
285
#endif
286
287
#if ITK_TEMPLATE_TXX
288
#include "itkFixedArray.hxx"
289
#endif
290
291
#include "
itkNumericTraitsFixedArrayPixel.h
"
292
293
#endif
294
Generated on Tue Jul 10 2012 23:25:39 for ITK by
1.8.1