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/09/10 14:29:09 $ 00007 Version: $Revision: 1.112 $ 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 00027 namespace itk 00028 { 00029 00078 template <class TPixel, unsigned int VImageDimension=2> 00079 class ITK_EXPORT Image : public ImageBase<VImageDimension> 00080 { 00081 public: 00083 typedef Image Self; 00084 typedef ImageBase<VImageDimension> Superclass; 00085 typedef SmartPointer<Self> Pointer; 00086 typedef SmartPointer<const Self> ConstPointer; 00087 00089 itkNewMacro(Self); 00090 00092 itkTypeMacro(Image, ImageBase); 00093 00096 typedef TPixel PixelType; 00097 00099 typedef TPixel ValueType ; 00100 00105 typedef TPixel InternalPixelType; 00106 00109 typedef DefaultPixelAccessor< PixelType > AccessorType; 00110 00115 itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension); 00116 00118 typedef ImportImageContainer<unsigned long, PixelType> PixelContainer; 00119 00121 typedef Index<VImageDimension> IndexType; 00122 00124 typedef Offset<VImageDimension> OffsetType; 00125 00127 typedef Size<VImageDimension> SizeType; 00128 00130 typedef ImageRegion<VImageDimension> RegionType; 00131 00133 typedef typename PixelContainer::Pointer PixelContainerPointer; 00134 00137 void Allocate(); 00138 00142 void SetRegions(RegionType region) 00143 { 00144 this->SetLargestPossibleRegion(region); 00145 this->SetBufferedRegion(region); 00146 this->SetRequestedRegion(region); 00147 }; 00148 00149 void SetRegions(SizeType size) 00150 { 00151 RegionType region; region.SetSize(size); 00152 this->SetLargestPossibleRegion(region); 00153 this->SetBufferedRegion(region); 00154 this->SetRequestedRegion(region); 00155 }; 00156 00159 virtual void Initialize(); 00160 00163 void FillBuffer (const TPixel& value); 00164 00170 void SetPixel(const IndexType &index, const TPixel& value) 00171 { 00172 typename Superclass::OffsetValueType offset = this->ComputeOffset(index); 00173 (*m_Buffer)[offset] = value; 00174 } 00175 00180 const TPixel& GetPixel(const IndexType &index) const 00181 { 00182 typename Superclass::OffsetValueType offset = this->ComputeOffset(index); 00183 return ( (*m_Buffer)[offset] ); 00184 } 00185 00190 TPixel& GetPixel(const IndexType &index) 00191 { 00192 typename Superclass::OffsetValueType offset = this->ComputeOffset(index); 00193 return ( (*m_Buffer)[offset] ); 00194 } 00195 00200 TPixel & operator[](const IndexType &index) 00201 { return this->GetPixel(index); } 00202 00207 const TPixel& operator[](const IndexType &index) const 00208 { return this->GetPixel(index); } 00209 00212 TPixel *GetBufferPointer() 00213 { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; } 00214 const TPixel *GetBufferPointer() const 00215 { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; } 00216 00218 PixelContainer* GetPixelContainer() 00219 { return m_Buffer.GetPointer(); } 00220 00223 void SetPixelContainer( PixelContainer *container ); 00224 00226 AccessorType GetPixelAccessor( void ) 00227 { return AccessorType(); } 00228 00230 const AccessorType GetPixelAccessor( void ) const 00231 { return AccessorType(); } 00232 00237 virtual void SetSpacing( const double spacing[VImageDimension] ); 00238 virtual void SetSpacing( const float spacing[VImageDimension] ); 00239 00244 virtual void SetOrigin( const double origin[VImageDimension] ); 00245 virtual void SetOrigin( const float origin[VImageDimension] ); 00246 00251 template<class TCoordRep> 00252 bool TransformPhysicalPointToContinuousIndex( 00253 const Point<TCoordRep, VImageDimension>& point, 00254 ContinuousIndex<TCoordRep, VImageDimension>& index ) const 00255 { 00256 // Update the output index 00257 for (unsigned int i = 0 ; i < VImageDimension ; i++) 00258 { 00259 index[i] = static_cast<TCoordRep>( (point[i]- m_Origin[i]) / m_Spacing[i] ); 00260 } 00261 00262 // Now, check to see if the index is within allowed bounds 00263 const bool isInside = 00264 this->GetLargestPossibleRegion().IsInside( index ); 00265 00266 return isInside; 00267 } 00268 00273 template<class TCoordRep> 00274 bool TransformPhysicalPointToIndex( 00275 const Point<TCoordRep, VImageDimension>& point, 00276 IndexType & index ) const 00277 { 00278 typedef typename IndexType::IndexValueType IndexValueType; 00279 00280 // Update the output index 00281 for (unsigned int i = 0 ; i < VImageDimension ; i++) 00282 { 00283 index[i] = static_cast<IndexValueType>( (point[i]- m_Origin[i]) / m_Spacing[i] ); 00284 } 00285 00286 // Now, check to see if the index is within allowed bounds 00287 const bool isInside = 00288 this->GetLargestPossibleRegion().IsInside( index ); 00289 00290 return isInside; 00291 } 00292 00297 template<class TCoordRep> 00298 void TransformContinuousIndexToPhysicalPoint( 00299 const ContinuousIndex<TCoordRep, VImageDimension>& index, 00300 Point<TCoordRep, VImageDimension>& point ) const 00301 { 00302 for (unsigned int i = 0 ; i < VImageDimension ; i++) 00303 { 00304 point[i] = static_cast<TCoordRep>( m_Spacing[i] * index[i] + m_Origin[i] ); 00305 } 00306 } 00307 00313 template<class TCoordRep> 00314 void TransformIndexToPhysicalPoint( 00315 const IndexType & index, 00316 Point<TCoordRep, VImageDimension>& point ) const 00317 { 00318 for (unsigned int i = 0 ; i < VImageDimension ; i++) 00319 { 00320 point[i] = static_cast<TCoordRep>( m_Spacing[i] * 00321 static_cast<double>( index[i] ) + m_Origin[i] ); 00322 } 00323 } 00324 00341 virtual void CopyInformation(const DataObject *data); 00342 00343 protected: 00344 Image(); 00345 void PrintSelf(std::ostream& os, Indent indent) const; 00346 virtual ~Image() {}; 00347 private: 00348 Image(const Self&); //purposely not implemented 00349 void operator=(const Self&); //purposely not implemented 00350 00352 PixelContainerPointer m_Buffer; 00353 }; 00354 00355 } // end namespace itk 00356 00357 #ifndef ITK_MANUAL_INSTANTIATION 00358 #include "itkImage.txx" 00359 #endif 00360 00361 #endif 00362

Generated at Sat Mar 31 02:20:50 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000