/* * Copyright (c) ICG. All rights reserved. * See copyright.txt for more information. * * Institute for Computer Graphics and Vision * Graz, University of Technology / Austria * * * This software is distributed WITHOUT ANY WARRANTY; without even * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the above copyright notices for more information. * * * Project : MIPItkProjects * Module : CommonItkUtilities * Class : $RCSfile: VolumeIOWrapper.h,v $ * Language : C++ * Description : * * Author : Martin Urschler * EMail : urschler@icg.tu-graz.ac.at * Date : $Date: 2006-09-11 08:44:08 $ * Version : $Revision: 1.11 $ * Full Id : $Id: VolumeIOWrapper.h,v 1.11 2006-09-11 08:44:08 urschler Exp $ * */ #ifndef __VOLUME_IO_WRAPPER_H__ #define __VOLUME_IO_WRAPPER_H__ // include files #include "commonTypedefs.h" #include "itkRescaleIntensityImageFilter.h" #include "itkImageSeriesReader.h" // typedefs // forward declarations /** * Class Documentation. * */ template< typename TImageType > class VolumeIOWrapper { public: typedef typename TImageType::Pointer TImageTypePointer; typedef typename itk::ImageSeriesReader< TImageType > TImageSeriesReaderType; typedef typename itk::ImageSeriesReader< TImageType >::Pointer TImageSeriesReaderPointerType; static std::string constructFinalFilename( const std::string& base_filename, const std::string& filename_extension ) { std::string write_filename = base_filename; std::string write_extension = filename_extension + std::string(".hdr"); write_filename.replace( write_filename.find(".hdr"), 4, write_extension ); return write_filename; } // this method reads a dicom image series and returns a volume and the meta information static TImageTypePointer readITKDicomSeries( const std::string& input_directory_name, TImageSeriesReaderPointerType& series_reader_ret_val, int whichSeries=0 ); // this method writes a dicom image series static bool writeITKDicomSeries( const TImageTypePointer& image, const std::string& input_directory_name, const std::string& output_directory_name, const TImageSeriesReaderPointerType& series_reader ); // this method reads a volume static TImageTypePointer readITKVolume( const std::string& filename, const std::string& extension ); // this method performs a simple cast of the input image type to signed short // and writes it static bool writeITKVolume16Bit( const TImageTypePointer& image, const std::string& base_filename, const std::string& filename_extension ); // this method performs a rescale intensity transform on the input image // casts it to unsigned char and writes it static bool writeITKVolume8Bit( const TImageTypePointer& image, const std::string& base_filename, const std::string& filename_extension, bool cast_to_values_betw_0_255 = true ); static bool writeITKVolumeAsDicomFiles( const TImageTypePointer& image, const std::string& directory_filename ); private: VolumeIOWrapper(); ~VolumeIOWrapper(); static void convertShortTo2Bytes( const MY_UINT16& word_val, MY_UINT8& byte0, MY_UINT8& byte1, bool little_endian ); static void convertIntTo4Bytes( const MY_UINT32& int_val, MY_UINT8& byte0, MY_UINT8& byte1, MY_UINT8& byte2, MY_UINT8& byte3, bool little_endian ); static bool writeDicomValue32(std::ostream& stream, MY_UINT16 group_nr, MY_UINT16 tag_nr, MY_UINT8 cS_1, MY_UINT8 cS_2, MY_UINT32 val, bool little_endian); static bool writeDicomValue16(std::ostream& stream, MY_UINT16 group_nr, MY_UINT16 tag_nr, MY_UINT8 cS_1, MY_UINT8 cS_2, MY_UINT16 val, bool little_endian); static bool writeDicomString(std::ostream& stream, MY_UINT16 group_nr, MY_UINT16 tag_nr, MY_UINT8 cS_1, MY_UINT8 cS_2, const char* string, bool little_endian); static void writeDicomOBMetaInfoValue( std::ostream& stream, bool little_endian ); static void zipTheDataFile( const std::string& filename ); }; // inline declarations #endif // __VOLUME_IO_WRAPPER_H__