ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkVectorImage.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkVectorImage_h
00019 #define __itkVectorImage_h
00020 
00021 #include "itkImageRegion.h"
00022 #include "itkImportImageContainer.h"
00023 #include "itkDefaultVectorPixelAccessor.h"
00024 #include "itkDefaultVectorPixelAccessorFunctor.h"
00025 #include "itkVectorImageNeighborhoodAccessorFunctor.h"
00026 #include "itkWeakPointer.h"
00027 
00028 namespace itk
00029 {
00081 template< class TPixel, unsigned int VImageDimension = 3 >
00082 class ITK_EXPORT VectorImage:
00083   public ImageBase< VImageDimension >
00084 {
00085 public:
00087   typedef VectorImage                  Self;
00088   typedef ImageBase< VImageDimension > Superclass;
00089   typedef SmartPointer< Self >         Pointer;
00090   typedef SmartPointer< const Self >   ConstPointer;
00091   typedef WeakPointer< const Self >    ConstWeakPointer;
00092 
00094   itkNewMacro(Self);
00095 
00097   itkTypeMacro(VectorImage, ImageBase);
00098 
00103   typedef VariableLengthVector< TPixel > PixelType;
00104 
00108   typedef TPixel InternalPixelType;
00109 
00111   typedef PixelType ValueType;
00112 
00113   typedef InternalPixelType IOPixelType;
00114 
00117   typedef DefaultVectorPixelAccessor< InternalPixelType > AccessorType;
00118 
00121   typedef DefaultVectorPixelAccessorFunctor< Self > AccessorFunctorType;
00122 
00125   typedef VectorImageNeighborhoodAccessorFunctor<
00126     Self >              NeighborhoodAccessorFunctorType;
00127 
00132   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
00133 
00135   typedef typename Superclass::IndexType      IndexType;
00136   typedef typename Superclass::IndexValueType IndexValueType;
00137 
00139   typedef typename Superclass::OffsetType OffsetType;
00140 
00142   typedef typename Superclass::SizeType      SizeType;
00143 
00145   typedef ImportImageContainer< SizeValueType, InternalPixelType > PixelContainer;
00146 
00148   typedef typename Superclass::DirectionType DirectionType;
00149 
00152   typedef typename Superclass::RegionType RegionType;
00153 
00156   typedef typename Superclass::SpacingType SpacingType;
00157 
00160   typedef typename Superclass::PointType PointType;
00161 
00163   typedef typename PixelContainer::Pointer      PixelContainerPointer;
00164   typedef typename PixelContainer::ConstPointer PixelContainerConstPointer;
00165 
00167   typedef typename Superclass::OffsetValueType OffsetValueType;
00168 
00169   typedef unsigned int VectorLengthType;
00170 
00186   template <typename UPixelType, unsigned int UImageDimension = VImageDimension>
00187   struct Rebind
00188   {
00189     typedef itk::VectorImage<UPixelType, UImageDimension>  Type;
00190   };
00191 
00193   template <typename UElementType, unsigned int UImageDimension>
00194   struct Rebind< VariableLengthVector< UElementType >, UImageDimension>
00195   {
00196     typedef itk::VectorImage<UElementType, UImageDimension>  Type;
00197   };
00198 
00203   void Allocate();
00204 
00208   void SetRegions(RegionType region)
00209   {
00210     this->SetLargestPossibleRegion(region);
00211     this->SetBufferedRegion(region);
00212     this->SetRequestedRegion(region);
00213   }
00215 
00216   void SetRegions(SizeType size)
00217   {
00218     RegionType region; region.SetSize(size);
00219 
00220     this->SetLargestPossibleRegion(region);
00221     this->SetBufferedRegion(region);
00222     this->SetRequestedRegion(region);
00223   }
00224 
00227   virtual void Initialize();
00228 
00231   void FillBuffer(const PixelType & value);
00232 
00238   void SetPixel(const IndexType & index, const PixelType & value)
00239   {
00240     OffsetValueType offset = m_VectorLength * this->ComputeOffset(index);
00241 
00242     for ( VectorLengthType i = 0; i < m_VectorLength; i++ )
00243       {
00244       ( *m_Buffer )[offset + i] = value[i];
00245       }
00246   }
00247 
00253   const PixelType GetPixel(const IndexType & index) const
00254   {
00255     OffsetValueType offset = m_VectorLength * this->ComputeOffset(index);
00256     PixelType       p(&( ( *m_Buffer )[offset] ), m_VectorLength);
00257 
00258     return p;
00259   }
00260 
00265   PixelType  GetPixel(const IndexType & index)
00266   {
00267     OffsetValueType offset = m_VectorLength * this->ComputeOffset(index);
00268     PixelType       p(&( ( *m_Buffer )[offset] ), m_VectorLength);
00269 
00270     return p;
00271   }
00272 
00278   PixelType operator[](const IndexType & index) { return this->GetPixel(index); }
00279 
00285   PixelType operator[](const IndexType & index) const { return this->GetPixel(index); }
00286 
00289   InternalPixelType * GetBufferPointer()
00290   {
00291     return m_Buffer ? m_Buffer->GetBufferPointer() : 0;
00292   }
00293   const InternalPixelType * GetBufferPointer() const
00294   {
00295     return m_Buffer ? m_Buffer->GetBufferPointer() : 0;
00296   }
00298 
00300   PixelContainer * GetPixelContainer() { return m_Buffer.GetPointer(); }
00301 
00303   const PixelContainer * GetPixelContainer() const { return m_Buffer.GetPointer(); }
00304 
00307   void SetPixelContainer(PixelContainer *container);
00308 
00319   virtual void Graft(const DataObject *data);
00320 
00322   AccessorType GetPixelAccessor(void) { return AccessorType(m_VectorLength); }
00323 
00325   const AccessorType GetPixelAccessor(void) const { return AccessorType(m_VectorLength); }
00326 
00328   NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
00329   {
00330     return NeighborhoodAccessorFunctorType(m_VectorLength);
00331   }
00332 
00334   const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
00335   {
00336     return NeighborhoodAccessorFunctorType(m_VectorLength);
00337   }
00338 
00340   itkSetMacro(VectorLength, VectorLengthType);
00341   itkGetConstReferenceMacro(VectorLength, VectorLengthType);
00343 
00345   virtual unsigned int GetNumberOfComponentsPerPixel() const;
00346 
00347   virtual void SetNumberOfComponentsPerPixel(unsigned int n);
00348 
00349 protected:
00350   VectorImage();
00351   void PrintSelf(std::ostream & os, Indent indent) const;
00352 
00353   virtual ~VectorImage() {}
00354 private:
00355   VectorImage(const Self &);    // purposely not implementated
00356   void operator=(const Self &); //purposely not implemented
00357 
00359   VectorLengthType m_VectorLength;
00360 
00362   PixelContainerPointer m_Buffer;
00363 };
00364 } // end namespace itk
00365 
00366 // Define instantiation macro for this template.
00367 #define ITK_TEMPLATE_VectorImage(_, EXPORT, TypeX, TypeY)           \
00368   namespace itk                                                     \
00369   {                                                                 \
00370   _( 2 ( class EXPORT VectorImage< ITK_TEMPLATE_2 TypeX > ) )       \
00371   namespace Templates                                               \
00372   {                                                                 \
00373   typedef VectorImage< ITK_TEMPLATE_2 TypeX > VectorImage##TypeY; \
00374   }                                                                 \
00375   }
00376 
00377 #if ITK_TEMPLATE_EXPLICIT
00378 #include "Templates/itkVectorImage+-.h"
00379 #endif
00380 
00381 #if ITK_TEMPLATE_TXX
00382 #include "itkVectorImage.hxx"
00383 #endif
00384 
00385 #endif
00386