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