]> Creatis software - gdcm.git/commitdiff
ENH: Add Example stuff with real main:
authormalaterre <malaterre>
Fri, 30 Apr 2004 19:36:39 +0000 (19:36 +0000)
committermalaterre <malaterre>
Fri, 30 Apr 2004 19:36:39 +0000 (19:36 +0000)
1. Should be easier to use
2. This is a real example on how to read + write a dicom image, thus make sense to have it

CMakeLists.txt
Example/CMakeLists.txt [new file with mode: 0644]
Example/WriteDicom.cxx [new file with mode: 0644]

index 6889cca46931cf24c0cdc7bdbaf4ed0e2dd71a27..9bf969e28f4cccc05e138e5d07913a4000a179b9 100644 (file)
@@ -34,6 +34,7 @@ SUBDIRS(
   src\r
   Dicts\r
   Test\r
+  Example\r
 )\r
 \r
 #-----------------------------------------------------------------------------\r
diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt
new file mode 100644 (file)
index 0000000..59525c6
--- /dev/null
@@ -0,0 +1,12 @@
+SET(EXAMPLE_SOURCES
+  WriteDicom.cxx
+)
+
+# include stuff
+INCLUDE_DIRECTORIES(
+  ${GDCM_SOURCE_DIR}/src/
+  ${GDCM_BINARY_DIR}/
+)
+
+ADD_EXECUTABLE(WriteDicom WriteDicom.cxx)
+TARGET_LINK_LIBRARIES(WriteDicom gdcm)
diff --git a/Example/WriteDicom.cxx b/Example/WriteDicom.cxx
new file mode 100644 (file)
index 0000000..0323863
--- /dev/null
@@ -0,0 +1,67 @@
+#include "gdcmHeader.h"
+#include "gdcmFile.h"
+
+// Writting of a DICOM file based on a correct dicom header
+// and data pixel of another image
+
+int main(int argc, char* argv[])
+{
+
+  if (argc < 3) 
+    {
+    std::cerr << "Usage :" << std::endl << argv[0] << 
+      " HeaderFileName DataFileName" << std::endl;
+    return 0;  
+    }
+
+  const char *first = argv[1];
+  gdcmFile *f1 = new gdcmFile( first );
+       
+  const char *second = argv[2];
+  gdcmFile *f2 = new gdcmFile( second );
+       
+       // f1->PrintPubElVal();
+       
+  // We assume that DICOM fields of second file actually exists :
+       
+  std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008);
+  if(nbFrames != "gdcm::Unfound") {
+      f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
+  }
+         
+  f1->GetHeader()->ReplaceOrCreateByNumber(
+    f2->GetHeader()->GetEntryByNumber(0x0028, 0x0010), 0x0028, 0x0010); // nbLig
+  f1->GetHeader()->ReplaceOrCreateByNumber( 
+    f2->GetHeader()->GetEntryByNumber(0x0028, 0x0011), 0x0028, 0x0011); // nbCol
+
+  // Some other tags should be updated:
+       
+       // TODO : add a default value
+  // TODO : a function which take as input a list of tuple (gr, el)
+  //        and that does the job
+
+  int dataSize    = f2->GetImageDataSize();
+  void *imageData = f2->GetImageData();
+
+  std::cout << "dataSize :" << dataSize << std::endl;
+                       
+  // TODO : Shouldn't we merge those two functions ?
+  f1->SetImageData( imageData, dataSize);
+  f1->GetHeader()->SetImageDataSize( dataSize );
+       
+  f1->GetHeader()->PrintEntry();
+       
+  std::string s0  = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0000);
+  std::string s10 = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0010);
+
+  std::cout << "lgr 7fe0, 0000 " << s0  << std::endl;
+  std::cout << "lgr 7fe0, 0010 " << s10 << std::endl;  
+
+  std::cout << "WriteDCM" << std::endl;
+
+  f1->WriteDcmExplVR("WriteDicom.dcm");
+  //f1->WriteDcmImplVR(resultat);
+  //f1->WriteAcr(resultat);
+
+  return 0;
+}