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: 2006/03/28 16:02:11 $
00007   Version:   $Revision: 1.15 $
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 TPixel 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 
00237   TPixel & operator[](const IndexType &index)
00238      { return this->GetPixel(index); }
00239 
00244   const TPixel& operator[](const IndexType &index) const
00245      { return this->GetPixel(index); }
00246 
00249   InternalPixelType *GetBufferPointer()
00250     { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00251   const InternalPixelType *GetBufferPointer() const
00252     { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00254 
00256   PixelContainer* GetPixelContainer()
00257     { return m_Buffer.GetPointer(); }
00258 
00260   const PixelContainer* GetPixelContainer() const
00261     { return m_Buffer.GetPointer(); }
00262 
00265   void SetPixelContainer( PixelContainer *container );
00266 
00277   virtual void Graft(const DataObject *data);
00278 
00280   AccessorType GetPixelAccessor( void ) 
00281     { return AccessorType( m_VectorLength ); }
00282 
00284   const AccessorType GetPixelAccessor( void ) const
00285     { return AccessorType( m_VectorLength ); }
00286 
00288   NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() 
00289     { return NeighborhoodAccessorFunctorType( m_VectorLength ); }
00290 
00292   const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
00293     { return NeighborhoodAccessorFunctorType(m_VectorLength); }
00294 
00295   
00297   itkSetMacro( VectorLength, VectorLengthType );
00298   itkGetConstReferenceMacro( VectorLength, VectorLengthType );
00300 
00302   virtual unsigned int GetNumberOfComponentsPerPixel() const;
00303   virtual void SetNumberOfComponentsPerPixel( unsigned int  n );
00305 
00310   template<class TCoordRep>
00311   bool TransformPhysicalPointToContinuousIndex(
00312               const Point<TCoordRep, VImageDimension>& point,
00313               ContinuousIndex<TCoordRep, VImageDimension>& index   ) const
00314     {
00315     // Update the output index
00316     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00317       {
00318       index[i] = static_cast<TCoordRep>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00319       }
00320 
00321     // Now, check to see if the index is within allowed bounds
00322     const bool isInside =
00323       this->GetLargestPossibleRegion().IsInside( index );
00324 
00325     return isInside;
00326     }
00327 
00332   template<class TCoordRep>
00333   bool TransformPhysicalPointToIndex(
00334             const Point<TCoordRep, VImageDimension>& point,
00335             IndexType & index                                ) const
00336     {
00337     typedef typename IndexType::IndexValueType IndexValueType;
00338 
00339     // Update the output index
00340     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00341       {
00342       index[i] = static_cast<IndexValueType>( (point[i]- this->m_Origin[i]) / this->m_Spacing[i] );
00343       }
00344 
00345     // Now, check to see if the index is within allowed bounds
00346     const bool isInside =
00347       this->GetLargestPossibleRegion().IsInside( index );
00348 
00349     return isInside;
00350     }
00351 
00356   template<class TCoordRep>
00357   void TransformContinuousIndexToPhysicalPoint(
00358             const ContinuousIndex<TCoordRep, VImageDimension>& index,
00359             Point<TCoordRep, VImageDimension>& point        ) const
00360     {
00361     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00362       {
00363       point[i] = static_cast<TCoordRep>( this->m_Spacing[i] * index[i] + this->m_Origin[i] );
00364       }
00365     }
00367 
00373   template<class TCoordRep>
00374   void TransformIndexToPhysicalPoint(
00375                       const IndexType & index,
00376                       Point<TCoordRep, VImageDimension>& point ) const
00377     {
00378     for (unsigned int i = 0 ; i < VImageDimension ; i++)
00379       {
00380       point[i] = static_cast<TCoordRep>( this->m_Spacing[i] *
00381         static_cast<double>( index[i] ) + this->m_Origin[i] );
00382       }
00383     }
00385 
00386 protected:
00387   VectorImage();
00388   void PrintSelf( std::ostream& os, Indent indent ) const;
00389   virtual ~VectorImage() {};
00390   
00391 private:
00392   VectorImage( const Self & ); // purposely not implementated
00393   void operator=(const Self&); //purposely not implemented
00394  
00396   VectorLengthType m_VectorLength;
00397 
00399   PixelContainerPointer m_Buffer;
00400 }; 
00401 
00402 
00403 } // end namespace itk
00404 #ifndef ITK_MANUAL_INSTANTIATION
00405 #include "itkVectorImage.txx"
00406 #endif
00407 
00408 #endif
00409 

Generated at Fri Sep 8 04:17:15 2006 for ITK by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2000