ITK  4.2.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 
00207   virtual void Initialize();
00208 
00211   void FillBuffer(const PixelType & value);
00212 
00218   void SetPixel(const IndexType & index, const PixelType & value)
00219   {
00220     OffsetValueType offset = m_VectorLength * this->ComputeOffset(index);
00221 
00222     for ( VectorLengthType i = 0; i < m_VectorLength; i++ )
00223       {
00224       ( *m_Buffer )[offset + i] = value[i];
00225       }
00226   }
00227 
00233   const PixelType GetPixel(const IndexType & index) const
00234   {
00235     OffsetValueType offset = m_VectorLength * this->ComputeOffset(index);
00236     PixelType       p(&( ( *m_Buffer )[offset] ), m_VectorLength);
00237 
00238     return p;
00239   }
00240 
00245   PixelType  GetPixel(const IndexType & index)
00246   {
00247     OffsetValueType offset = m_VectorLength * this->ComputeOffset(index);
00248     PixelType       p(&( ( *m_Buffer )[offset] ), m_VectorLength);
00249 
00250     return p;
00251   }
00252 
00258   PixelType operator[](const IndexType & index) { return this->GetPixel(index); }
00259 
00265   PixelType operator[](const IndexType & index) const { return this->GetPixel(index); }
00266 
00269   InternalPixelType * GetBufferPointer()
00270   {
00271     return m_Buffer ? m_Buffer->GetBufferPointer() : 0;
00272   }
00273   const InternalPixelType * GetBufferPointer() const
00274   {
00275     return m_Buffer ? m_Buffer->GetBufferPointer() : 0;
00276   }
00278 
00280   PixelContainer * GetPixelContainer() { return m_Buffer.GetPointer(); }
00281 
00283   const PixelContainer * GetPixelContainer() const { return m_Buffer.GetPointer(); }
00284 
00287   void SetPixelContainer(PixelContainer *container);
00288 
00299   virtual void Graft(const DataObject *data);
00300 
00302   AccessorType GetPixelAccessor(void) { return AccessorType(m_VectorLength); }
00303 
00305   const AccessorType GetPixelAccessor(void) const { return AccessorType(m_VectorLength); }
00306 
00308   NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
00309   {
00310     return NeighborhoodAccessorFunctorType(m_VectorLength);
00311   }
00312 
00314   const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
00315   {
00316     return NeighborhoodAccessorFunctorType(m_VectorLength);
00317   }
00318 
00320   itkSetMacro(VectorLength, VectorLengthType);
00321   itkGetConstReferenceMacro(VectorLength, VectorLengthType);
00323 
00325   virtual unsigned int GetNumberOfComponentsPerPixel() const;
00326 
00327   virtual void SetNumberOfComponentsPerPixel(unsigned int n);
00328 
00329 protected:
00330   VectorImage();
00331   void PrintSelf(std::ostream & os, Indent indent) const;
00332 
00333   virtual ~VectorImage() {}
00334 private:
00335   VectorImage(const Self &);    // purposely not implementated
00336   void operator=(const Self &); //purposely not implemented
00337 
00339   VectorLengthType m_VectorLength;
00340 
00342   PixelContainerPointer m_Buffer;
00343 };
00344 } // end namespace itk
00345 
00346 // Define instantiation macro for this template.
00347 #define ITK_TEMPLATE_VectorImage(_, EXPORT, TypeX, TypeY)           \
00348   namespace itk                                                     \
00349   {                                                                 \
00350   _( 2 ( class EXPORT VectorImage< ITK_TEMPLATE_2 TypeX > ) )       \
00351   namespace Templates                                               \
00352   {                                                                 \
00353   typedef VectorImage< ITK_TEMPLATE_2 TypeX > VectorImage##TypeY; \
00354   }                                                                 \
00355   }
00356 
00357 #if ITK_TEMPLATE_EXPLICIT
00358 #include "Templates/itkVectorImage+-.h"
00359 #endif
00360 
00361 #if ITK_TEMPLATE_TXX
00362 #include "itkVectorImage.hxx"
00363 #endif
00364 
00365 #endif
00366