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: 2008-02-04 12:34:11 $
00007   Version:   $Revision: 1.143 $
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 
00120   typedef NeighborhoodAccessorFunctor< Self >  NeighborhoodAccessorFunctorType;
00121 
00126   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
00127 
00129   typedef ImportImageContainer<unsigned long, PixelType> PixelContainer;
00130 
00132   typedef typename Superclass::IndexType       IndexType;
00133   typedef typename Superclass::IndexValueType  IndexValueType;
00134 
00136   typedef typename Superclass::OffsetType OffsetType;
00137 
00139   typedef typename Superclass::SizeType  SizeType;
00140 
00142   typedef typename Superclass::DirectionType  DirectionType;
00143 
00145   typedef typename Superclass::RegionType  RegionType;
00146 
00149   typedef typename Superclass::SpacingType SpacingType;
00150 
00153   typedef typename Superclass::PointType PointType;
00154 
00156   typedef typename PixelContainer::Pointer        PixelContainerPointer;
00157   typedef typename PixelContainer::ConstPointer   PixelContainerConstPointer;
00158 
00160   typedef typename Superclass::OffsetValueType OffsetValueType;
00161 
00164   void Allocate();
00165 
00169   void SetRegions(RegionType region)
00170     {
00171     this->SetLargestPossibleRegion(region);
00172     this->SetBufferedRegion(region);
00173     this->SetRequestedRegion(region);
00174     };
00176 
00177   void SetRegions(SizeType size)
00178     {
00179     RegionType region; region.SetSize(size);
00180     this->SetLargestPossibleRegion(region);
00181     this->SetBufferedRegion(region);
00182     this->SetRequestedRegion(region);
00183     };
00184 
00187   virtual void Initialize();
00188 
00191   void FillBuffer (const TPixel& value);
00192 
00198   void SetPixel(const IndexType &index, const TPixel& value)
00199     {
00200     typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00201     (*m_Buffer)[offset] = value;
00202     }
00203 
00208   const TPixel& GetPixel(const IndexType &index) const
00209     {
00210     typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00211     return ( (*m_Buffer)[offset] );
00212     }
00213 
00218   TPixel& GetPixel(const IndexType &index)
00219     {
00220     typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00221     return ( (*m_Buffer)[offset] );
00222     }
00223 
00228   TPixel & operator[](const IndexType &index)
00229     { return this->GetPixel(index); }
00230 
00235   const TPixel& operator[](const IndexType &index) const
00236      { return this->GetPixel(index); }
00237 
00240   TPixel *GetBufferPointer()
00241     { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00242   const TPixel *GetBufferPointer() const
00243     { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00245 
00247   PixelContainer* GetPixelContainer()
00248     { return m_Buffer.GetPointer(); }
00249 
00250   const PixelContainer* GetPixelContainer() const
00251     { return m_Buffer.GetPointer(); }
00252 
00255   void SetPixelContainer( PixelContainer *container );
00256 
00267   virtual void Graft(const DataObject *data);
00268 
00269   
00271   AccessorType GetPixelAccessor( void ) 
00272     { return AccessorType(); }
00273 
00275   const AccessorType GetPixelAccessor( void ) const
00276     { return AccessorType(); }
00277 
00279   NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() 
00280     { return NeighborhoodAccessorFunctorType(); }
00281 
00283   const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
00284     { return NeighborhoodAccessorFunctorType(); }
00285 
00286 
00291   template<class TCoordRep>
00292   bool TransformPhysicalPointToContinuousIndex(
00293               const Point<TCoordRep, VImageDimension>& point,
00294               ContinuousIndex<TCoordRep, VImageDimension>& index   ) const
00295     {
00296     // Update the output index
00297     for (unsigned int i = 0; i < VImageDimension; i++)
00298       {
00299       index[i] = static_cast<TCoordRep>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00300       }
00301 
00302     // Now, check to see if the index is within allowed bounds
00303     const bool isInside =
00304       this->GetLargestPossibleRegion().IsInside( index );
00305 
00306     return isInside;
00307     }
00308 
00313   template<class TCoordRep>
00314   bool TransformPhysicalPointToIndex(
00315             const Point<TCoordRep, VImageDimension>& point,
00316             IndexType & index                                ) const
00317     {
00318     // Update the output index
00319     for (unsigned int i = 0; i < VImageDimension; i++)
00320       {
00321       index[i] = static_cast<IndexValueType>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00322       }
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 
00378   template<class TCoordRep>
00379   void TransformLocalVectorToPhysicalVector(
00380     const FixedArray<TCoordRep, VImageDimension> & inputGradient,
00381           FixedArray<TCoordRep, VImageDimension> & outputGradient ) const
00382     {
00383     for( unsigned int i = 0; i < VImageDimension; i++ )
00384       {
00385       outputGradient[i] = inputGradient[i];
00386       }
00387     }
00389 
00390 protected:
00391   Image();
00392   void PrintSelf(std::ostream& os, Indent indent) const;
00393   virtual ~Image() {};
00394 private:
00395   Image(const Self&); //purposely not implemented
00396   void operator=(const Self&); //purposely not implemented
00397 
00399   PixelContainerPointer m_Buffer;
00400 };
00401 
00402 } // end namespace itk
00403 
00404 // Define instantiation macro for this template.
00405 #define ITK_TEMPLATE_Image(_, EXPORT, x, y) namespace itk { \
00406   _(2(class EXPORT Image< ITK_TEMPLATE_2 x >)) \
00407   namespace Templates { typedef Image< ITK_TEMPLATE_2 x > Image##y; } \
00408   }
00409 
00410 #if ITK_TEMPLATE_EXPLICIT
00411 # include "Templates/itkImage+-.h"
00412 #endif
00413 
00414 #if ITK_TEMPLATE_TXX
00415 # include "itkImage.txx"
00416 #endif
00417 
00418 #endif
00419 

Generated at Mon Apr 14 12:49:02 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000