]> Creatis software - gdcm.git/blobdiff - Testing/TestChangeHeader.cxx
* src/gdcmFile.cxx : now delete the PixelConvert instance.
[gdcm.git] / Testing / TestChangeHeader.cxx
index d249f67ae8cc362a536f8bdcf11e8f83a5c7e30b..4c7f0ffadc15104874caa070b373196b67ff263b 100644 (file)
@@ -1,61 +1,87 @@
-#include <iostream>
-//#include "gdcm.h"
 #include "gdcmHeader.h"
 #include "gdcmFile.h"
+#include <string>
 
+// Writting of a DICOM file, using a correct gdcmHeader.
+// and pixels of an other image
+
+
+int TestChangeHeader(int argc, char* argv[])
+{
+   if (argc < 3)
+   {
+      std::cerr << "usage :" << std::endl << 
+      argv[0] << " FileForHeader FileForPixels" << std::endl;
+      return 1;
+   }
+
+   std::string premier = argv[1];
+   gdcmFile  *f1 = new gdcmFile(premier);
+
+   std::string deuxieme = argv[2];
+   gdcmFile  *f2 = new gdcmFile(deuxieme);
+
+   //f1->PrintPubElVal();
+
+   // We suppose the DICOM Entries of the second file *do* exist !
+
+   std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008);
+   if(nbFrames != "gdcm::Unfound")
+   {
+      f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
+   }
 
-       // ecriture d'un fichier DICOM à partir d'un dcmHeader correct.
-       // et des pixels d'une autre image
-       
-       
-int main(int argc, char* argv[])
-{  
-       string premier, deuxieme;
-       char resultat[200];
-       
-       gdcmFile  *f1, *f2;
-       //gdcmHeader *e1, *e2;
-       void* imageData;
-       int dataSize;
-               
-       if (argc < 3) {
-               printf ("usage :\n testChangeEntete nomFichierPourEntete nomFichierPourDonnées \n");
-               exit(0);        
-       }
-
-       premier = argv[1];
-       f1 = new gdcmFile(premier);
-       
-       deuxieme = argv[2];
-       f2 = new gdcmFile(deuxieme);
-       
-       //f1->PrintPubElVal();
-       
-       // On suppose que les champs DICOM du 2ieme fichier existent *effectivement*
-       
-   // FIXME : floowing lines commented out in order to make compilation work.
-   //FIXME f1->ReplaceOrCreateByNumber(0x0028, 0x0008, f2->GetPubElValSet().GetElValueByNumber(0x0028, 0x0008));// nb Frames
-       //FIXME f1->ReplaceOrCreateByNumber(0x0028, 0x0010, f2->GetPubElValSet().GetElValueByNumber(0x0028, 0x0010));// nbLig
-       //FIXME f1->ReplaceOrCreateByNumber(0x0028, 0x0011, f2->GetPubElValSet().GetElValueByNumber(0x0028, 0x0011));// nbCol
-       
-       // sans doute d'autres à mettre à jour...
-       
-       // TODO : une routine qui recoit une liste de couples (gr,el), et qui fasse le boulot.
-
-                               
-       dataSize = f2->GetImageDataSize();
-       printf ("dataSize %d\n",dataSize);
-       imageData= f2->GetImageData();
-       
-       f1->SetImageData(imageData,dataSize);
-       
-       // ou, plus joli:
-       //f1->SetImageData(f2->GetImageData(),f2->GetImageDataSize());  
-
-       sprintf(resultat, "%s.vol", deuxieme.c_str());
-       printf ("WriteDCM\n");
-       f1->WriteDcm(resultat);         
-}
 
+// WARNING : If user tries to 'merge' two mismatching images
+// e.g. a LUT image and a RGB image
+// or a compressed and an uncompressed one
+// or a single frame and a multiframe,
+// or a '12 Bits Allocated' image and anything else, etc
+// Probabely TestChangeHeader will fail !
+// It was not designed as a 'Test' program, but as a utility
+// provided to 'transform' an image 'Siemens MRI New version' into an image 'Siemens MRI old version'
+         
+   f1->GetHeader()->ReplaceOrCreateByNumber(
+      f2->GetHeader()->GetEntryByNumber(0x0028, 0x0010), 0x0028, 0x0010);// nbLig
+   f1->GetHeader()->ReplaceOrCreateByNumber( 
+      f2->GetHeader()->GetEntryByNumber(0x0028, 0x0011), 0x0028, 0x0011);// nbCol
+   f1->GetHeader()->ReplaceOrCreateByNumber( 
+      f2->GetHeader()->GetEntryByNumber(0x0028, 0x0100), 0x0028, 0x0100);// BitsAllocated
+   f1->GetHeader()->ReplaceOrCreateByNumber( 
+      f2->GetHeader()->GetEntryByNumber(0x0028, 0x0101), 0x0028, 0x0101);// BitsStored
+   f1->GetHeader()->ReplaceOrCreateByNumber( 
+      f2->GetHeader()->GetEntryByNumber(0x0028, 0x0102), 0x0028, 0x0102);// HighBit
+   f1->GetHeader()->ReplaceOrCreateByNumber( 
+      f2->GetHeader()->GetEntryByNumber(0x0028, 0x0103), 0x0028, 0x0103);// Pixel Representation
+// Probabely some more to update (?)
 
+// TODO : add a default value
+// TODO : add a method that receives a list of pairs  (gr,el), 
+//                        and that does the work.
 
+   int dataSize = f2->GetImageDataSize();
+   printf ("dataSize %d\n",dataSize);
+   uint8_t* imageData= f2->GetImageData();
+
+// TODO : Why don't we merge theese 2 functions ?
+
+   f1->SetImageData(imageData,dataSize);
+   f1->GetHeader()->SetImageDataSize(dataSize);
+
+   f1->GetHeader()->Print();
+
+   std::string s0 =f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0000);
+   std::string s10=f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0010);
+   printf("lgr 7fe0, 0000 %s\n",s0.c_str());
+   printf("lgr 7fe0, 0010 %s\n",s10.c_str());
+
+   char resultat[512];
+
+   sprintf(resultat, "%s.vol", deuxieme.c_str());
+   printf ("WriteDCM\n");
+  //f1->WriteDcmExplVR("itk-gdcm-ex.dcm");
+  //f1->WriteDcmImplVR(resultat);
+   f1->WriteAcr(resultat);
+
+   return 0;
+}