X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestWriteSimple.cxx;h=19b216bc1e901c5a116bcfcd7584bb821cda2da5;hb=819712afaad76d8be1e21c506507814c32f5ccfd;hp=7b3160f5ab8d6a7a7857841d4532c47000a6f597;hpb=6716d29ca667ace886c25bcaf083325fa57ca348;p=gdcm.git diff --git a/Testing/TestWriteSimple.cxx b/Testing/TestWriteSimple.cxx index 7b3160f5..19b216bc 100644 --- a/Testing/TestWriteSimple.cxx +++ b/Testing/TestWriteSimple.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestWriteSimple.cxx,v $ Language: C++ - Date: $Date: 2004/12/14 13:05:33 $ - Version: $Revision: 1.9 $ + Date: $Date: 2005/02/10 14:23:18 $ + Version: $Revision: 1.25 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -22,10 +22,12 @@ * The image content is a horizontal grayscale from * */ -#include "gdcmHeader.h" #include "gdcmFile.h" +#include "gdcmFileHelper.h" +#include "gdcmDebug.h" #include +#include typedef struct { @@ -61,7 +63,40 @@ 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'}, + + {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'}, + {0, 0, 1, 1, 8, 8, 0, 'i'} // to find the end }; int WriteSimple(Image &img) @@ -70,54 +105,54 @@ int WriteSimple(Image &img) // Step 1 : Create the header of the image std::cout << " 1..."; - gdcm::Header *header = new gdcm::Header(); + gdcm::File *fileToBuild = new gdcm::File(); std::ostringstream str; // Set the image size str.str(""); str << img.sizeX; - header->ReplaceOrCreateByNumber(str.str(),0x0028,0x0011); // Columns + fileToBuild->InsertValEntry(str.str(),0x0028,0x0011); // Columns str.str(""); str << img.sizeY; - header->ReplaceOrCreateByNumber(str.str(),0x0028,0x0010); // Rows + fileToBuild->InsertValEntry(str.str(),0x0028,0x0010); // Rows if(img.sizeZ>1) { str.str(""); str << img.sizeZ; - header->ReplaceOrCreateByNumber(str.str(),0x0028,0x0008); // Number of Frames + fileToBuild->InsertValEntry(str.str(),0x0028,0x0008); // Number of Frames } // Set the pixel type str.str(""); str << img.componentSize; - header->ReplaceOrCreateByNumber(str.str(),0x0028,0x0100); // Bits Allocated + fileToBuild->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated str.str(""); str << img.componentUse; - header->ReplaceOrCreateByNumber(str.str(),0x0028,0x0101); // Bits Stored + fileToBuild->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored str.str(""); str << img.componentSize - 1; - header->ReplaceOrCreateByNumber(str.str(),0x0028,0x0102); // High Bit + fileToBuild->InsertValEntry(str.str(),0x0028,0x0102); // High Bit // Set the pixel representation str.str(""); str << img.sign; - header->ReplaceOrCreateByNumber(str.str(),0x0028,0x0103); // Pixel Representation + fileToBuild->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation // Set the samples per pixel str.str(""); str << img.components; - header->ReplaceOrCreateByNumber(str.str(),0x0028,0x0002); // Samples per Pixel + fileToBuild->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel - if( !header->IsReadable() ) + if( !fileToBuild->IsReadable() ) { std::cout << "Failed\n" << " Prepared image isn't readable\n"; - delete header; + delete fileToBuild; return 1; } @@ -131,7 +166,7 @@ int WriteSimple(Image &img) * img.components * img.componentSize / 8; unsigned char *imageData = new unsigned char[size]; - // FIXME : find a best heuristic to create the image + // FIXME : find a better heuristic to create the image unsigned char *tmp = imageData; for(int k=0;kSetImageData(imageData,size); // Step 4 : Set the writting mode and write the image @@ -180,7 +215,7 @@ int WriteSimple(Image &img) << " Write mode '"<GetHeader()->IsReadable() ) + gdcm::FileHelper *reread = new gdcm::FileHelper( fileName ); + if( !reread->GetFile()->IsReadable() ) { - std::cerr << "Failed" << std::endl - << "Test::TestReadWriteReadCompare: Could not reread image " - << "written:" << fileName << std::endl; - delete header; - delete file; - delete reread; - return 1; + std::cerr << "Failed" << std::endl + << "Could not reread image written: " << fileName << std::endl; + delete fileToBuild; + delete file; + delete reread; + delete[] imageData; + return 1; } // Step 6 : Compare to the written image std::cout << "6..."; size_t dataSizeWritten = reread->GetImageDataSize(); - uint8_t* imageDataWritten = reread->GetImageData(); + uint8_t *imageDataWritten = reread->GetImageData(); // Test the image size - if (header->GetXSize() != reread->GetHeader()->GetXSize() || - header->GetYSize() != reread->GetHeader()->GetYSize() || - header->GetZSize() != reread->GetHeader()->GetZSize()) + if (fileToBuild->GetXSize() != reread->GetFile()->GetXSize() || + fileToBuild->GetYSize() != reread->GetFile()->GetYSize() || + fileToBuild->GetZSize() != reread->GetFile()->GetZSize()) { std::cout << "Failed" << std::endl << " X Size differs: " - << "X: " << header->GetXSize() << " # " - << reread->GetHeader()->GetXSize() << " | " - << "Y: " << header->GetYSize() << " # " - << reread->GetHeader()->GetYSize() << " | " - << "Z: " << header->GetZSize() << " # " - << reread->GetHeader()->GetZSize() << std::endl; - delete header; + << "X: " << fileToBuild->GetXSize() << " # " + << reread->GetFile()->GetXSize() << " | " + << "Y: " << fileToBuild->GetYSize() << " # " + << reread->GetFile()->GetYSize() << " | " + << "Z: " << fileToBuild->GetZSize() << " # " + << reread->GetFile()->GetZSize() << std::endl; + delete fileToBuild; delete file; delete reread; delete[] imageData; @@ -242,7 +277,7 @@ int WriteSimple(Image &img) std::cout << "Failed" << std::endl << " Pixel areas lengths differ: " << size << " # " << dataSizeWritten << std::endl; - delete header; + delete fileToBuild; delete file; delete reread; delete[] imageData; @@ -251,12 +286,11 @@ int WriteSimple(Image &img) } // Test the data's content - if (int res = memcmp(imageData, imageDataWritten, size) !=0) + if ( memcmp(imageData, imageDataWritten, size) !=0 ) { - (void)res; std::cout << "Failed" << std::endl << " Pixel differ (as expanded in memory)." << std::endl; - delete header; + delete fileToBuild; delete file; delete reread; delete[] imageData; @@ -266,7 +300,7 @@ int WriteSimple(Image &img) std::cout << "OK" << std::endl; - delete header; + delete fileToBuild; delete file; delete reread; delete[] imageData; @@ -274,7 +308,7 @@ int WriteSimple(Image &img) return 0; } -int TestWriteSimple(int argc, char* argv[]) +int TestWriteSimple(int argc, char *argv[]) { if (argc < 1) {