X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestWriteSimple.cxx;h=f349bcee1de3cd7ac88f8dc4dcafd0aa3d651b2d;hb=e30768c5d2c9057ca9be9bdb2d12ff1eb1384539;hp=fe79c983ddf3cf7c632ece400997683e00feb15a;hpb=55549bad693bd883a36acace3a3bbd265f95dd13;p=gdcm.git diff --git a/Testing/TestWriteSimple.cxx b/Testing/TestWriteSimple.cxx index fe79c983..f349bcee 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/07 18:43:38 $ - Version: $Revision: 1.21 $ + Date: $Date: 2005/06/03 10:15:19 $ + Version: $Revision: 1.30 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -64,18 +64,46 @@ Image Images [] = { {256, 512, 1, 1, 16, 16, 0, 'e'}, {256, 512, 1, 1, 16, 16, 0, 'i'}, - {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 + {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) { - std::string fileName = "TestWriteSimple.dcm"; + std::ostringstream fileName; + fileName.str(""); + fileName << "TestWriteSimple"; // Step 1 : Create the header of the image std::cout << " 1..."; @@ -86,7 +114,6 @@ int WriteSimple(Image &img) str.str(""); str << img.sizeX; fileToBuild->InsertValEntry(str.str(),0x0028,0x0011); // Columns - str.str(""); str << img.sizeY; fileToBuild->InsertValEntry(str.str(),0x0028,0x0010); // Rows @@ -98,29 +125,19 @@ int WriteSimple(Image &img) fileToBuild->InsertValEntry(str.str(),0x0028,0x0008); // Number of Frames } + fileName << "-" << img.sizeX << "-" << img.sizeY << "-" << img.sizeZ; + // Set the pixel type str.str(""); str << img.componentSize; fileToBuild->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated - /******************************************/ - /******************************************/ - // Super duper kludge !! - if( img.componentSize == 16 ) - { - // I guess by design user should know that... - fileToBuild->InsertBinEntry(0,0, 0x7fe0, 0x0010, "OW"); - } - /******************************************/ - /******************************************/ - - str.str(""); str << img.componentUse; fileToBuild->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored str.str(""); - str << img.componentSize - 1; + str << ( img.componentSize - 1 ); fileToBuild->InsertValEntry(str.str(),0x0028,0x0102); // High Bit // Set the pixel representation @@ -128,19 +145,28 @@ int WriteSimple(Image &img) str << img.sign; fileToBuild->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation + fileName << "-" << img.componentSize; + if(img.sign == 0) + fileName << "U"; + else + fileName << "S"; + + switch (img.writeMode) + { + case 'a' : + fileName << ".ACR"; break; + case 'e' : + fileName << ".EXPL"; break; + case 'i' : + fileName << ".IMPL"; break; +} + // Set the samples per pixel str.str(""); str << img.components; fileToBuild->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel - if( !fileToBuild->IsReadable() ) - { - std::cout << "Failed\n" - << " Prepared image isn't readable\n"; - delete fileToBuild; - return 1; - } // Step 2 : Create the output image std::cout << "2..."; @@ -152,7 +178,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;k8 ) { - *(tmp+1) = j/256; + *(tmp+1) = (unsigned char)(j/256); } - tmp += img.components/8; + tmp += img.componentSize/8; } } } @@ -175,43 +201,43 @@ int WriteSimple(Image &img) // Step 3 : Create the file of the image std::cout << "3..."; - gdcm::FileHelper *file = new gdcm::FileHelper(fileToBuild); - file->SetImageData(imageData,size); + gdcm::FileHelper *fileH = new gdcm::FileHelper(fileToBuild); + fileH->SetImageData(imageData,size); // Step 4 : Set the writting mode and write the image std::cout << "4..."; - file->SetWriteModeToRaw(); + fileH->SetWriteModeToRaw(); switch (img.writeMode) { case 'a' : // Write an ACR file - file->SetWriteTypeToAcr(); + fileH->SetWriteTypeToAcr(); break; case 'e' : // Write a DICOM Explicit VR file - file->SetWriteTypeToDcmExplVR(); + fileH->SetWriteTypeToDcmExplVR(); break; case 'i' : // Write a DICOM Implicit VR file - file->SetWriteTypeToDcmImplVR(); + fileH->SetWriteTypeToDcmImplVR(); break; default : std::cout << "Failed\n" << " Write mode '"<Write(fileName) ) + if( !fileH->Write(fileName.str()) ) { std::cout << "Failed\n" - << "File in unwrittable\n"; + << " File in unwrittable\n"; - delete file; + delete fileH; delete fileToBuild; delete[] imageData; return 1; @@ -219,13 +245,13 @@ int WriteSimple(Image &img) // Step 5 : Read the written image std::cout << "5..."; - gdcm::FileHelper *reread = new gdcm::FileHelper( fileName ); + gdcm::FileHelper *reread = new gdcm::FileHelper( fileName.str() ); if( !reread->GetFile()->IsReadable() ) { std::cerr << "Failed" << std::endl - << "Could not reread image written: " << fileName << std::endl; + << "Could not read written image : " << fileName << std::endl; delete fileToBuild; - delete file; + delete fileH; delete reread; delete[] imageData; return 1; @@ -236,6 +262,21 @@ int WriteSimple(Image &img) size_t dataSizeWritten = reread->GetImageDataSize(); uint8_t *imageDataWritten = reread->GetImageData(); + // Test the image write mode + if (reread->GetFile()->GetFileType() != fileH->GetWriteType()) + { + std::cout << "Failed" << std::endl + << " File type differ: " + << fileH->GetWriteType() << " # " + << reread->GetFile()->GetFileType() << std::endl; + delete fileToBuild; + delete fileH; + delete reread; + delete[] imageData; + + return 1; + } + // Test the image size if (fileToBuild->GetXSize() != reread->GetFile()->GetXSize() || fileToBuild->GetYSize() != reread->GetFile()->GetYSize() || @@ -250,7 +291,7 @@ int WriteSimple(Image &img) << "Z: " << fileToBuild->GetZSize() << " # " << reread->GetFile()->GetZSize() << std::endl; delete fileToBuild; - delete file; + delete fileH; delete reread; delete[] imageData; @@ -264,7 +305,7 @@ int WriteSimple(Image &img) << " Pixel areas lengths differ: " << size << " # " << dataSizeWritten << std::endl; delete fileToBuild; - delete file; + delete fileH; delete reread; delete[] imageData; @@ -272,13 +313,12 @@ 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 fileToBuild; - delete file; + delete fileH; delete reread; delete[] imageData; @@ -288,7 +328,7 @@ int WriteSimple(Image &img) std::cout << "OK" << std::endl; delete fileToBuild; - delete file; + delete fileH; delete reread; delete[] imageData; @@ -305,11 +345,14 @@ int TestWriteSimple(int argc, char *argv[]) return 1; } + gdcm::Debug::DebugOn(); + int ret=0; int i=0; while( Images[i].sizeX>0 && Images[i].sizeY>0 ) { - ret += WriteSimple(Images[i]); + std::cout << "Test n :" << i; + ret += WriteSimple(Images[i] ); i++; }