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: 2003/02/16 07:04:01 $
00007   Version:   $Revision: 1.109 $
00008 
00009   Copyright (c) 2002 Insight 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 "itkPoint.h"
00025 #include "itkContinuousIndex.h"
00026 
00027 namespace itk
00028 {
00029 
00078 template <class TPixel, unsigned int VImageDimension=2>
00079 class ITK_EXPORT Image : public ImageBase<VImageDimension>
00080 {
00081 public:
00083   typedef Image               Self;
00084   typedef ImageBase<VImageDimension>  Superclass;
00085   typedef SmartPointer<Self>  Pointer;
00086   typedef SmartPointer<const Self>  ConstPointer;
00087   
00089   itkNewMacro(Self);  
00090 
00092   itkTypeMacro(Image, ImageBase);
00093 
00096   typedef TPixel PixelType;
00097 
00099   typedef TPixel ValueType ;
00100 
00105   typedef TPixel InternalPixelType;
00106 
00109   typedef DefaultPixelAccessor< PixelType > AccessorType;
00110 
00115   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
00116   
00118   typedef ImportImageContainer<unsigned long, PixelType> PixelContainer;
00119 
00121   typedef Index<VImageDimension>  IndexType;
00122 
00124   typedef Offset<VImageDimension>  OffsetType;
00125 
00127   typedef Size<VImageDimension>  SizeType;
00128 
00130   typedef ImageRegion<VImageDimension>  RegionType;
00131   
00133   typedef typename PixelContainer::Pointer PixelContainerPointer;
00134 
00137   void Allocate();
00138 
00142   void SetRegions(RegionType region)
00143     {
00144     this->SetLargestPossibleRegion(region);
00145     this->SetBufferedRegion(region);
00146     this->SetRequestedRegion(region);
00147     };
00148 
00149   void SetRegions(SizeType size)
00150     {
00151     RegionType region; region.SetSize(size);
00152     this->SetLargestPossibleRegion(region);
00153     this->SetBufferedRegion(region);
00154     this->SetRequestedRegion(region);
00155     };
00156 
00159   virtual void Initialize();
00160 
00162   void FillBuffer (const TPixel& value);
00163   
00168   void SetPixel(const IndexType &index, const TPixel& value)
00169     {
00170     typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00171     (*m_Buffer)[offset] = value;
00172     }
00173   
00178   const TPixel& GetPixel(const IndexType &index) const
00179   {
00180     typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00181     return ( (*m_Buffer)[offset] );
00182   }
00183 
00188   TPixel& GetPixel(const IndexType &index)
00189     {
00190     typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00191     return ( (*m_Buffer)[offset] );
00192     }
00193     
00198   TPixel & operator[](const IndexType &index)
00199      { return this->GetPixel(index); }
00200   
00205   const TPixel& operator[](const IndexType &index) const
00206      { return this->GetPixel(index); }
00207 
00210   TPixel *GetBufferPointer()
00211     { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00212   const TPixel *GetBufferPointer() const
00213     { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00214   
00216   PixelContainer* GetPixelContainer()
00217     { return m_Buffer.GetPointer(); }
00218 
00221   void SetPixelContainer( PixelContainer *container );
00222   
00224   AccessorType GetPixelAccessor( void ) 
00225     { return AccessorType(); }
00226     
00228   const AccessorType GetPixelAccessor( void ) const
00229     { return AccessorType(); }
00230     
00235   virtual void SetSpacing( const double spacing[VImageDimension] );
00236   virtual void SetSpacing( const float spacing[VImageDimension] );
00237   
00242   virtual void SetOrigin( const double origin[VImageDimension] );
00243   virtual void SetOrigin( const float origin[VImageDimension] );
00244 
00249   template<class TCoordRep> 
00250   bool TransformPhysicalPointToContinuousIndex(
00251               const Point<TCoordRep, VImageDimension>& point, 
00252               ContinuousIndex<TCoordRep, VImageDimension>& index   ) const
00253     {
00254     // Update the output index
00255     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00256       { 
00257       index[i] = static_cast<TCoordRep>( (point[i]- m_Origin[i]) / m_Spacing[i] );
00258       }
00259     
00260     // Now, check to see if the index is within allowed bounds
00261     const bool isInside = 
00262       this->GetLargestPossibleRegion().IsInside( index );
00263 
00264     return isInside;
00265     }
00266 
00271   template<class TCoordRep> 
00272   bool TransformPhysicalPointToIndex(
00273             const Point<TCoordRep, VImageDimension>& point, 
00274             IndexType & index                                ) const
00275     {
00276     typedef typename IndexType::IndexValueType IndexValueType;
00277 
00278     // Update the output index
00279     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00280       { 
00281       index[i] = static_cast<IndexValueType>( (point[i]- m_Origin[i]) / m_Spacing[i] );
00282       }
00283     
00284     // Now, check to see if the index is within allowed bounds
00285     const bool isInside = 
00286       this->GetLargestPossibleRegion().IsInside( index );
00287 
00288     return isInside;
00289     }
00290 
00295   template<class TCoordRep> 
00296   void TransformContinuousIndexToPhysicalPoint( 
00297             const ContinuousIndex<TCoordRep, VImageDimension>& index, 
00298             Point<TCoordRep, VImageDimension>& point        ) const
00299     {
00300     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00301       {
00302       point[i] = static_cast<TCoordRep>( m_Spacing[i] * index[i] + m_Origin[i] );
00303       }
00304     }
00305 
00311   template<class TCoordRep> 
00312   void TransformIndexToPhysicalPoint(  
00313                       const IndexType & index, 
00314                       Point<TCoordRep, VImageDimension>& point ) const 
00315     {
00316     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00317       {
00318       point[i] = static_cast<TCoordRep>( m_Spacing[i] * 
00319         static_cast<double>( index[i] ) + m_Origin[i] );
00320       }
00321     }
00322 
00339   virtual void CopyInformation(const DataObject *data);
00340 
00341 protected:
00342   Image();
00343   virtual ~Image();
00344   void PrintSelf(std::ostream& os, Indent indent) const;
00345 
00346 private:
00347   Image(const Self&); //purposely not implemented
00348   void operator=(const Self&); //purposely not implemented
00349 
00351   PixelContainerPointer m_Buffer;
00352 };
00353 
00354 } // end namespace itk
00355   
00356 #ifndef ITK_MANUAL_INSTANTIATION
00357 #include "itkImage.txx"
00358 #endif
00359 
00360 #endif
00361 

Generated at Fri May 21 01:14:52 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000