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
itkImageTransformHelper.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 __itkImageTransformHelper_h
19
#define __itkImageTransformHelper_h
20
21
#include "
itkConceptChecking.h
"
22
#include "
itkImageBase.h
"
23
#include "
itkMatrix.h
"
24
#include "vnl/vnl_math.h"
25
#include "
itkImageBase.h
"
26
27
namespace
itk
28
{
33
template
<
unsigned
int
NImageDimension,
unsigned
int
R,
unsigned
int
C >
34
class
ImageTransformHelper
35
{
36
public
:
37
typedef
ImageBase< NImageDimension >
ImageType
;
38
typedef
typename
ImageType::IndexType
IndexType
;
39
typedef
typename
ImageType::SpacingType
SpacingType
;
40
typedef
Matrix< double, NImageDimension, NImageDimension >
MatrixType
;
41
typedef
typename
ImageType::PointType
OriginType
;
42
typedef
Point< double, NImageDimension >
DoublePoint
;
43
typedef
Point< float, NImageDimension >
FloatPoint
;
44
typedef
Concept::Detail::UniqueType_bool< false >
UniqueTypeBoolFalse
;
45
typedef
Concept::Detail::UniqueType_bool< true >
UniqueTypeBoolTrue
;
46
47
//
48
// Methods with DoublePoint
49
//
50
51
// IndexToPhysicalPoint with full matrix
52
//
53
//
54
inline
static
void
TransformIndexToPhysicalPoint
(
55
const
MatrixType
& matrix,
const
OriginType
& origin,
56
const
IndexType
& index,
DoublePoint
& point)
57
{
58
ImageTransformHelper< NImageDimension, R, C >::
59
TransformIndexToPhysicalPointRow
(
60
matrix, origin,
61
index, point,
62
Concept::Detail::UniqueType_bool
< ( R + 1 == 0 ) >() );
63
}
64
65
inline
static
void
TransformIndexToPhysicalPointRow
(
66
const
MatrixType
& matrix,
const
OriginType
& origin,
67
const
IndexType
& index,
DoublePoint
& point,
68
const
UniqueTypeBoolFalse
&)
69
{
70
point[R] = origin[R];
71
72
// Start column
73
ImageTransformHelper< NImageDimension, R, C >
74
::TransformIndexToPhysicalPointCol
(
75
matrix,
76
index, point,
77
Concept::Detail::UniqueType_bool
< ( C + 1 == 0 ) >() );
78
// Do Next Row
79
ImageTransformHelper< NImageDimension, R - 1, C >
80
::TransformIndexToPhysicalPointRow
(
81
matrix, origin,
82
index, point,
83
Concept::Detail::UniqueType_bool
< ( R == 0 ) >() );
84
}
85
86
inline
static
void
TransformIndexToPhysicalPointRow
(
87
const
MatrixType
&,
const
OriginType
&,
88
const
IndexType
&,
DoublePoint
&,
89
const
UniqueTypeBoolTrue
&)
90
{
91
// Do last row
92
}
93
94
inline
static
void
TransformIndexToPhysicalPointCol
(
95
const
MatrixType
& matrix,
96
const
IndexType
& index,
DoublePoint
& point,
97
const
UniqueTypeBoolFalse
&)
98
{
99
point[R] = point[R] + matrix[R][C] * index[C];
100
101
// Do next dimension
102
ImageTransformHelper< NImageDimension, R, C - 1 >
103
::TransformIndexToPhysicalPointCol
(
104
matrix,
105
index, point,
106
Concept::Detail::UniqueType_bool
< ( C == 0 ) >() );
107
}
108
109
inline
static
void
TransformIndexToPhysicalPointCol
(
110
const
MatrixType
&,
111
const
IndexType
&,
DoublePoint
&,
112
const
UniqueTypeBoolTrue
&)
113
{}
114
115
// PhysicalPointToIndex with full matrix
116
//
117
//
118
inline
static
void
TransformPhysicalPointToIndex
(
119
const
MatrixType
& matrix,
const
OriginType
& origin,
120
const
DoublePoint
& point,
IndexType
& index)
121
{
122
DoublePoint
rindex;
123
124
ImageTransformHelper< NImageDimension, R, C >::
125
TransformPhysicalPointToIndexRow
(
126
matrix, origin,
127
point, rindex, index,
128
Concept::Detail::UniqueType_bool
< ( R + 1 == 0 ) >() );
129
}
130
131
inline
static
void
TransformPhysicalPointToIndexRow
(
132
const
MatrixType
& matrix,
const
OriginType
& origin,
133
const
DoublePoint
& point,
DoublePoint
& rindex,
IndexType
& index,
134
const
UniqueTypeBoolFalse
&)
135
{
136
rindex[R] = 0.0;
137
// Start column
138
ImageTransformHelper< NImageDimension, R, C >
139
::TransformPhysicalPointToIndexCol
(
140
matrix, origin,
141
point, rindex, index,
142
Concept::Detail::UniqueType_bool
< ( C + 1 == 0 ) >() );
143
// Do next row
144
ImageTransformHelper< NImageDimension, R - 1, C >
145
::TransformPhysicalPointToIndexRow
(
146
matrix, origin,
147
point, rindex, index,
148
Concept::Detail::UniqueType_bool
< ( R == 0 ) >() );
149
}
150
151
inline
static
void
TransformPhysicalPointToIndexRow
(
152
const
MatrixType
&,
const
OriginType
&,
153
const
DoublePoint
&,
DoublePoint
&,
IndexType
&,
154
const
UniqueTypeBoolTrue
&)
155
{
156
// Do last row
157
}
158
159
inline
static
void
TransformPhysicalPointToIndexCol
(
160
const
MatrixType
& matrix,
const
OriginType
& origin,
161
const
DoublePoint
& point,
DoublePoint
& rindex,
IndexType
& index,
162
const
UniqueTypeBoolFalse
&)
163
{
164
rindex[R] = rindex[R] + matrix[R][C] * ( point[C] - origin[C] );
165
166
// Do next dimension
167
ImageTransformHelper< NImageDimension, R, C - 1 >
168
::TransformPhysicalPointToIndexCol
(
169
matrix, origin,
170
point, rindex, index,
171
Concept::Detail::UniqueType_bool
< ( C == 0 ) >() );
172
}
173
174
inline
static
void
TransformPhysicalPointToIndexCol
(
175
const
MatrixType
&,
const
OriginType
&,
176
const
DoublePoint
&,
DoublePoint
& rindex,
IndexType
& index,
177
const
UniqueTypeBoolTrue
&)
178
{
179
index[R] = Math::RoundHalfIntegerUp< IndexValueType >(rindex[R]);
180
}
181
182
//
183
// Methods with FloatPoint
184
//
185
186
// IndexToPhysicalPoint with full matrix
187
//
188
//
189
inline
static
void
TransformIndexToPhysicalPoint
(
190
const
MatrixType
& matrix,
const
OriginType
& origin,
191
const
IndexType
& index,
FloatPoint
& point)
192
{
193
ImageTransformHelper< NImageDimension, R, C >::
194
TransformIndexToPhysicalPointRow
(
195
matrix, origin,
196
index, point,
197
Concept::Detail::UniqueType_bool
< ( R + 1 == 0 ) >() );
198
}
199
200
inline
static
void
TransformIndexToPhysicalPointRow
(
201
const
MatrixType
& matrix,
const
OriginType
& origin,
202
const
IndexType
& index,
FloatPoint
& point,
203
const
UniqueTypeBoolFalse
&)
204
{
205
point[R] = origin[R];
206
207
// Start column
208
ImageTransformHelper< NImageDimension, R, C >
209
::TransformIndexToPhysicalPointCol
(
210
matrix,
211
index, point,
212
Concept::Detail::UniqueType_bool
< ( C + 1 == 0 ) >() );
213
// Do Next Row
214
ImageTransformHelper< NImageDimension, R - 1, C >
215
::TransformIndexToPhysicalPointRow
(
216
matrix, origin,
217
index, point,
218
Concept::Detail::UniqueType_bool
< ( R == 0 ) >() );
219
}
220
221
inline
static
void
TransformIndexToPhysicalPointRow
(
222
const
MatrixType
&,
const
OriginType
&,
223
const
IndexType
&,
FloatPoint
&,
224
const
UniqueTypeBoolTrue
&)
225
{
226
// Do last row
227
}
228
229
inline
static
void
TransformIndexToPhysicalPointCol
(
230
const
MatrixType
& matrix,
231
const
IndexType
& index,
FloatPoint
& point,
232
const
UniqueTypeBoolFalse
&)
233
{
234
point[R] = point[R] + matrix[R][C] * index[C];
235
236
// Do next dimension
237
ImageTransformHelper< NImageDimension, R, C - 1 >
238
::TransformIndexToPhysicalPointCol
(
239
matrix,
240
index, point,
241
Concept::Detail::UniqueType_bool
< ( C == 0 ) >() );
242
}
243
244
inline
static
void
TransformIndexToPhysicalPointCol
(
245
const
MatrixType
&,
246
const
IndexType
&,
FloatPoint
&,
247
const
UniqueTypeBoolTrue
&)
248
{}
249
250
// PhysicalPointToIndex with full matrix
251
//
252
//
253
inline
static
void
TransformPhysicalPointToIndex
(
254
const
MatrixType
& matrix,
const
OriginType
& origin,
255
const
FloatPoint
& point,
IndexType
& index)
256
{
257
FloatPoint
rindex;
258
259
ImageTransformHelper< NImageDimension, R, C >::
260
TransformPhysicalPointToIndexRow
(
261
matrix, origin,
262
point, rindex, index,
263
Concept::Detail::UniqueType_bool
< ( R + 1 == 0 ) >() );
264
}
265
266
inline
static
void
TransformPhysicalPointToIndexRow
(
267
const
MatrixType
& matrix,
const
OriginType
& origin,
268
const
FloatPoint
& point,
FloatPoint
& rindex,
IndexType
& index,
269
const
UniqueTypeBoolFalse
&)
270
{
271
rindex[R] = 0.0;
272
// Start column
273
ImageTransformHelper< NImageDimension, R, C >
274
::TransformPhysicalPointToIndexCol
(
275
matrix, origin,
276
point, rindex, index,
277
Concept::Detail::UniqueType_bool
< ( C + 1 == 0 ) >() );
278
// Do next row
279
ImageTransformHelper< NImageDimension, R - 1, C >
280
::TransformPhysicalPointToIndexRow
(
281
matrix, origin,
282
point, rindex, index,
283
Concept::Detail::UniqueType_bool
< ( R == 0 ) >() );
284
}
285
286
inline
static
void
TransformPhysicalPointToIndexRow
(
287
const
MatrixType
&,
const
OriginType
&,
288
const
FloatPoint
&,
FloatPoint
&,
IndexType
&,
289
const
UniqueTypeBoolTrue
&)
290
{
291
// Do last row
292
}
293
294
inline
static
void
TransformPhysicalPointToIndexCol
(
295
const
MatrixType
& matrix,
const
OriginType
& origin,
296
const
FloatPoint
& point,
FloatPoint
& rindex,
IndexType
& index,
297
const
UniqueTypeBoolFalse
&)
298
{
299
rindex[R] = rindex[R] + matrix[R][C] * ( point[C] - origin[C] );
300
301
// Do next dimension
302
ImageTransformHelper< NImageDimension, R, C - 1 >
303
::TransformPhysicalPointToIndexCol
(
304
matrix, origin,
305
point, rindex, index,
306
Concept::Detail::UniqueType_bool
< ( C == 0 ) >() );
307
}
308
309
inline
static
void
TransformPhysicalPointToIndexCol
(
310
const
MatrixType
&,
const
OriginType
&,
311
const
FloatPoint
&,
FloatPoint
& rindex,
IndexType
& index,
312
const
UniqueTypeBoolTrue
&)
313
{
314
index[R] = Math::RoundHalfIntegerUp< IndexValueType >(rindex[R]);
315
}
316
};
317
}
// end namespace itk
318
319
#endif
320
Generated on Sun Dec 9 2012 01:10:20 for ITK by
1.8.2