ITK  4.2.0
Insight Segmentation and Registration Toolkit
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 >
35 {
36 public:
38  typedef typename ImageType::IndexType IndexType;
41  typedef typename ImageType::PointType OriginType;
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  {
60  matrix, origin,
61  index, point,
62  Concept::Detail::UniqueType_bool< ( R + 1 == 0 ) >() );
63  }
64 
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
75  matrix,
76  index, point,
77  Concept::Detail::UniqueType_bool< ( C + 1 == 0 ) >() );
78  // Do Next Row
81  matrix, origin,
82  index, point,
83  Concept::Detail::UniqueType_bool< ( R == 0 ) >() );
84  }
85 
87  const MatrixType &, const OriginType &,
88  const IndexType &, DoublePoint &,
89  const UniqueTypeBoolTrue &)
90  {
91  // Do last row
92  }
93 
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
104  matrix,
105  index, point,
106  Concept::Detail::UniqueType_bool< ( C == 0 ) >() );
107  }
108 
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 
126  matrix, origin,
127  point, rindex, index,
128  Concept::Detail::UniqueType_bool< ( R + 1 == 0 ) >() );
129  }
130 
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
140  matrix, origin,
141  point, rindex, index,
142  Concept::Detail::UniqueType_bool< ( C + 1 == 0 ) >() );
143  // Do next row
146  matrix, origin,
147  point, rindex, index,
148  Concept::Detail::UniqueType_bool< ( R == 0 ) >() );
149  }
150 
152  const MatrixType &, const OriginType &,
153  const DoublePoint &, DoublePoint &, IndexType &,
154  const UniqueTypeBoolTrue &)
155  {
156  // Do last row
157  }
158 
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
169  matrix, origin,
170  point, rindex, index,
171  Concept::Detail::UniqueType_bool< ( C == 0 ) >() );
172  }
173 
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  {
195  matrix, origin,
196  index, point,
197  Concept::Detail::UniqueType_bool< ( R + 1 == 0 ) >() );
198  }
199 
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
210  matrix,
211  index, point,
212  Concept::Detail::UniqueType_bool< ( C + 1 == 0 ) >() );
213  // Do Next Row
216  matrix, origin,
217  index, point,
218  Concept::Detail::UniqueType_bool< ( R == 0 ) >() );
219  }
220 
222  const MatrixType &, const OriginType &,
223  const IndexType &, FloatPoint &,
224  const UniqueTypeBoolTrue &)
225  {
226  // Do last row
227  }
228 
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
239  matrix,
240  index, point,
241  Concept::Detail::UniqueType_bool< ( C == 0 ) >() );
242  }
243 
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 
261  matrix, origin,
262  point, rindex, index,
263  Concept::Detail::UniqueType_bool< ( R + 1 == 0 ) >() );
264  }
265 
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
275  matrix, origin,
276  point, rindex, index,
277  Concept::Detail::UniqueType_bool< ( C + 1 == 0 ) >() );
278  // Do next row
281  matrix, origin,
282  point, rindex, index,
283  Concept::Detail::UniqueType_bool< ( R == 0 ) >() );
284  }
285 
287  const MatrixType &, const OriginType &,
288  const FloatPoint &, FloatPoint &, IndexType &,
289  const UniqueTypeBoolTrue &)
290  {
291  // Do last row
292  }
293 
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
304  matrix, origin,
305  point, rindex, index,
306  Concept::Detail::UniqueType_bool< ( C == 0 ) >() );
307  }
308 
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