ITK  4.8.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 
26 namespace itk
27 {
32 template< unsigned int NImageDimension, unsigned int R, unsigned int C, typename TPointValue = double, typename TMatrixValue=double >
33 class ImageTransformHelper
34 {
35 public:
37  typedef typename ImageType::IndexType IndexType;
40  typedef typename ImageType::PointType OriginType;
45 
46  //
47  // Methods with DoublePoint
48  //
49 
50  // IndexToPhysicalPoint with full matrix
51  //
52  //
53  inline static void TransformIndexToPhysicalPoint(
54  const MatrixType & matrix, const OriginType & origin,
55  const IndexType & index, DoublePoint & point)
56  {
59  matrix, origin,
60  index, point,
61  Concept::Detail::UniqueType_bool< ( R + 1 == 0 ) >() );
62  }
63 
65  const MatrixType & matrix, const OriginType & origin,
66  const IndexType & index, DoublePoint & point,
67  const UniqueTypeBoolFalse &)
68  {
69  point[R] = origin[R];
70 
71  // Start column
74  matrix,
75  index, point,
76  Concept::Detail::UniqueType_bool< ( C + 1 == 0 ) >() );
77  // Do Next Row
80  matrix, origin,
81  index, point,
82  Concept::Detail::UniqueType_bool< ( R == 0 ) >() );
83  }
84 
86  const MatrixType &, const OriginType &,
87  const IndexType &, DoublePoint &,
88  const UniqueTypeBoolTrue &)
89  {
90  // Do last row
91  }
92 
94  const MatrixType & matrix,
95  const IndexType & index, DoublePoint & point,
96  const UniqueTypeBoolFalse &)
97  {
98  point[R] = point[R] + matrix[R][C] * index[C];
99 
100  // Do next dimension
103  matrix,
104  index, point,
105  Concept::Detail::UniqueType_bool< ( C == 0 ) >() );
106  }
107 
109  const MatrixType &,
110  const IndexType &, DoublePoint &,
111  const UniqueTypeBoolTrue &)
112  {}
113 
114  // PhysicalPointToIndex with full matrix
115  //
116  //
117  inline static void TransformPhysicalPointToIndex(
118  const MatrixType & matrix, const OriginType & origin,
119  const DoublePoint & point, IndexType & index)
120  {
121  DoublePoint rindex;
122 
125  matrix, origin,
126  point, rindex, index,
127  Concept::Detail::UniqueType_bool< ( R + 1 == 0 ) >() );
128  }
129 
131  const MatrixType & matrix, const OriginType & origin,
132  const DoublePoint & point, DoublePoint & rindex, IndexType & index,
133  const UniqueTypeBoolFalse &)
134  {
135  rindex[R] = 0.0;
136  // Start column
139  matrix, origin,
140  point, rindex, index,
141  Concept::Detail::UniqueType_bool< ( C + 1 == 0 ) >() );
142  // Do next row
145  matrix, origin,
146  point, rindex, index,
147  Concept::Detail::UniqueType_bool< ( R == 0 ) >() );
148  }
149 
151  const MatrixType &, const OriginType &,
152  const DoublePoint &, DoublePoint &, IndexType &,
153  const UniqueTypeBoolTrue &)
154  {
155  // Do last row
156  }
157 
159  const MatrixType & matrix, const OriginType & origin,
160  const DoublePoint & point, DoublePoint & rindex, IndexType & index,
161  const UniqueTypeBoolFalse &)
162  {
163  rindex[R] = rindex[R] + matrix[R][C] * ( point[C] - origin[C] );
164 
165  // Do next dimension
168  matrix, origin,
169  point, rindex, index,
170  Concept::Detail::UniqueType_bool< ( C == 0 ) >() );
171  }
172 
174  const MatrixType &, const OriginType &,
175  const DoublePoint &, DoublePoint & rindex, IndexType & index,
176  const UniqueTypeBoolTrue &)
177  {
178  index[R] = Math::RoundHalfIntegerUp< IndexValueType >(rindex[R]);
179  }
180 
181  //
182  // Methods with FloatPoint
183  //
184 
185  // IndexToPhysicalPoint with full matrix
186  //
187  //
188  inline static void TransformIndexToPhysicalPoint(
189  const MatrixType & matrix, const OriginType & origin,
190  const IndexType & index, FloatPoint & point)
191  {
194  matrix, origin,
195  index, point,
196  Concept::Detail::UniqueType_bool< ( R + 1 == 0 ) >() );
197  }
198 
200  const MatrixType & matrix, const OriginType & origin,
201  const IndexType & index, FloatPoint & point,
202  const UniqueTypeBoolFalse &)
203  {
204  point[R] = origin[R];
205 
206  // Start column
209  matrix,
210  index, point,
211  Concept::Detail::UniqueType_bool< ( C + 1 == 0 ) >() );
212  // Do Next Row
215  matrix, origin,
216  index, point,
217  Concept::Detail::UniqueType_bool< ( R == 0 ) >() );
218  }
219 
221  const MatrixType &, const OriginType &,
222  const IndexType &, FloatPoint &,
223  const UniqueTypeBoolTrue &)
224  {
225  // Do last row
226  }
227 
229  const MatrixType & matrix,
230  const IndexType & index, FloatPoint & point,
231  const UniqueTypeBoolFalse &)
232  {
233  point[R] = point[R] + matrix[R][C] * index[C];
234 
235  // Do next dimension
238  matrix,
239  index, point,
240  Concept::Detail::UniqueType_bool< ( C == 0 ) >() );
241  }
242 
244  const MatrixType &,
245  const IndexType &, FloatPoint &,
246  const UniqueTypeBoolTrue &)
247  {}
248 
249  // PhysicalPointToIndex with full matrix
250  //
251  //
252  inline static void TransformPhysicalPointToIndex(
253  const MatrixType & matrix, const OriginType & origin,
254  const FloatPoint & point, IndexType & index)
255  {
256  FloatPoint rindex;
257 
260  matrix, origin,
261  point, rindex, index,
262  Concept::Detail::UniqueType_bool< ( R + 1 == 0 ) >() );
263  }
264 
266  const MatrixType & matrix, const OriginType & origin,
267  const FloatPoint & point, FloatPoint & rindex, IndexType & index,
268  const UniqueTypeBoolFalse &)
269  {
270  rindex[R] = 0.0;
271  // Start column
274  matrix, origin,
275  point, rindex, index,
276  Concept::Detail::UniqueType_bool< ( C + 1 == 0 ) >() );
277  // Do next row
280  matrix, origin,
281  point, rindex, index,
282  Concept::Detail::UniqueType_bool< ( R == 0 ) >() );
283  }
284 
286  const MatrixType &, const OriginType &,
287  const FloatPoint &, FloatPoint &, IndexType &,
288  const UniqueTypeBoolTrue &)
289  {
290  // Do last row
291  }
292 
294  const MatrixType & matrix, const OriginType & origin,
295  const FloatPoint & point, FloatPoint & rindex, IndexType & index,
296  const UniqueTypeBoolFalse &)
297  {
298  rindex[R] = rindex[R] + matrix[R][C] * ( point[C] - origin[C] );
299 
300  // Do next dimension
303  matrix, origin,
304  point, rindex, index,
305  Concept::Detail::UniqueType_bool< ( C == 0 ) >() );
306  }
307 
309  const MatrixType &, const OriginType &,
310  const FloatPoint &, FloatPoint & rindex, IndexType & index,
311  const UniqueTypeBoolTrue &)
312  {
313  index[R] = Math::RoundHalfIntegerUp< IndexValueType >(rindex[R]);
314  }
315 };
316 } // end namespace itk
317 
318 #endif
static void TransformIndexToPhysicalPoint(const MatrixType &matrix, const OriginType &origin, const IndexType &index, DoublePoint &point)
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:46
static void TransformPhysicalPointToIndexRow(const MatrixType &matrix, const OriginType &origin, const DoublePoint &point, DoublePoint &rindex, IndexType &index, const UniqueTypeBoolFalse &)
static void TransformPhysicalPointToIndexCol(const MatrixType &matrix, const OriginType &origin, const DoublePoint &point, DoublePoint &rindex, IndexType &index, const UniqueTypeBoolFalse &)
Point< double, NImageDimension > DoublePoint
Concept::Detail::UniqueType_bool< true > UniqueTypeBoolTrue
static void TransformIndexToPhysicalPoint(const MatrixType &matrix, const OriginType &origin, const IndexType &index, FloatPoint &point)
static void TransformIndexToPhysicalPointCol(const MatrixType &, const IndexType &, DoublePoint &, const UniqueTypeBoolTrue &)
static void TransformIndexToPhysicalPointRow(const MatrixType &matrix, const OriginType &origin, const IndexType &index, DoublePoint &point, const UniqueTypeBoolFalse &)
Point< float, NImageDimension > FloatPoint
ImageBase< NImageDimension > ImageType
static void TransformPhysicalPointToIndexCol(const MatrixType &, const OriginType &, const DoublePoint &, DoublePoint &rindex, IndexType &index, const UniqueTypeBoolTrue &)
static void TransformIndexToPhysicalPointCol(const MatrixType &matrix, const IndexType &index, DoublePoint &point, const UniqueTypeBoolFalse &)
static void TransformPhysicalPointToIndexCol(const MatrixType &matrix, const OriginType &origin, const FloatPoint &point, FloatPoint &rindex, IndexType &index, const UniqueTypeBoolFalse &)
static void TransformIndexToPhysicalPointCol(const MatrixType &, const IndexType &, FloatPoint &, const UniqueTypeBoolTrue &)
static void TransformPhysicalPointToIndex(const MatrixType &matrix, const OriginType &origin, const FloatPoint &point, IndexType &index)
static void TransformPhysicalPointToIndexRow(const MatrixType &matrix, const OriginType &origin, const FloatPoint &point, FloatPoint &rindex, IndexType &index, const UniqueTypeBoolFalse &)
static void TransformPhysicalPointToIndex(const MatrixType &matrix, const OriginType &origin, const DoublePoint &point, IndexType &index)
static void TransformIndexToPhysicalPointRow(const MatrixType &, const OriginType &, const IndexType &, DoublePoint &, const UniqueTypeBoolTrue &)
Base class for templated image classes.
Definition: itkImageBase.h:112
static void TransformIndexToPhysicalPointCol(const MatrixType &matrix, const IndexType &index, FloatPoint &point, const UniqueTypeBoolFalse &)
static void TransformIndexToPhysicalPointRow(const MatrixType &, const OriginType &, const IndexType &, FloatPoint &, const UniqueTypeBoolTrue &)
static void TransformIndexToPhysicalPointRow(const MatrixType &matrix, const OriginType &origin, const IndexType &index, FloatPoint &point, const UniqueTypeBoolFalse &)
static void TransformPhysicalPointToIndexRow(const MatrixType &, const OriginType &, const FloatPoint &, FloatPoint &, IndexType &, const UniqueTypeBoolTrue &)
Matrix< TMatrixValue, NImageDimension, NImageDimension > MatrixType
ImageType::SpacingType SpacingType
Concept::Detail::UniqueType_bool< false > UniqueTypeBoolFalse
static void TransformPhysicalPointToIndexCol(const MatrixType &, const OriginType &, const FloatPoint &, FloatPoint &rindex, IndexType &index, const UniqueTypeBoolTrue &)
static void TransformPhysicalPointToIndexRow(const MatrixType &, const OriginType &, const DoublePoint &, DoublePoint &, IndexType &, const UniqueTypeBoolTrue &)