]> Creatis software - gdcm.git/blob - Example/FindTags.cxx
Fix mistypings
[gdcm.git] / Example / FindTags.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: FindTags.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/05/23 14:18:04 $
7   Version:   $Revision: 1.17 $
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 "gdcmFile.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 fileName;
28
29    GDCM_NAME_SPACE::FileHelper *h;
30    GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
31    
32    
33    if(argc > 1 ) 
34      f->SetFileName(argv[1]);
35    else  
36    {
37       fileName = GDCM_DATA_ROOT;
38       fileName += "/test.acr";
39       f->SetFileName(fileName);
40    }
41    
42    f->Load();
43    // Should test if it worked !
44    
45    h = GDCM_NAME_SPACE::FileHelper::New(f);
46    
47    std::string ManufacturerName="SIEMENS ";
48    std::string RecCode="ACR-NEMA 2.0";
49    std::string ImagePositionPatient, Location, ImageLocation;
50    std::string fileNameToWrite;
51    char c;
52
53    float x, y, z, l;
54
55    int dataSize = h->GetImageDataSize();
56    std::cout << "---> pourFindTaggs : dataSize " << dataSize << std::endl;
57
58    h->SetEntryString(RecCode ,0x0008,0x0010);
59    h->SetEntryString(ManufacturerName ,0x0008,0x0070);
60
61 // ImagePositionPatient
62    ImagePositionPatient = h->GetFile()->GetEntryString(0x0020,0x0032);
63
64 // Image Position (RET)
65    h->SetEntryString(ImagePositionPatient, 0x0020,0x0030);
66
67    sscanf(ImagePositionPatient.c_str(), "%f%c%f%c%f", &x,&c,&y,&c,&z);
68
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);
73
74 // Will not work if we move on a Z constant :-(
75    l=z;
76 // existerait-il qq chose qui marche à tout coup?
77
78 // Location
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);
82
83 // sinon, la longueur du champ est erronée (?!?) 
84 // Probable sac de noeud entre strlen(xxx.c_str()) et xxx.length()
85 // a eclaircir !
86
87 // SetEntryLength is private now.
88 //TO DO : see if the pb goes on...
89
90 //h->GetFile()->SetEntryLength(strlen(Location.c_str())-1, 0x0020,0x0050);
91
92 // Image Location 
93
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 !
98
99 // void *imageData= h->GetImageData();
100
101 // ecriture d'un fichier ACR à partir d'un dcmFile correct.
102
103    std::cout << "----------------before PrintEntry---------------------" << std::endl;
104    h->GetFile()->Print();
105    std::cout << "----------------before WriteDcm---------------------" << std::endl;
106
107
108 // ecriture d'un fichier ACR à partir d'un dcmFile correct.
109
110    fileNameToWrite = fileName + ".acr";
111    std::cout << "WriteACR" << std::endl;
112    h->WriteAcr(fileNameToWrite);
113
114    std::cout << "----------------apres Write---------------------" << std::endl;
115
116    h->Delete();
117    f->Delete();
118
119    return 0;
120 }
121
122
123