]> Creatis software - gdcm.git/blobdiff - Example/FindTags.cxx
According to Benoit's suggestion, and without any objection from anybody
[gdcm.git] / Example / FindTags.cxx
index 20a3d52ae9007dfeb699c0c746d176989116f1be..83c6e599f1ab073059e64975a55a4207425f9310 100644 (file)
@@ -1,9 +1,29 @@
-#include <iostream>
-#include "gdcm.h"
-#include "math.h"
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: FindTags.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/01/08 15:03:57 $
+  Version:   $Revision: 1.8 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+#include "gdcmFile.h"
+#include "gdcmHeader.h"
+#include "gdcmUtil.h"
 
-int main(int argc, char* argv[]) {  
+#include <iostream>
+#include <stdio.h> // for sscanf
 
+int main(int argc, char* argv[])
+{
    std::string toto, titi;
 
    gdcm::File  * f1;
@@ -19,22 +39,22 @@ int main(int argc, char* argv[]) {
    std::string ManufacturerName="SIEMENS ";
    std::string RecCode="ACR-NEMA 2.0";
    std::string ImagePositionPatient, Location, ImageLocation;
-   char zozo[100], zizi[50];
+   std::string zozo;
    char c;
 
    float x, y, z, l;
 
    int dataSize = f1->GetImageDataSize();
-   printf ("---> pourFindTaggs : dataSize %d\n",dataSize);
+   std::cout << "---> pourFindTaggs : dataSize " << dataSize << std::endl;
 
-   f1->SetEntryByNumber(RecCode ,0x0008,0x0010);
-   f1->SetEntryByNumber(ManufacturerName ,0x0008,0x0070);
+   f1->SetEntry(RecCode ,0x0008,0x0010);
+   f1->SetEntry(ManufacturerName ,0x0008,0x0070);
 
 // ImagePositionPatient
-   ImagePositionPatient = f1->GetHeader()->GetEntryByNumber(0x0020,0x0032);
+   ImagePositionPatient = f1->GetHeader()->GetEntry(0x0020,0x0032);
 
 // Image Position (RET)
-   f1->SetEntryByNumber(ImagePositionPatient, 0x0020,0x0030);
+   f1->SetEntry(ImagePositionPatient, 0x0020,0x0030);
 
    sscanf(ImagePositionPatient.c_str(), "%f%c%f%c%f", &x,&c,&y,&c,&z);
 
@@ -48,44 +68,44 @@ int main(int argc, char* argv[]) {
 // existerait-il qq chose qui marche à tout coup?
 
 // Location
-   sprintf(zizi,"%f\n",l);
-   Location = zizi;
-   f1->SetEntryByNumber(Location, 0x0020,0x0050);
+   std::string zizi = gdcm::Util::Format("%f",l);
+   Location = gdcm::Util::DicomString(zizi.c_str());
+   f1->SetEntry(Location, 0x0020,0x0050);
 
 // sinon, la longueur du champ est erronée (?!?) 
 // Probable sac de noeud entre strlen(xxx.c_str()) et xxx.length()
 // a eclaircir !
 
-// SetEntryLengthByNumber is private now.
+// SetEntryLength is private now.
 //TO DO : see is the pb goes on...
 
-//f1->GetHeader()->SetEntryLengthByNumber(strlen(Location.c_str())-1, 0x0020,0x0050);
+//f1->GetHeader()->SetEntryLength(strlen(Location.c_str())-1, 0x0020,0x0050);
 
 // Image Location 
 
-   sprintf(zizi,"%d\n",0x7FE0);
-   ImageLocation = zizi;
-//f1->SetEntryByNumber(Location, 0x0028,0x0200);
-//f1->GetHeader()->SetEntryLengthByNumber(strlen(ImageLocation.c_str())-1, 0x0020,0x0050); // prudence !
+   zizi = gdcm::Util::Format("%d",0x7FE0);
+   ImageLocation = gdcm::Util::DicomString(zizi.c_str());
+//f1->SetEntry(Location, 0x0028,0x0200);
+//f1->GetHeader()->SetEntryLength(strlen(ImageLocation.c_str())-1, 0x0020,0x0050); // prudence !
 
 // void* imageData= f1->GetImageData();
 
 // ecriture d'un fichier ACR à partir d'un dcmHeader correct.
 
-   printf ("----------------avant PrintEntry---------------------\n");
+   std::cout << "----------------avant PrintEntry---------------------" << std::endl;
    f1->GetHeader()->Print();
-   printf ("----------------avant WriteDcm---------------------\n");
+   std::cout << "----------------avant WriteDcm---------------------" << std::endl;
 
 
 // ecriture d'un fichier ACR à partir d'un dcmHeader correct.
 
-   sprintf(zozo, "%s.acr", toto.c_str());
-   printf ("WriteACR\n");
+   zozo = toto + ".acr";
+   std::cout << "WriteACR" << std::endl;
    f1->WriteAcr(zozo);
 
-   printf ("----------------apres Write---------------------\n");
+   std::cout << "----------------apres Write---------------------" << std::endl;
 
-  return 0;
+   return 0;
 }