]> Creatis software - gdcm.git/commitdiff
Add the 'WriteRead' example
authorjpr <jpr>
Mon, 28 Jun 2004 15:06:33 +0000 (15:06 +0000)
committerjpr <jpr>
Mon, 28 Jun 2004 15:06:33 +0000 (15:06 +0000)
Example/CMakeLists.txt
Example/WriteRead.cxx [new file with mode: 0644]

index 0111b05aa8c51903593a0f41552b93d7d71959e3..449533c94b29e4851ec7d99dda92c81fa7a48d57 100644 (file)
@@ -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 (file)
index 0000000..b45de30
--- /dev/null
@@ -0,0 +1,80 @@
+#include <iostream>
+#include "gdcm.h"
+#include "gdcmHeader.h"
+#include "gdcmDocument.h"
+
+#include <stdio.h>
+
+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"
+                 <<std::endl;
+       return 0;
+   }
+   
+   f1 = new gdcmFile(e1);
+   imageData= f1->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"  
+                 <<std::endl;
+       return 0;
+   }
+   f2 = new gdcmFile(e2);
+   imageData2= f2->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;
+}
+