1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef clitkChangeDicomTagGenericFilter_txx
19 #define clitkChangeDicomTagGenericFilter_txx
21 /* =================================================
22 * @file clitkChangeDicomTagGenericFilter.txx
28 ===================================================*/
31 #include "clitkResampleImageWithOptionsFilter.h"
32 #if GDCM_MAJOR_VERSION >= 2
33 #include "gdcmUIDGenerator.h"
34 #include <gdcmImageHelper.h>
35 #include <gdcmAttribute.h>
36 #include <gdcmReader.h>
37 #include <gdcmWriter.h>
38 #include <gdcmDataElement.h>
50 //-----------------------------------------------------------
52 //-----------------------------------------------------------
53 template<class args_info_type>
54 ChangeDicomTagGenericFilter<args_info_type>::ChangeDicomTagGenericFilter()
60 //-----------------------------------------------------------
62 //-----------------------------------------------------------
63 template<class args_info_type>
64 void ChangeDicomTagGenericFilter<args_info_type>::Update()
66 UpdateWithDimAndPixelType();
69 //-------------------------------------------------------------------
70 // Update with the number of dimensions and the pixeltype read from
71 // the dicom files. The MHD files may be resampled to match the
72 // dicom spacing (and number of slices). Rounding errors in resampling
73 // are handled by removing files when generating the output dicom
75 //-------------------------------------------------------------------
76 template<class args_info_type>
78 ChangeDicomTagGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
82 reader.SetFileName( m_ArgsInfo.input_arg );
84 gdcm::File &fileOutput = reader.GetFile();
85 gdcm::DataSet &dsOutput = fileOutput.GetDataSet();
86 const unsigned int ptr_len = 42;
87 char *ptr = new char[ptr_len];
88 memset(ptr,0,ptr_len);
90 unsigned int numberOfKeysGiven=m_ArgsInfo.key_given;
92 for (unsigned int i = 0; i < numberOfKeysGiven; i++) {
93 // Split the tag element separated with '|' in 2 parts
94 char* copy = (char*)m_ArgsInfo.key_arg[i];
96 char* chars_array = strtok(copy, "|");
98 v.push_back(chars_array);
99 chars_array = strtok(NULL, "|");
101 std::stringstream str0(v[0]), str1(v[1]);
106 //Change the tag element by the corresponding value
107 gdcm::DataElement tagDE( gdcm::Tag(first, second) );
108 std::string value( m_ArgsInfo.tag_arg[i] );
109 tagDE.SetByteValue(value.c_str(), (uint32_t)strlen(value.c_str()));
110 dsOutput.Insert(tagDE);
113 //Write the output dicom file
115 w.SetFile( fileOutput );
116 w.SetFileName( m_ArgsInfo.output_arg );
122 #endif //#define clitkChangeDicomTagGenericFilter_txx