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 inline static void TransformIndexToPhysicalPoint(
00047 const MatrixType & matrix, const OriginType & origin,
00048 const IndexType & index, DoublePoint & point)
00049 {
00050 ImageTransformHelper<NImageDimension, R, C>::
00051 TransformIndexToPhysicalPointRow(
00052 matrix, origin,
00053 index, point,
00054 Concept::Detail::UniqueType_bool<(R==0)>());
00055 }
00056
00057 inline static void TransformIndexToPhysicalPointRow(
00058 const MatrixType & matrix, const OriginType & origin,
00059 const IndexType & index, DoublePoint & point,
00060 const UniqueTypeBoolFalse& )
00061 {
00062
00063 point[R] = origin[R];
00064
00065
00066 ImageTransformHelper<NImageDimension,R,C>
00067 ::TransformIndexToPhysicalPointCol(
00068 matrix,
00069 index,point,
00070 Concept::Detail::UniqueType_bool<(C==0)>());
00071
00072 ImageTransformHelper<NImageDimension,R-1,C>
00073 ::TransformIndexToPhysicalPointRow(
00074 matrix,origin,
00075 index,point,
00076 Concept::Detail::UniqueType_bool<(R==0)>());
00077 }
00078
00079 inline static void TransformIndexToPhysicalPointRow(
00080 const MatrixType &, const OriginType &,
00081 const IndexType &, DoublePoint &,
00082 const UniqueTypeBoolTrue& )
00083 {
00084
00085 }
00086
00087 inline static void TransformIndexToPhysicalPointCol(
00088 const MatrixType & matrix,
00089 const IndexType & index, DoublePoint & point,
00090 const UniqueTypeBoolFalse& )
00091 {
00092
00093 point[R] = point[R] + matrix[R][C]*index[C];
00094
00095
00096 ImageTransformHelper<NImageDimension,R,C-1>
00097 ::TransformIndexToPhysicalPointCol(
00098 matrix,
00099 index,point,
00100 Concept::Detail::UniqueType_bool<(C==0)>());
00101 }
00102
00103 inline static void TransformIndexToPhysicalPointCol(
00104 const MatrixType &,
00105 const IndexType &, DoublePoint &,
00106 const UniqueTypeBoolTrue& )
00107 {
00108 }
00109
00110
00111
00112
00113 inline static void TransformPhysicalPointToIndex(
00114 const MatrixType & matrix, const OriginType & origin,
00115 const DoublePoint & point, IndexType & index)
00116 {
00117 DoublePoint rindex;
00118 ImageTransformHelper<NImageDimension, R, C>::
00119 TransformPhysicalPointToIndexRow(
00120 matrix, origin,
00121 point, rindex, index,
00122 Concept::Detail::UniqueType_bool<(R==0)>());
00123 }
00124
00125 inline static void TransformPhysicalPointToIndexRow(
00126 const MatrixType & matrix, const OriginType & origin,
00127 const DoublePoint & point, DoublePoint & rindex, IndexType & index,
00128 const UniqueTypeBoolFalse& )
00129 {
00130
00131 rindex[R] = 0.0;
00132
00133 ImageTransformHelper<NImageDimension,R,C>
00134 ::TransformPhysicalPointToIndexCol(
00135 matrix,origin,
00136 point,rindex,index,
00137 Concept::Detail::UniqueType_bool<(C==0)>());
00138
00139 ImageTransformHelper<NImageDimension,R-1,C>
00140 ::TransformPhysicalPointToIndexRow(
00141 matrix,origin,
00142 point,rindex,index,
00143 Concept::Detail::UniqueType_bool<(R==0)>());
00144 }
00145
00146 inline static void TransformPhysicalPointToIndexRow(
00147 const MatrixType &, const OriginType &,
00148 const DoublePoint &, DoublePoint &, IndexType &,
00149 const UniqueTypeBoolTrue& )
00150 {
00151
00152 }
00153
00154 inline static void TransformPhysicalPointToIndexCol(
00155 const MatrixType & matrix, const OriginType & origin,
00156 const DoublePoint & point, DoublePoint & rindex, IndexType & index,
00157 const UniqueTypeBoolFalse& )
00158 {
00159
00160 rindex[R] = rindex[R] + matrix[R][C]*(point[C] - origin[C]);
00161
00162
00163 ImageTransformHelper<NImageDimension,R,C-1>
00164 ::TransformPhysicalPointToIndexCol(
00165 matrix,origin,
00166 point,rindex,index,
00167 Concept::Detail::UniqueType_bool<(C==0)>());
00168 }
00169
00170 inline static void TransformPhysicalPointToIndexCol(
00171 const MatrixType &, const OriginType &,
00172 const DoublePoint &, DoublePoint &rindex, IndexType &index,
00173 const UniqueTypeBoolTrue& )
00174 {
00175
00176 index[R] = static_cast<typename IndexType::IndexValueType>(rindex[R]);
00177 }
00178 };
00179 }
00180
00181 #endif
00182