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: 2006/04/20 14:54:09 $
00007   Version:   $Revision: 1.68 $
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 
00025 #include "itkImageRegion.h"
00026 #include "itkIndex.h"
00027 #include "itkObjectFactory.h"
00028 #include "itkOffset.h"
00029 #include "itkPoint.h"
00030 #include "itkSize.h"
00031 #include "itkFixedArray.h"
00032 #include "itkPoint.h"
00033 #include "itkMatrix.h"
00034 #include "itkImageHelper.h"
00035 #include <vnl/vnl_matrix_fixed.txx>
00036 
00037 #include "itkImageRegion.h"
00038 
00039 namespace itk
00040 {
00041 
00048 template <typename TImage>
00049 struct GetImageDimension
00050 {
00051   itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
00052 }; 
00053 
00081 template<unsigned int VImageDimension=2>
00082 class ITK_EXPORT ImageBase : public DataObject
00083 {
00084 public:
00086   typedef ImageBase           Self;
00087   typedef DataObject  Superclass;
00088   typedef SmartPointer<Self>  Pointer;
00089   typedef SmartPointer<const Self>  ConstPointer;
00090 
00092   itkNewMacro(Self);
00093 
00095   itkTypeMacro(ImageBase, DataObject);
00096 
00101   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension );
00102 
00104   typedef Index<VImageDimension>  IndexType;
00105   typedef typename IndexType::IndexValueType  IndexValueType;
00106 
00109   typedef Offset<VImageDimension>  OffsetType;
00110   typedef typename OffsetType::OffsetValueType OffsetValueType;
00111 
00113   typedef Size<VImageDimension>  SizeType;
00114   typedef typename SizeType::SizeValueType SizeValueType;
00115 
00117   typedef ImageRegion<VImageDimension>  RegionType;
00118 
00123   typedef Vector<double, VImageDimension> SpacingType;
00124 
00127   typedef Point<double, VImageDimension> PointType;
00128 
00131   typedef Matrix<double, VImageDimension, VImageDimension> DirectionType;
00132 
00134   void Initialize();
00135 
00137   static unsigned int GetImageDimension() 
00138     { return VImageDimension; }
00139 
00144   itkSetMacro(Origin, PointType);
00145   virtual void SetOrigin( const double origin[VImageDimension] );
00146   virtual void SetOrigin( const float origin[VImageDimension] );
00148 
00152   virtual void SetDirection( const DirectionType direction );
00153 
00157   itkGetConstReferenceMacro(Direction, DirectionType);
00158 
00163   itkSetMacro(Spacing, SpacingType);
00164   virtual void SetSpacing( const double spacing[VImageDimension] );
00165   virtual void SetSpacing( const float spacing[VImageDimension] );
00167 
00172   itkGetConstReferenceMacro(Spacing, SpacingType);
00173 
00178   itkGetConstReferenceMacro(Origin, PointType);
00179 
00186   virtual void SetLargestPossibleRegion(const RegionType &region);
00187 
00194   virtual const RegionType& GetLargestPossibleRegion() const
00195     { return m_LargestPossibleRegion;};
00196 
00200   virtual void SetBufferedRegion(const RegionType &region);
00201 
00205   virtual const RegionType& GetBufferedRegion() const
00206   { return m_BufferedRegion;};
00207 
00215   virtual void SetRequestedRegion(const RegionType &region);
00216 
00224   virtual void SetRequestedRegion(DataObject *data);
00225 
00230   virtual const RegionType& GetRequestedRegion() const
00231   { return m_RequestedRegion;};
00232 
00243   const OffsetValueType *GetOffsetTable() const { return m_OffsetTable; };
00245 
00254 #if 1
00255   inline OffsetValueType ComputeOffset(const IndexType &ind) const
00256   {
00257     OffsetValueType offset = 0;
00258     ImageHelper<VImageDimension,VImageDimension>::ComputeOffset(this->GetBufferedRegion().GetIndex(),
00259                                                                 ind,
00260                                                                 m_OffsetTable,
00261                                                                 offset);
00262     return offset;
00263   }
00264 #else
00265   OffsetValueType ComputeOffset(const IndexType &ind) const
00266   {
00267     // need to add bounds checking for the region/buffer?
00268     OffsetValueType offset=0;
00269     const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
00270   
00271     // data is arranged as [][][][slice][row][col]
00272     // with Index[0] = col, Index[1] = row, Index[2] = slice
00273     for (int i=VImageDimension-1; i > 0; i--)
00274       {
00275       offset += (ind[i] - bufferedRegionIndex[i])*m_OffsetTable[i];
00276       }
00277     offset += (ind[0] - bufferedRegionIndex[0]);
00278 
00279     return offset;    
00280   }
00281 #endif
00282 
00289 #if 1
00290   inline IndexType ComputeIndex(OffsetValueType offset) const
00291   {
00292     IndexType index;
00293     const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
00294     ImageHelper<VImageDimension,VImageDimension>::ComputeIndex(bufferedRegionIndex,
00295                                                                offset,
00296                                                                m_OffsetTable,
00297                                                                index);
00298     return index;
00299   }
00300 #else
00301   IndexType ComputeIndex(OffsetValueType offset) const
00302   {
00303     IndexType index;
00304     const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
00306 
00307     for (int i=VImageDimension-1; i > 0; i--)
00308       {
00309       index[i] = static_cast<IndexValueType>(offset / m_OffsetTable[i]);
00310       offset -= (index[i] * m_OffsetTable[i]);
00311       index[i] += bufferedRegionIndex[i];
00312       }
00313     index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
00314 
00315     return index;    
00316   }
00317 #endif
00318 
00328   virtual void CopyInformation(const DataObject *data);
00329 
00340   virtual void Graft(const DataObject *data);
00341 
00349   virtual void UpdateOutputInformation();
00350 
00354   virtual void SetRequestedRegionToLargestPossibleRegion();
00355 
00365   virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
00366 
00375   virtual bool VerifyRequestedRegion();
00376 
00393   virtual unsigned int GetNumberOfComponentsPerPixel() const;
00394   virtual void SetNumberOfComponentsPerPixel( unsigned int ); 
00396 
00397 protected:
00398   ImageBase();
00399   ~ImageBase();
00400   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00401 
00406   void ComputeOffsetTable();
00407 
00408 protected:
00412   SpacingType  m_Spacing;
00413   PointType   m_Origin;
00414   DirectionType m_Direction;
00415 
00416 private:
00417   ImageBase(const Self&); //purposely not implemented
00418   void operator=(const Self&); //purposely not implemented
00419 
00420   OffsetValueType  m_OffsetTable[VImageDimension+1];
00421 
00422   RegionType          m_LargestPossibleRegion;
00423   RegionType          m_RequestedRegion;
00424   RegionType          m_BufferedRegion;
00425 };
00426 
00427 } // end namespace itk
00428 
00429 // Define instantiation macro for this template.
00430 #define ITK_TEMPLATE_ImageBase(_, EXPORT, x, y) namespace itk { \
00431   _(1(class EXPORT ImageBase< ITK_TEMPLATE_1 x >)) \
00432   namespace Templates { typedef ImageBase< ITK_TEMPLATE_1 x > ImageBase##y; } \
00433   }
00434 
00435 #if ITK_TEMPLATE_EXPLICIT
00436 # include "Templates/itkImageBase+-.h"
00437 #endif
00438 
00439 #if ITK_TEMPLATE_TXX
00440 # include "itkImageBase.txx"
00441 #endif
00442 
00443 #endif
00444 

Generated at Sun Sep 23 12:55:05 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000