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