1 #include "bruker2dicom.h"
2 #include <boost/filesystem/path.hpp>
3 #include <boost/filesystem/operations.hpp>
4 #include "brukerexception.h"
6 #ifndef PATH_MAX // If not defined yet : do it
12 bool Bruker2Dicom::Execute()
14 // ----- Check input directory name -----
16 bool bigEndian = GDCM_NAME_SPACE::Util::IsCurrentProcessorBigEndian();
18 //if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(InputDirName) )
19 if ( ! boost::filesystem::is_directory(InputDirName) )
21 std::cout << "KO : [" << InputDirName << "] is not a Directory." << std::endl;
27 std::cout << "OK : [" << InputDirName << "] is a Directory." << std::endl;
30 // ----- Check output directory name -----
32 std::string strDirNameOut(OutputDirName);
33 bool res=CreateDirectory(strDirNameOut);
35 std::cout << "[" << OutputDirName << "] Directory creation failure " << std::endl;
37 throw ( BrukerHopelessException ("Output directory creation failure "));
40 std::string strDirNamein(InputDirName);
41 GDCM_NAME_SPACE::DirList dirList(strDirNamein, false, true); // DON'T get recursively the list of files
42 std::string strDirNameout(OutputDirName);
47 std::cout << "------------List of found files ------------" << std::endl;
49 std::cout << std::endl;
55 // e.g : at level 0, in : B67d1.Bp1
57 // 1 2 3 4 5 6 AdjStatePerStudy subject
60 GDCM_NAME_SPACE::DirListType fileNames;
61 fileNames = dirList.GetFilenames();
63 std::string outputFileName;
66 // BrukerDataSet br_subject;
68 subject = GDCM_NAME_SPACE::Util::GetPath(*(fileNames.begin()))+
69 GDCM_NAME_SPACE::GDCM_FILESEPARATOR +
72 std::cout << " Subject : [" << subject << "]" << std::endl;
73 canOpen =br_subject.LoadFile(subject);
77 std::cout << "Hopeless! no 'subject' found" << std::endl;
78 throw ( BrukerHopelessException ("Hopeless! no 'subject' found in root input directory "));
79 //exit(0); /// \TODO throw an exception !
85 //br_subject.PrintSelf();
87 // get info for 'Study Description'
89 BrukerFieldData b_name=br_subject.GetFieldData("SUBJECT_name_string");
90 std::string subject_name = b_name.GetStringValue()[0];
91 strPatientName = subject_name;
92 cleanString(subject_name);
94 // creation directory : 'nom du patient'
95 std::string tempStringPatDir(OutputDirName);
96 tempStringPatDir = tempStringPatDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR + subject_name;
98 res=CreateDirectory(tempStringPatDir);
100 std::cout << "[" << tempStringPatDir << "] Directory creation failure " << std::endl;
101 throw ( BrukerHopelessException ("Patient directory creation failure "));
104 BrukerFieldData b_entry=br_subject.GetFieldData("SUBJECT_entry");
105 std::string subject_entry = b_entry.GetStringValue()[0];
106 //cleanString(subject_entry);
107 subject_entry = subject_entry.substr(11, subject_entry.size()-11);
109 BrukerFieldData b_position=br_subject.GetFieldData("SUBJECT_position");
110 std::string subject_position = b_position.GetStringValue()[0];
111 //cleanString(subject_position);
112 subject_position = subject_position.substr(9, subject_position.size()-9);
114 BrukerFieldData b_date=br_subject.GetFieldData("SUBJECT_date");
115 std::string subject_date = b_date.GetStringValue()[0];
116 strStudyTimeDate = subject_date;
117 cleanString(subject_date);
119 BrukerFieldData b_study_name=br_subject.GetFieldData("SUBJECT_study_name");
120 std::string subject_study_name = b_study_name.GetStringValue()[0];
121 subject_study_name = subject_study_name.substr(1, subject_study_name.size()-2);
122 cleanString(subject_study_name);
124 // subject_name is already in 'Patient Name'
125 strStudyDescr = /*subject_name + "." + */ subject_study_name + "." + subject_entry + "." + subject_position + "." + subject_date;
127 // creation directory : 'nom de la Study'
129 std::string tempStringStudyDir(OutputDirName);
130 tempStringStudyDir = tempStringPatDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR + strStudyDescr;
132 res=CreateDirectory(tempStringStudyDir);
134 std::cout << "[" << tempStringStudyDir << "] Directory creation failure " << std::endl;
135 throw ( BrukerHopelessException ("Study directory creation failure "));
138 char outputDirName[(unsigned int) PATH_MAX+2];
140 strStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
143 // -----------------------------------------------------
144 // Iterate to ALL the objets(files/directories) found in the input directory
145 // (this is level ZERO)
146 // each Directory (name : 1, 2, 3, ...) will be a Dicom Serie
147 // -----------------------------------------------------
149 GDCM_NAME_SPACE::DirListType::iterator it;
151 for (it = fileNames.begin();
152 it != fileNames.end();
155 if ( boost::filesystem::is_directory(*it) )
158 std::cout << "[" << *it << "] is a directory" << std::endl;
160 //BrukerDataSet br_acqp;
163 GDCM_NAME_SPACE::GDCM_FILESEPARATOR +
166 br_acqp.LoadFile(strAcqp);
169 std::string acqp_scan_name;
170 std::string acqp_method;
171 std::string acqp_protocol_location;
173 BrukerFieldData b_protocol_location=br_acqp.GetFieldData("ACQ_protocol_location");
174 acqp_protocol_location = b_protocol_location.GetStringValue()[0];
175 cleanString(acqp_protocol_location);
177 BrukerFieldData b_scan_name=br_acqp.GetFieldData("ACQ_scan_name");
178 acqp_scan_name = b_scan_name.GetStringValue()[0];
179 cleanString(acqp_scan_name);
181 BrukerFieldData b_method=br_acqp.GetFieldData("ACQ_method");
182 acqp_method = b_method.GetStringValue()[0];
183 cleanString(acqp_method);
185 BrukerFieldData b_list_size = br_acqp.GetFieldData("ACQ_O1_list_size");
186 //b_list_size.PrintSelf(); //JP
188 nbSlices = b_list_size.GetIntValue()[0];
190 strSerieDescr = GDCM_NAME_SPACE::Util::GetName(*it)
191 /* + "." + acqp_protocol_location */ // always the same (in each acquisition)
192 + "." + acqp_scan_name
193 + "." + acqp_method.c_str();
195 sprintf(outputDirName, "%s%c%s", tempStringStudyDir.c_str(), //OutputDirName.c_str(),
196 GDCM_NAME_SPACE::GDCM_FILESEPARATOR,
197 strSerieDescr.c_str() );
199 std::cout << " ================================================================================\n"
200 << " === [" << GDCM_NAME_SPACE::Util::GetName(*it) << "] -> [" << strSerieDescr << "]\n"
201 << " ================================================================================"
206 printf ("outputDirName [%s]\n", outputDirName);
208 DealWithNiveau1(*it, outputDirName);
210 catch (BrukerHopelessException &e)
212 std::cout << "And Exception was thrown in DealWithNiveau1 (" << e.what() << ") " << std::endl;
216 } // end of : for (GDCM_NAME_SPACE::DirListType::iterator it
220 // =====================================================================
222 void Bruker2Dicom::DealWithNiveau1(std::string level1Directory, std::string currentOutputDirName) {
224 // e.g. : at level 1, in B67d1.Bp1/6
226 // acqp fid imnd pdata pulseprogram spnam0 spnam1
228 bool res = CreateDirectory(currentOutputDirName);
231 std::cout << "[" << currentOutputDirName << "] Directory creation failure " << std::endl;
232 throw ( BrukerHopelessException ("Level 1 output directory creation failure "));
235 GDCM_NAME_SPACE::DirList dirList(level1Directory, false, true); // DON'T get recursively the list of files
236 GDCM_NAME_SPACE::DirListType fileNames;
237 fileNames = dirList.GetFilenames();
238 // -----------------------------------------------------
239 // Iterate to ALL the objets(files/directories) found in the input directory
240 // -----------------------------------------------------
241 GDCM_NAME_SPACE::DirListType::iterator it;
243 for (it = fileNames.begin();
244 it != fileNames.end();
247 if ( boost::filesystem::is_regular(*it) )
248 //if ( ! boost::filesystem::is_directory(*it) )
251 std::cout << "--- [" << *it << "] is a file." << std::endl;
255 char outputDirName[(unsigned int) PATH_MAX+2];
256 //std::string firstName;
258 for (it = fileNames.begin();
259 it != fileNames.end();
262 if ( boost::filesystem::is_directory(*it) )
264 // will be always "pdata" ...
266 std::cout << "--- [" << *it << "] is a directory" << std::endl;
269 if (FileLine.startsWith("##$ACQ_size=")) {
270 if (FileLine.startsWith("##$NI=")) {
271 if (FileLine.startsWith("##$NR=")) {
272 if (FileLine.startsWith("##$ACQ_obj_order=")) {
273 if (FileLine.startsWith("##$ACQ_word_size=")) {
274 if (FileLine.startsWith("##$BYTORDA=")) {
275 if (FileLine.startsWith("##$PULPROG=")) {
278 sprintf(outputDirName, "%s%c%s", currentOutputDirName.c_str(),
279 GDCM_NAME_SPACE::GDCM_FILESEPARATOR,
280 GDCM_NAME_SPACE::Util::GetName(*it).c_str());
283 std::string strMethod;
284 //std::string firstName = *(fileNames.begin());
286 strMethod = GDCM_NAME_SPACE::Util::GetPath(*(fileNames.begin())) +
287 GDCM_NAME_SPACE::GDCM_FILESEPARATOR +
289 // std::cout << "---strMethod (for method)=> [" << strMethod << "]" << std::endl;
290 canOpen = br_method.LoadFile(strMethod);
293 strMethod = GDCM_NAME_SPACE::Util::GetPath(*(fileNames.begin()))+
294 GDCM_NAME_SPACE::GDCM_FILESEPARATOR +
296 //std::cout << "---strMethod (for imnd) => [" << strMethod << "]" << std::endl;
297 canOpen = br_method.LoadFile(strMethod);
300 std::cout << "Hopeless! neither 'method' nor 'imnd' found in ["
301 << level1Directory << "]; we skip it!" << std::endl;
303 //throw ( BrukerHopelessException ("Hopeless! neither 'method' nor 'imnd' found "));
304 //exit(0); /// \TODO throw an exception !
308 std::cout << "open => [" << strMethod << "] successfully" << std::endl;
312 ##$PVM_Fov (dimension)
315 dans method (pour perfusion seulement?) :
316 ##$PVM_ObjOrderList=( 8 )
319 ##$PVM_SPackArrNSlices=( 2 )
323 DealWithNiveau2(*it,outputDirName );
325 catch (BrukerHopelessException &e)
327 std::cout << "And Exception was thrown in DealWithNiveau2 (" << e.what() << ") " << std::endl;
334 // =====================================================================
336 void Bruker2Dicom::DealWithNiveau2(std::string level2Directory, std::string currentOutputDirName) {
338 // e.g. : at level 2 in B67d1.Bp1/6/pdata
340 // acqp fid imnd pdata pulseprogram spnam0 spnam1
343 bool res = CreateDirectory(currentOutputDirName);
346 std::cout << "[" << currentOutputDirName << "] Directory creation failure " << std::endl;
347 throw ( BrukerHopelessException ("Hopeless! Level2 output directory creation failure"));
351 GDCM_NAME_SPACE::DirList dirList(level2Directory, false, true); // DON'T get recursively the list of files
353 GDCM_NAME_SPACE::DirListType fileNames;
354 fileNames = dirList.GetFilenames();
356 char outputDirName[(unsigned int) PATH_MAX+2];
358 // -----------------------------------------------------
359 // Iterate to ALL the objets(files/directories) found in the input directory
360 // -----------------------------------------------------
361 GDCM_NAME_SPACE::DirListType::iterator it;
365 for (it = fileNames.begin();
366 it != fileNames.end();
369 if ( ! boost::filesystem::is_directory(*it) )
371 std::cout << "--- --- [" << *it << "] is a file.." << std::endl;
376 for (it = fileNames.begin();
377 it != fileNames.end();
380 if ( boost::filesystem::is_directory(*it) )
384 std::cout << "--- --- [" << *it << "] is a directory" << std::endl;
386 // sprintf(outputDirName, "%s%c%s", currentOutputDirName.c_str(),
387 // GDCM_NAME_SPACE::GDCM_FILESEPARATOR,
388 // GDCM_NAME_SPACE::Util::GetName(*it).c_str() );
392 // (interest of previous method :
393 // If unaware user changed the pdata name, it goes on working
397 GDCM_NAME_SPACE::GDCM_FILESEPARATOR +
400 std::string str_isa_func_name;
401 canOpen = br_isa.LoadFile(str_isa);
404 sprintf(outputDirName, "%s%c%s", currentOutputDirName.c_str(),
405 GDCM_NAME_SPACE::GDCM_FILESEPARATOR,
406 GDCM_NAME_SPACE::Util::GetName(*it).c_str() );
411 BrukerFieldData b_isa_func_name = br_isa.GetFieldData("ISA_func_name");
413 str_isa_func_name = b_isa_func_name.GetStringValue()[0];
414 cleanString(str_isa_func_name);
416 sprintf(outputDirName, "%s%c%s.%s", currentOutputDirName.c_str(),
417 GDCM_NAME_SPACE::GDCM_FILESEPARATOR,
418 GDCM_NAME_SPACE::Util::GetName(*it).c_str(),
419 str_isa_func_name.c_str());
422 DealWithNiveau3(*it, outputDirName);
424 catch (BrukerHopelessException &e)
426 std::cout << "And Exception was thrown in DealWithNiveau3 (" << e.what() << "); "
427 << " We skip [" << level2Directory << "]" << std::endl;
430 catch (BrukerInitException &e)
432 std::cout << "And Init Exception was thrown in DealWithNiveau3 (" << e.what() << "); "
433 << " We skip [" << level2Directory << "]" << std::endl;
442 // =====================================================================
445 void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string currentOutputDirName){
448 // e.g. at level 3, in
450 // just to be able to go on checking // JP
451 if ( GDCM_NAME_SPACE::Util::GetName(level3Directory) != "1")
454 bool res = CreateDirectory(currentOutputDirName);
458 std::cout << "[" << currentOutputDirName << "] Directory creation failure " << std::endl;
459 throw ( BrukerHopelessException ("Hopeless! Level3 output directory creation failure"));
463 GDCM_NAME_SPACE::DirList dirList(level3Directory, false, true); // DON'T get recursively the list of files
464 GDCM_NAME_SPACE::DirListType::iterator it;
465 GDCM_NAME_SPACE::DirListType fileNames;
466 fileNames = dirList.GetFilenames();
468 char original2dseqName [(unsigned int) PATH_MAX+2];
469 char original2dseqName_XXX [(unsigned int) PATH_MAX+2];
470 char currentOutputMhdDirName [(unsigned int) PATH_MAX+2];
472 char outputMhdFileName [(unsigned int) PATH_MAX+2];
473 char output2dseqSliceFileName[(unsigned int) PATH_MAX+6]; // think about extra '.dcm'
474 char output2dseqName [(unsigned int) PATH_MAX+6];
475 char output2dseqCartoName [(unsigned int) PATH_MAX+6];
477 char copyFile[PATH_MAX + PATH_MAX + 5]; // Should be enough!
480 //-------------- try d3proc;
481 char char_d3proc[(unsigned int) PATH_MAX+2];
483 sprintf(char_d3proc,"%s%c%s", level3Directory.c_str(), GDCM_NAME_SPACE::GDCM_FILESEPARATOR,"d3proc" );
486 std::cout << "d3proc: --- => [" << char_d3proc << "]" << std::endl;
487 std::string str_d3proc(char_d3proc);
488 canOpen = br_d3proc.LoadFile(str_d3proc);
492 std::cout << "Hopeless! no 'd3proc' found" << std::endl;
493 throw ( BrukerHopelessException ("Hopeless! no 'd3proc' found"));
494 //exit(0); /// \TODO throw an exception !
497 canOpen = br_d3proc.FillMap();
500 std::cout << "Hopeless! FillMap failed on 'd3proc'" << std::endl;
501 throw ( BrukerHopelessException ("Hopeless! FillMap failed on 'd3proc'"));
502 //exit(0); /// \TODO throw an exception !
505 //-------------- end try d3proc;
508 // -------------------try reco
510 char char_reco[(unsigned int) PATH_MAX+2];
512 sprintf(char_reco,"%s%c%s", level3Directory.c_str(), GDCM_NAME_SPACE::GDCM_FILESEPARATOR,"reco" );
513 //str_d3proc = GDCM_NAME_SPACE::Util::GetPath(*(fileNames.begin()))+
514 // GDCM_NAME_SPACE::GDCM_FILESEPARATOR +
517 std::cout << "reco --- => [" << char_reco << "]" << std::endl;
518 std::string str_reco(char_reco);
519 canOpen = br_reco.LoadFile(str_reco);
521 if (!canOpen) // we try in directory ../1
524 std::cout << "[" << str_reco << "] not found " << std::endl;
525 std::string lastDirName = GDCM_NAME_SPACE::Util::GetPath(level3Directory);
526 //lastDirName = GDCM_NAME_SPACE::Util::GetPath(lastDirName);
527 sprintf(char_reco,"%s%c1%c%s", lastDirName.c_str(), GDCM_NAME_SPACE::GDCM_FILESEPARATOR,GDCM_NAME_SPACE::GDCM_FILESEPARATOR,"reco" );
529 canOpen = br_reco.LoadFile(str_reco);
532 std::cout << "Hopeless! cannot find 'reco' in [" << str_reco << "]" << std::endl;
533 throw ( BrukerHopelessException ("Hopeless! cannot find 'reco'"));
534 //exit(0); /// \TODO throw an exception !
538 canOpen = br_reco.FillMap();
541 std::cout << "Hopeless! FillMap failed on [" << str_reco << "]" << std::endl;
542 throw ( BrukerHopelessException ("Hopeless! FillMap failed on 'reco'"));
543 //exit(0); /// \TODO throw an exception !
545 //std::cout << "------------------------------------------------------------------------------------------------" << std::cout;
546 // br_reco.PrintSelf();
547 // std::cout << "------------------------------------------------------------------------------------------------" << std::cout;
549 // -------------------end try reco
552 BrukerFieldData bX = br_d3proc.GetFieldData("IM_SIX");
553 int NX = bX.GetIntValue()[0];
556 std::cout << "IM_SIX " << NX << std::endl;
557 BrukerFieldData bY=br_d3proc.GetFieldData("IM_SIY");
558 int NY = bY.GetIntValue()[0];
561 std::cout << "IM_SIY " << NY << std::endl;
562 /// \todo : check if there are actually 3 dimensions or only 2
564 BrukerFieldData bZ= br_d3proc.GetFieldData("IM_SIZ");
565 int nbFrames = bZ.GetIntValue()[0];
567 std::cout << "IM_SIZ " << nbFrames << std::endl;
569 // WARNING DATTYPE is, either in {ip_short, ip_int, ip_char, ...}, or in {1, 2, 3, ...}
571 BrukerFieldData bDPT = br_d3proc.GetFieldData("DATTYPE");
573 std::string mhdDataPixelType;
575 getImhDataType(bDPT, mhdDataPixelType, pixelSize);
577 BrukerFieldData fov = br_method.GetFieldData("PVM_Fov");
578 double fovX = fov.GetDoubleValue()[0];
579 double fovY = fov.GetDoubleValue()[1];
581 std::cout << "FOV (ds method) " << fovX << " " << fovY << std::endl;
583 BrukerFieldData spatResol = br_method.GetFieldData("PVM_SpatResol");
584 double spatResolX = spatResol.GetDoubleValue()[0];
585 double spatResolY = spatResol.GetDoubleValue()[1];
587 std::cout << "SpatResol (ds method) " << spatResolX << " " << spatResolY << std::endl;
590 /// \TODO probabely a more sophisticated accessor will be necessary :
591 /// (cf : non contiguous slices, overlapping, slice thickness, space between slices, etc)
592 BrukerFieldData bsliceDistance = br_method.GetFieldData("PVM_SPackArrSliceDistance");
593 double sliceDistance = bsliceDistance.GetDoubleValue()[0];
597 sprintf(currentOutputMhdDirName, "%s%c%s", currentOutputDirName.c_str(),
598 GDCM_NAME_SPACE::GDCM_FILESEPARATOR, "MhdFiles");
599 res = CreateDirectory( currentOutputMhdDirName );
601 std::cout << "[" << currentOutputDirName << "] Directory creation failure " << std::endl;
602 throw ( BrukerHopelessException ("Hopeless!FillMap failed on 'reco'"));
607 std::cout << "Directory creation [" << currentOutputDirName << "]" << std::endl;
611 std::cout << "nbFrames " << nbFrames << std::endl;
613 std::cout << "nbSlices " << nbSlices << std::endl;
615 int nbInstants = nbFrames/nbSlices;
617 std::cout << "nbInstants (deduced )" << nbInstants << std::endl;
620 FILE *fp; // for MHD files
622 sprintf( original2dseqName, "%s%c%s", level3Directory.c_str(), GDCM_NAME_SPACE::GDCM_FILESEPARATOR, "2dseq");
625 // \TODO : tenir compte du bazar precedent
627 // load 2dseq in memory
629 fp = fopen(original2dseqName, "rb");
632 // try 2dseq_Angio2D ?!?
634 sprintf( original2dseqName_XXX, "%s%s", original2dseqName, "_Angio2D");
635 fp = fopen(original2dseqName_XXX, "rb");
638 std::cout << "Cannot open [" << original2dseqName << "] nor [" << original2dseqName_XXX << "] for reading" << std::endl;
640 throw ( BrukerHopelessException ("Hopeless! Cannot open '2dseq'"));
645 unsigned char *buffer_2dseq = new unsigned char[NX*NY*pixelSize*nbSlices*nbInstants];
646 ///\ TODO : find a safer way to be sure to read everything!
647 size_t lgr = fread(buffer_2dseq, 1, NX*NY*pixelSize*nbSlices*nbInstants, fp);
649 // This one will be important!
650 // ---------------------------
652 imageSet = CreateImageSet ( );
654 catch (BrukerInitException& e)
657 std::cout << "an Init Exception was thrown in CreateImageSet ( ); " << e.what()
658 << "catched in DealWithNiveau3" << std::endl;
664 strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
665 if (nbInstants==1) // creer un seul fichier .mhd pour toutes les Slices! (images natives)
668 std::cout << "Single instant : do not split" << std::endl;
671 sprintf(outputMhdFileName, "%s%cMhdData_All_the_Slices.mhd", currentOutputMhdDirName,
672 GDCM_NAME_SPACE::GDCM_FILESEPARATOR);
673 fp=fopen(outputMhdFileName, "w");
676 std::cout << "Cannot open [" << outputMhdFileName << "] for writting" << std::endl;
677 throw ( BrukerHopelessException ("Hopeless! Cannot open mhd file for writting"));
682 fprintf(fp, "ObjectType = Image\n");
683 fprintf(fp, "NDims = 3\n" );
684 fprintf(fp, "BinaryData = True \n" );
685 fprintf(fp, "BinaryDataByteOrderMSB = False\n" );
686 fprintf(fp, "DimSize = %d %d %d\n", NX, NY, nbSlices );
687 fprintf(fp, "HeaderSize = %d\n", 0);
688 //fprintf(fp, "ElementSpacing = %lf %lf %lf\n",fovX/NY, fovY/NY, sliceDistance );
689 fprintf(fp, "ElementSpacing = %lf %lf %lf\n", spatResolX, spatResolY, sliceDistance );
690 fprintf(fp, "Position = 0 0 %d\n", 0 );
691 fprintf(fp, "Offset = 0 0 0\n" );
692 fprintf(fp, "CenterOfRotation = 0 0 0\n" );
693 fprintf(fp, "ElementNumberOfChannels = 1\n" );
694 fprintf(fp, "ElementType = %s\n", mhdDataPixelType.c_str() );
695 fprintf(fp, "ElementDataFile = %s\n", "../2dseq_All_the_Slices" );
698 sprintf(output2dseqSliceFileName, "%s%c2dseq_All_the_Slices",
699 currentOutputDirName.c_str(), GDCM_NAME_SPACE::GDCM_FILESEPARATOR);
700 fp=fopen(output2dseqSliceFileName, "wb");
703 std::cout << "Cannot open [" << output2dseqSliceFileName << "] for writting" << std::endl;
704 throw ( BrukerHopelessException ("Hopeless! Cannot open 2dseq file for writting"));
708 fwrite( buffer_2dseq, NX*NY*pixelSize, nbSlices, fp);
712 strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
716 sprintf(output2dseqSliceFileName, "%s%c2dseq_All_the_Slices.dcm",
717 currentOutputDirName.c_str(), GDCM_NAME_SPACE::GDCM_FILESEPARATOR);
719 /* ----------- Write Dicom Image ---------------*/
720 MakeDicomImage(buffer_2dseq,
725 //fovX/NY, fovY/NY, sliceDistance,
726 spatResolX, spatResolY, sliceDistance,
727 output2dseqSliceFileName,
735 0,// index frame number
736 GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE
739 } // end if nbInstants = 1
741 else // more than ONE instant
744 // it's (slice1,slide2, ...)t1 ; (slice1,slide2, ...)t2 ; ...
746 unsigned char *pixelsForCurrentSlice = new unsigned char[NX*NY*pixelSize*nbInstants];
749 for (sliceNb=0; sliceNb<nbSlices; sliceNb++)
753 sprintf(outputMhdFileName, "%s%cMhdData_%03d.mhd", currentOutputMhdDirName,
754 GDCM_NAME_SPACE::GDCM_FILESEPARATOR, k );
756 std::cout << "--- Output MHD file [" << outputMhdFileName << "]" << std::endl;
757 fp=fopen(outputMhdFileName, "w");
760 std::cout << "Cannot open [" << outputMhdFileName << "] for writting" << std::endl;
761 throw ( BrukerHopelessException ("Hopeless! Cannot open mhd file for writting"));
766 /* ----------- Write MHD Image ---------------*/
768 // std::cout << "Open sucessfully[" << outputMhdFileName << "] for writting" << std::endl;
769 fprintf(fp, "ObjectType = Image\n");
770 fprintf(fp, "NDims = 3\n" );
771 fprintf(fp, "BinaryData = True \n" );
772 fprintf(fp, "BinaryDataByteOrderMSB = False\n" );
773 fprintf(fp, "DimSize = %d %d %d\n", NX, NY, nbInstants);
774 fprintf(fp, "HeaderSize = %d\n", 0);
775 //fprintf(fp, "ElementSpacing = %lf %lf %lf\n",fovX/NY, fovY/NY, 1.0 ); //
776 fprintf(fp, "ElementSpacing = %lf %lf %lf\n",spatResolX, spatResolY, 1.0 ); //slice distance : no meaning for temporal serie
777 fprintf(fp, "Position = 0 0 %d\n", sliceNb );
778 fprintf(fp, "Offset = 0 0 0\n" );
779 fprintf(fp, "CenterOfRotation = 0 0 0\n" );
780 fprintf(fp, "ElementNumberOfChannels = 1\n" );
781 fprintf(fp, "ElementType = %s\n", mhdDataPixelType.c_str() );
782 fprintf(fp, "ElementDataFile = ..%c2dseq_Slice_%d\n", GDCM_NAME_SPACE::GDCM_FILESEPARATOR, sliceNb );
786 sprintf(output2dseqSliceFileName, "%s%c2dseq_Slice_%d",
787 currentOutputDirName.c_str(), GDCM_NAME_SPACE::GDCM_FILESEPARATOR,sliceNb);
788 fp=fopen(output2dseqSliceFileName, "wb");
791 std::cout << "Cannot open [" << output2dseqSliceFileName << "] for writting" << std::endl;
792 throw ( BrukerHopelessException ("Hopeless! Cannot open 2dseqSliceFile file for writting"));
795 int frameSize = NX*NY*pixelSize;
796 for (instantNb=0; instantNb<nbInstants; instantNb++)
798 // std::cout << "------------SN " << sliceNb << " IN " << instantNb << " T " << nbSlices*instantNb + sliceNb << std::endl;
799 fwrite( buffer_2dseq +(nbSlices*instantNb + sliceNb)*frameSize,
804 // std::cout << "end writting[" << output2dseqSliceFileName << "]" << std::endl;
811 sprintf(output2dseqSliceFileName, "%sdummy_buffer",
812 currentOutputDirName.c_str(), GDCM_NAME_SPACE::GDCM_FILESEPARATOR);
813 fp=fopen(output2dseqSliceFileName, "wb");
816 std::cout << "Cannot open [" << output2dseqSliceFileName << "] for writting" << std::endl;
819 int frameSize = NX*NY*pixelSize;
820 for (instantNb=0; instantNb<nbInstants; instantNb++)
822 // std::cout << "------------SN " << sliceNb << " IN " << instantNb << " T " << nbSlices*instantNb + sliceNb << std::endl;
823 fwrite( buffer_2dseq +(nbSlices*instantNb + sliceNb)*frameSize,
829 fp=fopen(output2dseqSliceFileName, "rb");
832 std::cout << "Cannot open [" << output2dseqSliceFileName << "] for reading" << std::endl;
835 fread( pixelsForCurrentSlice,
836 frameSize*nbInstants,
839 // end of desperate try !
842 /* ----------- Write Dicom Image ---------------*/
844 int frameSize = NX*NY*pixelSize;
845 for (instantNb=0; instantNb<nbInstants; instantNb++)
847 memcpy(pixelsForCurrentSlice + frameSize*instantNb, buffer_2dseq +(nbSlices*instantNb + sliceNb)*frameSize, frameSize);
850 int indOfFirsImageWithinImageSet = nbSlices*instantNb;
851 sprintf(output2dseqSliceFileName, "%s%c2dseq_Slice_%d.dcm",
852 currentOutputDirName.c_str(), GDCM_NAME_SPACE::GDCM_FILESEPARATOR, sliceNb);
855 pixelsForCurrentSlice,
860 spatResolX, spatResolY, sliceDistance,
861 //fovX/NY, fovY/NY, sliceDistance,
862 output2dseqSliceFileName,
871 GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE
874 std::cout << "--- Output DCM file [" << output2dseqSliceFileName << "]" << std::endl;
880 delete [] pixelsForCurrentSlice;
881 } // end nbInstants == 1
882 delete [] buffer_2dseq;
886 // -----------------------------------------------------
887 // deal with MatLab-generated Carto file.
888 // -----------------------------------------------------
890 dealWithCarto(fileNames, NX, NY, nbSlices, /*fovX, fovY,*/ spatResolX, spatResolY, sliceDistance,
891 copyFile, currentOutputDirName, outputMhdFileName, output2dseqCartoName);
895 // ===========================================================================================
897 void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX, int NY, int nbSlices,
898 /*double fovX, double fovY, */
899 double spatResolX, double spatResolY, double sliceDistance,
900 char *copyFile, std::string ¤tOutputDirName,
901 char *outputMhdFileName, char *output2dseqCartoName)
903 // -----------------------------------------------------
904 // deal with MatLab-generated Carto file.
905 // -----------------------------------------------------
907 char *code[] = { "ADC", "adc", "TTP", "ttp", "PEAK", "peak", "" }; // add more carto file name identifiers if necessary; end with ""
908 char *separator[] = { "_", ".", "-", "" }; // add more, if necessary, to ckeck for 2dseq.ADC, 2dseq_ADC, 2dseq-ADC, etc; end with ""
911 GDCM_NAME_SPACE::DirListType::iterator it;
912 char file_name_ident[500];
915 // Iterate to ALL the objets(files/directories) found in the input directory
916 for (it = fileNames.begin();
917 it != fileNames.end();
920 if ( boost::filesystem::is_regular(*it) )
921 //if ( ! boost::filesystem::is_directory(*it) )
924 std::cout << "--- [" << *it << "] is a file..." << std::endl;
927 while (code[icode][0] != 0)
930 while (separator[iseparator][0] != 0)
932 sprintf(file_name_ident, "2dseq%s%s",separator[iseparator],code[icode]); // e.g "2dseq_ADC"
934 // std::cout << "check name ["<<(*it) << "] for string [" << file_name_ident << "]" << std::endl;
935 std::string::size_type loc = (*it).rfind(file_name_ident);
937 if ( loc != std::string::npos )
940 ///\ TODO : find a safer way to be sure to read everything!
941 unsigned char *buffer_carto = new unsigned char[NX*NY*sizeof(double)*nbSlices];
942 fp = fopen ( (*it).c_str(), "rb");
944 std::cout << "Cannot open [" << *it << "] for reading" << std::endl;
945 throw ( BrukerHopelessException ("Level 1 Unable to open 'carto' file "));
947 fread(buffer_carto, NX*NY*sizeof(double), nbSlices, fp);
949 // ?!? sprintf(copyFile, "cp %s %s%c%s", (*it).c_str() ,
950 std::cout << "Deal with Carto file :[" <<*it << "], computed length : "
951 << NX*NY*sizeof(double)*nbSlices << std::endl;
952 std::string lastFileName = GDCM_NAME_SPACE::Util::GetName((*it).c_str());
955 // Copy the data file in the new directory
956 sprintf(copyFile, "cp %s %s%c%s", (*it).c_str() ,
957 currentOutputDirName.c_str(),GDCM_NAME_SPACE::GDCM_FILESEPARATOR, lastFileName.c_str());
959 sprintf(outputMhdFileName, "%s%c%s%s",
960 currentOutputDirName.c_str(),GDCM_NAME_SPACE::GDCM_FILESEPARATOR, lastFileName.c_str(), ".mhd" );
962 std::cout << "--- Output Carto MHD file [" << outputMhdFileName << "]" << std::endl;
965 fp=fopen(outputMhdFileName, "w");
968 std::cout << "Cannot open [" << outputMhdFileName << "] for writting" << std::endl;
972 fprintf(fp, "ObjectType = Image\n");
973 fprintf(fp, "NDims = 3\n" );
974 fprintf(fp, "BinaryData = True \n" );
975 fprintf(fp, "BinaryDataByteOrderMSB = False\n" );
976 fprintf(fp, "DimSize = %d %d %d\n", NX, NY, nbSlices);
977 fprintf(fp, "HeaderSize = %d\n", 0 );
978 fprintf(fp, "ElementSpacing = %lf %lf %lf\n",spatResolX, spatResolY, sliceDistance );
979 fprintf(fp, "Position = 0 0 0\n" );
980 fprintf(fp, "Offset = 0 0 0\n" );
981 fprintf(fp, "CenterOfRotation = 0 0 0\n" );
982 fprintf(fp, "ElementNumberOfChannels = 1\n" );
983 fprintf(fp, "ElementType = %s\n", "MET_DOUBLE" );
984 fprintf(fp, "ElementDataFile = %s\n", lastFileName.c_str() );
989 std::cout << "--- end write Carto MHD file [" << outputMhdFileName << "]" << std::endl;
992 // ----------- Write Dicom Image ---------------
996 sprintf(output2dseqCartoName, "%s%c%s%s",
997 currentOutputDirName.c_str(),GDCM_NAME_SPACE::GDCM_FILESEPARATOR, lastFileName.c_str(), ".dcm" );
999 std::cout << "--- end create name output2dseqCartoName file [" << output2dseqCartoName << "]" << std::endl;
1001 strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); //New SerieUID for each carto.
1002 std::string strNewSerieDescr(strSerieDescr+ "_" +GDCM_NAME_SPACE::Util::GetName((*it).c_str()));
1003 MakeDicomImage(buffer_carto,
1008 //fovX/NY, fovY/NY, sliceDistance,
1009 spatResolX, spatResolY, sliceDistance,
1010 output2dseqCartoName,
1019 GDCM_NAME_SPACE::CREATED_IMAGE
1023 delete [] buffer_carto;
1025 std::cout << "--- End writing Carto DICOM file [" << output2dseqCartoName << "]" << std::endl;
1026 break; // don't check for more ident on same file name!
1028 } // end deal with _ADC, -adc, etc
1030 } // end iterate speparators
1032 } // end iterate code
1033 } // end boost::filesystem::is_regular(*it)
1034 } // end iterate on all objects (files, dir, etc)
1038 // ==========================================================================================================
1040 bool Bruker2Dicom::CreateDirectory(std::string OutputDirName)
1042 std::string systemCommand;
1045 std::cout << "Check for output directory :[" << OutputDirName << "]."
1047 if ( ! boost::filesystem::is_directory(OutputDirName) ) // dirout not found
1049 std::string strDirNameout(OutputDirName); // to please gcc 4
1050 systemCommand = "mkdir " + strDirNameout; // create it!
1052 std::cout << systemCommand << std::endl;
1053 system (systemCommand.c_str());
1054 if ( ! boost::filesystem::is_directory(OutputDirName) ) // be sure it worked
1057 std::cout << "KO : not a dir : [" << OutputDirName << "] (creation failure ?)" << std::endl;
1059 throw ( BrukerHopelessException ("Level 1 output directory creation failure "));
1064 std::cout << "Directory [" << OutputDirName << "] created." << std::endl;
1070 std::cout << "Output Directory [" << OutputDirName << "] already exists; Used as is." << std::endl;
1078 // ===========================================================================================
1080 /// \TODO move cleanString to 'crea' ?
1082 void Bruker2Dicom::cleanString(std::string &s)
1085 if (s[l-1] == 0x0A || s[l-1] == 0x0D ) // CR or NL
1090 if (s[l-1] == ' ' ) // blank space
1098 std::string repChar("_");
1099 GDCM_NAME_SPACE::Util::ReplaceSpecChar(s, repChar);
1104 // ===========================================================================================
1107 void Bruker2Dicom::getImhDataType(BrukerFieldData &bDPT, std::string &mhdDataPixelType, int &pixelSize)
1109 if(bDPT.GetDataType() == "string")
1111 std::string brukerDataPixelType = bDPT.GetStringValue()[0];
1113 std::cout << "DATTYPE " << brukerDataPixelType << std::endl;
1114 //std::string brukerDataPixelType = br_d3proc.GetFieldData("DATTYPE").GetStringValue()[0];
1116 if (brukerDataPixelType == "ip_short") {
1117 mhdDataPixelType = "MET_USHORT";
1120 if (brukerDataPixelType == "ip_int") {
1121 mhdDataPixelType = "MET_UINT";
1124 if (brukerDataPixelType == "ip_char") {
1125 mhdDataPixelType = "MET_UCHAR";
1128 /// \TODO : finish the list
1130 case 0 : fp << "ElementType = MET_CHAR" << std::endl;
1132 case 1 : fp << "ElementType = MET_UCHAR" << std::endl;
1134 case 2 : fp << "ElementType = MET_SHORT" << std::endl;
1136 case 3 : fp << "ElementType = MET_USHORT" << std::endl;
1138 case 4 : fp << "ElementType = MET_INT" << std::endl;
1140 case 5 : fp << "ElementType = MET_UINT" << std::endl;
1142 case 6 : fp << "ElementType = MET_FLOAT" << std::endl;
1144 case 7 : fp << "ElementType = MET_DOUBLE" << std::endl;
1149 int brukerDataPixelType = bDPT.GetIntValue()[0];
1151 std::cout << "DATTYPE " << brukerDataPixelType << std::endl;
1152 //std::string brukerDataPixelType = br_d3proc.GetFieldData("DATTYPE").GetStringValue()[0];
1154 // Cross your fingers !!!
1156 // pb : found values : 2, 3, 5
1158 if (brukerDataPixelType == 2) {
1159 mhdDataPixelType = "MET_USHORT";
1162 if (brukerDataPixelType == 3) {
1163 mhdDataPixelType = "MET_USHORT";
1166 if (brukerDataPixelType == 1) {
1167 mhdDataPixelType = "MET_UCHAR";
1173 // ===========================================================================================
1175 std::vector<BrukerImage> Bruker2Dicom::CreateImageSet ( )
1177 std::vector<BrukerImage> imageSet;
1178 br_acqp.SetLoopStructure();
1179 std::vector<int> tempVect = br_acqp.GetLoopStructure() ;
1180 std::map<std::string, BrukerFieldData> map = br_acqp.GetBrukerHeaderMap();
1182 bool result = br_acqp.ObjectVaryingProperties.init(map,tempVect);
1184 if (result == false)
1186 throw ( BrukerInitException ("ObjectVaryingProperties.init() failure in Bruker2Dicom::CreateImageSet()") );
1189 br_acqp.SetImageLoopStructure();
1190 br_acqp.SetBrukerImageList();
1191 std::vector<std::vector<int> > brukerImageList = br_acqp.GetBrukerImageList();
1193 BrukerImage image(br_acqp,br_reco);
1194 image.Init(br_acqp,br_reco,1);
1196 for(int i=0;i<brukerImageList.size();i++)
1198 image.Init(br_acqp,br_reco,i);
1199 imageSet.push_back(image);
1202 // Just for checking
1205 std::vector<std::vector <double> > imageOrientation;
1206 std::vector <double> imagePosition;
1207 for(int i=0;i<brukerImageList.size();i++)
1209 // fread(buffer_2dseq, NX*NY*pixelSize*nbSlices*nbInstants, 1, fp);
1211 imagePosition = imageSet[i].getTranslationVectorRPS2XYZ();
1212 std::cout << "Position " << imagePosition[0] << " "
1213 << imagePosition[1] << " " << imagePosition[2] ;
1214 imageOrientation = imageSet[i].getRotationMatrixRPS2XYZ();
1215 std::cout << "\t Orientation " ;
1216 for(int i1=0; i1<3;i1++)for(int i2=0; i2<3;i2++)
1217 std::cout << imageOrientation[i1][i2] << " ";CreateImageSet
1219 //std::cout << "\t Abs Time " << imageSet[i].getAbsoluteTimePosition();
1220 std::cout << "\t Relat Time " << imageSet[i].getRelativeTimePosition();
1222 std::cout << "\t [";
1223 for (int i3=0; i3<imageSet[i].getLoopStamp().size();i3++)
1224 std::cout << " " << imageSet[i].getLoopStamp()[i3];
1225 std::cout << "]" << std::endl;
1231 // ===========================================================================================
1233 void Bruker2Dicom::MakeDicomImage(unsigned char *tabPixels,
1238 double spacingX, double spacingY, double sliceDistance,
1239 std::string dcmImageName,
1240 const std::string &patientName,
1242 std::string &studyUID,
1243 std::string &serieUID,
1244 std::string &studyDescr,
1245 std::string &serieDescr,
1246 std::string &strStudyTimeDate,
1248 GDCM_NAME_SPACE::ImageContentType contentType
1251 std::ostringstream str;
1253 GDCM_NAME_SPACE::File *file;
1254 file = GDCM_NAME_SPACE::File::New();
1256 // Set the image size
1259 file->InsertEntryString(str.str(),0x0028,0x0011,"US"); // Columns
1262 file->InsertEntryString(str.str(),0x0028,0x0010,"US"); // Rows
1268 file->InsertEntryString(str.str(),0x0028,0x0008,"IS"); // Number of Frames
1271 // Set the pixel type
1272 // //8, 16, 32, 64 (for double ?)
1275 file->InsertEntryString(str.str(),0x0028,0x0100,"US"); // Bits Allocated
1277 file->InsertEntryString(str.str(),0x0028,0x0101,"US"); // Bits Stored
1280 str << pixelSize*8-1;
1281 file->InsertEntryString(str.str(),0x0028,0x0102,"US"); // High Bit
1283 // Set the pixel representation // 0/1 , 0=unsigned
1284 file->InsertEntryString("1",0x0028,0x0103, "US"); // Pixel Representation
1286 // Set the samples per pixel // 1:Grey level, 3:RGB
1287 file->InsertEntryString("1",0x0028,0x0002, "US"); // Samples per Pixel
1289 // 0028 0030 DS 2 Pixel Spacing
1291 str << spacingX << "\\" << spacingY;
1292 file->InsertEntryString(str.str(),0x0028,0x0030, "DS"); // Pixel Spacing
1294 // 0018 0050 DS 1 Slice Thickness
1296 str << sliceDistance;
1297 file->InsertEntryString(str.str(),0x0018,0x0050, "DS");
1299 // 0020 0011 IS 1 Series Number
1302 file->InsertEntryString(str.str(),0x0020,0x0011, "IS");
1304 // 0020|0013 [IS] [Instance Number]
1307 str << instanceNumber;
1308 file->InsertEntryString(str.str(),0x0020,0x0013, "IS");
1311 // 1.2.840.10008.5.1.4.1.1.4.1 : Enhanced MR Image Storage
1312 // file->InsertEntryString("1.2.840.10008.5.1.4.1.1.4.1" , 0x0002, 0x0002, "UI"); // [Media Storage SOP Class UID]
1313 // file->InsertEntryString("1.2.840.10008.5.1.4.1.1.4.1" , 0x0008, 0x0016, "UI"); // [SOP Class UID]
1316 // OK : MR is NOT multiframe, but I want just a quick an dirty solution
1318 // 1.2.840.10008.5.1.4.1.1.4 MR Image Storage
1319 file->InsertEntryString("1.2.840.10008.5.1.4.1.1.4" , 0x0002, 0x0002, "UI"); // [Media Storage SOP Class UID]
1320 file->InsertEntryString("1.2.840.10008.5.1.4.1.1.4" , 0x0008, 0x0016, "UI"); // [SOP Class UID]
1322 // if (strlen(patientName) != 0)
1323 file->InsertEntryString(patientName.c_str(),0x0010,0x0010, "PN"); // Patient's Name
1325 file->InsertEntryString(studyUID, 0x0020, 0x000d, "UI");
1326 file->InsertEntryString(serieUID, 0x0020, 0x000e, "UI");
1328 // 0008 0020 DA 1 Study Date
1329 // 0008 0030 TM 1 Study Time
1331 /// \TODO split into 2 strings!
1332 file->InsertEntryString(strStudyTimeDate.substr(10,11).c_str(),0x0008,0x0020, "DA");
1333 file->InsertEntryString(strStudyTimeDate.substr(1,8).c_str(), 0x0008,0x0030, "TM");
1335 file->InsertEntryString(studyDescr, 0x0008,0x1030, "LO"); // Study Description
1336 file->InsertEntryString(serieDescr, 0x0008,0x103e, "LO"); // Series Description
1338 //0008|0060 [CS] [Modality]
1339 file->InsertEntryString("MR",0x0008,0x0060, "CS");
1341 // 0020 0037 DS 6 Image Orientation (Patient)
1342 char charImageOrientation[256];
1345 std::cout << "charImageOrientation " <<
1346 imageSet[imgNum].getRotationMatrixRPS2XYZ()[0][0] << " " <<
1347 imageSet[imgNum].getRotationMatrixRPS2XYZ()[0][1] << " " <<
1348 imageSet[imgNum].getRotationMatrixRPS2XYZ()[0][2] << " " <<
1349 imageSet[imgNum].getRotationMatrixRPS2XYZ()[1][0] << " " <<
1350 imageSet[imgNum].getRotationMatrixRPS2XYZ()[1][1] << " " <<
1351 imageSet[imgNum].getRotationMatrixRPS2XYZ()[1][2] << std::endl ;
1353 sprintf(charImageOrientation,"%f\\%f\\%f \\ %f\\%f\\%f",
1354 imageSet[imgNum].getRotationMatrixRPS2XYZ()[0][0],
1355 imageSet[imgNum].getRotationMatrixRPS2XYZ()[0][1],
1356 imageSet[imgNum].getRotationMatrixRPS2XYZ()[0][2],
1357 imageSet[imgNum].getRotationMatrixRPS2XYZ()[1][0],
1358 imageSet[imgNum].getRotationMatrixRPS2XYZ()[1][1],
1359 imageSet[imgNum].getRotationMatrixRPS2XYZ()[1][2] ) ;
1361 file->InsertEntryString(charImageOrientation,0x0020,0x0037, "DS");
1364 // 0020 0032 DS 3 Image Position (Patient)
1366 char charImagePosition[256];
1367 sprintf(charImagePosition,"%f\\%f\\%f",
1368 imageSet[imgNum].getTranslationVectorRPS2XYZ()[0],
1369 imageSet[imgNum].getTranslationVectorRPS2XYZ()[1],
1370 imageSet[imgNum].getTranslationVectorRPS2XYZ()[2]);
1372 file->InsertEntryString(charImagePosition,0x0020,0x0032, "DS"); //0020 0032 DS 3 Image Position (Patient)
1376 // 0020 0x1041 DS 1 Slice Location
1377 // sprintf(charImagePosition,"%f",float(imgNum));
1378 // file->InsertEntryString(charImagePosition,0x0020,0x1041, "DS");
1380 // Set Rescale Intercept
1383 file->InsertEntryString(str.str(),0x0028,0x1052,"DS");
1385 // Set Rescale Slope
1388 file->InsertEntryString(str.str(),0x0028,0x1053,"DS");
1391 GDCM_NAME_SPACE::FileHelper *fileH;
1392 fileH = GDCM_NAME_SPACE::FileHelper::New(file);
1393 fileH->SetContentType(contentType);
1395 // cast is just to avoid warnings (*no* conversion is performed)
1396 //fileH->SetImageData((uint8_t *)img,int(maxX*maxY)*sizeof(uint16_t)); // troubles when maxX, mayY are *actually* float!
1398 //std::cout << "-------------------------------- X*Y*nbFrames*pixelSize " << X << " " << Y << " " << nbFrames << " " << pixelSize << std::endl;
1400 fileH->SetImageData((uint8_t *)tabPixels, X*Y*nbFrames*pixelSize);
1401 fileH->SetWriteModeToRaw();
1402 fileH->SetWriteTypeToDcmExplVR();
1403 if( !fileH->Write(dcmImageName)) {
1404 std::cout << "Failed for [" << dcmImageName << "]\n"
1405 << " File is unwrittable" << std::endl;
1408 throw ( BrukerHopelessException ("Level 1 Unable to write Dicom file "));