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: 2006/11/17 14:54:59 $
00007   Version:   $Revision: 1.5 $
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 
00039   typedef SmartPointer<Self>       Pointer;
00040   typedef SmartPointer<const Self> ConstPointer;
00041 
00043   itkNewMacro(Self);
00044 
00046   itkTypeMacro(MetaArrayReader, LightProcessObject);
00047 
00049   itkSetStringMacro(FileName);
00050 
00052   itkGetStringMacro(FileName);
00053 
00056   MetaArray * GetMetaArrayPointer(void);
00057 
00059   void SetBuffer(void * _buffer);
00060 
00062   void Update();
00063 
00065   MET_ValueEnumType GetDataType(void) const
00066     {
00067     return m_MetaArray.ElementType();
00068     }
00069 
00071   int Size(void) const
00072     {
00073     return m_MetaArray.Length();
00074     }
00075 
00077   int GetNumberOfElements(void) const
00078     {
00079     return m_MetaArray.Length();
00080     }
00081 
00083   int GetVectorDimension(void) const
00084     {
00085     return m_MetaArray.Length();
00086     }
00087 
00089   int GetNumberOfComponents(void) const
00090     {
00091     return m_MetaArray.Length();
00092     }
00093 
00095   int GetCovariantVectorDimension(void) const
00096     {
00097     return m_MetaArray.Length();
00098     }
00099 
00101   template <typename TValueType>
00102   inline void GetElement( TValueType & value, unsigned int i,
00103                           unsigned int channel=0 ) const
00104     {
00105     value = static_cast<TValueType>(m_MetaArray.ElementData( 
00106               i * m_MetaArray.ElementNumberOfChannels() + channel));
00107     }
00108 
00117   template <typename TValueType>
00118   void GetOutput(MET_ValueEnumType _metaElementType,
00119                    Array<TValueType> * _array,
00120                    bool _letArrayManageData = true)
00121     {
00122     if(m_MetaArray.ElementType() != _metaElementType)
00123       {
00124       m_MetaArray.ConvertElementDataTo(_metaElementType);
00125       }
00126     _array->SetData((TValueType *)(m_MetaArray.ElementData()), 
00127                     m_MetaArray.Length(),
00128                     _letArrayManageData);
00129     if(_letArrayManageData)
00130       {
00131       m_MetaArray.AutoFreeElementData(false);
00132       }
00133     }
00135 
00137   template <typename TValueType, unsigned int vLength>
00138   bool GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType),
00139                  FixedArray<TValueType, vLength> * _array)
00140     {
00141     if(static_cast<int>(vLength) <= m_MetaArray.Length())
00142       {
00143       unsigned int i;
00144       for(i = 0; i<vLength; i++)
00145         {
00146         this->GetElement( (*_array)[i], i );
00147         }
00148       return true;
00149       }
00150     return false;
00151     }
00153 
00157   template <typename TValueType, unsigned int vLength>
00158   bool GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType),
00159                  Vector<TValueType, vLength> * _vector)
00160     {
00161     if(static_cast<int>(vLength) <= m_MetaArray.Length())
00162       {
00163       unsigned int i;
00164       for(i = 0; i<vLength; i++)
00165         {
00166         this->GetElement( (*_vector)[i], i );
00167         }
00168       return true;
00169       }
00170     return false;
00171     }
00173 
00174 
00179   template <typename TValueType, unsigned int vLength>
00180   bool GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType),
00181                  CovariantVector<TValueType, vLength> * _vector)
00182     {
00183     if(static_cast<int>(vLength) <= m_MetaArray.Length())
00184       {
00185       unsigned int i;
00186       for(i = 0; i<vLength; i++)
00187         {
00188         this->GetElement( (*_vector)[i], i );
00189         }
00190       return true;
00191       }
00192     return false;
00193     }
00195 
00205   template <typename TValueType>
00206   void GetOutput(MET_ValueEnumType _metaElementType,
00207                  VariableLengthVector<TValueType> * _vector,
00208                  bool _letVectorManageData = true)
00209     {
00210     if(m_MetaArray.ElementType() != _metaElementType)
00211       {
00212       m_MetaArray.ConvertElementDataTo(_metaElementType);
00213       }
00214     _vector->SetData((TValueType *)(m_MetaArray.ElementData()), 
00215                      m_MetaArray.Length(),
00216                      _letVectorManageData);
00217     if(_letVectorManageData)
00218       {
00219       m_MetaArray.AutoFreeElementData(false);
00220       }
00221     }
00223 
00229   template <typename TValueType>
00230   void GetMultiChannelOutput(MET_ValueEnumType _metaElementType,
00231                              Array<TValueType> * _array)
00232     {
00233     if(m_MetaArray.ElementType() != _metaElementType)
00234       {
00235       m_MetaArray.ConvertElementDataTo(_metaElementType);
00236       }
00237     int rows = m_MetaArray.Length();
00238     int cols = m_MetaArray.ElementNumberOfChannels();
00239     _array->SetSize(rows);
00240     for(int i=0; i<rows; i++)
00241       {
00242       (*_array)[i].SetSize(cols);
00243       for(int j=0; j<cols; j++)
00244         {
00245         (*_array)[i][j] = static_cast<typename TValueType::ValueType>
00246                                      (m_MetaArray.ElementData(i*cols+j));
00247         }
00248       }
00249     }
00251 
00252 protected:
00253 
00254   MetaArrayReader();
00255   virtual ~MetaArrayReader();
00256 
00257 private:
00258 
00259   MetaArray    m_MetaArray;
00260 
00261   std::string  m_FileName;
00262 
00263   void *       m_Buffer;
00264 
00265 };
00266 
00267 } // namespace itk
00268 
00269 
00270 #endif // __itkTransformFileReader_h
00271 

Generated at Mon Mar 12 01:38:05 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000