]> Creatis software - gdcm.git/blobdiff - Testing/TestWriteSimple.cxx
ENH: Adding ExportConfiguration
[gdcm.git] / Testing / TestWriteSimple.cxx
index 24281df6b15465231db78939ff56fc97163b8f1e..4b8685d150d0b919b8b791467396d1ccc0e92bb6 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestWriteSimple.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/26 08:28:56 $
-  Version:   $Revision: 1.44 $
+  Date:      $Date: 2006/04/11 16:05:03 $
+  Version:   $Revision: 1.49 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -25,6 +25,8 @@
 #include "gdcmFile.h"
 #include "gdcmFileHelper.h"
 #include "gdcmDebug.h"
+#include "gdcmGlobal.h"
+#include "gdcmDictSet.h"
 
 #include <iostream>
 #include <sstream>
@@ -45,56 +47,60 @@ typedef struct
 } Image;
 
 Image Images [] = {
-   {256, 256, 1, 1, 8,  8,  0, 'a'},
-   {256, 256, 1, 1, 8,  8,  0, 'e'},
-   {256, 256, 1, 1, 8,  8,  0, 'i'},
-   {512, 256, 1, 1, 8,  8,  0, 'a'},
-   {512, 256, 1, 1, 8,  8,  0, 'e'},
-   {512, 256, 1, 1, 8,  8,  0, 'i'},
-
-   {256, 512, 1, 1, 8,  8,  0, 'a'},
-   {256, 512, 1, 1, 8,  8,  0, 'e'},
-   {256, 512, 1, 1, 8,  8,  0, 'i'},
-
-   {256, 512, 1, 1, 16, 16, 0, 'a'},
-   {256, 512, 1, 1, 16, 16, 0, 'e'},
-   {256, 512, 1, 1, 16, 16, 0, 'i'},
-   {256, 512, 1, 1, 16, 16, 0, 'a'},
-   {256, 512, 1, 1, 16, 16, 0, 'e'},
-   {256, 512, 1, 1, 16, 16, 0, 'i'},
-
-   {512, 256, 10, 1, 8, 8,  0, 'a'},
-   {512, 256, 10, 1, 8, 8,  0, 'e'},
-   {512, 256, 10, 1, 8, 8,  0, 'i'},
-   {512, 256, 10, 3, 8, 8,  0, 'a'},
-   {512, 256, 10, 3, 8, 8,  0, 'e'},
-   {512, 256, 10, 3, 8, 8,  0, 'i'},
-
-   {256, 256, 1, 1, 8,  8,  1, 'a'},
-   {256, 256, 1, 1, 8,  8,  1, 'e'},
-   {256, 256, 1, 1, 8,  8,  1, 'i'},
-
-   {512, 256, 1, 1, 8,  8,  1, 'a'},
-   {512, 256, 1, 1, 8,  8,  1, 'e'},
-   {512, 256, 1, 1, 8,  8,  1, 'i'},
-
-   {256, 512, 1, 1, 8,  8,  1, 'a'},
-   {256, 512, 1, 1, 8,  8,  1, 'e'},
-   {256, 512, 1, 1, 8,  8,  1, 'i'},
-
-   {256, 512, 1, 1, 16, 16, 1, 'a'},
-   {256, 512, 1, 1, 16, 16, 1, 'e'},
-   {256, 512, 1, 1, 16, 16, 1, 'i'},
-   {256, 512, 1, 1, 16, 16, 1, 'a'},
-   {256, 512, 1, 1, 16, 16, 1, 'e'},
-   {256, 512, 1, 1, 16, 16, 1, 'i'},
-
-   {512, 256, 10, 1, 8, 8,  1, 'a'},
-   {512, 256, 10, 1, 8, 8,  1, 'e'},
-   {512, 256, 10, 1, 8, 8,  1, 'i'},
-   {512, 256, 10, 3, 8, 8,  1, 'a'},
-   {512, 256, 10, 3, 8, 8,  1, 'e'},
-   {512, 256, 10, 3, 8, 8,  1, 'i'},
+   {128, 128, 1, 1, 8,  8,  0, 'e'},
+   {256, 128, 1, 1, 8,  8,  0, 'a'},
+   {128, 128, 1, 1, 8,  8,  0, 'i'},
+
+   {128, 128, 1, 1, 8,  8,  0, 'a'},    
+   {256, 128, 1, 1, 8,  8,  0, 'i'},
+     
+
+   {256, 128, 1, 1, 8,  8,  0, 'e'},
+   {128, 128, 1, 1, 16, 16, 0, 'e'},      
+   {128, 256, 1, 1, 16, 16, 0, 'e'},   
+   
+   {128, 256, 1, 1, 8,  8,  0, 'e'},
+   {128, 256, 1, 1, 8,  8,  0, 'i'},
+   {128, 256, 1, 1, 8,  8,  0, 'a'},
+   
+   {128, 256, 1, 1, 16, 16, 0, 'i'},
+   {128, 256, 1, 1, 16, 16, 0, 'i'},
+   {128, 256, 1, 1, 16, 16, 0, 'a'},
+   {128, 256, 1, 1, 16, 16, 0, 'a'},
+
+   {256, 128, 10, 1, 8, 8,  0, 'e'},
+   {256, 128, 10, 3, 8, 8,  0, 'e'},
+   {256, 128, 10, 3, 8, 8,  0, 'i'},
+   {256, 128, 10, 1, 8, 8,  0, 'i'},
+   {256, 128, 10, 1, 8, 8,  0, 'a'},
+   {256, 128, 10, 3, 8, 8,  0, 'a'},
+      
+   {128, 128, 1, 1, 8,  8,  1, 'e'},
+   {128, 128, 1, 1, 8,  8,  1, 'i'},
+   {128, 128, 1, 1, 8,  8,  1, 'a'},
+   
+   {256, 128, 1, 1, 8,  8,  1, 'e'},
+   {256, 128, 1, 1, 8,  8,  1, 'i'},
+   {256, 128, 1, 1, 8,  8,  1, 'a'},
+   
+   {128, 256, 1, 1, 8,  8,  1, 'a'},
+   {128, 256, 1, 1, 8,  8,  1, 'e'},
+   {128, 256, 1, 1, 8,  8,  1, 'i'},
+
+   {128, 256, 1, 1, 16, 16, 1, 'e'},
+   {128, 256, 1, 1, 16, 16, 1, 'e'},
+   {128, 256, 1, 1, 16, 16, 1, 'i'},
+   {128, 256, 1, 1, 16, 16, 1, 'i'},
+   {128, 256, 1, 1, 16, 16, 1, 'a'},
+   {128, 256, 1, 1, 16, 16, 1, 'a'},     
+
+   {256, 128, 10, 1, 8, 8,  1, 'e'},
+   {256, 128, 10, 1, 8, 8,  1, 'i'},
+   {256, 128, 10, 1, 8, 8,  1, 'a'},   
+   
+   {256, 128, 10, 3, 8, 8,  1, 'e'},
+   {256, 128, 10, 3, 8, 8,  1, 'i'},
+   {256, 128, 10, 3, 8, 8,  1, 'a'},
    {0,   0,   1,  1, 8, 8,  0, 'i'} // to find the end
 };
 
@@ -103,6 +109,8 @@ const unsigned int MAX_NUMBER_OF_DIFFERENCE = 10;
 
 int WriteSimple(Image &img)
 {
+   
+   std::cout << "======================= WriteSimple =========(begin of processing current image)" << std::endl;
    std::ostringstream fileName;
    fileName.str("");
    fileName << "TestWriteSimple";
@@ -119,16 +127,16 @@ int WriteSimple(Image &img)
    // Set the image size
    str.str("");
    str << img.sizeX;
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0011); // Columns
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0011,"US"); // Columns
    str.str("");
    str << img.sizeY;
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0010); // Rows
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0010,"US"); // Rows
 
    if(img.sizeZ>1)
    {
       str.str("");
       str << img.sizeZ;
-      fileToBuild->InsertEntryString(str.str(),0x0028,0x0008); // Number of Frames
+      fileToBuild->InsertEntryString(str.str(),0x0028,0x0008, "IS"); // Number of Frames
    }
 
    fileName << "-" << img.sizeX << "-" << img.sizeY << "-" << img.sizeZ;
@@ -136,20 +144,20 @@ int WriteSimple(Image &img)
    // Set the pixel type
    str.str("");
    str << img.componentSize;
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0100); // Bits Allocated
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0100,"US"); // Bits Allocated
 
    str.str("");
    str << img.componentUse;
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0101); // Bits Stored
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0101,"US"); // Bits Stored
 
    str.str("");
    str << ( img.componentSize - 1 );
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0102); // High Bit
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0102,"US"); // High Bit
 
    // Set the pixel representation
    str.str("");
    str << img.sign;
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0103); // Pixel Representation
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0103, "US"); // Pixel Representation
 
    fileName << "-" << img.componentSize;
    if(img.sign == 0)
@@ -171,7 +179,7 @@ int WriteSimple(Image &img)
    // Set the samples per pixel
    str.str("");
    str << img.components;
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0002); // Samples per Pixel
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0002, "US"); // Samples per Pixel
 
 // Step 2 : Create the output image
    std::cout << "2...";
@@ -209,9 +217,9 @@ int WriteSimple(Image &img)
    fileH->SetImageData(imageData,size);
 
 // Step 4 : Set the writting mode and write the image
-   std::cout << "4...";
 
    fileH->SetWriteModeToRaw();
+   std::cout << "4'...";   
    switch (img.writeMode)
    {
       case 'a' : // Write an ACR file
@@ -235,10 +243,13 @@ int WriteSimple(Image &img)
          return 1;
    }
 
+   std::cout << std::endl;
+   fileToBuild->Print();
+
    if( !fileH->Write(fileName.str()) )
    {
       std::cout << "Failed for [" << fileName.str() << "]\n"
-                << "           File is unwrittable\n";
+                << "           File is unwrittable" << std::endl;
 
       fileH->Delete();
 
@@ -247,20 +258,28 @@ int WriteSimple(Image &img)
    }
 
 // Step 5 : Read the written image
-   std::cout << "5...";
+   std::cout << "5..." << std::endl;
    // old form.
    //gdcm::FileHelper *reread = new gdcm::FileHelper( fileName.str() );
    // Better use :
-   gdcm::FileHelper *reread = gdcm::FileHelper::New( );
-   reread->SetFileName( fileName.str() );
-   reread->SetLoadMode(gdcm::LD_ALL); // Load everything
+   gdcm::File *f = gdcm::File::New( );
+   f->SetLoadMode(gdcm::LD_ALL);
+   f->SetFileName( fileName.str() );
+   
+   //reread->SetFileName( fileName.str() );
+   //reread->SetLoadMode(gdcm::LD_ALL); // Load everything
                            // Possible values are 
                            //              gdcm::LD_ALL, 
                            //              gdcm::LD_NOSEQ, 
                            //              gdcm::LD_NOSHADOW,
                            //              gdcm::LD_NOSEQ|gdcm::LD_NOSHADOW, 
                            //              gdcm::LD_NOSHADOWSEQ
-   reread->Load();
+   
+   f->Load();
+  // reread->Load();
+   gdcm::FileHelper *reread = gdcm::FileHelper::New( f );  
+
+   reread->Print();
 
    if( !reread->GetFile()->IsReadable() )
    {
@@ -274,7 +293,7 @@ int WriteSimple(Image &img)
    }
 
 // Step 6 : Compare to the written image
-   std::cout << "6...";
+   std::cout << "6..." << std::endl;
    size_t dataSizeWritten = reread->GetImageDataSize();
    uint8_t *imageDataWritten = reread->GetImageData();
 
@@ -328,7 +347,7 @@ int WriteSimple(Image &img)
       return 1;
    }
 
-   // Test the data's content
+   // Test the data content
    if ( memcmp(imageData, imageDataWritten, size) !=0 )
    {
       std::cout << "Failed" << std::endl
@@ -358,12 +377,9 @@ int WriteSimple(Image &img)
       return 1;
    }
 
-   std::cout << "OK" << std::endl;
-
    fileH->Delete();
    reread->Delete();
    delete[] imageData;
-
    return 0;
 }
 
@@ -377,15 +393,16 @@ int TestWriteSimple(int argc, char *argv[])
       return 1;
    }
 
-   gdcm::Debug::DebugOn();
-       
+  // gdcm::Debug::DebugOn();
+
    int ret=0;
    int i=0;
    while( Images[i].sizeX>0 && Images[i].sizeY>0 )
    {
-      std::cout << "Test n :" << i; 
+      std::cout << "Test n :" << i <<std::endl;
       ret += WriteSimple(Images[i] );
       i++;
+
    }
 
    return ret;