Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __mitkNrrdDiffusionImageWriter__cpp
00019 #define __mitkNrrdDiffusionImageWriter__cpp
00020
00021 #include "mitkNrrdDiffusionImageWriter.h"
00022 #include "itkMetaDataDictionary.h"
00023 #include "itkMetaDataObject.h"
00024 #include "itkNrrdImageIO.h"
00025 #include "itkImageFileWriter.h"
00026
00027 template<typename TPixelType>
00028 mitk::NrrdDiffusionImageWriter<TPixelType>::NrrdDiffusionImageWriter()
00029 : m_FileName(""), m_FilePrefix(""), m_FilePattern(""), m_Success(false)
00030 {
00031 this->SetNumberOfRequiredInputs( 1 );
00032 }
00033
00034 template<typename TPixelType>
00035 mitk::NrrdDiffusionImageWriter<TPixelType>::~NrrdDiffusionImageWriter()
00036 {}
00037
00038 template<typename TPixelType>
00039 void mitk::NrrdDiffusionImageWriter<TPixelType>::GenerateData()
00040 {
00041 m_Success = false;
00042 InputType* input = this->GetInput();
00043 if (input == NULL)
00044 {
00045 itkWarningMacro(<<"Sorry, input to NrrdDiffusionImageWriter is NULL!");
00046 return;
00047 }
00048 if ( m_FileName == "" )
00049 {
00050 itkWarningMacro( << "Sorry, filename has not been set!" );
00051 return ;
00052 }
00053
00054 char keybuffer[512];
00055 char valbuffer[512];
00056 std::string tmp;
00057
00058 itk::VectorImage<short,3>::Pointer img = input->GetVectorImage();
00059 img->GetMetaDataDictionary();
00060
00061
00062 sprintf( valbuffer, "(%1f,%1f,%1f) (%1f,%1f,%1f) (%1f,%1f,%1f)", 1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,1.0f);
00063 itk::EncapsulateMetaData<std::string>(input->GetVectorImage()->GetMetaDataDictionary(),std::string("measurement frame"),std::string(valbuffer));
00064
00065 sprintf( valbuffer, "DWMRI");
00066 itk::EncapsulateMetaData<std::string>(input->GetVectorImage()->GetMetaDataDictionary(),std::string("modality"),std::string(valbuffer));
00067
00068 if(input->GetDirections()->Size())
00069 {
00070 sprintf( valbuffer, "%1f", input->GetB_Value() );
00071 itk::EncapsulateMetaData<std::string>(input->GetVectorImage()->GetMetaDataDictionary(),std::string("DWMRI_b-value"),std::string(valbuffer));
00072 }
00073
00074 for(unsigned int i=0; i<input->GetDirections()->Size(); i++)
00075 {
00076 sprintf( keybuffer, "DWMRI_gradient_%04d", i );
00077
00078
00079
00080
00081
00082 sprintf( valbuffer, "%1f %1f %1f", input->GetDirections()->ElementAt(i).get(0),
00083 input->GetDirections()->ElementAt(i).get(1), input->GetDirections()->ElementAt(i).get(2));
00084
00085 itk::EncapsulateMetaData<std::string>(input->GetVectorImage()->GetMetaDataDictionary(),std::string(keybuffer),std::string(valbuffer));
00086 }
00087
00088 itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New();
00089
00090 io->SetFileType( itk::ImageIOBase::Binary );
00091
00092 typedef itk::VectorImage<TPixelType,3> ImageType;
00093 typedef itk::ImageFileWriter<ImageType> WriterType;
00094 typename WriterType::Pointer nrrdWriter = WriterType::New();
00095 nrrdWriter->UseInputMetaDataDictionaryOn();
00096 nrrdWriter->SetInput( input->GetVectorImage() );
00097 nrrdWriter->SetImageIO(io);
00098 nrrdWriter->SetFileName(m_FileName);
00099
00100 try
00101 {
00102 nrrdWriter->Update();
00103 }
00104 catch (itk::ExceptionObject e)
00105 {
00106 std::cout << e << std::endl;
00107 }
00108
00109 m_Success = true;
00110 }
00111
00112 template<typename TPixelType>
00113 void mitk::NrrdDiffusionImageWriter<TPixelType>::SetInput( InputType* diffVolumes )
00114 {
00115 this->ProcessObject::SetNthInput( 0, diffVolumes );
00116 }
00117
00118 template<typename TPixelType>
00119 mitk::DiffusionImage<TPixelType>* mitk::NrrdDiffusionImageWriter<TPixelType>::GetInput()
00120 {
00121 if ( this->GetNumberOfInputs() < 1 )
00122 {
00123 return NULL;
00124 }
00125 else
00126 {
00127 return dynamic_cast<InputType*> ( this->ProcessObject::GetInput( 0 ) );
00128 }
00129 }
00130
00131 template<typename TPixelType>
00132 std::vector<std::string> mitk::NrrdDiffusionImageWriter<TPixelType>::GetPossibleFileExtensions()
00133 {
00134 std::vector<std::string> possibleFileExtensions;
00135 possibleFileExtensions.push_back(".dwi");
00136 possibleFileExtensions.push_back(".hdwi");
00137 return possibleFileExtensions;
00138 }
00139
00140 #endif //__mitkNrrdDiffusionImageWriter__cpp