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: 2005/03/21 02:08:37 $
00007   Version:   $Revision: 1.122.2.1 $
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 "itkPoint.h"
00025 #include "itkContinuousIndex.h"
00026 #include "itkFixedArray.h"
00027 #include "itkWeakPointer.h"
00028 
00029 namespace itk
00030 {
00031 
00080 template <class TPixel, unsigned int VImageDimension=2>
00081 class ITK_EXPORT Image : public ImageBase<VImageDimension>
00082 {
00083 public:
00085   typedef Image               Self;
00086   typedef ImageBase<VImageDimension>  Superclass;
00087   typedef SmartPointer<Self>  Pointer;
00088   typedef SmartPointer<const Self>  ConstPointer;
00089   typedef WeakPointer<const Self>  ConstWeakPointer;
00090 
00092   itkNewMacro(Self);
00093 
00095   itkTypeMacro(Image, ImageBase);
00096 
00099   typedef TPixel PixelType;
00100 
00102   typedef TPixel ValueType ;
00103 
00108   typedef TPixel InternalPixelType;
00109 
00112   typedef DefaultPixelAccessor< PixelType > AccessorType;
00113 
00118   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
00119 
00121   typedef ImportImageContainer<unsigned long, PixelType> PixelContainer;
00122 
00124   typedef typename Superclass::IndexType  IndexType;
00125 
00127   typedef typename Superclass::OffsetType OffsetType;
00128 
00130   typedef typename Superclass::SizeType  SizeType;
00131 
00133   typedef typename Superclass::RegionType  RegionType;
00134 
00137   typedef typename Superclass::SpacingType SpacingType;
00138 
00141   typedef typename Superclass::PointType PointType;
00142 
00144   typedef typename PixelContainer::Pointer PixelContainerPointer;
00145   typedef typename PixelContainer::ConstPointer PixelContainerConstPointer;
00146 
00149   void Allocate();
00150 
00154   void SetRegions(RegionType region)
00155     {
00156     this->SetLargestPossibleRegion(region);
00157     this->SetBufferedRegion(region);
00158     this->SetRequestedRegion(region);
00159     };
00160 
00161   void SetRegions(SizeType size)
00162     {
00163     RegionType region; region.SetSize(size);
00164     this->SetLargestPossibleRegion(region);
00165     this->SetBufferedRegion(region);
00166     this->SetRequestedRegion(region);
00167     };
00168 
00171   virtual void Initialize();
00172 
00175   void FillBuffer (const TPixel& value);
00176 
00182   void SetPixel(const IndexType &index, const TPixel& value)
00183     {
00184     typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00185     (*m_Buffer)[offset] = value;
00186     }
00187 
00192   const TPixel& GetPixel(const IndexType &index) const
00193   {
00194     typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00195     return ( (*m_Buffer)[offset] );
00196   }
00197 
00202   TPixel& GetPixel(const IndexType &index)
00203     {
00204     typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00205     return ( (*m_Buffer)[offset] );
00206     }
00207 
00212   TPixel & operator[](const IndexType &index)
00213      { return this->GetPixel(index); }
00214 
00219   const TPixel& operator[](const IndexType &index) const
00220      { return this->GetPixel(index); }
00221 
00224   TPixel *GetBufferPointer()
00225     { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00226   const TPixel *GetBufferPointer() const
00227     { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00228 
00230   PixelContainer* GetPixelContainer()
00231     { return m_Buffer.GetPointer(); }
00232 
00233   const PixelContainer* GetPixelContainer() const
00234     { return m_Buffer.GetPointer(); }
00235 
00238   void SetPixelContainer( PixelContainer *container );
00239 
00250   virtual void Graft(const ImageBase<VImageDimension> *data);
00251 
00252   
00254   AccessorType GetPixelAccessor( void )
00255     { return AccessorType(); }
00256 
00258   const AccessorType GetPixelAccessor( void ) const
00259     { return AccessorType(); }
00260 
00265   template<class TCoordRep>
00266   bool TransformPhysicalPointToContinuousIndex(
00267               const Point<TCoordRep, VImageDimension>& point,
00268               ContinuousIndex<TCoordRep, VImageDimension>& index   ) const
00269     {
00270     // Update the output index
00271     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00272       {
00273       index[i] = static_cast<TCoordRep>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00274       }
00275 
00276     // Now, check to see if the index is within allowed bounds
00277     const bool isInside =
00278       this->GetLargestPossibleRegion().IsInside( index );
00279 
00280     return isInside;
00281     }
00282 
00287   template<class TCoordRep>
00288   bool TransformPhysicalPointToIndex(
00289             const Point<TCoordRep, VImageDimension>& point,
00290             IndexType & index                                ) const
00291     {
00292     typedef typename IndexType::IndexValueType IndexValueType;
00293 
00294     // Update the output index
00295     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00296       {
00297       index[i] = static_cast<IndexValueType>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00298       }
00299 
00300     // Now, check to see if the index is within allowed bounds
00301     const bool isInside =
00302       this->GetLargestPossibleRegion().IsInside( index );
00303 
00304     return isInside;
00305     }
00306 
00311   template<class TCoordRep>
00312   void TransformContinuousIndexToPhysicalPoint(
00313             const ContinuousIndex<TCoordRep, VImageDimension>& index,
00314             Point<TCoordRep, VImageDimension>& point        ) const
00315     {
00316     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00317       {
00318       point[i] = static_cast<TCoordRep>( this->m_Spacing[i] * index[i] + this->m_Origin[i] );
00319       }
00320     }
00321 
00327   template<class TCoordRep>
00328   void TransformIndexToPhysicalPoint(
00329                       const IndexType & index,
00330                       Point<TCoordRep, VImageDimension>& point ) const
00331     {
00332     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00333       {
00334       point[i] = static_cast<TCoordRep>( this->m_Spacing[i] *
00335         static_cast<double>( index[i] ) + this->m_Origin[i] );
00336       }
00337     }
00338 
00339 protected:
00340   Image();
00341   void PrintSelf(std::ostream& os, Indent indent) const;
00342   virtual ~Image() {};
00343 private:
00344   Image(const Self&); //purposely not implemented
00345   void operator=(const Self&); //purposely not implemented
00346 
00348   PixelContainerPointer m_Buffer;
00349 };
00350 #ifdef ITK_EXPLICIT_INSTANTIATION
00351    extern template class Image<float         ,2>;
00352    extern template class Image<double        ,2>;
00353    extern template class Image<unsigned char ,2>;
00354    extern template class Image<unsigned short,2>;
00355    extern template class Image<unsigned int  ,2>;
00356    extern template class Image<signed char   ,2>;
00357    extern template class Image<signed short  ,2>;
00358    extern template class Image<signed int    ,2>;
00359    extern template class Image<float         ,3>;
00360    extern template class Image<double        ,3>;
00361    extern template class Image<unsigned char ,3>;
00362    extern template class Image<unsigned short,3>;
00363    extern template class Image<unsigned int  ,3>;
00364    extern template class Image<signed char   ,3>;
00365    extern template class Image<signed short  ,3>;
00366    extern template class Image<signed int    ,3>;
00367 #endif
00368 } // end namespace itk
00369 #ifndef ITK_MANUAL_INSTANTIATION
00370 #include "itkImage.txx"
00371 #endif
00372 
00373 #endif
00374 

Generated at Tue Mar 29 23:54:20 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000