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/08/06 03:28:43 $
00007   Version:   $Revision: 1.57 $
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 "itkMatrix.h"
00031 #include <vnl/vnl_matrix_fixed.txx>
00032 
00033 #include "itkImageRegion.h"
00034 
00035 namespace itk
00036 {
00037 
00044 template <typename TImage>
00045 struct GetImageDimension
00046 {
00047   itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
00048 }; 
00049   
00077 template<unsigned int VImageDimension=2>
00078 class ITK_EXPORT ImageBase : public DataObject
00079 {
00080 public:
00082   typedef ImageBase           Self;
00083   typedef DataObject  Superclass;
00084   typedef SmartPointer<Self>  Pointer;
00085   typedef SmartPointer<const Self>  ConstPointer;
00086   
00088   itkNewMacro(Self);
00089 
00091   itkTypeMacro(ImageBase, DataObject);
00092 
00097   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension );
00098 
00100   typedef Index<VImageDimension>  IndexType;
00101   typedef typename IndexType::IndexValueType  IndexValueType;
00102   
00105   typedef Offset<VImageDimension>  OffsetType;
00106   typedef typename OffsetType::OffsetValueType OffsetValueType;
00107 
00109   typedef Size<VImageDimension>  SizeType;
00110   typedef typename SizeType::SizeValueType SizeValueType;
00111     
00113   typedef ImageRegion<VImageDimension>  RegionType;
00114 
00119   typedef Vector<double, VImageDimension> SpacingType;
00120 
00123   typedef Point<double, VImageDimension> PointType;
00124 
00127   typedef Matrix<double, VImageDimension, VImageDimension> DirectionType;
00128 
00130   void Initialize();
00131 
00133   static unsigned int GetImageDimension() 
00134     { return VImageDimension; }
00135 
00140   itkSetMacro(Origin, PointType);
00141   virtual void SetOrigin( const double origin[VImageDimension] );
00142   virtual void SetOrigin( const float origin[VImageDimension] );
00143 
00147   virtual void SetDirection( const DirectionType direction );
00148 
00152   itkGetConstReferenceMacro(Direction, DirectionType);
00153 
00158   itkSetMacro(Spacing, SpacingType);
00159   virtual void SetSpacing( const double spacing[VImageDimension] );
00160   virtual void SetSpacing( const float spacing[VImageDimension] );
00161 
00166   itkGetConstReferenceMacro(Spacing, SpacingType);
00167 
00172   itkGetConstReferenceMacro(Origin, PointType);
00173 
00180   virtual void SetLargestPossibleRegion(const RegionType &region);
00181 
00188   virtual const RegionType& GetLargestPossibleRegion() const
00189     { return m_LargestPossibleRegion;};
00190 
00194   virtual void SetBufferedRegion(const RegionType &region);
00195 
00199   virtual const RegionType& GetBufferedRegion() const
00200   { return m_BufferedRegion;};
00201   
00209   virtual void SetRequestedRegion(const RegionType &region);
00210 
00218   virtual void SetRequestedRegion(DataObject *data);
00219 
00224   virtual const RegionType& GetRequestedRegion() const
00225   { return m_RequestedRegion;};
00226 
00237   const OffsetValueType *GetOffsetTable() const { return m_OffsetTable; };
00238   
00245   OffsetValueType ComputeOffset(const IndexType &ind) const
00246   {
00247     // need to add bounds checking for the region/buffer?
00248     OffsetValueType offset=0;
00249     const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
00250   
00251     // data is arranged as [][][][slice][row][col]
00252     // with Index[0] = col, Index[1] = row, Index[2] = slice
00253     for (int i=VImageDimension-1; i > 0; i--)
00254       {
00255       offset += (ind[i] - bufferedRegionIndex[i])*m_OffsetTable[i];
00256       }
00257     offset += (ind[0] - bufferedRegionIndex[0]);
00258 
00259     return offset;    
00260   }
00261 
00269   IndexType ComputeIndex(OffsetValueType offset) const
00270   {
00271     IndexType index;
00272     const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
00273     
00274     for (int i=VImageDimension-1; i > 0; i--)
00275       {
00276       index[i] = static_cast<IndexValueType>(offset / m_OffsetTable[i]);
00277       offset -= (index[i] * m_OffsetTable[i]);
00278       index[i] += bufferedRegionIndex[i];
00279       }
00280     index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
00281 
00282     return index;    
00283   }
00284 
00294   virtual void CopyInformation(const DataObject *data);
00295 
00306   virtual void Graft(const ImageBase<VImageDimension> *data);
00307 
00315   virtual void UpdateOutputInformation();
00316 
00320   virtual void SetRequestedRegionToLargestPossibleRegion();
00321 
00331   virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
00332 
00341   virtual bool VerifyRequestedRegion();
00342   
00343 protected:
00344   ImageBase();
00345   ~ImageBase();
00346   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00347 
00352   void ComputeOffsetTable();
00353 
00354 protected:
00358   SpacingType  m_Spacing;
00359   PointType   m_Origin;
00360   DirectionType m_Direction;
00361 
00362 private:
00363   ImageBase(const Self&); //purposely not implemented
00364   void operator=(const Self&); //purposely not implemented
00365 
00366   OffsetValueType  m_OffsetTable[VImageDimension+1];
00367 
00368   RegionType          m_LargestPossibleRegion;
00369   RegionType          m_RequestedRegion;
00370   RegionType          m_BufferedRegion;
00371 };
00372 
00373 #ifdef ITK_EXPLICIT_INSTANTIATION
00374    extern template class ImageBase<2>;
00375    extern template class ImageBase<3>;
00376 #endif
00377 
00378 } // end namespace itk
00379 
00380 #ifndef ITK_MANUAL_INSTANTIATION
00381 #include "itkImageBase.txx"
00382 #endif
00383 
00384 #endif
00385 

Generated at Tue Aug 30 16:44:21 2005 for ITK by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2000