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
00030 namespace itk
00031 {
00032
00081 template <class TPixel, unsigned int VImageDimension=2>
00082 class ITK_EXPORT Image : public ImageBase<VImageDimension>
00083 {
00084 public:
00086 typedef Image Self;
00087 typedef ImageBase<VImageDimension> Superclass;
00088 typedef SmartPointer<Self> Pointer;
00089 typedef SmartPointer<const Self> ConstPointer;
00090 typedef WeakPointer<const Self> ConstWeakPointer;
00091
00093 itkNewMacro(Self);
00094
00096 itkTypeMacro(Image, ImageBase);
00097
00100 typedef TPixel PixelType;
00101
00103 typedef TPixel ValueType ;
00104
00109 typedef TPixel InternalPixelType;
00110
00113 typedef DefaultPixelAccessor< PixelType > AccessorType;
00114 typedef DefaultPixelAccessorFunctor< Self > AccessorFunctorType;
00115
00120 itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
00121
00123 typedef ImportImageContainer<unsigned long, PixelType> PixelContainer;
00124
00126 typedef typename Superclass::IndexType IndexType;
00127
00129 typedef typename Superclass::OffsetType OffsetType;
00130
00132 typedef typename Superclass::SizeType SizeType;
00133
00135 typedef typename Superclass::DirectionType DirectionType;
00136
00138 typedef typename Superclass::RegionType RegionType;
00139
00142 typedef typename Superclass::SpacingType SpacingType;
00143
00146 typedef typename Superclass::PointType PointType;
00147
00149 typedef typename PixelContainer::Pointer PixelContainerPointer;
00150 typedef typename PixelContainer::ConstPointer PixelContainerConstPointer;
00151
00153 typedef typename Superclass::OffsetValueType OffsetValueType;
00154
00157 void Allocate();
00158
00162 void SetRegions(RegionType region)
00163 {
00164 this->SetLargestPossibleRegion(region);
00165 this->SetBufferedRegion(region);
00166 this->SetRequestedRegion(region);
00167 };
00168
00169 void SetRegions(SizeType size)
00170 {
00171 RegionType region; region.SetSize(size);
00172 this->SetLargestPossibleRegion(region);
00173 this->SetBufferedRegion(region);
00174 this->SetRequestedRegion(region);
00175 };
00176
00179 virtual void Initialize();
00180
00183 void FillBuffer (const TPixel& value);
00184
00190 void SetPixel(const IndexType &index, const TPixel& value)
00191 {
00192 typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00193 (*m_Buffer)[offset] = value;
00194 }
00195
00200 const TPixel& GetPixel(const IndexType &index) const
00201 {
00202 typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00203 return ( (*m_Buffer)[offset] );
00204 }
00205
00210 TPixel& GetPixel(const IndexType &index)
00211 {
00212 typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
00213 return ( (*m_Buffer)[offset] );
00214 }
00215
00220 TPixel & operator[](const IndexType &index)
00221 { return this->GetPixel(index); }
00222
00227 const TPixel& operator[](const IndexType &index) const
00228 { return this->GetPixel(index); }
00229
00232 TPixel *GetBufferPointer()
00233 { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00234 const TPixel *GetBufferPointer() const
00235 { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00236
00238 PixelContainer* GetPixelContainer()
00239 { return m_Buffer.GetPointer(); }
00240
00241 const PixelContainer* GetPixelContainer() const
00242 { return m_Buffer.GetPointer(); }
00243
00246 void SetPixelContainer( PixelContainer *container );
00247
00258 virtual void Graft(const ImageBase<VImageDimension> *data);
00259
00260
00262 AccessorType GetPixelAccessor( void )
00263 { return AccessorType(); }
00264
00266 const AccessorType GetPixelAccessor( void ) const
00267 { return AccessorType(); }
00268
00273 template<class TCoordRep>
00274 bool TransformPhysicalPointToContinuousIndex(
00275 const Point<TCoordRep, VImageDimension>& point,
00276 ContinuousIndex<TCoordRep, VImageDimension>& index ) const
00277 {
00278
00279 for (unsigned int i = 0 ; i < VImageDimension ; i++)
00280 {
00281 index[i] = static_cast<TCoordRep>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00282 }
00283
00284
00285 const bool isInside =
00286 this->GetLargestPossibleRegion().IsInside( index );
00287
00288 return isInside;
00289 }
00290
00295 template<class TCoordRep>
00296 bool TransformPhysicalPointToIndex(
00297 const Point<TCoordRep, VImageDimension>& point,
00298 IndexType & index ) const
00299 {
00300 typedef typename IndexType::IndexValueType IndexValueType;
00301
00302
00303 for (unsigned int i = 0 ; i < VImageDimension ; i++)
00304 {
00305 index[i] = static_cast<IndexValueType>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00306 }
00307
00308
00309 const bool isInside =
00310 this->GetLargestPossibleRegion().IsInside( index );
00311
00312 return isInside;
00313 }
00314
00319 template<class TCoordRep>
00320 void TransformContinuousIndexToPhysicalPoint(
00321 const ContinuousIndex<TCoordRep, VImageDimension>& index,
00322 Point<TCoordRep, VImageDimension>& point ) const
00323 {
00324 for (unsigned int i = 0 ; i < VImageDimension ; i++)
00325 {
00326 point[i] = static_cast<TCoordRep>( this->m_Spacing[i] * index[i] + this->m_Origin[i] );
00327 }
00328 }
00329
00335 template<class TCoordRep>
00336 void TransformIndexToPhysicalPoint(
00337 const IndexType & index,
00338 Point<TCoordRep, VImageDimension>& point ) const
00339 {
00340 for (unsigned int i = 0 ; i < VImageDimension ; i++)
00341 {
00342 point[i] = static_cast<TCoordRep>( this->m_Spacing[i] *
00343 static_cast<double>( index[i] ) + this->m_Origin[i] );
00344 }
00345 }
00346
00347 protected:
00348 Image();
00349 void PrintSelf(std::ostream& os, Indent indent) const;
00350 virtual ~Image() {};
00351 private:
00352 Image(const Self&);
00353 void operator=(const Self&);
00354
00356 PixelContainerPointer m_Buffer;
00357 };
00358 #ifdef ITK_EXPLICIT_INSTANTIATION
00359 extern template class Image<float ,2>;
00360 extern template class Image<double ,2>;
00361 extern template class Image<unsigned char ,2>;
00362 extern template class Image<unsigned short,2>;
00363 extern template class Image<unsigned int ,2>;
00364 extern template class Image<signed char ,2>;
00365 extern template class Image<signed short ,2>;
00366 extern template class Image<signed int ,2>;
00367 extern template class Image<float ,3>;
00368 extern template class Image<double ,3>;
00369 extern template class Image<unsigned char ,3>;
00370 extern template class Image<unsigned short,3>;
00371 extern template class Image<unsigned int ,3>;
00372 extern template class Image<signed char ,3>;
00373 extern template class Image<signed short ,3>;
00374 extern template class Image<signed int ,3>;
00375 #endif
00376 }
00377 #ifndef ITK_MANUAL_INSTANTIATION
00378 #include "itkImage.txx"
00379 #endif
00380
00381 #endif
00382