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