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

itkVectorImage.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkVectorImage.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-06-04 15:38:35 $
00007   Version:   $Revision: 1.19 $
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 __itkVectorImage_h
00018 #define __itkVectorImage_h
00019 
00020 #include "itkImageBase.h"
00021 #include "itkImageRegion.h"
00022 #include "itkImportImageContainer.h"
00023 #include "itkDefaultVectorPixelAccessor.h"
00024 #include "itkDefaultVectorPixelAccessorFunctor.h"
00025 #include "itkVectorImageNeighborhoodAccessorFunctor.h"
00026 #include "itkPoint.h"
00027 #include "itkContinuousIndex.h"
00028 #include "itkVariableLengthVector.h"
00029 #include "itkWeakPointer.h"
00030 
00031 namespace itk
00032 {
00033 
00078 template <class TPixel, unsigned int VImageDimension=3 >
00079 class ITK_EXPORT VectorImage : 
00080     public ImageBase< VImageDimension >
00081 {
00082 public:
00084   typedef VectorImage                  Self;
00085   typedef ImageBase< VImageDimension > Superclass;
00086   typedef SmartPointer<Self>           Pointer;
00087   typedef SmartPointer<const Self>     ConstPointer;
00088   typedef WeakPointer<const Self>      ConstWeakPointer;
00089 
00091   itkNewMacro(Self);
00092 
00094   itkTypeMacro(VectorImage, ImageBase);
00095 
00100   typedef VariableLengthVector< TPixel > PixelType;
00101 
00105   typedef TPixel InternalPixelType;
00106 
00108   typedef PixelType ValueType;
00109 
00110   typedef InternalPixelType  IOPixelType;
00111 
00114   typedef DefaultVectorPixelAccessor< InternalPixelType > AccessorType;
00115 
00118   typedef DefaultVectorPixelAccessorFunctor< Self >       AccessorFunctorType;
00119 
00121   typedef VectorImageNeighborhoodAccessorFunctor< 
00122                           Self >              NeighborhoodAccessorFunctorType;
00123 
00128   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
00129 
00131   typedef ImportImageContainer<unsigned long, InternalPixelType> PixelContainer;
00132 
00134   typedef typename Superclass::IndexType  IndexType;
00135 
00137   typedef typename Superclass::OffsetType OffsetType;
00138 
00140   typedef typename Superclass::SizeType  SizeType;
00141 
00143   typedef typename Superclass::DirectionType  DirectionType;
00144 
00146   typedef typename Superclass::RegionType  RegionType;
00147 
00150   typedef typename Superclass::SpacingType SpacingType;
00151 
00154   typedef typename Superclass::PointType PointType;
00155 
00157   typedef typename PixelContainer::Pointer PixelContainerPointer;
00158   typedef typename PixelContainer::ConstPointer PixelContainerConstPointer;
00159 
00161   typedef typename Superclass::OffsetValueType OffsetValueType;
00162 
00163   typedef unsigned int VectorLengthType;
00164 
00167   void Allocate();
00168 
00172   void SetRegions(RegionType region)
00173     {
00174     this->SetLargestPossibleRegion(region);
00175     this->SetBufferedRegion(region);
00176     this->SetRequestedRegion(region);
00177     };
00179 
00180   void SetRegions(SizeType size)
00181     {
00182     RegionType region; region.SetSize(size);
00183     this->SetLargestPossibleRegion(region);
00184     this->SetBufferedRegion(region);
00185     this->SetRequestedRegion(region);
00186     };
00187 
00190   virtual void Initialize();
00191 
00194   void FillBuffer(const PixelType& value);
00195 
00201    void SetPixel( const IndexType &index, const PixelType& value )
00202     {
00203     OffsetValueType offset = m_VectorLength * this->ComputeOffset(index);
00204     for( VectorLengthType i = 0; i < m_VectorLength; i++ )
00205       {
00206       (*m_Buffer)[offset + i] = value[i];
00207       }
00208     }
00209 
00215   const PixelType GetPixel(const IndexType &index) const
00216     {
00217     OffsetValueType offset = m_VectorLength * this->ComputeOffset(index);
00218     PixelType p( &((*m_Buffer)[offset]), m_VectorLength ); 
00219     return p;
00220     }
00221 
00226   PixelType  GetPixel(const IndexType &index )
00227     {
00228     OffsetValueType offset = m_VectorLength * this->ComputeOffset(index);
00229     PixelType p( &((*m_Buffer)[offset]), m_VectorLength ); 
00230     return p;
00231     }
00232 
00238   PixelType operator[](const IndexType &index)
00239      { return this->GetPixel(index); }
00240 
00246   PixelType operator[](const IndexType &index) const
00247      { return this->GetPixel(index); }
00248 
00251   InternalPixelType * GetBufferPointer()
00252     { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00253   const InternalPixelType *GetBufferPointer() const
00254     { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00256 
00258   PixelContainer* GetPixelContainer()
00259     { return m_Buffer.GetPointer(); }
00260 
00262   const PixelContainer* GetPixelContainer() const
00263     { return m_Buffer.GetPointer(); }
00264 
00267   void SetPixelContainer( PixelContainer *container );
00268 
00279   virtual void Graft(const DataObject *data);
00280 
00282   AccessorType GetPixelAccessor( void ) 
00283     { return AccessorType( m_VectorLength ); }
00284 
00286   const AccessorType GetPixelAccessor( void ) const
00287     { return AccessorType( m_VectorLength ); }
00288 
00290   NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() 
00291     { return NeighborhoodAccessorFunctorType( m_VectorLength ); }
00292 
00294   const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
00295     { return NeighborhoodAccessorFunctorType(m_VectorLength); }
00296 
00297   
00299   itkSetMacro( VectorLength, VectorLengthType );
00300   itkGetConstReferenceMacro( VectorLength, VectorLengthType );
00302 
00304   virtual unsigned int GetNumberOfComponentsPerPixel() const;
00305   virtual void SetNumberOfComponentsPerPixel( unsigned int  n );
00307 
00312   template<class TCoordRep>
00313   bool TransformPhysicalPointToContinuousIndex(
00314               const Point<TCoordRep, VImageDimension>& point,
00315               ContinuousIndex<TCoordRep, VImageDimension>& index   ) const
00316     {
00317     // Update the output index
00318     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00319       {
00320       index[i] = static_cast<TCoordRep>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00321       }
00322 
00323     // Now, check to see if the index is within allowed bounds
00324     const bool isInside =
00325       this->GetLargestPossibleRegion().IsInside( index );
00326 
00327     return isInside;
00328     }
00329 
00334   template<class TCoordRep>
00335   bool TransformPhysicalPointToIndex(
00336             const Point<TCoordRep, VImageDimension>& point,
00337             IndexType & index                                ) const
00338     {
00339     typedef typename IndexType::IndexValueType IndexValueType;
00340 
00341     // Update the output index
00342     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00343       {
00344       index[i] = static_cast<IndexValueType>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00345       }
00346 
00347     // Now, check to see if the index is within allowed bounds
00348     const bool isInside =
00349       this->GetLargestPossibleRegion().IsInside( index );
00350 
00351     return isInside;
00352     }
00353 
00358   template<class TCoordRep>
00359   void TransformContinuousIndexToPhysicalPoint(
00360             const ContinuousIndex<TCoordRep, VImageDimension>& index,
00361             Point<TCoordRep, VImageDimension>& point        ) const
00362     {
00363     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00364       {
00365       point[i] = static_cast<TCoordRep>( this->m_Spacing[i] * index[i] + this->m_Origin[i] );
00366       }
00367     }
00369 
00375   template<class TCoordRep>
00376   void TransformIndexToPhysicalPoint(
00377                       const IndexType & index,
00378                       Point<TCoordRep, VImageDimension>& point ) const
00379     {
00380     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00381       {
00382       point[i] = static_cast<TCoordRep>( this->m_Spacing[i] *
00383         static_cast<double>( index[i] ) + this->m_Origin[i] );
00384       }
00385     }
00387 
00388 protected:
00389   VectorImage();
00390   void PrintSelf( std::ostream& os, Indent indent ) const;
00391   virtual ~VectorImage() {};
00392   
00393 private:
00394   VectorImage( const Self & ); // purposely not implementated
00395   void operator=(const Self&); //purposely not implemented
00396  
00398   VectorLengthType m_VectorLength;
00399 
00401   PixelContainerPointer m_Buffer;
00402 }; 
00403 
00404 
00405 } // end namespace itk
00406 
00407 // Define instantiation macro for this template.
00408 #define ITK_TEMPLATE_VectorImage(_, EXPORT, x, y) namespace itk { \
00409   _(2(class EXPORT VectorImage< ITK_TEMPLATE_2 x >)) \
00410   namespace Templates { typedef VectorImage< ITK_TEMPLATE_2 x > VectorImage##y; } \
00411   }
00412 
00413 #if ITK_TEMPLATE_EXPLICIT
00414 # include "Templates/itkVectorImage+-.h"
00415 #endif
00416 
00417 #if ITK_TEMPLATE_TXX
00418 # include "itkVectorImage.txx"
00419 #endif
00420 
00421 #endif
00422 

Generated at Tue Jul 29 23:23:34 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000