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: 2007/06/13 00:37:51 $
00007   Version:   $Revision: 1.8 $
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   // IndexToPhysicalPoint with full matrix
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       point[R] = origin[R];
00063 
00064       // Start column
00065       ImageTransformHelper<NImageDimension,R,C>
00066         ::TransformIndexToPhysicalPointCol(
00067           matrix,
00068           index,point,
00069           Concept::Detail::UniqueType_bool<(C==0)>());
00070       // Do Next Row
00071       ImageTransformHelper<NImageDimension,R-1,C>
00072         ::TransformIndexToPhysicalPointRow(
00073           matrix,origin,
00074           index,point,
00075           Concept::Detail::UniqueType_bool<(R==0)>());
00076     }
00077 
00078   inline static void TransformIndexToPhysicalPointRow(
00079     const MatrixType &, const OriginType  &,
00080     const IndexType &, DoublePoint &,
00081     const UniqueTypeBoolTrue& )
00082     {
00083       // Do last row
00084     }
00085 
00086   inline static void TransformIndexToPhysicalPointCol(
00087     const MatrixType & matrix,
00088     const IndexType & index, DoublePoint & point,
00089     const UniqueTypeBoolFalse& )
00090     {
00091       point[R] = point[R] + matrix[R][C]*index[C];
00092 
00093       // Do next dimension
00094       ImageTransformHelper<NImageDimension,R,C-1>
00095         ::TransformIndexToPhysicalPointCol(
00096           matrix,
00097           index,point,
00098           Concept::Detail::UniqueType_bool<(C==0)>());
00099     }
00100 
00101   inline static void TransformIndexToPhysicalPointCol(
00102     const MatrixType &,
00103     const IndexType &, DoublePoint &,
00104     const UniqueTypeBoolTrue& )
00105     {
00106     }
00107 
00108   // PhysicalPointToIndex with full matrix
00109   //
00110   //
00111   inline static void TransformPhysicalPointToIndex(
00112     const MatrixType & matrix, const OriginType  & origin,
00113     const DoublePoint & point, IndexType  & index)
00114     {
00115       DoublePoint rindex;
00116       ImageTransformHelper<NImageDimension, R, C>::
00117         TransformPhysicalPointToIndexRow(
00118           matrix, origin,
00119           point, rindex, index,
00120           Concept::Detail::UniqueType_bool<(R==0)>());
00121     }
00122 
00123   inline static void TransformPhysicalPointToIndexRow(
00124     const MatrixType & matrix, const OriginType  & origin,
00125     const DoublePoint & point, DoublePoint & rindex, IndexType & index,
00126     const UniqueTypeBoolFalse& )
00127     {
00128       rindex[R] = 0.0;
00129       // Start column
00130       ImageTransformHelper<NImageDimension,R,C>
00131         ::TransformPhysicalPointToIndexCol(
00132           matrix,origin,
00133           point,rindex,index,
00134           Concept::Detail::UniqueType_bool<(C==0)>());
00135       // Do next row
00136       ImageTransformHelper<NImageDimension,R-1,C>
00137         ::TransformPhysicalPointToIndexRow(
00138           matrix,origin,
00139           point,rindex,index,
00140           Concept::Detail::UniqueType_bool<(R==0)>());
00141     }
00142 
00143   inline static void TransformPhysicalPointToIndexRow(
00144     const MatrixType &, const OriginType &,
00145     const DoublePoint &, DoublePoint &, IndexType &,
00146     const UniqueTypeBoolTrue& )
00147     {
00148       // Do last row
00149     }
00150 
00151   inline static void TransformPhysicalPointToIndexCol(
00152     const MatrixType & matrix, const OriginType  & origin,
00153     const DoublePoint & point, DoublePoint & rindex, IndexType & index,
00154     const UniqueTypeBoolFalse& )
00155     {
00156       rindex[R] = rindex[R] + matrix[R][C]*(point[C] - origin[C]);
00157 
00158       // Do next dimension
00159       ImageTransformHelper<NImageDimension,R,C-1>
00160         ::TransformPhysicalPointToIndexCol(
00161           matrix,origin,
00162           point,rindex,index,
00163           Concept::Detail::UniqueType_bool<(C==0)>());
00164     }
00165 
00166   inline static void TransformPhysicalPointToIndexCol(
00167     const MatrixType &, const OriginType  &,
00168     const DoublePoint &, DoublePoint &rindex, IndexType &index,
00169     const UniqueTypeBoolTrue& )
00170     {
00171      index[R] = static_cast<typename IndexType::IndexValueType>(rindex[R]);
00172     }
00173 };
00174 } // end namespace itk
00175 
00176 #endif
00177 
00178 

Generated at Sun Sep 23 13:11:54 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000