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

itkMetaArrayReader.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkMetaArrayReader.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007-03-22 14:28:51 $
00007   Version:   $Revision: 1.6 $
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 __itkMetaArrayReader_h
00018 #define __itkMetaArrayReader_h
00019 
00020 #include "itkLightProcessObject.h"
00021 #include "itkArray.h"
00022 #include "itkFixedArray.h"
00023 #include "itkVector.h"
00024 #include "itkCovariantVector.h"
00025 #include "itkVariableLengthVector.h"
00026 #include "metaArray.h"
00027 
00028 namespace itk
00029 {
00030 
00031 class MetaArrayReader : public LightProcessObject
00032 {
00033 public:
00034 
00036   typedef MetaArrayReader          Self;
00037   typedef LightProcessObject       Superclass;
00038   typedef SmartPointer<Self>       Pointer;
00039   typedef SmartPointer<const Self> ConstPointer;
00040 
00042   itkNewMacro(Self);
00043 
00045   itkTypeMacro(MetaArrayReader, LightProcessObject);
00046 
00048   itkSetStringMacro(FileName);
00049 
00051   itkGetStringMacro(FileName);
00052 
00055   MetaArray * GetMetaArrayPointer(void);
00056 
00058   void SetBuffer(void * _buffer);
00059 
00061   void Update();
00062 
00064   MET_ValueEnumType GetDataType(void) const
00065     {
00066     return m_MetaArray.ElementType();
00067     }
00068 
00070   int Size(void) const
00071     {
00072     return m_MetaArray.Length();
00073     }
00074 
00076   int GetNumberOfElements(void) const
00077     {
00078     return m_MetaArray.Length();
00079     }
00080 
00082   int GetVectorDimension(void) const
00083     {
00084     return m_MetaArray.Length();
00085     }
00086 
00088   int GetNumberOfComponents(void) const
00089     {
00090     return m_MetaArray.Length();
00091     }
00092 
00094   int GetCovariantVectorDimension(void) const
00095     {
00096     return m_MetaArray.Length();
00097     }
00098 
00100   template <typename TValueType>
00101   inline void GetElement( TValueType & value, unsigned int i,
00102                           unsigned int channel=0 ) const
00103     {
00104     value = static_cast<TValueType>(m_MetaArray.ElementData( 
00105               i * m_MetaArray.ElementNumberOfChannels() + channel));
00106     }
00107 
00116   template <typename TValueType>
00117   void GetOutput(MET_ValueEnumType _metaElementType,
00118                    Array<TValueType> * _array,
00119                    bool _letArrayManageData = true)
00120     {
00121     if(m_MetaArray.ElementType() != _metaElementType)
00122       {
00123       m_MetaArray.ConvertElementDataTo(_metaElementType);
00124       }
00125     _array->SetData((TValueType *)(m_MetaArray.ElementData()), 
00126                     m_MetaArray.Length(),
00127                     _letArrayManageData);
00128     if(_letArrayManageData)
00129       {
00130       m_MetaArray.AutoFreeElementData(false);
00131       }
00132     }
00134 
00136   template <typename TValueType, unsigned int VLength>
00137   bool GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType),
00138                  FixedArray<TValueType, VLength> * _array)
00139     {
00140     if(static_cast<int>(VLength) <= m_MetaArray.Length())
00141       {
00142       unsigned int i;
00143       for(i = 0; i<VLength; i++)
00144         {
00145         this->GetElement( (*_array)[i], i );
00146         }
00147       return true;
00148       }
00149     return false;
00150     }
00152 
00156   template <typename TValueType, unsigned int VLength>
00157   bool GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType),
00158                  Vector<TValueType, VLength> * _vector)
00159     {
00160     if(static_cast<int>(VLength) <= m_MetaArray.Length())
00161       {
00162       unsigned int i;
00163       for(i = 0; i<VLength; i++)
00164         {
00165         this->GetElement( (*_vector)[i], i );
00166         }
00167       return true;
00168       }
00169     return false;
00170     }
00172 
00173 
00178   template <typename TValueType, unsigned int VLength>
00179   bool GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType),
00180                  CovariantVector<TValueType, VLength> * _vector)
00181     {
00182     if(static_cast<int>(VLength) <= m_MetaArray.Length())
00183       {
00184       unsigned int i;
00185       for(i = 0; i<VLength; i++)
00186         {
00187         this->GetElement( (*_vector)[i], i );
00188         }
00189       return true;
00190       }
00191     return false;
00192     }
00194 
00204   template <typename TValueType>
00205   void GetOutput(MET_ValueEnumType _metaElementType,
00206                  VariableLengthVector<TValueType> * _vector,
00207                  bool _letVectorManageData = true)
00208     {
00209     if(m_MetaArray.ElementType() != _metaElementType)
00210       {
00211       m_MetaArray.ConvertElementDataTo(_metaElementType);
00212       }
00213     _vector->SetData((TValueType *)(m_MetaArray.ElementData()), 
00214                      m_MetaArray.Length(),
00215                      _letVectorManageData);
00216     if(_letVectorManageData)
00217       {
00218       m_MetaArray.AutoFreeElementData(false);
00219       }
00220     }
00222 
00228   template <typename TValueType>
00229   void GetMultiChannelOutput(MET_ValueEnumType _metaElementType,
00230                              Array<TValueType> * _array)
00231     {
00232     if(m_MetaArray.ElementType() != _metaElementType)
00233       {
00234       m_MetaArray.ConvertElementDataTo(_metaElementType);
00235       }
00236     int rows = m_MetaArray.Length();
00237     int cols = m_MetaArray.ElementNumberOfChannels();
00238     _array->SetSize(rows);
00239     for(int i=0; i<rows; i++)
00240       {
00241       (*_array)[i].SetSize(cols);
00242       for(int j=0; j<cols; j++)
00243         {
00244         (*_array)[i][j] = static_cast<typename TValueType::ValueType>
00245                                      (m_MetaArray.ElementData(i*cols+j));
00246         }
00247       }
00248     }
00250 
00251 protected:
00252 
00253   MetaArrayReader();
00254   virtual ~MetaArrayReader();
00255 
00256 private:
00257 
00258   MetaArray    m_MetaArray;
00259 
00260   std::string  m_FileName;
00261 
00262   void *       m_Buffer;
00263 
00264 };
00265 
00266 } // namespace itk
00267 
00268 
00269 #endif // __itkTransformFileReader_h
00270 

Generated at Tue Sep 15 03:57:42 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000