Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkImageTransformHelper.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageTransformHelper.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-02-05 19:04:57 $
00007   Version:   $Revision: 1.11 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notices for more information.
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   // Methods with DoublePoint
00046   //
00047 
00048   // IndexToPhysicalPoint with full matrix
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     // Start column
00070     ImageTransformHelper<NImageDimension,R,C>
00071       ::TransformIndexToPhysicalPointCol(
00072         matrix,
00073         index,point,
00074         Concept::Detail::UniqueType_bool<(C+1==0)>());
00075     // Do Next Row
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     // Do last row
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     // Do next dimension
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   // PhysicalPointToIndex with full matrix
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     // Start column
00135     ImageTransformHelper<NImageDimension,R,C>
00136       ::TransformPhysicalPointToIndexCol(
00137         matrix,origin,
00138         point,rindex,index,
00139         Concept::Detail::UniqueType_bool<(C+1==0)>());
00140     // Do next row
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     // Do last row
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     // Do next dimension
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   // Methods with FloatPoint
00181   //
00182 
00183   // IndexToPhysicalPoint with full matrix
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     // Start column
00205     ImageTransformHelper<NImageDimension,R,C>
00206       ::TransformIndexToPhysicalPointCol(
00207         matrix,
00208         index,point,
00209         Concept::Detail::UniqueType_bool<(C+1==0)>());
00210     // Do Next Row
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     // Do last row
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     // Do next dimension
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   // PhysicalPointToIndex with full matrix
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     // Start column
00270     ImageTransformHelper<NImageDimension,R,C>
00271       ::TransformPhysicalPointToIndexCol(
00272         matrix,origin,
00273         point,rindex,index,
00274         Concept::Detail::UniqueType_bool<(C+1==0)>());
00275     // Do next row
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     // Do last row
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     // Do next dimension
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 } // end namespace itk
00316 
00317 #endif
00318 

Generated at Sat Feb 28 12:48:59 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000