00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 "itkImageHelper.h"
00032 #include <vnl/vnl_matrix_fixed.txx>
00033
00034 #include "itkImageRegion.h"
00035
00036 namespace itk
00037 {
00038
00045 template <typename TImage>
00046 struct GetImageDimension
00047 {
00048 itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
00049 };
00050
00078 template<unsigned int VImageDimension=2>
00079 class ITK_EXPORT ImageBase : public DataObject
00080 {
00081 public:
00083 typedef ImageBase Self;
00084 typedef DataObject Superclass;
00085 typedef SmartPointer<Self> Pointer;
00086 typedef SmartPointer<const Self> ConstPointer;
00087
00089 itkNewMacro(Self);
00090
00092 itkTypeMacro(ImageBase, DataObject);
00093
00098 itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension );
00099
00101 typedef Index<VImageDimension> IndexType;
00102 typedef typename IndexType::IndexValueType IndexValueType;
00103
00106 typedef Offset<VImageDimension> OffsetType;
00107 typedef typename OffsetType::OffsetValueType OffsetValueType;
00108
00110 typedef Size<VImageDimension> SizeType;
00111 typedef typename SizeType::SizeValueType SizeValueType;
00112
00114 typedef ImageRegion<VImageDimension> RegionType;
00115
00120 typedef Vector<double, VImageDimension> SpacingType;
00121
00124 typedef Point<double, VImageDimension> PointType;
00125
00128 typedef Matrix<double, VImageDimension, VImageDimension> DirectionType;
00129
00131 void Initialize();
00132
00134 static unsigned int GetImageDimension()
00135 { return VImageDimension; }
00136
00141 itkSetMacro(Origin, PointType);
00142 virtual void SetOrigin( const double origin[VImageDimension] );
00143 virtual void SetOrigin( const float origin[VImageDimension] );
00144
00148 virtual void SetDirection( const DirectionType direction );
00149
00153 itkGetConstReferenceMacro(Direction, DirectionType);
00154
00159 itkSetMacro(Spacing, SpacingType);
00160 virtual void SetSpacing( const double spacing[VImageDimension] );
00161 virtual void SetSpacing( const float spacing[VImageDimension] );
00162
00167 itkGetConstReferenceMacro(Spacing, SpacingType);
00168
00173 itkGetConstReferenceMacro(Origin, PointType);
00174
00181 virtual void SetLargestPossibleRegion(const RegionType ®ion);
00182
00189 virtual const RegionType& GetLargestPossibleRegion() const
00190 { return m_LargestPossibleRegion;};
00191
00195 virtual void SetBufferedRegion(const RegionType ®ion);
00196
00200 virtual const RegionType& GetBufferedRegion() const
00201 { return m_BufferedRegion;};
00202
00210 virtual void SetRequestedRegion(const RegionType ®ion);
00211
00219 virtual void SetRequestedRegion(DataObject *data);
00220
00225 virtual const RegionType& GetRequestedRegion() const
00226 { return m_RequestedRegion;};
00227
00238 const OffsetValueType *GetOffsetTable() const { return m_OffsetTable; };
00239
00248 #if 1
00249 inline OffsetValueType ComputeOffset(const IndexType &ind) const
00250 {
00251 OffsetValueType offset = 0;
00252 ImageHelper<VImageDimension,VImageDimension>::ComputeOffset(this->GetBufferedRegion().GetIndex(),
00253 ind,
00254 m_OffsetTable,
00255 offset);
00256 return offset;
00257 }
00258 #else
00259 OffsetValueType ComputeOffset(const IndexType &ind) const
00260 {
00261
00262 OffsetValueType offset=0;
00263 const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
00264
00265
00266
00267 for (int i=VImageDimension-1; i > 0; i--)
00268 {
00269 offset += (ind[i] - bufferedRegionIndex[i])*m_OffsetTable[i];
00270 }
00271 offset += (ind[0] - bufferedRegionIndex[0]);
00272
00273 return offset;
00274 }
00275 #endif
00276
00283 #if 1
00284 inline IndexType ComputeIndex(OffsetValueType offset) const
00285 {
00286 IndexType index;
00287 const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
00288 ImageHelper<VImageDimension,VImageDimension>::ComputeIndex(bufferedRegionIndex,
00289 offset,
00290 m_OffsetTable,
00291 index);
00292 return index;
00293 }
00294 #else
00295 IndexType ComputeIndex(OffsetValueType offset) const
00296 {
00297 IndexType index;
00298 const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
00299
00300 for (int i=VImageDimension-1; i > 0; i--)
00301 {
00302 index[i] = static_cast<IndexValueType>(offset / m_OffsetTable[i]);
00303 offset -= (index[i] * m_OffsetTable[i]);
00304 index[i] += bufferedRegionIndex[i];
00305 }
00306 index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
00307
00308 return index;
00309 }
00310 #endif
00311
00321 virtual void CopyInformation(const DataObject *data);
00322
00333 virtual void Graft(const DataObject *data);
00334
00342 virtual void UpdateOutputInformation();
00343
00347 virtual void SetRequestedRegionToLargestPossibleRegion();
00348
00358 virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
00359
00368 virtual bool VerifyRequestedRegion();
00369
00370 protected:
00371 ImageBase();
00372 ~ImageBase();
00373 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00374
00379 void ComputeOffsetTable();
00380
00381 protected:
00385 SpacingType m_Spacing;
00386 PointType m_Origin;
00387 DirectionType m_Direction;
00388
00389 private:
00390 ImageBase(const Self&);
00391 void operator=(const Self&);
00392
00393 OffsetValueType m_OffsetTable[VImageDimension+1];
00394
00395 RegionType m_LargestPossibleRegion;
00396 RegionType m_RequestedRegion;
00397 RegionType m_BufferedRegion;
00398 };
00399
00400 #ifdef ITK_EXPLICIT_INSTANTIATION
00401 extern template class ImageBase<2>;
00402 extern template class ImageBase<3>;
00403 #endif
00404
00405 }
00406
00407 #ifndef ITK_MANUAL_INSTANTIATION
00408 #include "itkImageBase.txx"
00409 #endif
00410
00411 #endif
00412