Tomato
Tomato_exportT1.hxx
Go to the documentation of this file.
1 
7 #ifndef Tomato_Tomato_EXPORT_HXX
8 #define Tomato_Tomato_EXPORT_HXX
9 
10 #include "CmakeConfigForTomato.h"
11 #ifdef USE_ITK
12 
13 #include "gdcmUIDGenerator.h"
14 #include "itkGDCMImageIO.h"
15 #include "itkGDCMSeriesFileNames.h"
16 #include "itkMultiplyImageFilter.h"
17 #include "itkImageFileWriter.h"
18 #include "itkFileTools.h"
19 #include "itkAdaptImageFilter.h"
20 
21 namespace Ox {
22 
23  template< typename MeasureType >
24  int
25  Tomato<MeasureType>
26  ::exportT1ToDicom(){
27 
28  if (_opts->dir_output_map.empty()){
29  printf("No DICOM export, dir_output_map not given.\n");
30  return EXIT_FAILURE;
31  }
32 
33  // OxColorbarImageFilter
34  typedef itk::Colorbar2DImageFilter< ImageType2D > OxColorbarImageFilterType;
35  typename OxColorbarImageFilterType::Pointer OxColorbarFilter = OxColorbarImageFilterType::New();
36  OxColorbarFilter->SetInput(_imageCalculatorItk->GetT1Image());
37  OxColorbarFilter->SetAddColorbar(_opts->use_colorbar);
38 
39  // this one I want to reset
40  itk::EncapsulateMetaData<std::string>( _dictionaryInput, std::string("0028|1052"), "0"); // Rescale intercept
41  itk::EncapsulateMetaData<std::string>( _dictionaryInput, std::string("0028|1053"), "1"); // Rescale slope
42 
43  // T1 map with color
44  DictionaryType dictionaryOutput_T1Color(_dictionaryInput);
45 
46  // UIDs
47  gdcm::UIDGenerator sopuid;
48  std::string sopInstanceUID_T1Color = sopuid.Generate();
49  gdcm::UIDGenerator suid;
50  std::string seriesUID_T1 = suid.Generate();
51 
52  // seriesNumber
53  std::string seriesNumber;
54  itk::ExposeMetaData<std::string>(_dictionaryInput, "0020|0011", seriesNumber);
55  if (_opts->output_map_series_number == 0) {
56  _opts->output_map_series_number = KWUtil::StringToNumber<int>(seriesNumber) + 10002;
57  }
58  std::string newSeriesNumber_T1 = KWUtil::NumberToString(_opts->output_map_series_number);
59 
60 
61  // dicom tags dependent on the MagneticFieldStrength
62  std::string MagneticFieldStrength;
63  itk::ExposeMetaData<std::string>(_dictionaryInput, "0018|0087", MagneticFieldStrength);
64  std::string ImageCommentsT1mapWithColormap, clutRedString, clutGreenString, clutBlueString;
65  if (MagneticFieldStrength.find("1.5") != std::string::npos){
66  ImageCommentsT1mapWithColormap = ImageCommentsT1mapWithColormap.append("ShMOLLI color 980SD265ms");
67  clutRedString = getEncodedSting(getShmolliColormapRed15TArray());
68  clutGreenString = getEncodedSting(getShmolliColormapGreen15TArray());
69  clutBlueString = getEncodedSting(getShmolliColormapBlue15TArray());
70  printf("Colormap for MagneticFieldStrength 1.5T is used.\n");
71  } else if (MagneticFieldStrength.find('3') != std::string::npos){
72  ImageCommentsT1mapWithColormap = ImageCommentsT1mapWithColormap.append("ShMOLLI color 1198SD175ms");
73  clutRedString = getEncodedSting(getShmolliColormapRed3TArray());
74  clutGreenString = getEncodedSting(getShmolliColormapGreen3TArray());
75  clutBlueString = getEncodedSting(getShmolliColormapBlue3TArray());
76  printf("Colormap for MagneticFieldStrength 3T is used.\n");
77  } else {
78  printf("MagneticFieldStrength not detected, colormap will not be used.\n");
79  }
80 
81  // PaletteColorLookupTableUID
82  std::string PaletteColorLookupTableUID;
83  itk::ExposeMetaData<std::string>(_dictionaryInput, "0028|1199", PaletteColorLookupTableUID);
84 
85  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0008|0018"), sopInstanceUID_T1Color);
86  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0002|0003"), sopInstanceUID_T1Color);
87  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0020|000e"), seriesUID_T1);
88  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0028|1199"), PaletteColorLookupTableUID); // color look up table UID
89 
90  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0020|0011"), newSeriesNumber_T1); // series number
91 
92  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0020|4000"), ImageCommentsT1mapWithColormap); // series number
93  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0020|0013"), std::string("1")); // instance number
94  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0028|0106"), std::string("0")); // smallest pixel
95  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0028|0107"), std::string("4096")); // largest pixel
96  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0028|1050"), std::string("2048")); // window center
97  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0028|1051"), std::string("4096")); // window width
98 
99  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0028|1101"), std::string("4096\\0\\16")); // red color look up table descriptor
100  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0028|1102"), std::string("4096\\0\\16")); // green color look up table descriptor
101  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0028|1103"), std::string("4096\\0\\16")); // blue color look up table descriptor
102 
103  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0028|1201"), clutRedString);
104  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0028|1202"), clutGreenString);
105  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1Color, std::string("0028|1203"), clutBlueString);
106 
107  // T1 map no color
108  DictionaryType dictionaryOutput_T1(_dictionaryInput);
109 
110  std::string sopInstanceUID_T1 = sopuid.Generate();
111 
112  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1, std::string("0008|0018"), sopInstanceUID_T1);
113  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1, std::string("0002|0003"), sopInstanceUID_T1);
114  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1, std::string("0020|000e"), seriesUID_T1);
115 
116  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1, std::string("0020|0011"), newSeriesNumber_T1); // series number
117 
118  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1, std::string("0020|4000"), std::string("ShMOLLI T1 map")); // series number
119  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1, std::string("0020|0013"), std::string("2")); // instance number
120  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1, std::string("0028|0106"), std::string("0")); // smallest pixel
121  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1, std::string("0028|0107"), std::string("4096")); // largest pixel
122  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1, std::string("0028|1050"), std::string("2048")); // window center
123  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1, std::string("0028|1051"), std::string("4096")); // window width
124 
125  // R2 map
126  DictionaryType dictionaryOutput_R2(_dictionaryInput);
127 
128  std::string sopInstanceUID_R2 = sopuid.Generate();
129  std::string seriesUID_R2 = suid.Generate();
130 
131  itk::ExposeMetaData<std::string>(_dictionaryInput, "0020|0011", seriesNumber);
132  if (_opts->output_fitparams_series_number == 0) {
133  _opts->output_fitparams_series_number = KWUtil::StringToNumber<int>(seriesNumber) + 10003;
134  }
135  std::string newSeriesNumber_R2 = KWUtil::NumberToString(_opts->output_fitparams_series_number);
136 
137 
138  itk::EncapsulateMetaData<std::string>( dictionaryOutput_R2, std::string("0008|0018"), sopInstanceUID_R2);
139  itk::EncapsulateMetaData<std::string>( dictionaryOutput_R2, std::string("0002|0003"), sopInstanceUID_R2);
140  itk::EncapsulateMetaData<std::string>( dictionaryOutput_R2, std::string("0020|000e"), seriesUID_R2);
141 
142  itk::EncapsulateMetaData<std::string>( dictionaryOutput_R2, std::string("0020|0011"), newSeriesNumber_R2); // series number
143 
144  itk::EncapsulateMetaData<std::string>( dictionaryOutput_R2, std::string("0020|4000"), std::string("Rsquare*4000 Map")); // series number
145  itk::EncapsulateMetaData<std::string>( dictionaryOutput_R2, std::string("0020|0013"), std::string("3")); // instance number
146  itk::EncapsulateMetaData<std::string>( dictionaryOutput_R2, std::string("0028|0106"), std::string("0")); // smallest pixel
147  itk::EncapsulateMetaData<std::string>( dictionaryOutput_R2, std::string("0028|0107"), std::string("4096")); // largest pixel
148  itk::EncapsulateMetaData<std::string>( dictionaryOutput_R2, std::string("0028|1050"), std::string("3900")); // window center
149  itk::EncapsulateMetaData<std::string>( dictionaryOutput_R2, std::string("0028|1051"), std::string("200")); // window width
150 
151  // A map
152  DictionaryType dictionaryOutput_A(_dictionaryInput);
153 
154  std::string sopInstanceUID_A = sopuid.Generate();
155 
156  itk::EncapsulateMetaData<std::string>( dictionaryOutput_A, std::string("0008|0018"), sopInstanceUID_A);
157  itk::EncapsulateMetaData<std::string>( dictionaryOutput_A, std::string("0002|0003"), sopInstanceUID_A);
158  itk::EncapsulateMetaData<std::string>( dictionaryOutput_A, std::string("0020|000e"), seriesUID_R2);
159 
160  itk::EncapsulateMetaData<std::string>( dictionaryOutput_A, std::string("0020|0011"), newSeriesNumber_R2); // series number
161 
162  itk::EncapsulateMetaData<std::string>( dictionaryOutput_A, std::string("0020|4000"), std::string("Signal(TI)=[___AMap___]-B*exp(-TI/T1star)")); // series number
163  itk::EncapsulateMetaData<std::string>( dictionaryOutput_A, std::string("0020|0013"), std::string("4")); // instance number
164  itk::EncapsulateMetaData<std::string>( dictionaryOutput_A, std::string("0028|0106"), std::string("0")); // smallest pixel
165  itk::EncapsulateMetaData<std::string>( dictionaryOutput_A, std::string("0028|0107"), std::string("4096")); // largest pixel
166  itk::EncapsulateMetaData<std::string>( dictionaryOutput_A, std::string("0028|1050"), std::string("2000")); // window center
167  itk::EncapsulateMetaData<std::string>( dictionaryOutput_A, std::string("0028|1051"), std::string("4000")); // window width
168 
169  // B map
170  DictionaryType dictionaryOutput_B(_dictionaryInput);
171 
172  std::string sopInstanceUID_B = sopuid.Generate();
173 
174  itk::EncapsulateMetaData<std::string>( dictionaryOutput_B, std::string("0008|0018"), sopInstanceUID_B);
175  itk::EncapsulateMetaData<std::string>( dictionaryOutput_B, std::string("0002|0003"), sopInstanceUID_B);
176  itk::EncapsulateMetaData<std::string>( dictionaryOutput_B, std::string("0020|000e"), seriesUID_R2);
177 
178  itk::EncapsulateMetaData<std::string>( dictionaryOutput_B, std::string("0020|0011"), newSeriesNumber_R2); // series number
179 
180  itk::EncapsulateMetaData<std::string>( dictionaryOutput_B, std::string("0020|4000"), std::string("Signal(TI)=A-[___BMap___]*exp(-TI/T1star)")); // series number
181  itk::EncapsulateMetaData<std::string>( dictionaryOutput_B, std::string("0020|0013"), std::string("5")); // instance number
182  itk::EncapsulateMetaData<std::string>( dictionaryOutput_B, std::string("0028|0106"), std::string("0")); // smallest pixel
183  itk::EncapsulateMetaData<std::string>( dictionaryOutput_B, std::string("0028|0107"), std::string("4096")); // largest pixel
184  itk::EncapsulateMetaData<std::string>( dictionaryOutput_B, std::string("0028|1050"), std::string("2000")); // window center
185  itk::EncapsulateMetaData<std::string>( dictionaryOutput_B, std::string("0028|1051"), std::string("4000")); // window width
186 
187  // T1star map
188  DictionaryType dictionaryOutput_T1star(_dictionaryInput);
189 
190  std::string sopInstanceUID_T1star = sopuid.Generate();
191 
192  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1star, std::string("0008|0018"), sopInstanceUID_T1star);
193  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1star, std::string("0002|0003"), sopInstanceUID_T1star);
194  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1star, std::string("0020|000e"), seriesUID_R2);
195 
196  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1star, std::string("0020|0011"), newSeriesNumber_R2); // series number
197 
198  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1star, std::string("0020|4000"), std::string("Signal(TI)=A-B*exp(-TI/[___T1starMap___])")); // series number
199  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1star, std::string("0020|0013"), std::string("6")); // instance number
200  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1star, std::string("0028|0106"), std::string("0")); // smallest pixel
201  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1star, std::string("0028|0107"), std::string("4096")); // largest pixel
202  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1star, std::string("0028|1050"), std::string("2000")); // window center
203  itk::EncapsulateMetaData<std::string>( dictionaryOutput_T1star, std::string("0028|1051"), std::string("4000")); // window width
204 
205  // _ShMOLLIT1range map
206  DictionaryType dictionaryOutput_ShMolliT1Range(_dictionaryInput);
207 
208  std::string sopInstanceUID_ShMolliT1Range = sopuid.Generate();
209 
210  itk::EncapsulateMetaData<std::string>( dictionaryOutput_ShMolliT1Range, std::string("0008|0018"), sopInstanceUID_ShMolliT1Range);
211  itk::EncapsulateMetaData<std::string>( dictionaryOutput_ShMolliT1Range, std::string("0002|0003"), sopInstanceUID_ShMolliT1Range);
212  itk::EncapsulateMetaData<std::string>( dictionaryOutput_ShMolliT1Range, std::string("0020|000e"), seriesUID_R2);
213 
214  itk::EncapsulateMetaData<std::string>( dictionaryOutput_ShMolliT1Range, std::string("0020|0011"), newSeriesNumber_R2); // series number
215 
216  itk::EncapsulateMetaData<std::string>( dictionaryOutput_ShMolliT1Range, std::string("0020|4000"), std::string("_ShMOLLIT1range")); // series number
217  itk::EncapsulateMetaData<std::string>( dictionaryOutput_ShMolliT1Range, std::string("0020|0013"), std::string("7")); // instance number
218  itk::EncapsulateMetaData<std::string>( dictionaryOutput_ShMolliT1Range, std::string("0028|0106"), std::string("0")); // smallest pixel
219  itk::EncapsulateMetaData<std::string>( dictionaryOutput_ShMolliT1Range, std::string("0028|0107"), std::string("4096")); // largest pixel
220  itk::EncapsulateMetaData<std::string>( dictionaryOutput_ShMolliT1Range, std::string("0028|1050"), std::string("1500")); // window center
221  itk::EncapsulateMetaData<std::string>( dictionaryOutput_ShMolliT1Range, std::string("0028|1051"), std::string("3000")); // window width
222 
223  // _nAmebaCallFinal map
224  DictionaryType dictionaryOutput_nAmebaCallFinal(_dictionaryInput);
225 
226  std::string sopInstanceUID_nAmebaCallFinal = sopuid.Generate();
227 
228  itk::EncapsulateMetaData<std::string>( dictionaryOutput_nAmebaCallFinal, std::string("0008|0018"), sopInstanceUID_nAmebaCallFinal);
229  itk::EncapsulateMetaData<std::string>( dictionaryOutput_nAmebaCallFinal, std::string("0002|0003"), sopInstanceUID_nAmebaCallFinal);
230  itk::EncapsulateMetaData<std::string>( dictionaryOutput_nAmebaCallFinal, std::string("0020|000e"), seriesUID_R2);
231 
232  itk::EncapsulateMetaData<std::string>( dictionaryOutput_nAmebaCallFinal, std::string("0020|0011"), newSeriesNumber_R2); // series number
233 
234  itk::EncapsulateMetaData<std::string>( dictionaryOutput_nAmebaCallFinal, std::string("0020|4000"), std::string("_nAmebaCallFinal")); // series number
235  itk::EncapsulateMetaData<std::string>( dictionaryOutput_nAmebaCallFinal, std::string("0020|0013"), std::string("8")); // instance number
236  itk::EncapsulateMetaData<std::string>( dictionaryOutput_nAmebaCallFinal, std::string("0028|0106"), std::string("0")); // smallest pixel
237  itk::EncapsulateMetaData<std::string>( dictionaryOutput_nAmebaCallFinal, std::string("0028|0107"), std::string("4096")); // largest pixel
238  itk::EncapsulateMetaData<std::string>( dictionaryOutput_nAmebaCallFinal, std::string("0028|1050"), std::string("2000")); // window center
239  itk::EncapsulateMetaData<std::string>( dictionaryOutput_nAmebaCallFinal, std::string("0028|1051"), std::string("4000")); // window width
240 
241  // _RelSNRFinal map
242  DictionaryType dictionaryOutput_RelSNRFinal(_dictionaryInput);
243 
244  std::string sopInstanceUID_RelSNRFinal = sopuid.Generate();
245 
246  itk::EncapsulateMetaData<std::string>( dictionaryOutput_RelSNRFinal, std::string("0008|0018"), sopInstanceUID_RelSNRFinal);
247  itk::EncapsulateMetaData<std::string>( dictionaryOutput_RelSNRFinal, std::string("0002|0003"), sopInstanceUID_RelSNRFinal);
248  itk::EncapsulateMetaData<std::string>( dictionaryOutput_RelSNRFinal, std::string("0020|000e"), seriesUID_R2);
249 
250  itk::EncapsulateMetaData<std::string>( dictionaryOutput_RelSNRFinal, std::string("0020|0011"), newSeriesNumber_R2); // series number
251 
252  itk::EncapsulateMetaData<std::string>( dictionaryOutput_RelSNRFinal, std::string("0020|4000"), std::string("_RelSNRFinal")); // series number
253  itk::EncapsulateMetaData<std::string>( dictionaryOutput_RelSNRFinal, std::string("0020|0013"), std::string("9")); // instance number
254  itk::EncapsulateMetaData<std::string>( dictionaryOutput_RelSNRFinal, std::string("0028|0106"), std::string("0")); // smallest pixel
255  itk::EncapsulateMetaData<std::string>( dictionaryOutput_RelSNRFinal, std::string("0028|0107"), std::string("4096")); // largest pixel
256  itk::EncapsulateMetaData<std::string>( dictionaryOutput_RelSNRFinal, std::string("0028|1050"), std::string("2000")); // window center
257  itk::EncapsulateMetaData<std::string>( dictionaryOutput_RelSNRFinal, std::string("0028|1051"), std::string("4000")); // window width
258 
259  // get GDCMImageIO ready before export
260  typedef itk::GDCMImageIO ImageIOType;
261  ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
262  gdcmImageIO->KeepOriginalUIDOn();
263 
264  // to cast
265  typedef itk::AdaptImageFilter < ImageType2D, OutputImageType, CastPixelAccessor< InputPixelType, OutputPixelType > > ImageAdaptorType;
266  typename ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
267 
268  // get the writer ready before export
269  typedef itk::ImageFileWriter<OutputImageType> WriterType;
270  typename WriterType::Pointer writer = WriterType::New();
271  writer->SetUseInputMetaDataDictionary(false);
272 
273  // maybe this? http://www.cplusplus.com/reference/string/string/find_last_of/
274  if (!_opts->dir_output_map.empty()) {
275 
276  printf("Saving to: %s ", _opts->dir_output_map.c_str());
277  //std::cout << "Saving to: " << _opts->dir_output_map << std::flush;
278 
279  itk::FileTools::CreateDirectory(_opts->dir_output_map);
280 
281  // export T1 color
282  gdcmImageIO->SetMetaDataDictionary(dictionaryOutput_T1Color);
283 
284  // export to dicom
285  adaptor->SetInput(OxColorbarFilter->GetOutput());
286  writer->SetFileName(_opts->dir_output_map + KWUtil::PathSeparator() + newSeriesNumber_T1 + "_T1color.dcm");
287  writer->SetInput(adaptor->GetOutput());
288  writer->SetImageIO(gdcmImageIO);
289  try {
290  writer->Update();
291  } catch (itk::ExceptionObject &e) {
292  std::cerr << "Exception in file writer " << std::endl;
293  std::cerr << e << std::endl;
294  }
295 
296  // export T1 color
297  gdcmImageIO->SetMetaDataDictionary(dictionaryOutput_T1);
298 
299  // export to dicom
300  adaptor->SetInput(OxColorbarFilter->GetOutput());
301  writer->SetFileName( _opts->dir_output_map + KWUtil::PathSeparator() + newSeriesNumber_T1 + "_T1.dcm");
302  writer->SetInput(adaptor->GetOutput());
303  writer->SetImageIO(gdcmImageIO);
304  try {
305  writer->Update();
306  } catch (itk::ExceptionObject &e) {
307  std::cerr << "Exception in file writer " << std::endl;
308  std::cerr << e << std::endl;
309  }
310  std::cout << " Saved!" << std::endl;
311  }
312 
313  if (!_opts->dir_output_fitparams.empty()) {
314 
315  printf("Saving to: %s ", _opts->dir_output_fitparams.c_str());
316  //std::cout << "Saving to: " << _opts->dir_output_fitparams << std::flush;
317 
318  // scaling R2 * 4000
319  typedef itk::MultiplyImageFilter< ImageType2D, ImageType2D, ImageType2D > MultiplyImageFilterType;
320  typename MultiplyImageFilterType::Pointer multiplyFilter = MultiplyImageFilterType::New();
321  multiplyFilter->SetInput( _imageCalculatorItk->GetR2AbsImage() );
322  multiplyFilter->SetConstant( 4000 );
323 
324  OxColorbarFilter->SetInput(multiplyFilter->GetOutput());
325  OxColorbarFilter->SetZerosInsteadOfColorbar(true);
326 
327  // mkdir
328  itk::FileTools::CreateDirectory(_opts->dir_output_fitparams);
329 
330  // export R2
331  gdcmImageIO->SetMetaDataDictionary(dictionaryOutput_R2);
332 
333  // export to dicom
334  adaptor->SetInput(OxColorbarFilter->GetOutput());
335  writer->SetFileName(_opts->dir_output_fitparams + KWUtil::PathSeparator() + newSeriesNumber_R2 + "_R2.dcm");
336  writer->SetInput(adaptor->GetOutput());
337  writer->SetImageIO(gdcmImageIO);
338  try {
339  writer->Update();
340  } catch (itk::ExceptionObject &e) {
341  std::cerr << "Exception in file writer " << std::endl;
342  std::cerr << e << std::endl;
343  }
344 
345  // export A
346  gdcmImageIO->SetMetaDataDictionary(dictionaryOutput_A);
347 
348  OxColorbarFilter->SetInput(_imageCalculatorItk->GetAImage());
349  OxColorbarFilter->SetZerosInsteadOfColorbar(true);
350 
351  // export to dicom
352  adaptor->SetInput(OxColorbarFilter->GetOutput());
353  writer->SetFileName(_opts->dir_output_fitparams + KWUtil::PathSeparator() + newSeriesNumber_R2 + "_A.dcm");
354  writer->SetInput(adaptor->GetOutput());
355  writer->SetImageIO(gdcmImageIO);
356  try {
357  writer->Update();
358  } catch (itk::ExceptionObject &e) {
359  std::cerr << "Exception in file writer " << std::endl;
360  std::cerr << e << std::endl;
361  }
362 
363  // export B
364  gdcmImageIO->SetMetaDataDictionary(dictionaryOutput_B);
365 
366  OxColorbarFilter->SetInput(_imageCalculatorItk->GetBImage());
367  OxColorbarFilter->SetZerosInsteadOfColorbar(true);
368 
369  // export to dicom
370  adaptor->SetInput(OxColorbarFilter->GetOutput());
371  writer->SetFileName(_opts->dir_output_fitparams + KWUtil::PathSeparator() + newSeriesNumber_R2 + "_B.dcm");
372  writer->SetInput(adaptor->GetOutput());
373  writer->SetImageIO(gdcmImageIO);
374  try {
375  writer->Update();
376  } catch (itk::ExceptionObject &e) {
377  std::cerr << "Exception in file writer " << std::endl;
378  std::cerr << e << std::endl;
379  }
380 
381  // export T1star
382  gdcmImageIO->SetMetaDataDictionary(dictionaryOutput_T1star);
383 
384  OxColorbarFilter->SetInput(_imageCalculatorItk->GetT1starImage());
385  OxColorbarFilter->SetZerosInsteadOfColorbar(true);
386 
387  // export to dicom
388  adaptor->SetInput(OxColorbarFilter->GetOutput());
389  writer->SetFileName(_opts->dir_output_fitparams + KWUtil::PathSeparator() + newSeriesNumber_R2 + "_T1star.dcm");
390  writer->SetInput(adaptor->GetOutput());
391  writer->SetImageIO(gdcmImageIO);
392  try {
393  writer->Update();
394  } catch (itk::ExceptionObject &e) {
395  std::cerr << "Exception in file writer " << std::endl;
396  std::cerr << e << std::endl;
397  }
398 
399  // export ShMolliRange
400  gdcmImageIO->SetMetaDataDictionary(dictionaryOutput_ShMolliT1Range);
401 
402  typedef itk::NShmolliSamplesUsedTo123ImageFilter <ImageType2D> nShmolliSamplesUsedTo123FilterType;
403  typename nShmolliSamplesUsedTo123FilterType::Pointer nShmolliSamplesUsedTo123Filter = nShmolliSamplesUsedTo123FilterType::New();
404  nShmolliSamplesUsedTo123Filter->SetInput(_imageCalculatorItk->GetNShmolliSamplesUsedImage());
405 
406  OxColorbarFilter->SetInput(nShmolliSamplesUsedTo123Filter->GetOutput());
407  OxColorbarFilter->SetZerosInsteadOfColorbar(true);
408 
409  // export to dicom
410  adaptor->SetInput(OxColorbarFilter->GetOutput());
411  writer->SetFileName(_opts->dir_output_fitparams + KWUtil::PathSeparator() + newSeriesNumber_R2 + "_ShMolliRange.dcm");
412  writer->SetInput(adaptor->GetOutput());
413  writer->SetImageIO(gdcmImageIO);
414  try {
415  writer->Update();
416  } catch (itk::ExceptionObject &e) {
417  std::cerr << "Exception in file writer " << std::endl;
418  std::cerr << e << std::endl;
419  }
420 
421  // TODO: change chisquare to final call value
422  // export nAmebaCalls
423  gdcmImageIO->SetMetaDataDictionary(dictionaryOutput_nAmebaCallFinal);
424 
425  OxColorbarFilter->SetInput(_imageCalculatorItk->GetChiSqrtImage());
426  OxColorbarFilter->SetZerosInsteadOfColorbar(true);
427 
428  // export to dicom
429  adaptor->SetInput(OxColorbarFilter->GetOutput());
430  writer->SetFileName(_opts->dir_output_fitparams + KWUtil::PathSeparator() + newSeriesNumber_R2 + "_nAmebaCallFinal.dcm");
431  writer->SetInput(adaptor->GetOutput());
432  writer->SetImageIO(gdcmImageIO);
433  try {
434  writer->Update();
435  } catch (itk::ExceptionObject &e) {
436  std::cerr << "Exception in file writer " << std::endl;
437  std::cerr << e << std::endl;
438  }
439 
440  // TODO: check, values seem a little low
441  // export RelSNRFinal
442  gdcmImageIO->SetMetaDataDictionary(dictionaryOutput_RelSNRFinal);
443 
444  OxColorbarFilter->SetInput(_imageCalculatorItk->GetSNRImage());
445  OxColorbarFilter->SetZerosInsteadOfColorbar(true);
446 
447  // export to dicom
448  adaptor->SetInput(OxColorbarFilter->GetOutput());
449  writer->SetFileName(_opts->dir_output_fitparams + KWUtil::PathSeparator() + newSeriesNumber_R2 + "_RelSNRFinal.dcm");
450  writer->SetInput(adaptor->GetOutput());
451  writer->SetImageIO(gdcmImageIO);
452  try {
453  writer->Update();
454  } catch (itk::ExceptionObject &e) {
455  std::cerr << "Exception in file writer " << std::endl;
456  std::cerr << e << std::endl;
457  }
458  std::cout << " Saved!" << std::endl;
459  }
460 
461 
462 
463  return 0; // EXIT_SUCCESS
464  }
465 
466 } // namespace Ox
467 
468 #endif // USE_ITK
469 
470 #endif //Tomato_Tomato_EXPORT_HXX
Definition: OxCalculator.h:19