go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkImageFileCastWriter.h
Go to the documentation of this file.
00001 /*======================================================================
00002 
00003   This file is part of the elastix software.
00004 
00005   Copyright (c) University Medical Center Utrecht. All rights reserved.
00006   See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for
00007   details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE. See the above copyright notices for more information.
00012 
00013 ======================================================================*/
00014 
00015 #ifndef __itkImageFileCastWriter_h
00016 #define __itkImageFileCastWriter_h
00017 
00018 #include "itkImageFileWriter.h"
00019 #include "itkImageIOBase.h"
00020 #include "itkExceptionObject.h"
00021 #include "itkSize.h"
00022 #include "itkImageIORegion.h"
00023 #include "itkCastImageFilter.h"
00024 
00025 
00026 namespace itk
00027 {
00028 
00037 template <class TInputImage >
00038   class ImageFileCastWriter : public ImageFileWriter<TInputImage>
00039 {
00040 public:
00042   typedef ImageFileCastWriter                   Self;
00043   typedef ImageFileWriter<TInputImage>       Superclass;
00044   typedef SmartPointer<Self>                 Pointer;
00045   typedef SmartPointer<const Self>           ConstPointer;
00046 
00048   itkNewMacro(Self);
00049 
00051   itkTypeMacro(ImageFileCastWriter,ImageFileWriter);
00052 
00054   typedef typename Superclass::InputImageType         InputImageType;
00055   typedef typename Superclass::InputImagePointer      InputImagePointer;
00056   typedef typename Superclass::InputImageRegionType   InputImageRegionType;
00057   typedef typename Superclass::InputImagePixelType    InputImagePixelType;
00058 
00059   itkStaticConstMacro( InputImageDimension, unsigned int, InputImageType::ImageDimension );
00060 
00064   itkSetStringMacro(OutputComponentType);
00065   itkGetStringMacro(OutputComponentType);
00066 
00068   std::string GetDefaultOutputComponentType(void) const;
00069 
00070 protected:
00071   ImageFileCastWriter();
00072   ~ImageFileCastWriter();
00073 
00075   void GenerateData(void);
00076 
00081   template < class OutputComponentType >
00082     void * ConvertScalarImage( const DataObject * inputImage,
00083       const OutputComponentType & itkNotUsed( dummy ) )
00084   {
00085     typedef Image< OutputComponentType, InputImageDimension>      DiskImageType;
00086     typedef typename PixelTraits<InputImagePixelType>::ValueType  InputImageComponentType;
00087     typedef Image<InputImageComponentType, InputImageDimension>   ScalarInputImageType;
00088     typedef CastImageFilter< ScalarInputImageType, DiskImageType> CasterType;
00089 
00091     this->GetImageIO()->SetPixelTypeInfo( typeid(OutputComponentType) );
00092 
00094     typename CasterType::Pointer caster = CasterType::New();
00095     this->m_Caster = caster;
00096     typename ScalarInputImageType::Pointer localInputImage = ScalarInputImageType::New();
00097     localInputImage->Graft( inputImage );
00098     caster->SetInput( localInputImage );
00099     caster->Update();
00100 
00102     OutputComponentType * pixelBuffer = caster->GetOutput()->GetBufferPointer();
00103     void * convertedBuffer = static_cast<void *>(pixelBuffer);
00104     return convertedBuffer;
00105   }
00106 
00107   ProcessObject::Pointer m_Caster;
00108 
00109 private:
00110   ImageFileCastWriter(const Self&); //purposely not implemented
00111   void operator=(const Self&); //purposely not implemented
00112 
00113   std::string m_OutputComponentType;
00114 };
00115 
00116 
00117 } // end namespace itk
00118 
00119 #ifndef ITK_MANUAL_INSTANTIATION
00120 #include "itkImageFileCastWriter.txx"
00121 #endif
00122 
00123 #endif // __itkImageFileCastWriter_h
00124 


Generated on 11-05-2012 for elastix by doxygen 1.7.6.1 elastix logo