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

itkOrientedImage.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkOrientedImage.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/10/31 22:16:22 $
00007   Version:   $Revision: 1.14 $
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 __itkOrientedImage_h
00018 #define __itkOrientedImage_h
00019 
00020 #include "itkImage.h"
00021 #include "itkImageTransformHelper.h"
00022 
00023 namespace itk
00024 {
00025 
00035 template <class TPixel, unsigned int VImageDimension>
00036 class ITK_EXPORT OrientedImage : public Image<TPixel, VImageDimension>
00037 {
00038 public:
00040   typedef OrientedImage               Self;
00041   typedef Image<TPixel, VImageDimension>  Superclass;
00042   typedef SmartPointer<Self>  Pointer;
00043   typedef SmartPointer<const Self>  ConstPointer;
00044   typedef WeakPointer<const Self>  ConstWeakPointer;
00045 
00047   itkNewMacro(Self);
00048 
00050   itkTypeMacro(OrientedImage, Image);
00051 
00053   typedef typename Superclass::IndexType  IndexType;
00054 
00056   typedef typename Superclass::DirectionType  DirectionType;
00057 
00060   typedef typename Superclass::SpacingType SpacingType;
00061 
00062   typedef typename Superclass::AccessorType        AccessorType;
00063   typedef typename Superclass::AccessorFunctorType AccessorFunctorType;
00064 
00066   typedef NeighborhoodAccessorFunctor< Self > 
00067                                             NeighborhoodAccessorFunctorType;
00068 
00071   NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() 
00072     { return NeighborhoodAccessorFunctorType(); }
00073   
00076   const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
00077     { return NeighborhoodAccessorFunctorType(); }
00078   
00081   virtual void SetSpacing (const SpacingType spacing)
00082     {
00083     Superclass::SetSpacing(spacing);
00084 
00085     DirectionType scale;
00086     for (unsigned int i=0; i < VImageDimension; i++)
00087       {
00088       scale[i][i] = this->m_Spacing[i];
00089       }
00090     m_IndexToPhysicalPoint = this->m_Direction * scale;
00091     m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse();
00092     }
00093 
00094   virtual void SetSpacing (const double spacing[VImageDimension])
00095     {
00096     Superclass::SetSpacing(spacing);
00097 
00098     DirectionType scale;
00099     for (unsigned int i=0; i < VImageDimension; i++)
00100       {
00101       scale[i][i] = this->m_Spacing[i];
00102       }
00103     m_IndexToPhysicalPoint = this->m_Direction * scale;
00104     m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse();
00105     }
00106 
00107   virtual void SetSpacing (const float spacing[VImageDimension])
00108     {
00109     Superclass::SetSpacing(spacing);
00110 
00111     DirectionType scale;
00112     for (unsigned int i=0; i < VImageDimension; i++)
00113       {
00114       scale[i][i] = this->m_Spacing[i];
00115       }
00116     m_IndexToPhysicalPoint = this->m_Direction * scale;
00117     m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse();
00118     }
00119 
00122   virtual void SetDirection (const DirectionType direction)
00123     {
00124     Superclass::SetDirection(direction);
00125 
00126     DirectionType scale;
00127     for (unsigned int i=0; i < VImageDimension; i++)
00128       {
00129       scale[i][i] = this->m_Spacing[i];
00130       }
00131     m_IndexToPhysicalPoint = this->m_Direction * scale;
00132     m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse();
00133     }
00134 
00139   template<class TCoordRep>
00140   bool TransformPhysicalPointToContinuousIndex(
00141               const Point<TCoordRep, VImageDimension>& point,
00142               ContinuousIndex<TCoordRep, VImageDimension>& index   ) const
00143     {
00144     Vector<double, VImageDimension> cvector;
00145 
00146     cvector = m_PhysicalPointToIndex * (point - this->m_Origin);
00147     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00148       {
00149       index[i] = static_cast<TCoordRep>(cvector[i]);
00150       }
00151 
00152     // Now, check to see if the index is within allowed bounds
00153     const bool isInside =
00154       this->GetLargestPossibleRegion().IsInside( index );
00155 
00156     return isInside;
00157     }
00158 
00163 #if 1
00164   template<class TCoordRep>
00165   bool TransformPhysicalPointToIndex(
00166     const Point<TCoordRep, VImageDimension>& point,
00167     IndexType & index ) const
00168     {
00169       ImageTransformHelper<VImageDimension,VImageDimension-1,VImageDimension-1>::TransformPhysicalPointToIndex(
00170         this->m_PhysicalPointToIndex, this->m_Origin, point, index);
00171 
00172     // Now, check to see if the index is within allowed bounds
00173     const bool isInside =
00174       this->GetLargestPossibleRegion().IsInside( index );
00175     return isInside;
00176     }
00177 #else
00178   template<class TCoordRep>
00179   bool TransformPhysicalPointToIndex(
00180             const Point<TCoordRep, VImageDimension>& point,
00181             IndexType & index                                ) const
00182     {
00183     typedef typename IndexType::IndexValueType IndexValueType;
00184     for (unsigned int i = 0; i < VImageDimension; i++)
00185       {
00186       index[i] = 0.0;
00187       for (unsigned int j = 0; j < VImageDimension; j++)
00188         {
00189         index[i] += 
00190           m_PhysicalPointToIndex[i][j] * (point[j] - this->m_Origin[j]);
00191         }
00192       }
00193 
00194     // Now, check to see if the index is within allowed bounds
00195     const bool isInside =
00196       this->GetLargestPossibleRegion().IsInside( index );
00197 
00198     return isInside;
00199     }
00200 #endif
00201 
00205   template<class TCoordRep>
00206   void TransformContinuousIndexToPhysicalPoint(
00207             const ContinuousIndex<TCoordRep, VImageDimension>& index,
00208             Point<TCoordRep, VImageDimension>& point        ) const
00209     {
00210     Vector<double,VImageDimension> cvector;
00211     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00212       {
00213       cvector[i] = index[i];
00214       }
00215 
00216     point = this->m_Origin + m_IndexToPhysicalPoint * cvector;
00217     }
00218 
00224 #if 1
00225   template<class TCoordRep>
00226   void TransformIndexToPhysicalPoint(
00227                       const IndexType & index,
00228                       Point<TCoordRep, VImageDimension>& point ) const
00229     {
00230       ImageTransformHelper<VImageDimension,VImageDimension-1,VImageDimension-1>::TransformIndexToPhysicalPoint(
00231         this->m_IndexToPhysicalPoint, this->m_Origin, index, point);
00232     }
00233 #else
00234   template<class TCoordRep>
00235   void TransformIndexToPhysicalPoint(
00236                       const IndexType & index,
00237                       Point<TCoordRep, VImageDimension>& point ) const
00238     {
00239     for (unsigned int i = 0; i < VImageDimension; i++)
00240       {
00241       point[i] = this->m_Origin[i];
00242       for (unsigned int j = 0; j < VImageDimension; j++)
00243         {
00244         point[i] += m_IndexToPhysicalPoint[i][j] * index[j];
00245         }
00246       }
00247     }
00248 #endif
00249 protected:
00250   OrientedImage();
00251   virtual ~OrientedImage() {};
00252 
00253 private:
00254   OrientedImage(const Self&); //purposely not implemented
00255   void operator=(const Self&); //purposely not implemented
00256 
00257   DirectionType m_IndexToPhysicalPoint;
00258   DirectionType m_PhysicalPointToIndex;
00259 };
00260 #ifdef ITK_EXPLICIT_INSTANTIATION
00261    extern template class OrientedImage<float         ,2>;
00262    extern template class OrientedImage<double        ,2>;
00263    extern template class OrientedImage<unsigned char ,2>;
00264    extern template class OrientedImage<unsigned short,2>;
00265    extern template class OrientedImage<unsigned int  ,2>;
00266    extern template class OrientedImage<signed char   ,2>;
00267    extern template class OrientedImage<signed short  ,2>;
00268    extern template class OrientedImage<signed int    ,2>;
00269    extern template class OrientedImage<float         ,3>;
00270    extern template class OrientedImage<double        ,3>;
00271    extern template class OrientedImage<unsigned char ,3>;
00272    extern template class OrientedImage<unsigned short,3>;
00273    extern template class OrientedImage<unsigned int  ,3>;
00274    extern template class OrientedImage<signed char   ,3>;
00275    extern template class OrientedImage<signed short  ,3>;
00276    extern template class OrientedImage<signed int    ,3>;
00277 #endif
00278 } // end namespace itk
00279 #ifndef ITK_MANUAL_INSTANTIATION
00280 #include "itkOrientedImage.txx"
00281 #endif
00282 
00283 #endif
00284 

Generated at Wed May 24 23:48:46 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000