From: regrain Date: Mon, 7 Feb 2005 12:53:58 +0000 (+0000) Subject: * Testing/TestSequence.cxx : add test for sequences of images... test that X-Git-Tag: Version1.0.bp~62 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=33ea6274972a853d1214fc5e6ea31309ec7e2ad8;p=gdcm.git * Testing/TestSequence.cxx : add test for sequences of images... test that we have the same serie or the same study UID -- BeNours --- diff --git a/ChangeLog b/ChangeLog index f035da73..52dceec6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-02-07 Benoit Regrain + * 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 * gdcmPython/gdcm.i : bug fix. Now string are correctly converted in python string type diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 5f53ece9..913593ce 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -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 index 00000000..838d5e70 --- /dev/null +++ b/Testing/TestSequence.cxx @@ -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 +#include +#include + +typedef std::list 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 instUID; + std::map mediaUID; + std::map serieUID; + std::map 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; +} diff --git a/Testing/TestWriteSimple.cxx b/Testing/TestWriteSimple.cxx index 42f710a3..531d9f0b 100644 --- a/Testing/TestWriteSimple.cxx +++ b/Testing/TestWriteSimple.cxx @@ -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; diff --git a/gdcmPython/demo/PrintFile.py.in b/gdcmPython/demo/PrintFile.py.in index a0539c7f..77b1058c 100644 --- a/gdcmPython/demo/PrintFile.py.in +++ b/gdcmPython/demo/PrintFile.py.in @@ -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 + diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 8db56dbf..064eb84a 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -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