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: 2005/04/12 19:02:58 $
00007   Version:   $Revision: 1.7 $
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       // std::cout << "point[" << R << "] = origin[" << R << "];" << std::endl;
00063       point[R] = origin[R];
00064 
00065       // Start column
00066       ImageTransformHelper<NImageDimension,R,C>
00067         ::TransformIndexToPhysicalPointCol(
00068           matrix,
00069           index,point,
00070           Concept::Detail::UniqueType_bool<(C==0)>());
00071       // Do Next Row
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       // Do last row
00085     }
00086 
00087   inline static void TransformIndexToPhysicalPointCol(
00088     const MatrixType & matrix,
00089     const IndexType & index, DoublePoint & point,
00090     const UniqueTypeBoolFalse& )
00091     {
00092       // std::cout << "point[" << R << "] = point[" << R << "] + matrix[" << R << "][" << C << "]*rindex[" << C << "];" << std::endl;
00093       point[R] = point[R] + matrix[R][C]*index[C];
00094 
00095       // Do next dimension
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   // PhysicalPointToIndex with full matrix
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 //      std::cout << "rindex[" << R << "] = 0.0;" << std::endl;
00131       rindex[R] = 0.0;
00132       // Start column
00133       ImageTransformHelper<NImageDimension,R,C>
00134         ::TransformPhysicalPointToIndexCol(
00135           matrix,origin,
00136           point,rindex,index,
00137           Concept::Detail::UniqueType_bool<(C==0)>());
00138       // Do next row
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       // Do last row
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 //      std::cout << "rindex[" << R << "] = rindex[" << R << "] + matrix[" << R << "][" << C << "]*(point[" << C << "] - origin[" << C << "]);" << std::endl;
00160       rindex[R] = rindex[R] + matrix[R][C]*(point[C] - origin[C]);
00161 
00162       // Do next dimension
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 //      std::cout << "index[" << R << "] = rindex[" << R << "]);" << std::endl;
00176      index[R] = static_cast<typename IndexType::IndexValueType>(rindex[R]);
00177     }
00178 };
00179 } // end namespace itk
00180 
00181 #endif
00182 
00183 

Generated at Mon Mar 12 01:15:46 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000