Program: gdcm
Module: $RCSfile: TestWriteSimple.cxx,v $
Language: C++
- Date: $Date: 2005/10/28 13:16:48 $
- Version: $Revision: 1.46 $
+ 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
#include "gdcmFile.h"
#include "gdcmFileHelper.h"
#include "gdcmDebug.h"
+#include "gdcmGlobal.h"
+#include "gdcmDictSet.h"
#include <iostream>
#include <sstream>
} Image;
Image Images [] = {
-
{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, 128, 1, 1, 8, 8, 0, 'i'},
- {256, 128, 1, 1, 8, 8, 0, 'i'},
- {256, 128, 1, 1, 8, 8, 0, 'a'},
- {128, 128, 1, 1, 8, 8, 0, 'a'},
{128, 256, 1, 1, 8, 8, 0, 'e'},
{128, 256, 1, 1, 8, 8, 0, 'i'},
{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'},
+ {128, 256, 1, 1, 16, 16, 0, 'a'},
{256, 128, 10, 1, 8, 8, 0, 'e'},
{256, 128, 10, 3, 8, 8, 0, 'e'},
int WriteSimple(Image &img)
{
+
+ std::cout << "======================= WriteSimple =========(begin of processing current image)" << std::endl;
std::ostringstream fileName;
fileName.str("");
fileName << "TestWriteSimple";
// 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;
// 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)
// 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...";
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
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();
}
// 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() )
{
}
// 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();
return 1;
}
- // Test the data's content
+ // Test the data content
if ( memcmp(imageData, imageDataWritten, size) !=0 )
{
std::cout << "Failed" << std::endl
return 1;
}
- std::cout << "OK" << std::endl;
-
fileH->Delete();
reread->Delete();
delete[] imageData;
-
return 0;
}
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;