ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkMetaArrayWriter.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 __itkMetaArrayWriter_h
00019 #define __itkMetaArrayWriter_h
00020 
00021 #include "itkLightProcessObject.h"
00022 #include "itkArray.h"
00023 #include "itkCovariantVector.h"
00024 #include "itkVariableLengthVector.h"
00025 #include "metaArray.h"
00026 
00027 namespace itk
00028 {
00029 class ITK_EXPORT MetaArrayWriter:public LightProcessObject
00030 {
00031 public:
00032 
00034   typedef MetaArrayWriter    Self;
00035   typedef LightProcessObject Superclass;
00036 
00037   typedef SmartPointer< Self >       Pointer;
00038   typedef SmartPointer< const Self > ConstPointer;
00039 
00041   itkNewMacro(Self);
00042 
00044   itkTypeMacro(MetaArrayWriter, LightProcessObject);
00045 
00047   itkSetStringMacro(FileName);
00048 
00050   itkGetStringMacro(FileName);
00051 
00055   itkSetStringMacro(DataFileName);
00056 
00058   itkGetStringMacro(DataFileName);
00059 
00061   itkSetMacro(Binary, bool);
00062 
00065   itkGetConstMacro(Binary, bool);
00066 
00068   template< typename TValueType >
00069   void SetInput(MET_ValueEnumType _metaElementType,
00070                 const Array< TValueType > *_array)
00071   {
00072     m_Buffer = (const void *)( _array->data_block() );
00073     m_MetaArray.InitializeEssential(_array->Size(),
00074                                     _metaElementType);
00075   }
00077 
00079   template< typename TValueType, unsigned int VLength >
00080   void SetInput(MET_ValueEnumType _metaElementType,
00081                 const FixedArray< TValueType, VLength > *_array)
00082   {
00083     m_Buffer = (const void *)( _array->GetDataPointer() );
00084     m_MetaArray.InitializeEssential(VLength,
00085                                     _metaElementType);
00086   }
00088 
00090   template< typename TValueType, unsigned int VLength >
00091   void SetInput(MET_ValueEnumType _metaElementType,
00092                 const Vector< TValueType, VLength > *_vector)
00093   {
00094     m_Buffer = (const void *)( _vector->GetDataPointer() );
00095     m_MetaArray.InitializeEssential(VLength,
00096                                     _metaElementType);
00097   }
00099 
00101   template< typename TValueType, unsigned int VLength >
00102   void SetInput(MET_ValueEnumType _metaElementType,
00103                 const CovariantVector< TValueType, VLength > *_vector)
00104   {
00105     m_Buffer = (const void *)( _vector->GetDataPointer() );
00106     m_MetaArray.InitializeEssential(VLength,
00107                                     _metaElementType);
00108   }
00110 
00112   template< typename TValueType >
00113   void SetInput(MET_ValueEnumType _metaElementType,
00114                 const VariableLengthVector< TValueType > *_vector)
00115   {
00116     m_Buffer = (const void *)( _vector->GetDataPointer() );
00117     m_MetaArray.InitializeEssential(_vector->Size(),
00118                                     _metaElementType);
00119   }
00121 
00129   template< typename TValueType >
00130   void SetMultiChannelInput(MET_ValueEnumType _metaElementType,
00131                             int ,
00132                             const Array< TValueType > *_array)
00133   {
00134     int rows = _array->GetSize();
00135     int cols = ( *_array )[0].GetSize();
00137 
00138     m_MetaArray.InitializeEssential(rows,
00139                                     _metaElementType,
00140                                     cols,
00141                                     NULL,
00142                                     true,
00143                                     true);
00144     m_Buffer = m_MetaArray.ElementData();
00145     for ( int i = 0; i < rows; i++ )
00146       {
00147       for ( int j = 0; j < cols; j++ )
00148         {
00149         m_MetaArray.ElementData( i * cols + j, (double)( ( *_array )[i][j] ) );
00150         }
00151       }
00152   }
00153 
00155   itkSetMacro(Precision, unsigned int);
00156   itkGetConstMacro(Precision, unsigned int);
00158 
00160   void ConvertTo(MET_ValueEnumType _metaElementType);
00161 
00163   void Update();
00164 
00165 protected:
00166 
00167   MetaArrayWriter();
00168   virtual ~MetaArrayWriter();
00169   void PrintSelf(std::ostream & os, Indent indent) const;
00170 
00171 private:
00172 
00173   bool m_Binary;
00174 
00175   unsigned int m_Precision;
00176 
00177   std::string m_FileName;
00178   std::string m_DataFileName;
00179 
00180   MetaArray m_MetaArray;
00181 
00182   const void *m_Buffer;
00183 };
00184 } // namespace itk
00185 
00186 #endif // __itkMetaArrayWriter_h
00187