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: 2007/10/21 18:03:05 $
00007   Version:   $Revision: 1.69 $
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 
00132   typedef Matrix<double, VImageDimension, VImageDimension> DirectionType;
00133 
00135   void Initialize();
00136 
00138   static unsigned int GetImageDimension() 
00139     { return VImageDimension; }
00140 
00145   itkSetMacro(Origin, PointType);
00146   virtual void SetOrigin( const double origin[VImageDimension] );
00147   virtual void SetOrigin( const float origin[VImageDimension] );
00149 
00176   virtual void SetDirection( const DirectionType direction );
00177 
00181   itkGetConstReferenceMacro(Direction, DirectionType);
00182 
00187   itkSetMacro(Spacing, SpacingType);
00188   virtual void SetSpacing( const double spacing[VImageDimension] );
00189   virtual void SetSpacing( const float spacing[VImageDimension] );
00191 
00196   itkGetConstReferenceMacro(Spacing, SpacingType);
00197 
00202   itkGetConstReferenceMacro(Origin, PointType);
00203 
00210   virtual void SetLargestPossibleRegion(const RegionType &region);
00211 
00218   virtual const RegionType& GetLargestPossibleRegion() const
00219     { return m_LargestPossibleRegion;};
00220 
00224   virtual void SetBufferedRegion(const RegionType &region);
00225 
00229   virtual const RegionType& GetBufferedRegion() const
00230   { return m_BufferedRegion;};
00231 
00239   virtual void SetRequestedRegion(const RegionType &region);
00240 
00248   virtual void SetRequestedRegion(DataObject *data);
00249 
00254   virtual const RegionType& GetRequestedRegion() const
00255   { return m_RequestedRegion;};
00256 
00267   const OffsetValueType *GetOffsetTable() const { return m_OffsetTable; };
00269 
00278 #if 1
00279   inline OffsetValueType ComputeOffset(const IndexType &ind) const
00280   {
00281     OffsetValueType offset = 0;
00282     ImageHelper<VImageDimension,VImageDimension>::ComputeOffset(this->GetBufferedRegion().GetIndex(),
00283                                                                 ind,
00284                                                                 m_OffsetTable,
00285                                                                 offset);
00286     return offset;
00287   }
00288 #else
00289   OffsetValueType ComputeOffset(const IndexType &ind) const
00290   {
00291     // need to add bounds checking for the region/buffer?
00292     OffsetValueType offset=0;
00293     const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
00294   
00295     // data is arranged as [][][][slice][row][col]
00296     // with Index[0] = col, Index[1] = row, Index[2] = slice
00297     for (int i=VImageDimension-1; i > 0; i--)
00298       {
00299       offset += (ind[i] - bufferedRegionIndex[i])*m_OffsetTable[i];
00300       }
00301     offset += (ind[0] - bufferedRegionIndex[0]);
00302 
00303     return offset;    
00304   }
00305 #endif
00306 
00313 #if 1
00314   inline IndexType ComputeIndex(OffsetValueType offset) const
00315   {
00316     IndexType index;
00317     const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
00318     ImageHelper<VImageDimension,VImageDimension>::ComputeIndex(bufferedRegionIndex,
00319                                                                offset,
00320                                                                m_OffsetTable,
00321                                                                index);
00322     return index;
00323   }
00324 #else
00325   IndexType ComputeIndex(OffsetValueType offset) const
00326   {
00327     IndexType index;
00328     const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
00330 
00331     for (int i=VImageDimension-1; i > 0; i--)
00332       {
00333       index[i] = static_cast<IndexValueType>(offset / m_OffsetTable[i]);
00334       offset -= (index[i] * m_OffsetTable[i]);
00335       index[i] += bufferedRegionIndex[i];
00336       }
00337     index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
00338 
00339     return index;    
00340   }
00341 #endif
00342 
00352   virtual void CopyInformation(const DataObject *data);
00353 
00364   virtual void Graft(const DataObject *data);
00365 
00373   virtual void UpdateOutputInformation();
00374 
00378   virtual void SetRequestedRegionToLargestPossibleRegion();
00379 
00389   virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
00390 
00399   virtual bool VerifyRequestedRegion();
00400 
00417   virtual unsigned int GetNumberOfComponentsPerPixel() const;
00418   virtual void SetNumberOfComponentsPerPixel( unsigned int ); 
00420 
00421 protected:
00422   ImageBase();
00423   ~ImageBase();
00424   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00425 
00430   void ComputeOffsetTable();
00431 
00432 protected:
00436   SpacingType  m_Spacing;
00437   PointType   m_Origin;
00438   DirectionType m_Direction;
00439 
00440 private:
00441   ImageBase(const Self&); //purposely not implemented
00442   void operator=(const Self&); //purposely not implemented
00443 
00444   OffsetValueType  m_OffsetTable[VImageDimension+1];
00445 
00446   RegionType          m_LargestPossibleRegion;
00447   RegionType          m_RequestedRegion;
00448   RegionType          m_BufferedRegion;
00449 };
00450 
00451 } // end namespace itk
00452 
00453 // Define instantiation macro for this template.
00454 #define ITK_TEMPLATE_ImageBase(_, EXPORT, x, y) namespace itk { \
00455   _(1(class EXPORT ImageBase< ITK_TEMPLATE_1 x >)) \
00456   namespace Templates { typedef ImageBase< ITK_TEMPLATE_1 x > ImageBase##y; } \
00457   }
00458 
00459 #if ITK_TEMPLATE_EXPLICIT
00460 # include "Templates/itkImageBase+-.h"
00461 #endif
00462 
00463 #if ITK_TEMPLATE_TXX
00464 # include "itkImageBase.txx"
00465 #endif
00466 
00467 #endif
00468 

Generated at Tue Jul 29 20:29:16 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000