From e721c5ac27a49a7e4b1aafe426681acb6b9d12bf Mon Sep 17 00:00:00 2001 From: jpr Date: Mon, 28 Jun 2004 15:06:33 +0000 Subject: [PATCH] Add the 'WriteRead' example --- Example/CMakeLists.txt | 3 ++ Example/WriteRead.cxx | 80 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 Example/WriteRead.cxx diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt index 0111b05a..449533c9 100644 --- a/Example/CMakeLists.txt +++ b/Example/CMakeLists.txt @@ -13,3 +13,6 @@ TARGET_LINK_LIBRARIES(WriteDicom gdcm) ADD_EXECUTABLE(PrintDocument PrintDocument.cxx) TARGET_LINK_LIBRARIES(PrintDocument gdcm) + +ADD_EXECUTABLE(WriteRead WriteRead.cxx) +TARGET_LINK_LIBRARIES(WriteRead gdcm) diff --git a/Example/WriteRead.cxx b/Example/WriteRead.cxx new file mode 100644 index 00000000..b45de305 --- /dev/null +++ b/Example/WriteRead.cxx @@ -0,0 +1,80 @@ +#include +#include "gdcm.h" +#include "gdcmHeader.h" +#include "gdcmDocument.h" + +#include + +int main(int argc, char* argv[]) +{ + std::string toto; + char zozo[200]; + + gdcmHeader* e1, *e2; + gdcmFile * f1, *f2; + + void* imageData, *imageData2; + int dataSize, dataSize2; + + if( argc < 2 ) + { + std::cerr << "Usage " << argv[0] << " image.dcm" << std::endl; + return 1; + } + + toto = argv[1]; + +// --------------------- we read the input image + + + e1 = new gdcmHeader(toto, false, true); + if (!e1->IsReadable()) { + std::cerr << "Sorry, " << toto <<" not a Readable DICOM / ACR File" + <GetImageData(); + dataSize = f1->GetImageDataSize(); + +// --------------------- we write it as an Explicit VR DICOM file + + sprintf(zozo, "temp.XDCM" ); + std::cout << "WriteDCM Explicit VR" << std::endl; + f1->WriteDcmExplVR(zozo); + +// --------------------- we read the written image + + e2 = new gdcmHeader(zozo, false, true); + if (!e2->IsReadable()) { + std::cerr << "Sorry, " << zozo << " not a Readable DICOM / ACR File" + <GetImageData(); + dataSize2 = f2->GetImageDataSize(); + +// --------------------- we compare the pixel areas + + if (dataSize != dataSize2) { + std::cout << " ----------------------------------------- " + << "Bad shot! Lengthes are different : " + << dataSize << " # " << dataSize2 + << " for file : " << toto << std::endl; + + return 1; + } + if (int res=memcmp(imageData,imageData2,dataSize) !=0) { + std::cout << " ----------------------------------------- " + << "Bad shot! Pixels are different : " + << " for file : " << toto << std::endl; + std::cout << "memcmp(imageData,imageData2,dataSize) = " << res << std::endl; + return 1; + } + + //If we reach here everythin is fine, return 0 then: + return 0; +} + -- 2.45.1