]> Creatis software - gdcm.git/commitdiff
* Testing/TestSequence.cxx : add test for sequences of images... test that
authorregrain <regrain>
Mon, 7 Feb 2005 12:53:58 +0000 (12:53 +0000)
committerregrain <regrain>
Mon, 7 Feb 2005 12:53:58 +0000 (12:53 +0000)
     we have the same serie or the same study UID
   -- BeNours

ChangeLog
Testing/CMakeLists.txt
Testing/TestSequence.cxx [new file with mode: 0644]
Testing/TestWriteSimple.cxx
gdcmPython/demo/PrintFile.py.in
src/gdcmFile.cxx

index f035da73ac54caec347faf046b7e323a80b13e43..52dceec695c7406ab47049320a8aceea61b13600 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2005-02-07 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+   * Testing/TestSequence.cxx : add test for sequences of images... test that
+     we have the same serie or the same study UID
+
 2005-02-07 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
    * gdcmPython/gdcm.i : bug fix. Now string are correctly converted in python
      string type
index 5f53ece9ffd53912d4a36ce1777392111a34138c..913593ce8ad2c1d4abbfefa1badcbe79869812fa 100644 (file)
@@ -17,6 +17,7 @@ SET(TEST_SOURCES
   TestDicomString.cxx
   TestDict.cxx
   TestWriteSimple.cxx
+  TestSequence.cxx
 )
 
 # add tests that require data
diff --git a/Testing/TestSequence.cxx b/Testing/TestSequence.cxx
new file mode 100644 (file)
index 0000000..838d5e7
--- /dev/null
@@ -0,0 +1,327 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: TestSequence.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/02/07 12:53:59 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  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.
+                                                                                
+=========================================================================*/
+
+/**
+ * Write a dicom file from nothing
+ * The written image is 256x256, 8 bits, unsigned char
+ * The image content is a horizontal grayscale from 
+ * 
+ */
+#include "gdcmFile.h"
+#include "gdcmFileHelper.h"
+#include "gdcmValEntry.h"
+#include "gdcmUtil.h"
+#include "gdcmDebug.h"
+
+#include <iostream>
+#include <sstream>
+#include <list>
+
+typedef std::list<gdcm::File *> FileList;
+
+// If there is sameSerie, sameStudy is set to true
+int CompareImages(FileList &list,bool sameSerie,bool sameStudy)
+{
+   if( sameSerie )
+      sameStudy = true;
+
+   gdcm::ValEntry *entry;
+   std::map<std::string, int> instUID;
+   std::map<std::string, int> mediaUID;
+   std::map<std::string, int> serieUID;
+   std::map<std::string, int> studyUID;
+
+   FileList::iterator it;
+   for(it=list.begin();it!=list.end();++it)
+   {
+      // SOP Instance UID
+      entry=(*it)->GetValEntry(0x0008,0x0018);
+      if( entry )
+         if( instUID.find(entry->GetValue())!=instUID.end() )
+            instUID[entry->GetValue()]++;
+         else
+            instUID[entry->GetValue()]=1;
+      // Media Storage SOP Instance UID
+      entry=(*it)->GetValEntry(0x0002,0x0003);
+      if( entry )
+         if( mediaUID.find(entry->GetValue())!=mediaUID.end() )
+            mediaUID[entry->GetValue()]++;
+         else
+            mediaUID[entry->GetValue()]=1;
+      // Series Instance UID
+      entry=(*it)->GetValEntry(0x0020,0x000e);
+      if( entry )
+         if( serieUID.find(entry->GetValue())!=serieUID.end() )
+            serieUID[entry->GetValue()]++;
+         else
+            serieUID[entry->GetValue()]=1;
+      // Study Instance UID
+      entry=(*it)->GetValEntry(0x0020,0x000d);
+      if( entry )
+         if( studyUID.find(entry->GetValue())!=studyUID.end() )
+            studyUID[entry->GetValue()]++;
+         else
+            studyUID[entry->GetValue()]=1;
+   }
+
+   if( sameSerie )
+   {
+      if( serieUID.size()>1 )
+      {
+         std::cout << "Failed\n"
+                   << "        Series UID not same (0x0020,0x000e)\n";
+         return 1;
+      }
+   }
+   else
+   {
+      if( serieUID.size()!=list.size() )
+      {
+         std::cout << "Failed\n"
+                   << "        Some Series UID are same (0x0020,0x000e)\n";
+         return 1;
+      }
+   }
+
+   if( sameStudy )
+   {
+      if( studyUID.size()>1 )
+      {
+         std::cout << "Failed\n"
+                   << "        Studies UID not same (0x0020,0x000d)\n";
+         return 1;
+      }
+   }
+   else
+   {
+      if( studyUID.size()!=list.size() )
+      {
+         std::cout << "Failed\n"
+                   << "        Some Studies UID are same (0x0020,0x000d)\n";
+         return 1;
+      }
+   }
+
+   if( mediaUID.size()!=list.size() )
+   {
+      std::cout << "Failed\n"
+                << "        Some Media UID are same (0x0002,0x0003)\n";
+      return 1;
+   }
+
+   if( instUID.size()!=list.size() )
+   {
+      std::cout << "Failed\n"
+                << "        Some Instance UID are same (0x0008,0x0018)\n";
+      return 1;
+   }
+
+   return 0;
+}
+
+void ClearList(FileList &list)
+{
+   FileList::iterator it;
+   for(it=list.begin();it!=list.end();++it)
+   {
+      delete (*it);
+   }
+   list.clear();
+}
+
+gdcm::File *WriteImage(gdcm::File *file,const std::string &fileName)
+{
+   // Create a 256x256x1 image 8 bits, unsigned 
+   std::ostringstream str;
+
+   // Set the image size
+   file->InsertValEntry("256",0x0028,0x0011); // Columns
+   file->InsertValEntry("256",0x0028,0x0010); // Rows
+
+   // Set the pixel type
+   file->InsertValEntry("8",0x0028,0x0100); // Bits Allocated
+   file->InsertValEntry("8",0x0028,0x0101); // Bits Stored
+   file->InsertValEntry("7",0x0028,0x0102); // High Bit
+
+   // Set the pixel representation
+   file->InsertValEntry("0",0x0028,0x0103); // Pixel Representation
+
+   // Set the samples per pixel
+   file->InsertValEntry("1",0x0028,0x0002); // Samples per Pixel
+
+   if( !file->IsReadable() )
+   {
+      std::cout << "Failed\n"
+                << "        Prepared image isn't readable\n";
+      return NULL;
+   }
+
+   size_t size = 256 * 256 * 1;
+   unsigned char *imageData = new unsigned char[size];
+
+// Write the image
+   gdcm::FileHelper *hlp = new gdcm::FileHelper(file);
+   hlp->SetImageData(imageData,size);
+   hlp->SetWriteTypeToDcmExplVR();
+   if( !hlp->Write(fileName) )
+   {
+      std::cout << "Failed\n"
+                << "        File in unwrittable\n";
+
+      delete hlp;
+      delete[] imageData;
+      return NULL;
+   }
+   delete[] imageData;
+   delete hlp;
+
+// Read the written image
+   gdcm::File *reread = new gdcm::File( fileName );
+   if( !reread->IsReadable() )
+   {
+     std::cerr << "Failed" << std::endl
+               << "        Could not reread image written:" << fileName << std::endl;
+     delete reread;
+     return NULL;
+   }
+
+   return reread;
+}
+
+int TestSequence(int argc, char *argv[])
+{
+   if (argc < 1) 
+   {
+      std::cerr << "usage: \n" 
+                << argv[0] << " (without parameters) " << std::endl 
+                << std::endl;
+      return 1;
+   }
+
+   std::cout << "   Description (Test::TestSequence): " << std::endl;
+   std::cout << "   Will test the creation of sequences of 4 images" << std::endl;
+   std::cout << "   with the following steps : "<< std::endl;
+   std::cout << "   step 1: create separed images without correspondance" << std::endl
+             << "           in UID for study and serie" << std::endl;
+   std::cout << "   step 2: create serie of image." << std::endl
+             << "           So the Serie and Study UID must be equal" << std::endl;
+   std::cout << "   step 3: create separed serie of image with same study" << std::endl
+             << "           So the Study UID must be equal" << std::endl;
+   std::cout << std::endl << std::endl;
+
+   gdcm::File *file;
+   gdcm::File *newFile;
+   FileList fileList;
+   int i;
+
+   std::cout<<"     step...";
+   std::string studyUID = gdcm::Util::CreateUniqueUID();
+   std::string serieUID = gdcm::Util::CreateUniqueUID();
+
+   // Step 1 : All files have different UID 
+   fileList.clear();
+   for(i = 0;i < 4;i++)
+   {
+      std::ostringstream fileName;
+      fileName << "FileSeq" << i << ".dcm";
+      file = new gdcm::File();
+
+      newFile = WriteImage(file,fileName.str());
+      if( !newFile )
+      {
+         delete file;
+         return 1;
+      }
+      else
+         fileList.push_back(newFile);
+
+      delete file;
+   }
+
+   if( CompareImages(fileList,false,false) )
+   {
+      ClearList(fileList);
+      return 1;
+   }
+   ClearList(fileList);
+
+   std::cout<<"1...";
+
+   // Step 2 : Same Serie & Study
+   fileList.clear();
+   for(i = 0;i < 4;i++)
+   {
+      std::ostringstream fileName;
+      fileName << "FileSeq" << i << ".dcm";
+      file = new gdcm::File();
+      file->SetValEntry(studyUID,0x0020,0x000d);
+      file->SetValEntry(serieUID,0x0020,0x000e);
+
+      newFile = WriteImage(file,fileName.str());
+      if( !newFile )
+      {
+         delete file;
+         return(1);
+      }
+      else
+         fileList.push_back(newFile);
+
+      delete file;
+   }
+
+   if( CompareImages(fileList,true,true) )
+   {
+      ClearList(fileList);
+      return 1;
+   }
+   ClearList(fileList);
+
+   std::cout<<"2...";
+
+   // Step 3 : Same Study
+   fileList.clear();
+   for(i = 0;i < 4;i++)
+   {
+      std::ostringstream fileName;
+      fileName << "FileSeq" << i << ".dcm";
+      file = new gdcm::File();
+      file->SetValEntry(studyUID,0x0020,0x000d);
+
+      newFile = WriteImage(file,fileName.str());
+      if( !newFile )
+      {
+         delete file;
+         return(1);
+      }
+      else
+         fileList.push_back(newFile);
+
+      delete file;
+   }
+
+   if( CompareImages(fileList,false,true) )
+   {
+      ClearList(fileList);
+      return 1;
+   }
+   ClearList(fileList);
+
+   std::cout<<"3...OK";
+
+   return 0;
+}
index 42f710a32e6e0b70d77a7e86ce482c1cc5df1b7f..531d9f0b3252bb1e3137cd66e9e6655fcfd74a5a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestWriteSimple.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/05 03:12:28 $
-  Version:   $Revision: 1.19 $
+  Date:      $Date: 2005/02/07 12:53:59 $
+  Version:   $Revision: 1.20 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -63,7 +63,14 @@ Image Images [] = {
    {256, 512, 1, 1, 16, 16, 0, 'a'},
    {256, 512, 1, 1, 16, 16, 0, 'e'},
    {256, 512, 1, 1, 16, 16, 0, 'i'},
-   {0,   0,   1, 1, 8,  8,  0, 'i'} // to find the end
+
+   {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'},
+   {0,   0,   1,  1, 8,  8, 0, 'i'} // to find the end
 };
 
 int WriteSimple(Image &img)
@@ -100,10 +107,10 @@ int WriteSimple(Image &img)
    /******************************************/
    // Super duper kludge !!
    if( img.componentSize == 16 )
-     {
-     // I guess by design user should know that...
-     fileToBuild->InsertBinEntry(0,0, 0x7fe0, 0x0010, "OW");
-     }
+   {
+      // I guess by design user should know that...
+      fileToBuild->InsertBinEntry(0,0, 0x7fe0, 0x0010, "OW");
+   }
    /******************************************/
    /******************************************/
    
@@ -216,8 +223,7 @@ int WriteSimple(Image &img)
    if( !reread->GetFile()->IsReadable() )
    {
      std::cerr << "Failed" << std::endl
-               << "Test::TestReadWriteReadCompare: Could not reread image "
-               << "written:" << fileName << std::endl;
+               << "Could not reread image written: " << fileName << std::endl;
      delete fileToBuild;
      delete file;
      delete reread;
index a0539c7f322e2499cc575362d27432810e709565..77b1058c973ad20b40e4fd7b1a69f28b7c50dc13 100644 (file)
@@ -39,3 +39,15 @@ while(val):
    val=file.GetNextEntry()
 val=None
 
+print "##############################################################"
+val=file.GetFirstEntry()
+while(val):
+   if(isinstance(val,gdcm.ValEntryPtr)):
+      print "Val %04d|%04d [%s] : %s" % (val.GetGroup(),val.GetElement(),
+                                         val.GetName(),val.GetValue())
+   else:
+      print "Bin %04d|%04d [%s] : %s" % (val.GetGroup(),val.GetElement(),
+                                         val.GetName(),val.GetValue())
+   val=file.GetNextEntry()
+val=None
+
index 8db56dbf5d5ea306242db6d4e455ca53d701432a..064eb84a6d4b23a92dcb301db86e3caa80d929c0 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/07 12:28:40 $
-  Version:   $Revision: 1.215 $
+  Date:      $Date: 2005/02/07 12:54:00 $
+  Version:   $Revision: 1.216 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -1449,7 +1449,7 @@ void File::InitializeDefaultFile()
    // Media Storage SOP Class UID (CT Image Storage)
    InsertValEntry("1.2.840.10008.5.1.4.1.1.2", 0x0002, 0x0002);
    // Media Storage SOP Instance UID
-   InsertValEntry(uidClass.c_str(),            0x0002, 0x0003);
+   InsertValEntry(uidMedia.c_str(),            0x0002, 0x0003);
    // Transfer Syntax UID (Explicit VR Little Endian)
    InsertValEntry("1.2.840.10008.1.2.1 ",      0x0002, 0x0010);
    // META Implementation Class UID