]> Creatis software - gdcm.git/blob - Example/FindTags.cxx
ENH: Adding 'gdcm' namespace. Be nice with me this was a ~13000 lines patch. Also...
[gdcm.git] / Example / FindTags.cxx
1 #include <iostream>
2 #include "gdcm.h"
3 #include "math.h"
4
5 int main(int argc, char* argv[]) {  
6
7    std::string toto, titi;
8
9    gdcm::File  * f1;
10
11    if(argc > 1 )
12       f1 = new gdcm::File(argv[1]);
13    else  {
14       toto = GDCM_DATA_ROOT;
15       toto += "/test.acr";
16       f1 = new gdcm::File(toto);
17    }
18
19    std::string ManufacturerName="SIEMENS ";
20    std::string RecCode="ACR-NEMA 2.0";
21    std::string ImagePositionPatient, Location, ImageLocation;
22    char zozo[100], zizi[50];
23    char c;
24
25    float x, y, z, l;
26
27    int dataSize = f1->GetImageDataSize();
28    printf ("---> pourFindTaggs : dataSize %d\n",dataSize);
29
30    f1->SetEntryByNumber(RecCode ,0x0008,0x0010);
31    f1->SetEntryByNumber(ManufacturerName ,0x0008,0x0070);
32
33 // ImagePositionPatient
34    ImagePositionPatient = f1->GetHeader()->GetEntryByNumber(0x0020,0x0032);
35
36 // Image Position (RET)
37    f1->SetEntryByNumber(ImagePositionPatient, 0x0020,0x0030);
38
39    sscanf(ImagePositionPatient.c_str(), "%f%c%f%c%f", &x,&c,&y,&c,&z);
40
41 // ceci est probablement une mauvaise idée !
42 // (peut casser l'ordre des images si la pile d'images 
43 // traverse l'axe des X, ou des Y, ou des Z)
44 //l=sqrt(x*x + y*y + z*z);
45
46 // ceci ne marchera pas si on se déplace à Z constant :-(
47    l=z;
48 // existerait-il qq chose qui marche à tout coup?
49
50 // Location
51    sprintf(zizi,"%f\n",l);
52    Location = zizi;
53    f1->SetEntryByNumber(Location, 0x0020,0x0050);
54
55 // sinon, la longueur du champ est erronée (?!?) 
56 // Probable sac de noeud entre strlen(xxx.c_str()) et xxx.length()
57 // a eclaircir !
58
59 // SetEntryLengthByNumber is private now.
60 //TO DO : see is the pb goes on...
61
62 //f1->GetHeader()->SetEntryLengthByNumber(strlen(Location.c_str())-1, 0x0020,0x0050);
63
64 // Image Location 
65
66    sprintf(zizi,"%d\n",0x7FE0);
67    ImageLocation = zizi;
68 //f1->SetEntryByNumber(Location, 0x0028,0x0200);
69 //f1->GetHeader()->SetEntryLengthByNumber(strlen(ImageLocation.c_str())-1, 0x0020,0x0050); // prudence !
70
71 // void* imageData= f1->GetImageData();
72
73 // ecriture d'un fichier ACR à partir d'un dcmHeader correct.
74
75    printf ("----------------avant PrintEntry---------------------\n");
76    f1->GetHeader()->Print();
77    printf ("----------------avant WriteDcm---------------------\n");
78
79
80 // ecriture d'un fichier ACR à partir d'un dcmHeader correct.
81
82    sprintf(zozo, "%s.acr", toto.c_str());
83    printf ("WriteACR\n");
84    f1->WriteAcr(zozo);
85
86    printf ("----------------apres Write---------------------\n");
87
88   return 0;
89 }
90
91
92