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

itkImage.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImage.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/01/26 23:43:03 $
00007   Version:   $Revision: 1.138 $
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 __itkImage_h
00018 #define __itkImage_h
00019 
00020 #include "itkImageBase.h"
00021 #include "itkImageRegion.h"
00022 #include "itkImportImageContainer.h"
00023 #include "itkDefaultPixelAccessor.h"
00024 #include "itkDefaultPixelAccessorFunctor.h"
00025 #include "itkPoint.h"
00026 #include "itkContinuousIndex.h"
00027 #include "itkFixedArray.h"
00028 #include "itkWeakPointer.h"
00029 #include "itkNeighborhoodAccessorFunctor.h"
00030 
00031 namespace itk
00032 {
00081 template <class TPixel, unsigned int VImageDimension=2>
00082 class ITK_EXPORT Image : public ImageBase<VImageDimension>
00083 {
00084 public:
00086   typedef Image               Self;
00087   typedef ImageBase<VImageDimension>  Superclass;
00088   typedef SmartPointer<Self>  Pointer;
00089   typedef SmartPointer<const Self>  ConstPointer;
00090   typedef WeakPointer<const Self>  ConstWeakPointer;
00091 
00093   itkNewMacro(Self);
00094 
00096   itkTypeMacro(Image, ImageBase);
00097 
00100   typedef TPixel PixelType;
00101 
00103   typedef TPixel ValueType ;
00104 
00109   typedef TPixel InternalPixelType;
00110 
00111   typedef PixelType IOPixelType;
00112 
00115   typedef DefaultPixelAccessor< PixelType > AccessorType;
00116   typedef DefaultPixelAccessorFunctor< Self > AccessorFunctorType;
00117 
00119   typedef NeighborhoodAccessorFunctor< Self > 
00120                                             NeighborhoodAccessorFunctorType;
00121 
00126   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
00127 
00129   typedef ImportImageContainer<unsigned long, PixelType> PixelContainer;
00130 
00132   typedef typename Superclass::IndexType  IndexType;
00133 
00135   typedef typename Superclass::OffsetType OffsetType;
00136 
00138   typedef typename Superclass::SizeType  SizeType;
00139 
00141   typedef typename Superclass::DirectionType  DirectionType;
00142 
00144   typedef typename Superclass::RegionType  RegionType;
00145 
00148   typedef typename Superclass::SpacingType SpacingType;
00149 
00152   typedef typename Superclass::PointType PointType;
00153 
00155   typedef typename PixelContainer::Pointer PixelContainerPointer;
00156   typedef typename PixelContainer::ConstPointer PixelContainerConstPointer;
00157 
00159   typedef typename Superclass::OffsetValueType OffsetValueType;
00160 
00163   void Allocate();
00164 
00168   void SetRegions(RegionType region)
00169     {
00170     this->SetLargestPossibleRegion(region);
00171     this->SetBufferedRegion(region);
00172     this->SetRequestedRegion(region);
00173     };
00175 
00176   void SetRegions(SizeType size)
00177     {
00178     RegionType region; region.SetSize(size);
00179     this->SetLargestPossibleRegion(region);
00180     this->SetBufferedRegion(region);
00181     this->SetRequestedRegion(region);
00182     };
00183 
00186   virtual void Initialize();
00187 
00190   void FillBuffer (const TPixel& value);
00191 
00197   void SetPixel(const IndexType &index, const TPixel& value)
00198     {
00199     typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00200     (*m_Buffer)[offset] = value;
00201     }
00202 
00207   const TPixel& GetPixel(const IndexType &index) const
00208   {
00209     typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00210     return ( (*m_Buffer)[offset] );
00211   }
00212 
00217   TPixel& GetPixel(const IndexType &index)
00218     {
00219     typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00220     return ( (*m_Buffer)[offset] );
00221     }
00222 
00227   TPixel & operator[](const IndexType &index)
00228      { return this->GetPixel(index); }
00229 
00234   const TPixel& operator[](const IndexType &index) const
00235      { return this->GetPixel(index); }
00236 
00239   TPixel *GetBufferPointer()
00240     { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00241   const TPixel *GetBufferPointer() const
00242     { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00244 
00246   PixelContainer* GetPixelContainer()
00247     { return m_Buffer.GetPointer(); }
00248 
00249   const PixelContainer* GetPixelContainer() const
00250     { return m_Buffer.GetPointer(); }
00251 
00254   void SetPixelContainer( PixelContainer *container );
00255 
00266   virtual void Graft(const DataObject *data);
00267 
00268   
00270   AccessorType GetPixelAccessor( void ) 
00271     { return AccessorType(); }
00272 
00274   const AccessorType GetPixelAccessor( void ) const
00275     { return AccessorType(); }
00276 
00278   NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() 
00279     { return NeighborhoodAccessorFunctorType(); }
00280 
00282   const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
00283     { return NeighborhoodAccessorFunctorType(); }
00284 
00285 
00290   template<class TCoordRep>
00291   bool TransformPhysicalPointToContinuousIndex(
00292               const Point<TCoordRep, VImageDimension>& point,
00293               ContinuousIndex<TCoordRep, VImageDimension>& index   ) const
00294     {
00295     // Update the output index
00296     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00297       {
00298       index[i] = static_cast<TCoordRep>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00299       }
00300 
00301     // Now, check to see if the index is within allowed bounds
00302     const bool isInside =
00303       this->GetLargestPossibleRegion().IsInside( index );
00304 
00305     return isInside;
00306     }
00307 
00312   template<class TCoordRep>
00313   bool TransformPhysicalPointToIndex(
00314             const Point<TCoordRep, VImageDimension>& point,
00315             IndexType & index                                ) const
00316     {
00317     typedef typename IndexType::IndexValueType IndexValueType;
00318 
00319     // Update the output index
00320     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00321       {
00322       index[i] = static_cast<IndexValueType>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00323       }
00324 
00325     // Now, check to see if the index is within allowed bounds
00326     const bool isInside =
00327       this->GetLargestPossibleRegion().IsInside( index );
00328 
00329     return isInside;
00330     }
00331 
00336   template<class TCoordRep>
00337   void TransformContinuousIndexToPhysicalPoint(
00338             const ContinuousIndex<TCoordRep, VImageDimension>& index,
00339             Point<TCoordRep, VImageDimension>& point        ) const
00340     {
00341     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00342       {
00343       point[i] = static_cast<TCoordRep>( this->m_Spacing[i] * index[i] + this->m_Origin[i] );
00344       }
00345     }
00347 
00353   template<class TCoordRep>
00354   void TransformIndexToPhysicalPoint(
00355                       const IndexType & index,
00356                       Point<TCoordRep, VImageDimension>& point ) const
00357     {
00358     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00359       {
00360       point[i] = static_cast<TCoordRep>( this->m_Spacing[i] *
00361         static_cast<double>( index[i] ) + this->m_Origin[i] );
00362       }
00363     }
00365 
00366 protected:
00367   Image();
00368   void PrintSelf(std::ostream& os, Indent indent) const;
00369   virtual ~Image() {};
00370 private:
00371   Image(const Self&); //purposely not implemented
00372   void operator=(const Self&); //purposely not implemented
00373 
00375   PixelContainerPointer m_Buffer;
00376 };
00377 
00378 } // end namespace itk
00379 
00380 // Define instantiation macro for this template.
00381 #define ITK_TEMPLATE_Image(_, EXPORT, x, y) namespace itk { \
00382   _(2(class EXPORT Image< ITK_TEMPLATE_2 x >)) \
00383   namespace Templates { typedef Image< ITK_TEMPLATE_2 x > Image##y; } \
00384   }
00385 
00386 #if ITK_TEMPLATE_EXPLICIT
00387 # include "Templates/itkImage+-.h"
00388 #endif
00389 
00390 #if ITK_TEMPLATE_TXX
00391 # include "itkImage.txx"
00392 #endif
00393 
00394 #endif
00395 

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