00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkImageTransformHelper_h
00018 #define __itkImageTransformHelper_h
00019
00020 #include "itkConceptChecking.h"
00021 #include "itkPoint.h"
00022 #include "itkMatrix.h"
00023
00024 namespace itk
00025 {
00026
00030 template <unsigned int NImageDimension, unsigned int R, unsigned int C>
00031 class ImageTransformHelper
00032 {
00033 public:
00034 typedef ImageBase<NImageDimension> ImageType;
00035 typedef typename ImageType::IndexType IndexType;
00036 typedef typename ImageType::SpacingType SpacingType;
00037 typedef Matrix<double, NImageDimension, NImageDimension> MatrixType;
00038 typedef typename ImageType::PointType OriginType;
00039 typedef Point<double, NImageDimension> DoublePoint;
00040 typedef Point<float, NImageDimension> FloatPoint;
00041 typedef Concept::Detail::UniqueType_bool<false> UniqueTypeBoolFalse;
00042 typedef Concept::Detail::UniqueType_bool<true> UniqueTypeBoolTrue;
00043
00044
00045
00046
00047
00048
00049
00050
00051 inline static void TransformIndexToPhysicalPoint(
00052 const MatrixType & matrix, const OriginType & origin,
00053 const IndexType & index, DoublePoint & point)
00054 {
00055 ImageTransformHelper<NImageDimension, R, C>::
00056 TransformIndexToPhysicalPointRow(
00057 matrix, origin,
00058 index, point,
00059 Concept::Detail::UniqueType_bool<(R+1==0)>());
00060 }
00061
00062 inline static void TransformIndexToPhysicalPointRow(
00063 const MatrixType & matrix, const OriginType & origin,
00064 const IndexType & index, DoublePoint & point,
00065 const UniqueTypeBoolFalse& )
00066 {
00067 point[R] = origin[R];
00068
00069
00070 ImageTransformHelper<NImageDimension,R,C>
00071 ::TransformIndexToPhysicalPointCol(
00072 matrix,
00073 index,point,
00074 Concept::Detail::UniqueType_bool<(C+1==0)>());
00075
00076 ImageTransformHelper<NImageDimension,R-1,C>
00077 ::TransformIndexToPhysicalPointRow(
00078 matrix,origin,
00079 index,point,
00080 Concept::Detail::UniqueType_bool<(R==0)>());
00081 }
00082
00083 inline static void TransformIndexToPhysicalPointRow(
00084 const MatrixType &, const OriginType &,
00085 const IndexType &, DoublePoint &,
00086 const UniqueTypeBoolTrue& )
00087 {
00088
00089 }
00090
00091 inline static void TransformIndexToPhysicalPointCol(
00092 const MatrixType & matrix,
00093 const IndexType & index, DoublePoint & point,
00094 const UniqueTypeBoolFalse& )
00095 {
00096 point[R] = point[R] + matrix[R][C]*index[C];
00097
00098
00099 ImageTransformHelper<NImageDimension,R,C-1>
00100 ::TransformIndexToPhysicalPointCol(
00101 matrix,
00102 index,point,
00103 Concept::Detail::UniqueType_bool<(C==0)>());
00104 }
00105
00106 inline static void TransformIndexToPhysicalPointCol(
00107 const MatrixType &,
00108 const IndexType &, DoublePoint &,
00109 const UniqueTypeBoolTrue& )
00110 {
00111 }
00112
00113
00114
00115
00116 inline static void TransformPhysicalPointToIndex(
00117 const MatrixType & matrix, const OriginType & origin,
00118 const DoublePoint & point, IndexType & index)
00119 {
00120 DoublePoint rindex;
00121 ImageTransformHelper<NImageDimension, R, C>::
00122 TransformPhysicalPointToIndexRow(
00123 matrix, origin,
00124 point, rindex, index,
00125 Concept::Detail::UniqueType_bool<(R+1==0)>());
00126 }
00127
00128 inline static void TransformPhysicalPointToIndexRow(
00129 const MatrixType & matrix, const OriginType & origin,
00130 const DoublePoint & point, DoublePoint & rindex, IndexType & index,
00131 const UniqueTypeBoolFalse& )
00132 {
00133 rindex[R] = 0.0;
00134
00135 ImageTransformHelper<NImageDimension,R,C>
00136 ::TransformPhysicalPointToIndexCol(
00137 matrix,origin,
00138 point,rindex,index,
00139 Concept::Detail::UniqueType_bool<(C+1==0)>());
00140
00141 ImageTransformHelper<NImageDimension,R-1,C>
00142 ::TransformPhysicalPointToIndexRow(
00143 matrix,origin,
00144 point,rindex,index,
00145 Concept::Detail::UniqueType_bool<(R==0)>());
00146 }
00147
00148 inline static void TransformPhysicalPointToIndexRow(
00149 const MatrixType &, const OriginType &,
00150 const DoublePoint &, DoublePoint &, IndexType &,
00151 const UniqueTypeBoolTrue& )
00152 {
00153
00154 }
00155
00156 inline static void TransformPhysicalPointToIndexCol(
00157 const MatrixType & matrix, const OriginType & origin,
00158 const DoublePoint & point, DoublePoint & rindex, IndexType & index,
00159 const UniqueTypeBoolFalse& )
00160 {
00161 rindex[R] = rindex[R] + matrix[R][C]*(point[C] - origin[C]);
00162
00163
00164 ImageTransformHelper<NImageDimension,R,C-1>
00165 ::TransformPhysicalPointToIndexCol(
00166 matrix,origin,
00167 point,rindex,index,
00168 Concept::Detail::UniqueType_bool<(C==0)>());
00169 }
00170
00171 inline static void TransformPhysicalPointToIndexCol(
00172 const MatrixType &, const OriginType &,
00173 const DoublePoint &, DoublePoint &rindex, IndexType &index,
00174 const UniqueTypeBoolTrue& )
00175 {
00176 index[R] = static_cast<typename IndexType::IndexValueType>(rindex[R]);
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186 inline static void TransformIndexToPhysicalPoint(
00187 const MatrixType & matrix, const OriginType & origin,
00188 const IndexType & index, FloatPoint & point)
00189 {
00190 ImageTransformHelper<NImageDimension, R, C>::
00191 TransformIndexToPhysicalPointRow(
00192 matrix, origin,
00193 index, point,
00194 Concept::Detail::UniqueType_bool<(R+1==0)>());
00195 }
00196
00197 inline static void TransformIndexToPhysicalPointRow(
00198 const MatrixType & matrix, const OriginType & origin,
00199 const IndexType & index, FloatPoint & point,
00200 const UniqueTypeBoolFalse& )
00201 {
00202 point[R] = origin[R];
00203
00204
00205 ImageTransformHelper<NImageDimension,R,C>
00206 ::TransformIndexToPhysicalPointCol(
00207 matrix,
00208 index,point,
00209 Concept::Detail::UniqueType_bool<(C+1==0)>());
00210
00211 ImageTransformHelper<NImageDimension,R-1,C>
00212 ::TransformIndexToPhysicalPointRow(
00213 matrix,origin,
00214 index,point,
00215 Concept::Detail::UniqueType_bool<(R==0)>());
00216 }
00217
00218 inline static void TransformIndexToPhysicalPointRow(
00219 const MatrixType &, const OriginType &,
00220 const IndexType &, FloatPoint &,
00221 const UniqueTypeBoolTrue& )
00222 {
00223
00224 }
00225
00226 inline static void TransformIndexToPhysicalPointCol(
00227 const MatrixType & matrix,
00228 const IndexType & index, FloatPoint & point,
00229 const UniqueTypeBoolFalse& )
00230 {
00231 point[R] = point[R] + matrix[R][C]*index[C];
00232
00233
00234 ImageTransformHelper<NImageDimension,R,C-1>
00235 ::TransformIndexToPhysicalPointCol(
00236 matrix,
00237 index,point,
00238 Concept::Detail::UniqueType_bool<(C==0)>());
00239 }
00240
00241 inline static void TransformIndexToPhysicalPointCol(
00242 const MatrixType &,
00243 const IndexType &, FloatPoint &,
00244 const UniqueTypeBoolTrue& )
00245 {
00246 }
00247
00248
00249
00250
00251 inline static void TransformPhysicalPointToIndex(
00252 const MatrixType & matrix, const OriginType & origin,
00253 const FloatPoint & point, IndexType & index)
00254 {
00255 FloatPoint rindex;
00256 ImageTransformHelper<NImageDimension, R, C>::
00257 TransformPhysicalPointToIndexRow(
00258 matrix, origin,
00259 point, rindex, index,
00260 Concept::Detail::UniqueType_bool<(R+1==0)>());
00261 }
00262
00263 inline static void TransformPhysicalPointToIndexRow(
00264 const MatrixType & matrix, const OriginType & origin,
00265 const FloatPoint & point, FloatPoint & rindex, IndexType & index,
00266 const UniqueTypeBoolFalse& )
00267 {
00268 rindex[R] = 0.0;
00269
00270 ImageTransformHelper<NImageDimension,R,C>
00271 ::TransformPhysicalPointToIndexCol(
00272 matrix,origin,
00273 point,rindex,index,
00274 Concept::Detail::UniqueType_bool<(C+1==0)>());
00275
00276 ImageTransformHelper<NImageDimension,R-1,C>
00277 ::TransformPhysicalPointToIndexRow(
00278 matrix,origin,
00279 point,rindex,index,
00280 Concept::Detail::UniqueType_bool<(R==0)>());
00281 }
00282
00283 inline static void TransformPhysicalPointToIndexRow(
00284 const MatrixType &, const OriginType &,
00285 const FloatPoint &, FloatPoint &, IndexType &,
00286 const UniqueTypeBoolTrue& )
00287 {
00288
00289 }
00290
00291 inline static void TransformPhysicalPointToIndexCol(
00292 const MatrixType & matrix, const OriginType & origin,
00293 const FloatPoint & point, FloatPoint & rindex, IndexType & index,
00294 const UniqueTypeBoolFalse& )
00295 {
00296 rindex[R] = rindex[R] + matrix[R][C]*(point[C] - origin[C]);
00297
00298
00299 ImageTransformHelper<NImageDimension,R,C-1>
00300 ::TransformPhysicalPointToIndexCol(
00301 matrix,origin,
00302 point,rindex,index,
00303 Concept::Detail::UniqueType_bool<(C==0)>());
00304 }
00305
00306 inline static void TransformPhysicalPointToIndexCol(
00307 const MatrixType &, const OriginType &,
00308 const FloatPoint &, FloatPoint &rindex, IndexType &index,
00309 const UniqueTypeBoolTrue& )
00310 {
00311 index[R] = static_cast<typename IndexType::IndexValueType>(rindex[R]);
00312 }
00313
00314 };
00315 }
00316
00317 #endif
00318