]> Creatis software - gdcm.git/blobdiff - Example/FindTags.cxx
Fix mistypings
[gdcm.git] / Example / FindTags.cxx
index 8439e9f9df47789e6cea68ff56967b6f5828114a..e808d85b7d5d983eeaf979e78329638f5d230080 100644 (file)
-#include <iostream>
-#include "gdcm.h"
-#include "math.h"
-
-int main(int argc, char* argv[]) {  
-
-   std::string toto, titi;
-
-   gdcmFile  * f1;
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: FindTags.cxx,v $
+  Language:  C++
+  Date:      $Date: 2007/05/23 14:18:04 $
+  Version:   $Revision: 1.17 $
+                                                                                
+  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 "gdcmFileHelper.h"
+#include "gdcmFile.h"
+#include "gdcmUtil.h"
 
-   if(argc > 1 )
-      f1 = new gdcmFile(argv[1]);
-   else  {
-      toto = GDCM_DATA_ROOT;
-      toto += "/test.acr";
-      f1 = new gdcmFile(toto);
+#include <iostream>
+#include <stdio.h> // for sscanf
+
+int main(int argc, char *argv[])
+{
+   std::string fileName;
+
+   GDCM_NAME_SPACE::FileHelper *h;
+   GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
+   
+   
+   if(argc > 1 ) 
+     f->SetFileName(argv[1]);
+   else  
+   {
+      fileName = GDCM_DATA_ROOT;
+      fileName += "/test.acr";
+      f->SetFileName(fileName);
    }
-
+   
+   f->Load();
+   // Should test if it worked !
+   
+   h = GDCM_NAME_SPACE::FileHelper::New(f);
+   
    std::string ManufacturerName="SIEMENS ";
    std::string RecCode="ACR-NEMA 2.0";
    std::string ImagePositionPatient, Location, ImageLocation;
-   char zozo[100], zizi[50];
+   std::string fileNameToWrite;
    char c;
 
    float x, y, z, l;
 
-   int dataSize = f1->GetImageDataSize();
-   printf ("---> pourFindTaggs : dataSize %d\n",dataSize);
+   int dataSize = h->GetImageDataSize();
+   std::cout << "---> pourFindTaggs : dataSize " << dataSize << std::endl;
 
-   f1->SetEntryByNumber(RecCode ,0x0008,0x0010);
-   f1->SetEntryByNumber(ManufacturerName ,0x0008,0x0070);
+   h->SetEntryString(RecCode ,0x0008,0x0010);
+   h->SetEntryString(ManufacturerName ,0x0008,0x0070);
 
 // ImagePositionPatient
-   ImagePositionPatient = f1->GetHeader()->GetEntryByNumber(0x0020,0x0032);
+   ImagePositionPatient = h->GetFile()->GetEntryString(0x0020,0x0032);
 
 // Image Position (RET)
-   f1->SetEntryByNumber(ImagePositionPatient, 0x0020,0x0030);
+   h->SetEntryString(ImagePositionPatient, 0x0020,0x0030);
 
    sscanf(ImagePositionPatient.c_str(), "%f%c%f%c%f", &x,&c,&y,&c,&z);
 
-// ceci est probablement une mauvaise idée !
+// probablely a bad idea !
 // (peut casser l'ordre des images si la pile d'images 
 // traverse l'axe des X, ou des Y, ou des Z)
 //l=sqrt(x*x + y*y + z*z);
 
-// ceci ne marchera pas si on se déplace à Z constant :-(
+// Will not work if we move on a Z constant :-(
    l=z;
 // 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_NAME_SPACE::Util::Format("%f",l);
+   Location = GDCM_NAME_SPACE::Util::DicomString(zizi.c_str());
+   h->SetEntryString(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.
-//TO DO : see is the pb goes on...
+// SetEntryLength is private now.
+//TO DO : see if the pb goes on...
 
-//f1->GetHeader()->SetEntryLengthByNumber(strlen(Location.c_str())-1, 0x0020,0x0050);
+//h->GetFile()->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_NAME_SPACE::Util::Format("%d",0x7FE0);
+   ImageLocation = GDCM_NAME_SPACE::Util::DicomString(zizi.c_str());
+//h->SetEntryString(Location, 0x0028,0x0200);
+//h->GetFile()->SetEntryLength(strlen(ImageLocation.c_str())-1, 0x0020,0x0050); // prudence !
+
+// void *imageData= h->GetImageData();
 
-// void* imageData= f1->GetImageData();
+// ecriture d'un fichier ACR à partir d'un dcmFile correct.
 
-// ecriture d'un fichier ACR à partir d'un dcmHeader correct.
+   std::cout << "----------------before PrintEntry---------------------" << std::endl;
+   h->GetFile()->Print();
+   std::cout << "----------------before WriteDcm---------------------" << std::endl;
 
-   printf ("----------------avant PrintEntry---------------------\n");
-   f1->GetHeader()->Print();
-   printf ("----------------avant WriteDcm---------------------\n");
 
+// ecriture d'un fichier ACR à partir d'un dcmFile correct.
 
-// ecriture d'un fichier ACR à partir d'un dcmHeader correct.
+   fileNameToWrite = fileName + ".acr";
+   std::cout << "WriteACR" << std::endl;
+   h->WriteAcr(fileNameToWrite);
 
-   sprintf(zozo, "%s.acr", toto.c_str());
-   printf ("WriteACR\n");
-   f1->WriteAcr(zozo);
+   std::cout << "----------------apres Write---------------------" << std::endl;
 
-   printf ("----------------apres Write---------------------\n");
+   h->Delete();
+   f->Delete();
 
-  return 0;
+   return 0;
 }