00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkImage_h
00018 #define __itkImage_h
00019
00020 #include "itkImageBase.h"
00021 #include "itkImageRegion.h"
00022 #include "itkImportImageContainer.h"
00023 #include "itkDefaultPixelAccessor.h"
00024 #include "itkDefaultPixelAccessorFunctor.h"
00025 #include "itkPoint.h"
00026 #include "itkContinuousIndex.h"
00027 #include "itkFixedArray.h"
00028 #include "itkWeakPointer.h"
00029 #include "itkNeighborhoodAccessorFunctor.h"
00030
00031 namespace itk
00032 {
00033
00082 template <class TPixel, unsigned int VImageDimension=2>
00083 class ITK_EXPORT Image : public ImageBase<VImageDimension>
00084 {
00085 public:
00087 typedef Image Self;
00088 typedef ImageBase<VImageDimension> Superclass;
00089 typedef SmartPointer<Self> Pointer;
00090 typedef SmartPointer<const Self> ConstPointer;
00091 typedef WeakPointer<const Self> ConstWeakPointer;
00092
00094 itkNewMacro(Self);
00095
00097 itkTypeMacro(Image, ImageBase);
00098
00101 typedef TPixel PixelType;
00102
00104 typedef TPixel ValueType ;
00105
00110 typedef TPixel InternalPixelType;
00111
00114 typedef DefaultPixelAccessor< PixelType > AccessorType;
00115 typedef DefaultPixelAccessorFunctor< Self > AccessorFunctorType;
00116
00118 typedef NeighborhoodAccessorFunctor< Self >
00119 NeighborhoodAccessorFunctorType;
00120
00125 itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
00126
00128 typedef ImportImageContainer<unsigned long, PixelType> PixelContainer;
00129
00131 typedef typename Superclass::IndexType IndexType;
00132
00134 typedef typename Superclass::OffsetType OffsetType;
00135
00137 typedef typename Superclass::SizeType SizeType;
00138
00140 typedef typename Superclass::DirectionType DirectionType;
00141
00143 typedef typename Superclass::RegionType RegionType;
00144
00147 typedef typename Superclass::SpacingType SpacingType;
00148
00151 typedef typename Superclass::PointType PointType;
00152
00154 typedef typename PixelContainer::Pointer PixelContainerPointer;
00155 typedef typename PixelContainer::ConstPointer PixelContainerConstPointer;
00156
00158 typedef typename Superclass::OffsetValueType OffsetValueType;
00159
00162 void Allocate();
00163
00167 void SetRegions(RegionType region)
00168 {
00169 this->SetLargestPossibleRegion(region);
00170 this->SetBufferedRegion(region);
00171 this->SetRequestedRegion(region);
00172 };
00173
00174 void SetRegions(SizeType size)
00175 {
00176 RegionType region; region.SetSize(size);
00177 this->SetLargestPossibleRegion(region);
00178 this->SetBufferedRegion(region);
00179 this->SetRequestedRegion(region);
00180 };
00181
00184 virtual void Initialize();
00185
00188 void FillBuffer (const TPixel& value);
00189
00195 void SetPixel(const IndexType &index, const TPixel& value)
00196 {
00197 typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00198 (*m_Buffer)[offset] = value;
00199 }
00200
00205 const TPixel& GetPixel(const IndexType &index) const
00206 {
00207 typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00208 return ( (*m_Buffer)[offset] );
00209 }
00210
00215 TPixel& GetPixel(const IndexType &index)
00216 {
00217 typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00218 return ( (*m_Buffer)[offset] );
00219 }
00220
00225 TPixel & operator[](const IndexType &index)
00226 { return this->GetPixel(index); }
00227
00232 const TPixel& operator[](const IndexType &index) const
00233 { return this->GetPixel(index); }
00234
00237 TPixel *GetBufferPointer()
00238 { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00239 const TPixel *GetBufferPointer() const
00240 { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00241
00243 PixelContainer* GetPixelContainer()
00244 { return m_Buffer.GetPointer(); }
00245
00246 const PixelContainer* GetPixelContainer() const
00247 { return m_Buffer.GetPointer(); }
00248
00251 void SetPixelContainer( PixelContainer *container );
00252
00263 virtual void Graft(const DataObject *data);
00264
00265
00267 AccessorType GetPixelAccessor( void )
00268 { return AccessorType(); }
00269
00271 const AccessorType GetPixelAccessor( void ) const
00272 { return AccessorType(); }
00273
00275 NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
00276 { return NeighborhoodAccessorFunctorType(); }
00277
00279 const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
00280 { return NeighborhoodAccessorFunctorType(); }
00281
00282
00287 template<class TCoordRep>
00288 bool TransformPhysicalPointToContinuousIndex(
00289 const Point<TCoordRep, VImageDimension>& point,
00290 ContinuousIndex<TCoordRep, VImageDimension>& index ) const
00291 {
00292
00293 for (unsigned int i = 0 ; i < VImageDimension ; i++)
00294 {
00295 index[i] = static_cast<TCoordRep>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00296 }
00297
00298
00299 const bool isInside =
00300 this->GetLargestPossibleRegion().IsInside( index );
00301
00302 return isInside;
00303 }
00304
00309 template<class TCoordRep>
00310 bool TransformPhysicalPointToIndex(
00311 const Point<TCoordRep, VImageDimension>& point,
00312 IndexType & index ) const
00313 {
00314 typedef typename IndexType::IndexValueType IndexValueType;
00315
00316
00317 for (unsigned int i = 0 ; i < VImageDimension ; i++)
00318 {
00319 index[i] = static_cast<IndexValueType>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00320 }
00321
00322
00323 const bool isInside =
00324 this->GetLargestPossibleRegion().IsInside( index );
00325
00326 return isInside;
00327 }
00328
00333 template<class TCoordRep>
00334 void TransformContinuousIndexToPhysicalPoint(
00335 const ContinuousIndex<TCoordRep, VImageDimension>& index,
00336 Point<TCoordRep, VImageDimension>& point ) const
00337 {
00338 for (unsigned int i = 0 ; i < VImageDimension ; i++)
00339 {
00340 point[i] = static_cast<TCoordRep>( this->m_Spacing[i] * index[i] + this->m_Origin[i] );
00341 }
00342 }
00343
00349 template<class TCoordRep>
00350 void TransformIndexToPhysicalPoint(
00351 const IndexType & index,
00352 Point<TCoordRep, VImageDimension>& point ) const
00353 {
00354 for (unsigned int i = 0 ; i < VImageDimension ; i++)
00355 {
00356 point[i] = static_cast<TCoordRep>( this->m_Spacing[i] *
00357 static_cast<double>( index[i] ) + this->m_Origin[i] );
00358 }
00359 }
00360
00361 protected:
00362 Image();
00363 void PrintSelf(std::ostream& os, Indent indent) const;
00364 virtual ~Image() {};
00365 private:
00366 Image(const Self&);
00367 void operator=(const Self&);
00368
00370 PixelContainerPointer m_Buffer;
00371 };
00372 #ifdef ITK_EXPLICIT_INSTANTIATION
00373 extern template class Image<float ,2>;
00374 extern template class Image<double ,2>;
00375 extern template class Image<unsigned char ,2>;
00376 extern template class Image<unsigned short,2>;
00377 extern template class Image<unsigned int ,2>;
00378 extern template class Image<signed char ,2>;
00379 extern template class Image<signed short ,2>;
00380 extern template class Image<signed int ,2>;
00381 extern template class Image<float ,3>;
00382 extern template class Image<double ,3>;
00383 extern template class Image<unsigned char ,3>;
00384 extern template class Image<unsigned short,3>;
00385 extern template class Image<unsigned int ,3>;
00386 extern template class Image<signed char ,3>;
00387 extern template class Image<signed short ,3>;
00388 extern template class Image<signed int ,3>;
00389 #endif
00390 }
00391 #ifndef ITK_MANUAL_INSTANTIATION
00392 #include "itkImage.txx"
00393 #endif
00394
00395 #endif
00396