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

itkImageBase.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageBase.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/03/21 02:08:37 $
00007   Version:   $Revision: 1.53.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   Portions of this code are covered under the VTK copyright.
00013   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
00014 
00015      This software is distributed WITHOUT ANY WARRANTY; without even 
00016      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00017      PURPOSE.  See the above copyright notices for more information.
00018 
00019 =========================================================================*/
00020 #ifndef __itkImageBase_h
00021 #define __itkImageBase_h
00022 
00023 #include "itkDataObject.h"
00024 #include "itkProcessObject.h"
00025 #include "itkIndex.h"
00026 #include "itkOffset.h"
00027 #include "itkSize.h"
00028 #include "itkFixedArray.h"
00029 #include "itkPoint.h"
00030 #include "itkImageRegion.h"
00031 
00032 namespace itk
00033 {
00034 
00041 template <typename TImage>
00042 struct GetImageDimension
00043 {
00044   itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
00045 }; 
00046   
00047 
00075 template<unsigned int VImageDimension=2>
00076 class ITK_EXPORT ImageBase : public DataObject
00077 {
00078 public:
00080   typedef ImageBase           Self;
00081   typedef DataObject  Superclass;
00082   typedef SmartPointer<Self>  Pointer;
00083   typedef SmartPointer<const Self>  ConstPointer;
00084   
00086   itkNewMacro(Self);
00087 
00089   itkTypeMacro(ImageBase, DataObject);
00090 
00095   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension );
00096 
00098   typedef Index<VImageDimension>  IndexType;
00099   typedef typename IndexType::IndexValueType  IndexValueType;
00100   
00103   typedef Offset<VImageDimension>  OffsetType;
00104   typedef typename OffsetType::OffsetValueType OffsetValueType;
00105 
00107   typedef Size<VImageDimension>  SizeType;
00108   typedef typename SizeType::SizeValueType SizeValueType;
00109     
00111   typedef ImageRegion<VImageDimension>  RegionType;
00112 
00115   typedef Vector<double, VImageDimension> SpacingType;
00116 
00119   typedef Point<double, VImageDimension> PointType;
00120 
00122   void Initialize();
00123 
00125   static unsigned int GetImageDimension() 
00126     { return VImageDimension; }
00127 
00132   itkSetMacro(Origin, PointType);
00133   virtual void SetOrigin( const double origin[VImageDimension] );
00134   virtual void SetOrigin( const float origin[VImageDimension] );
00135 
00140   itkSetMacro(Spacing, SpacingType);
00141   virtual void SetSpacing( const double spacing[VImageDimension] );
00142   virtual void SetSpacing( const float spacing[VImageDimension] );
00143 
00148   itkGetConstReferenceMacro(Spacing, SpacingType);
00149 
00154   itkGetConstReferenceMacro(Origin, PointType);
00155 
00162   virtual void SetLargestPossibleRegion(const RegionType &region);
00163 
00170   virtual const RegionType& GetLargestPossibleRegion() const
00171     { return m_LargestPossibleRegion;};
00172 
00176   virtual void SetBufferedRegion(const RegionType &region);
00177 
00181   virtual const RegionType& GetBufferedRegion() const
00182   { return m_BufferedRegion;};
00183   
00191   virtual void SetRequestedRegion(const RegionType &region);
00192 
00200   virtual void SetRequestedRegion(DataObject *data);
00201 
00206   virtual const RegionType& GetRequestedRegion() const
00207   { return m_RequestedRegion;};
00208 
00219   const OffsetValueType *GetOffsetTable() const { return m_OffsetTable; };
00220   
00227   OffsetValueType ComputeOffset(const IndexType &ind) const
00228   {
00229     // need to add bounds checking for the region/buffer?
00230     OffsetValueType offset=0;
00231     const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00232   
00233     // data is arranged as [][][][slice][row][col]
00234     // with Index[0] = col, Index[1] = row, Index[2] = slice
00235     for (int i=VImageDimension-1; i > 0; i--)
00236       {
00237       offset += (ind[i] - bufferedRegionIndex[i])*m_OffsetTable[i];
00238       }
00239     offset += (ind[0] - bufferedRegionIndex[0]);
00240 
00241     return offset;
00242   }
00243 
00251   IndexType ComputeIndex(OffsetValueType offset) const
00252   {
00253     IndexType index;
00254     const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00255     
00256     for (int i=VImageDimension-1; i > 0; i--)
00257       {
00258       index[i] = static_cast<IndexValueType>(offset / m_OffsetTable[i]);
00259       offset -= (index[i] * m_OffsetTable[i]);
00260       index[i] += bufferedRegionIndex[i];
00261       }
00262     index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
00263 
00264     return index;
00265   }
00266 
00276   virtual void CopyInformation(const DataObject *data);
00277 
00288   virtual void Graft(const ImageBase<VImageDimension> *data);
00289 
00297   virtual void UpdateOutputInformation();
00298 
00302   virtual void SetRequestedRegionToLargestPossibleRegion();
00303 
00313   virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
00314 
00323   virtual bool VerifyRequestedRegion();
00324   
00325 protected:
00326   ImageBase();
00327   ~ImageBase();
00328   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00329 
00334   void ComputeOffsetTable();
00335 
00336 protected:
00340   SpacingType  m_Spacing;
00341   PointType   m_Origin;
00342 
00343 private:
00344   ImageBase(const Self&); //purposely not implemented
00345   void operator=(const Self&); //purposely not implemented
00346 
00347   OffsetValueType  m_OffsetTable[VImageDimension+1];
00348 
00349   RegionType          m_LargestPossibleRegion;
00350   RegionType          m_RequestedRegion;
00351   RegionType          m_BufferedRegion;
00352 };
00353 
00354 #ifdef ITK_EXPLICIT_INSTANTIATION
00355    extern template class ImageBase<2>;
00356    extern template class ImageBase<3>;
00357 #endif
00358 
00359 } // end namespace itk
00360 
00361 #ifndef ITK_MANUAL_INSTANTIATION
00362 #include "itkImageBase.txx"
00363 #endif
00364 
00365 #endif
00366 

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