Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkImage.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkImage.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/12/10 15:21:33 $ 00007 Version: $Revision: 1.118 $ 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 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 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 "itkPoint.h" 00025 #include "itkContinuousIndex.h" 00026 #include "itkFixedArray.h" 00027 00028 namespace itk 00029 { 00030 00079 template <class TPixel, unsigned int VImageDimension=2> 00080 class ITK_EXPORT Image : public ImageBase<VImageDimension> 00081 { 00082 public: 00084 typedef Image Self; 00085 typedef ImageBase<VImageDimension> Superclass; 00086 typedef SmartPointer<Self> Pointer; 00087 typedef SmartPointer<const Self> ConstPointer; 00088 00090 itkNewMacro(Self); 00091 00093 itkTypeMacro(Image, ImageBase); 00094 00097 typedef TPixel PixelType; 00098 00100 typedef TPixel ValueType ; 00101 00106 typedef TPixel InternalPixelType; 00107 00110 typedef DefaultPixelAccessor< PixelType > AccessorType; 00111 00116 itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension); 00117 00119 typedef ImportImageContainer<unsigned long, PixelType> PixelContainer; 00120 00122 typedef typename Superclass::IndexType IndexType; 00123 00125 typedef typename Superclass::OffsetType OffsetType; 00126 00128 typedef typename Superclass::SizeType SizeType; 00129 00131 typedef typename Superclass::RegionType RegionType; 00132 00135 typedef typename Superclass::SpacingType SpacingType; 00136 00139 typedef typename Superclass::PointType PointType; 00140 00142 typedef typename PixelContainer::Pointer PixelContainerPointer; 00143 typedef typename PixelContainer::ConstPointer PixelContainerConstPointer; 00144 00147 void Allocate(); 00148 00152 void SetRegions(RegionType region) 00153 { 00154 this->SetLargestPossibleRegion(region); 00155 this->SetBufferedRegion(region); 00156 this->SetRequestedRegion(region); 00157 }; 00158 00159 void SetRegions(SizeType size) 00160 { 00161 RegionType region; region.SetSize(size); 00162 this->SetLargestPossibleRegion(region); 00163 this->SetBufferedRegion(region); 00164 this->SetRequestedRegion(region); 00165 }; 00166 00169 virtual void Initialize(); 00170 00173 void FillBuffer (const TPixel& value); 00174 00180 void SetPixel(const IndexType &index, const TPixel& value) 00181 { 00182 typename Superclass::OffsetValueType offset = this->ComputeOffset(index); 00183 (*m_Buffer)[offset] = value; 00184 } 00185 00190 const TPixel& GetPixel(const IndexType &index) const 00191 { 00192 typename Superclass::OffsetValueType offset = this->ComputeOffset(index); 00193 return ( (*m_Buffer)[offset] ); 00194 } 00195 00200 TPixel& GetPixel(const IndexType &index) 00201 { 00202 typename Superclass::OffsetValueType offset = this->ComputeOffset(index); 00203 return ( (*m_Buffer)[offset] ); 00204 } 00205 00210 TPixel & operator[](const IndexType &index) 00211 { return this->GetPixel(index); } 00212 00217 const TPixel& operator[](const IndexType &index) const 00218 { return this->GetPixel(index); } 00219 00222 TPixel *GetBufferPointer() 00223 { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; } 00224 const TPixel *GetBufferPointer() const 00225 { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; } 00226 00228 PixelContainer* GetPixelContainer() 00229 { return m_Buffer.GetPointer(); } 00230 00231 const PixelContainer* GetPixelContainer() const 00232 { return m_Buffer.GetPointer(); } 00233 00236 void SetPixelContainer( PixelContainer *container ); 00237 00239 AccessorType GetPixelAccessor( void ) 00240 { return AccessorType(); } 00241 00243 const AccessorType GetPixelAccessor( void ) const 00244 { return AccessorType(); } 00245 00250 itkSetMacro(Spacing, SpacingType); 00251 virtual void SetSpacing( const double spacing[VImageDimension] ); 00252 virtual void SetSpacing( const float spacing[VImageDimension] ); 00253 00258 itkSetMacro(Origin, PointType); 00259 virtual void SetOrigin( const double origin[VImageDimension] ); 00260 virtual void SetOrigin( const float origin[VImageDimension] ); 00261 00266 template<class TCoordRep> 00267 bool TransformPhysicalPointToContinuousIndex( 00268 const Point<TCoordRep, VImageDimension>& point, 00269 ContinuousIndex<TCoordRep, VImageDimension>& index ) const 00270 { 00271 // Update the output index 00272 for (unsigned int i = 0 ; i < VImageDimension ; i++) 00273 { 00274 index[i] = static_cast<TCoordRep>( (point[i]- m_Origin[i]) / m_Spacing[i] ); 00275 } 00276 00277 // Now, check to see if the index is within allowed bounds 00278 const bool isInside = 00279 this->GetLargestPossibleRegion().IsInside( index ); 00280 00281 return isInside; 00282 } 00283 00288 template<class TCoordRep> 00289 bool TransformPhysicalPointToIndex( 00290 const Point<TCoordRep, VImageDimension>& point, 00291 IndexType & index ) const 00292 { 00293 typedef typename IndexType::IndexValueType IndexValueType; 00294 00295 // Update the output index 00296 for (unsigned int i = 0 ; i < VImageDimension ; i++) 00297 { 00298 index[i] = static_cast<IndexValueType>( (point[i]- m_Origin[i]) / m_Spacing[i] ); 00299 } 00300 00301 // Now, check to see if the index is within allowed bounds 00302 const bool isInside = 00303 this->GetLargestPossibleRegion().IsInside( index ); 00304 00305 return isInside; 00306 } 00307 00312 template<class TCoordRep> 00313 void TransformContinuousIndexToPhysicalPoint( 00314 const ContinuousIndex<TCoordRep, VImageDimension>& index, 00315 Point<TCoordRep, VImageDimension>& point ) const 00316 { 00317 for (unsigned int i = 0 ; i < VImageDimension ; i++) 00318 { 00319 point[i] = static_cast<TCoordRep>( m_Spacing[i] * index[i] + m_Origin[i] ); 00320 } 00321 } 00322 00328 template<class TCoordRep> 00329 void TransformIndexToPhysicalPoint( 00330 const IndexType & index, 00331 Point<TCoordRep, VImageDimension>& point ) const 00332 { 00333 for (unsigned int i = 0 ; i < VImageDimension ; i++) 00334 { 00335 point[i] = static_cast<TCoordRep>( m_Spacing[i] * 00336 static_cast<double>( index[i] ) + m_Origin[i] ); 00337 } 00338 } 00339 00356 virtual void CopyInformation(const DataObject *data); 00357 00358 protected: 00359 Image(); 00360 void PrintSelf(std::ostream& os, Indent indent) const; 00361 virtual ~Image() {}; 00362 private: 00363 Image(const Self&); //purposely not implemented 00364 void operator=(const Self&); //purposely not implemented 00365 00367 PixelContainerPointer m_Buffer; 00368 }; 00369 #ifdef ITK_EXPLICIT_INSTANTIATION 00370 extern template class Image<float ,2>; 00371 extern template class Image<double ,2>; 00372 extern template class Image<unsigned char ,2>; 00373 extern template class Image<unsigned short,2>; 00374 extern template class Image<unsigned int ,2>; 00375 extern template class Image<signed char ,2>; 00376 extern template class Image<signed short ,2>; 00377 extern template class Image<signed int ,2>; 00378 extern template class Image<float ,3>; 00379 extern template class Image<double ,3>; 00380 extern template class Image<unsigned char ,3>; 00381 extern template class Image<unsigned short,3>; 00382 extern template class Image<unsigned int ,3>; 00383 extern template class Image<signed char ,3>; 00384 extern template class Image<signed short ,3>; 00385 extern template class Image<signed int ,3>; 00386 #endif 00387 } // end namespace itk 00388 #ifndef ITK_MANUAL_INSTANTIATION 00389 #include "itkImage.txx" 00390 #endif 00391 00392 #endif 00393

Generated at Sun Apr 1 02:33:31 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000