1 /*=========================================================================
4 Module: $RCSfile: Dense2007ToDicom.cxx,v $
6 Date: $Date: 2008/03/31 15:05:07 $
7 Version: $Revision: 1.9 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
23 #if defined(__BORLANDC__)
28 #include "gdcmFileHelper.h"
29 #include "gdcmDebug.h"
30 #include "gdcmDirList.h"
32 #include "gdcmArgMgr.h"
36 * Converts the "Dense" ".txt" (2007 version) files into 16 bits Dicom Files,
37 * Hope they don't change soon!
40 void LoadPeakStrain(std::ifstream &from, std::string imageName, const char * patientname, std::string studyUID);
41 void LoadStrain(std::ifstream &from, std::string imageName, const char * patientname, bool createMultiFrame, std::string studyUID);
42 void MakeDicomImage(float *tabVal, float *X, float *Y, float *Z, int NP, std::string dcmImageName,
43 const char * patientname, int nbFrames, std::string studyUID, std::string serieUID);
47 int main(int argc, char *argv[])
50 " \n Dense2007ToDicom :\n ",
51 " Converts the '.txt' files into 16 bits Dicom Files, ",
53 " Dense2007ToDicom strain=...strain.txt peak_strain=...peak_strain.txt ",
54 " [patientname = Patient's name] ",
56 " [verbose] [debug] ",
58 " verbose : user wants to run the program in 'verbose mode' ",
59 " debug : *developer* wants to run the program in 'debug mode' ",
62 // ----- Initialize Arguments Manager ------
64 GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
66 if (argc == 1 || am->ArgMgrDefined("usage"))
68 am->ArgMgrUsage(usage); // Display 'usage'
72 // Seems that ArgMgrWantString doesn't work on MacOS
73 if(!am->ArgMgrDefined("strain"))
75 std::cout << "strain is mandatory" << std::endl;
78 if(!am->ArgMgrDefined("peak_strain"))
80 std::cout << "peak_strain is mandatory" << std::endl;
84 const char *strain = am->ArgMgrWantString("strain",usage);
85 const char *peak_strain = am->ArgMgrWantString("peak_strain",usage);
87 const char *patientName = am->ArgMgrGetString("patientname", "Patient^Name");
89 bool createMultiFrame = (am->ArgMgrDefined("m") != 0);
91 if (am->ArgMgrDefined("debug"))
92 GDCM_NAME_SPACE::Debug::DebugOn();
94 verbose = ( 0 != am->ArgMgrDefined("verbose") );
96 // if unused Param we give up
97 if ( am->ArgMgrPrintUnusedLabels() )
99 am->ArgMgrUsage(usage);
103 delete am; // we don't need Argument Manager any longer
105 // ----- Begin Processing -----
107 std::ifstream fromPeakStrain( peak_strain );
108 if ( !fromPeakStrain )
110 std::cout << "Can't open file [" << peak_strain << "]" << std::endl;
114 std::ifstream fromStrain( strain );
117 std::cout << "Can't open file [" << strain << "]" << std::endl;
121 std::string strStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
123 std::cout << "Success in open file [" << peak_strain << "]" << std::endl;
124 LoadPeakStrain(fromPeakStrain, GDCM_NAME_SPACE::Util::GetName(peak_strain), patientName,strStudyUID);
125 fromPeakStrain.close();
127 std::cout << "Success in open file [" << strain << "]" << std::endl;
128 LoadStrain(fromStrain, GDCM_NAME_SPACE::Util::GetName(strain), patientName, createMultiFrame, strStudyUID);
133 // =====================================================================================================================
135 void LoadPeakStrain(std::ifstream &from, std::string textFileName, const char * patientname,std::string studyUID)
137 // in sax_base_slice0_peak_strain.txt :
140 Number of material points (NP) = 181
141 Origin of (readout, phase enc, slice sel) coordinates in 3D = 87.3243 3.19392
143 Readout direction in 3D = -0.162314 -0.0771294 -0.983720
144 Phase Enc. direction in 3D = -0.540606 -0.827052 0.154046
145 Slice select direction in 3D = 0.825469 -0.556809 -0.0925458
146 The following are the (readout, phase enc, slice sel) coordinates (mm) of the grid points for which strains are calculated,
147 followed by their peak Ecc strain, an array of NP elements,
148 followed by their peak Err strain, an array of NP elements,
149 followed by their peak E11 strain, an array of NP elements,
150 followed by their Peak E22 strain, an array of NP elements,
151 42.0000 10.0000 0.000000
153 -0.154905 -0.0840482 -0.157350 -0.221403 -0.168118 -0.131331
154 -0.153781 -0.148481 -0.166602 -0.232858 -0.222650 -0.213712
164 //Number of material points (NP) = 181
173 std::cout << "NP : " << NP << std::endl;
175 //Origin of (readout, phase enc, slice sel) coordinates in 3D = 87.3243 3.19392 88.2381
188 float readout, phase_enc, slice_sel;
192 std::cout << " readout " << readout << " phase_enc " << phase_enc << " slice_sel " << slice_sel << std::endl;
194 // Readout direction in 3D = -0.162314 -0.0771294 -0.983720
202 float readoutX, readoutY, readoutZ;
206 std::cout << " readoutX " << readoutX << " readoutY " << readoutY << " readoutZ " << readoutZ << std::endl;
208 // Phase Enc. direction in 3D = -0.540606 -0.827052 0.154046
217 float phase_encX, phase_encY, phase_encZ;
221 std::cout << " phase_encX " << phase_encX << " phase_encY " << phase_encY << " phase_encZ " << phase_encZ << std::endl;
223 // Slice select direction in 3D = 0.825469 -0.556809 -0.0925458
231 float slice_selX, slice_selY, slice_selZ;
235 std::cout << " slice_selX " << slice_selX << " slice_selY " << slice_selY << " slice_selZ " << slice_selZ << std::endl;
240 The following are the (readout, phase enc, slice sel) coordinates (mm) of the grid points for which strains are calculated,
241 followed by their peak Ecc strain, an array of NP elements,
242 followed by their peak Err strain, an array of NP elements,
243 followed by their peak E11 strain, an array of NP elements,
244 followed by their Peak E22 strain, an array of NP elements,
247 std::cout << "------------start skipping 1 line---------------- " << std::endl;
248 std::getline(from, str1);
249 std::cout << "[" << str1 << "]" << std::endl;
250 std::cout << "------------start skipping 1 line---------------- " << std::endl;
251 std::getline(from, str1);
252 std::cout << "[" << str1 << "]" << std::endl;
253 std::cout << "------------start skipping 1 line---------------- " << std::endl;
254 std::getline(from, str1);
255 std::cout << "[" << str1 << "]" << std::endl;
256 std::cout << "------------start skipping 1 line---------------- " << std::endl;
257 std::getline(from, str1);
258 std::cout << "[" << str1 << "]" << std::endl;
259 std::cout << "------------start skipping 1 line---------------- " << std::endl;
260 std::getline(from, str1);
261 std::cout << "[" << str1 << "]" << std::endl;
262 std::cout << "------------start skipping 1 line---------------- " << std::endl;
263 std::getline(from, str1);
264 std::cout << "[" << str1 << "]" << std::endl;
265 std::cout << "------------stop skipping ---------------- " << std::endl;
267 float *X = new float[NP];
268 float *Y = new float[NP];
269 float *Z = new float[NP];
273 for (i=0; i<NP; i++) {
298 std::string dcmImageName;
299 std::string serieUID;
301 std::cout << "--------------- Ecc_strain ------------------" << std::endl;
302 float *ecc_strain = new float[NP];
303 for (i=0; i<NP; i++) {
304 from >> ecc_strain[i];
306 // std::cout << ecc_strain[i] << std::endl;
308 //followed by their peak Ecc strain, an array of NP elements,
309 serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
310 dcmImageName = textFileName + "_peak_Ecc_strain.dcm";
311 MakeDicomImage(ecc_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID);
314 std::cout << "--------------- Err_strain ------------------" << std::endl;
315 float *err_strain = new float[NP];
316 for (i=0; i<NP; i++) {
317 from >> err_strain[i];
319 // std::cout << err_strain[i] << std::endl;
321 //followed by their peak Err strain, an array of NP elements,
322 serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
323 dcmImageName = textFileName + "_peak_Err_strain.dcm";
324 MakeDicomImage(err_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID);
327 std::cout << "--------------- E11_strain ------------------" << std::endl;
328 float *e11_strain = new float[NP];
329 for (i=0; i<NP; i++) {
330 from >> e11_strain[i];
332 // std::cout << e11_strain[i] << std::endl;
334 //followed by their peak E11 strain, an array of NP elements,
335 serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
336 dcmImageName = textFileName + "_peak_E11_strain.dcm";
337 MakeDicomImage(e11_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID);
341 std::cout << "--------------- E22_strain ------------------" << std::endl;
342 float *e22_strain = new float[NP];
343 for (i=0; i<NP; i++) {
344 from >> e22_strain[i];
346 // std::cout << e22_strain[i] << std::endl;
348 //followed by their Peak E22 strain, an array of NP elements,
349 serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
350 dcmImageName = textFileName + "_peak_E22_strain.dcm";
351 MakeDicomImage(e22_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID);
356 // =====================================================================================================================
358 void LoadStrain(std::ifstream &from, std::string textFileName, const char * patientname, bool createMultiFrame, std::string studyUID)
361 // in sax_base_slice0_strain.txt :
363 Number of cine frames = 18
364 Temporal resolution = 32.0000 ms
365 First frame starts at 48.0000 ms
366 Number of material points (NP) = 181
367 Origin of (readout, phase enc, slice sel) coordinates in 3D = 87.324341 3.193918 88.238113
368 Readout direction in 3D = -0.162314 -0.0771294 -0.983720
369 Phase Enc. direction in 3D = -0.540606 -0.827052 0.154046
370 Slice select direction in 3D = 0.825469 -0.556809 -0.0925458
371 The following are the (readout, phase enc, slice sel) coordinates (mm) of the grid points for which strains are calculated,
372 followed by their Ecc strain, an array of dimensions(NP, number of cine frames),
373 followed by their Err strain, an array of dimensions(NP, number of cine frames),
374 followed by their E11 strain, an array of dimensions(NP, number of cine frames),
375 followed by their E22 strain, an array of dimensions(NP, number of cine frames),
376 Note that RV Err, E11 and E22 strains are not calculated due to the small thickness.
377 42.0000 10.0000 0.000000
378 44.0000 10.0000 0.000000
380 -0.0622793 -0.0840482 -0.157350 -0.196722 -0.105844 -0.131331
381 -0.153781 -0.00940573 -0.0542236 -0.100403 -0.0369671 -0.0696840
388 int NP; // Number of Points
389 int NCF; // Number of cine frames
390 float TR; // Temporal resolution
391 float FFS; // First frame starts
393 // Number of cine frames = 18
401 // Temporal resolution = 32.0000 ms
408 // First frame starts at 48.0000 ms
416 //Number of material points (NP) = 181
425 std::cout << "NP : " << NP << std::endl;
427 //Origin of (readout, phase enc, slice sel) coordinates in 3D = 87.324341 3.193918 88.238113
440 float readout, phase_enc, slice_sel;
444 std::cout << " readout " << readout << " phase_enc " << phase_enc << " slice_sel " << slice_sel << std::endl;
446 // Readout direction in 3D = -0.162314 -0.0771294 -0.983720
454 float readoutX, readoutY, readoutZ;
458 std::cout << " readoutX " << readoutX << " readoutY " << readoutY << " readoutZ " << readoutZ << std::endl;
460 // Phase Enc. direction in 3D = -0.540606 -0.827052 0.154046
469 float phase_encX, phase_encY, phase_encZ;
473 std::cout << " phase_encX " << phase_encX << " phase_encY " << phase_encY << " phase_encZ " << phase_encZ << std::endl;
475 // Slice select direction in 3D = 0.825469 -0.556809 -0.0925458
483 float slice_selX, slice_selY, slice_selZ;
487 std::cout << " slice_selX " << slice_selX << " slice_selY " << slice_selY << " slice_selZ " << slice_selZ << std::endl;
493 The following are the (readout, phase enc, slice sel) coordinates (mm) of the grid points for which strains are calculated,
494 followed by their Ecc strain, an array of dimensions(NP, number of cine frames),
495 followed by their Err strain, an array of dimensions(NP, number of cine frames),
496 followed by their E11 strain, an array of dimensions(NP, number of cine frames),
497 followed by their E22 strain, an array of dimensions(NP, number of cine frames),
498 Note that RV Err, E11 and E22 strains are not calculated due to the small thickness.
500 std::cout << "------------start skipping 1 line---------------- " << std::endl;
501 std::getline(from, str1);
502 std::cout << "[" << str1 << "]" << std::endl;
503 std::cout << "------------start skipping 1 line---------------- " << std::endl;
504 std::getline(from, str1);
505 std::cout << "[" << str1 << "]" << std::endl;
506 std::cout << "------------start skipping 1 line---------------- " << std::endl;
507 std::getline(from, str1);
508 std::cout << "[" << str1 << "]" << std::endl;
509 std::cout << "------------start skipping 1 line---------------- " << std::endl;
510 std::getline(from, str1);
511 std::cout << "[" << str1 << "]" << std::endl;
512 std::cout << "------------start skipping 1 line---------------- " << std::endl;
513 std::getline(from, str1);
514 std::cout << "[" << str1 << "]" << std::endl;
515 std::cout << "------------start skipping 1 line---------------- " << std::endl;
516 std::getline(from, str1);
517 std::cout << "[" << str1 << "]" << std::endl;
518 std::cout << "------------stop skipping ---------------- " << std::endl;
519 std::getline(from, str1);
520 std::cout << "[" << str1 << "]" << std::endl;
521 std::cout << "------------stop skipping ---------------- " << std::endl;
523 float *X = new float[NP];
524 float *Y = new float[NP];
525 float *Z = new float[NP];
529 for (i=0; i<NP; i++) {
553 std::string dcmImageName;
554 std::string serieUID;
556 std::cout << "=======================================================================================" << createMultiFrame << std::endl;
557 if(!createMultiFrame) { // One image per file here (single frame)
559 serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
560 float *ecc_strain = new float[NP];
561 for (int nbr_of_frames=0; nbr_of_frames < NCF; nbr_of_frames++)
563 sprintf(frame, "_%d", nbr_of_frames);
565 std::cout << "--------------- Ecc_strain ------------------" << std::endl;
566 for (i=0; i<NP; i++) {
567 from >> ecc_strain[i];
569 std::cout << ecc_strain[i] << std::endl;
571 //followed by their Ecc strain, an array of NP elements,
572 dcmImageName = textFileName + frame + "_Ecc_strain.dcm";
573 std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl;
574 MakeDicomImage(ecc_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID);
575 }// end for nbr_of_frames
578 serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
579 float *err_strain = new float[NP];
580 for (int nbr_of_frames=0; nbr_of_frames < NCF; nbr_of_frames++)
582 sprintf(frame, "_%d", nbr_of_frames);
583 std::cout << "--------------- Err_strain ------------------" << std::endl;
584 for (i=0; i<NP; i++) {
585 from >> err_strain[i];
587 std::cout << err_strain[i] << std::endl;
589 //followed by their Err strain, an array of NP elements,
590 dcmImageName = textFileName + frame + "_Err_strain.dcm";
591 std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl;
592 MakeDicomImage(err_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID);
593 }// end for nbr_of_frames
596 serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
597 float *e11_strain = new float[NP];
598 for (int nbr_of_frames=0; nbr_of_frames < NCF; nbr_of_frames++)
600 sprintf(frame, "_%d", nbr_of_frames);
601 std::cout << "--------------- E11_strain ------------------" << std::endl;
602 for (i=0; i<NP; i++) {
603 from >> e11_strain[i];
605 std::cout << e11_strain[i] << std::endl;
607 //followed by their E11 strain, an array of NP elements,
608 dcmImageName = textFileName + frame + "_E11_strain.dcm";
609 std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl;
610 MakeDicomImage(e11_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID);
611 }// end for nbr_of_frames
614 serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
615 float *e22_strain = new float[NP];
616 for (int nbr_of_frames=0; nbr_of_frames < NCF; nbr_of_frames++)
618 sprintf(frame, "_%d", nbr_of_frames);
619 std::cout << "--------------- E22_strain ------------------" << std::endl;
620 for (i=0; i<NP; i++) {
621 from >> e22_strain[i];
623 std::cout << e22_strain[i] << std::endl;
625 //followed by their E22 strain, an array of NP elements,
626 dcmImageName = textFileName + frame + "_E22_strain.dcm";
627 std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl;
628 MakeDicomImage(e22_strain, X, Y, Z, NP, dcmImageName, patientname, 1, studyUID, serieUID);
629 } // end for nbr_of_frames
630 delete [] e22_strain;
632 } // end of single frame
635 else // generate Multiframe files
639 serieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
640 float *ecc_strain = new float[NP*NCF];
641 std::cout << "--------------- Ecc_strain ------------------" << std::endl;
642 for (i=0; i<NP*NCF; i++) {
643 from >> ecc_strain[i];
645 std::cout << ecc_strain[i] << std::endl;
647 //followed by their Ecc strain, an array of NP elements,
648 dcmImageName = textFileName + "_Ecc_strain.dcm";
649 std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl;
650 MakeDicomImage(ecc_strain, X, Y, Z, NP, dcmImageName, patientname, NCF, studyUID, serieUID);
655 float *err_strain = new float[NP*NCF];
656 std::cout << "--------------- Err_strain ------------------" << std::endl;
657 for (i=0; i<NP*NCF; i++) {
658 from >> err_strain[i];
660 std::cout << err_strain[i] << std::endl;
662 //followed by their Ecc strain, an array of NP elements,
663 dcmImageName = textFileName + "_Err_strain.dcm";
664 std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl;
665 MakeDicomImage(err_strain, X, Y, Z, NP, dcmImageName, patientname, NCF, studyUID, serieUID);
670 float *e11_strain = new float[NP*NCF];
671 std::cout << "--------------- E11_strain ------------------" << std::endl;
672 for (i=0; i<NP*NCF; i++) {
673 from >> e11_strain[i];
675 std::cout << e11_strain[i] << std::endl;
677 //followed by their Ecc strain, an array of NP elements,
678 dcmImageName = textFileName + "_E11_strain.dcm";
679 std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl;
680 MakeDicomImage(e11_strain, X, Y, Z, NP, dcmImageName, patientname, NCF, studyUID, serieUID);
685 float *e22_strain = new float[NP*NCF];
686 std::cout << "--------------- E22_strain ------------------" << std::endl;
687 for (i=0; i<NP*NCF; i++) {
688 from >> e22_strain[i];
690 std::cout << e22_strain[i] << std::endl;
692 //followed by their Ecc strain, an array of NP elements,
693 dcmImageName = textFileName + "_E22_strain.dcm";
694 std::cout << "Try to make image :[" << dcmImageName << "]" << std::endl;
695 MakeDicomImage(e22_strain, X, Y, Z, NP, dcmImageName, patientname, NCF, studyUID, serieUID);
698 } // end of Multiframe
702 // =====================================================================================================================
705 void MakeDicomImage(float *tabVal, float *X, float *Y, float *Z, int NP, std::string dcmImageName, const char * patientName, int nbFrames, std::string studyUID, std::string serieUID)
708 std::cout << "=============================================================================="
709 << "enter MakeDicomImage [" << dcmImageName << "] [" << patientName << "]" << std::endl;
710 float minX = 99999., minY = 99999., minZ = 99999.;
711 float maxX = 0., maxY = 0., maxZ = 0.;
714 for (i=0; i<NP; i++) {
715 // std::cout << X[i] << " " << Y[i] << " " << Z[i] << std::endl;
730 std::cout << "Min X,Y,Z " << minX << " " << minY << " " << minZ << std::endl;
731 std::cout << "Max X,Y,Z " << maxX << " " << maxY << " " << maxZ << std::endl;
732 std::cout << "Size X,Y,Z " << maxX-minX << " " << maxY-minY << " " << maxZ-minZ << std::endl;
734 int lgrFrame = int(maxX*4.)*int(maxY*4.);
735 uint16_t *img = new uint16_t[lgrFrame*nbFrames ];
737 // Set whole image to 0
738 for(int i3=0; i3<lgrFrame*nbFrames; i3++)
741 for(int i4=0; i4<nbFrames; i4++)
742 for(int i2=0; i2<NP; i2++) {
743 int ordX = int(X[i2]*4.-30);
744 int ordY = int(maxY*4.) - int(Y[i2]*4.)+30;
745 img[ lgrFrame*i4 + ordX + ordY * int(maxX*4.) ] = int(tabVal[i2 + NP*i4]*100);
747 // Try to round up, just to see.
748 for(int iii=ordY-3; iii<ordY+4; iii++)
749 for(int jjj=ordX-3; jjj<ordX+4; jjj++)
750 img[ lgrFrame*i4 + jjj + iii * int(maxX*4.) ] = int(tabVal[i2 + NP*i4]*100);
753 std::cout << "===========sortie recup points" << std::endl;
754 // GDCM_NAME_SPACE::Debug::DebugOn();
756 std::ostringstream str;
758 GDCM_NAME_SPACE::File *file;
759 file = GDCM_NAME_SPACE::File::New();
761 // Set the image size
763 str << (int)(maxX*4.);
764 file->InsertEntryString(str.str(),0x0028,0x0011,"US"); // Columns
766 str << (int)(maxY*4.);
767 file->InsertEntryString(str.str(),0x0028,0x0010,"US"); // Rows
769 // Set the pixel type
771 file->InsertEntryString("16",0x0028,0x0100,"US"); // Bits Allocated
773 str << 16; // may be 12 or 16 if componentSize =16
774 file->InsertEntryString("16",0x0028,0x0101,"US"); // Bits Stored
775 file->InsertEntryString("15",0x0028,0x0102,"US"); // High Bit
777 // Set the pixel representation // 0/1 , 0=unsigned
778 file->InsertEntryString("1",0x0028,0x0103, "US"); // Pixel Representation
779 // Set the samples per pixel // 1:Grey level, 3:RGB
780 file->InsertEntryString("1",0x0028,0x0002, "US"); // Samples per Pixel
786 file->InsertEntryString(str.str(),0x0028,0x0008,"IS"); // Number of Frames
789 if (strlen(patientName) != 0)
790 file->InsertEntryString(patientName,0x0010,0x0010, "PN"); // Patient's Name
792 file->InsertEntryString(studyUID, 0x0020, 0x000d, "UI");
793 file->InsertEntryString(serieUID, 0x0020, 0x000e, "UI");
795 int pos = 0; // get the usefull part of the name
797 for(i=0, pos=0; pos<dcmImageName.size()-4; pos++, i++) {
798 if( dcmImageName[i]=='.' &&dcmImageName[i+1]=='t' && dcmImageName[i+2]=='x' && dcmImageName[i+3]=='t'
799 && dcmImageName[i+3]=='_') {
805 file->InsertEntryString(&(dcmImageName.c_str()[pos]),0x0008,0x103e, "LO"); // Series Description
807 // Set Rescale Intercept
810 file->InsertEntryString(str.str(),0x0028,0x1052,"DS");
815 file->InsertEntryString(str.str(),0x0028,0x1053,"DS");
818 GDCM_NAME_SPACE::FileHelper *fileH;
819 fileH = GDCM_NAME_SPACE::FileHelper::New(file);
820 // cast is just to avoid warnings (*no* conversion)
821 //fileH->SetImageData((uint8_t *)img,int(maxX*maxY)*sizeof(uint16_t)); // troubles when maxX, mayY are *actually* float!
823 fileH->SetImageData((uint8_t *)img,int(maxX*4.)*int(maxY*4.)*nbFrames*sizeof(uint16_t));
824 fileH->SetWriteModeToRaw();
825 fileH->SetWriteTypeToDcmExplVR();
827 if( !fileH->Write(dcmImageName))
828 std::cout << "Failed for [" << dcmImageName << "]\n"
829 << " File is unwrittable" << std::endl;