1 /*=========================================================================
4 Module: $RCSfile: FindTags.cxx,v $
6 Date: $Date: 2007/05/23 14:18:04 $
7 Version: $Revision: 1.17 $
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 =========================================================================*/
18 #include "gdcmFileHelper.h"
23 #include <stdio.h> // for sscanf
25 int main(int argc, char *argv[])
29 GDCM_NAME_SPACE::FileHelper *h;
30 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
34 f->SetFileName(argv[1]);
37 fileName = GDCM_DATA_ROOT;
38 fileName += "/test.acr";
39 f->SetFileName(fileName);
43 // Should test if it worked !
45 h = GDCM_NAME_SPACE::FileHelper::New(f);
47 std::string ManufacturerName="SIEMENS ";
48 std::string RecCode="ACR-NEMA 2.0";
49 std::string ImagePositionPatient, Location, ImageLocation;
50 std::string fileNameToWrite;
55 int dataSize = h->GetImageDataSize();
56 std::cout << "---> pourFindTaggs : dataSize " << dataSize << std::endl;
58 h->SetEntryString(RecCode ,0x0008,0x0010);
59 h->SetEntryString(ManufacturerName ,0x0008,0x0070);
61 // ImagePositionPatient
62 ImagePositionPatient = h->GetFile()->GetEntryString(0x0020,0x0032);
64 // Image Position (RET)
65 h->SetEntryString(ImagePositionPatient, 0x0020,0x0030);
67 sscanf(ImagePositionPatient.c_str(), "%f%c%f%c%f", &x,&c,&y,&c,&z);
69 // probablely a bad idea !
70 // (peut casser l'ordre des images si la pile d'images
71 // traverse l'axe des X, ou des Y, ou des Z)
72 //l=sqrt(x*x + y*y + z*z);
74 // Will not work if we move on a Z constant :-(
76 // existerait-il qq chose qui marche à tout coup?
79 std::string zizi = GDCM_NAME_SPACE::Util::Format("%f",l);
80 Location = GDCM_NAME_SPACE::Util::DicomString(zizi.c_str());
81 h->SetEntryString(Location, 0x0020,0x0050);
83 // sinon, la longueur du champ est erronée (?!?)
84 // Probable sac de noeud entre strlen(xxx.c_str()) et xxx.length()
87 // SetEntryLength is private now.
88 //TO DO : see if the pb goes on...
90 //h->GetFile()->SetEntryLength(strlen(Location.c_str())-1, 0x0020,0x0050);
94 zizi = GDCM_NAME_SPACE::Util::Format("%d",0x7FE0);
95 ImageLocation = GDCM_NAME_SPACE::Util::DicomString(zizi.c_str());
96 //h->SetEntryString(Location, 0x0028,0x0200);
97 //h->GetFile()->SetEntryLength(strlen(ImageLocation.c_str())-1, 0x0020,0x0050); // prudence !
99 // void *imageData= h->GetImageData();
101 // ecriture d'un fichier ACR à partir d'un dcmFile correct.
103 std::cout << "----------------before PrintEntry---------------------" << std::endl;
104 h->GetFile()->Print();
105 std::cout << "----------------before WriteDcm---------------------" << std::endl;
108 // ecriture d'un fichier ACR à partir d'un dcmFile correct.
110 fileNameToWrite = fileName + ".acr";
111 std::cout << "WriteACR" << std::endl;
112 h->WriteAcr(fileNameToWrite);
114 std::cout << "----------------apres Write---------------------" << std::endl;