--- /dev/null
+/*=========================================================================
+
+ 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;
+}
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
{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)
/******************************************/
// 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");
+ }
/******************************************/
/******************************************/
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;