]> Creatis software - clitk.git/commitdiff
clitkDicomWave2Text tool added
authorGauthier Bouilhol <bouilhol@creatis.insa-lyon.fr>
Fri, 7 Oct 2011 12:26:33 +0000 (14:26 +0200)
committerGauthier Bouilhol <bouilhol@creatis.insa-lyon.fr>
Fri, 7 Oct 2011 12:26:33 +0000 (14:26 +0200)
tools/CMakeLists.txt
tools/clitkDicomWave2Text.cxx [new file with mode: 0644]
tools/clitkDicomWave2Text.ggo [new file with mode: 0644]
tools/clitkDicomWave2Text.h [new file with mode: 0644]

index f5a62b443880ceb3c3c4dc18575b5f73d3a4e710..925c1f86e0db1c4abd5609c6a72d42bff9ec64d9 100644 (file)
@@ -35,6 +35,11 @@ IF (CLITK_BUILD_TOOLS)
   TARGET_LINK_LIBRARIES(clitkDicom2Image clitkCommon ${ITK_LIBRARIES})
   SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkDicom2Image)
 
+  WRAP_GGO(clitkDicomWave2Text_GGO_C clitkDicomWave2Text.ggo)
+  ADD_EXECUTABLE(clitkDicomWave2Text clitkDicomWave2Text.cxx ${clitkDicomWave2Text_GGO_C})
+  TARGET_LINK_LIBRARIES(clitkDicomWave2Text clitkCommon ${ITK_LIBRARIES})
+  SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkDicomWave2Text)
+
   WRAP_GGO(clitkImageInfo_GGO_C clitkImageInfo.ggo)
   ADD_EXECUTABLE(clitkImageInfo clitkImageInfo.cxx ${clitkImageInfo_GGO_C})
   TARGET_LINK_LIBRARIES(clitkImageInfo clitkCommon ${ITK_LIBRARIES})
diff --git a/tools/clitkDicomWave2Text.cxx b/tools/clitkDicomWave2Text.cxx
new file mode 100644 (file)
index 0000000..2ceef2d
--- /dev/null
@@ -0,0 +1,104 @@
+#include "clitkDicomWave2Text.h"
+#include "clitkDicomWave2Text_ggo.h"
+
+//gdcm include
+#include "gdcmUtil.h"
+#include "gdcmFile.h"
+#include "gdcmBinEntry.h"
+#include "gdcmValEntry.h"
+#include "gdcmSeqEntry.h"
+#include "gdcmSQItem.h"
+#include "gdcmSerieHelper.h"
+
+#include <iostream>
+#include <fstream>
+
+//==========================================================================================================================
+
+int main(int argc, char * argv[]) {
+
+//-----------------------------------------------------------------------------
+// init command line
+GGO(clitkDicomWave2Text, args_info);
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------
+// opening dicom input file
+gdcm::File * mDCMFile = new gdcm::File();
+mDCMFile->SetFileName(args_info.InputFile_arg);
+mDCMFile->AddForceLoadElement(0x01e1,0x1018); //Load wave data no matter its size
+
+if (!mDCMFile->OpenFile ()) {
+       std::cerr << "Sorry, the file does not exist or does not appear to be a DICOM file. Abort." << std::endl;
+    exit(0);
+}
+mDCMFile->Load();
+std::cout << "File:   "<< args_info.InputFile_arg << "   loaded !"<< std::endl;
+
+
+//-----------------------------------------------------------------------
+// read data
+gdcm::DocEntrySet* item = mDCMFile;
+#define T short
+
+gdcm::BinEntry* entry = item->GetBinEntry(0x01e1,0x1018);
+DD(entry);
+T* buffer = reinterpret_cast<T*>(entry->GetBinArea());
+int length=item->GetEntryLength(0x01e1,0x1018)/sizeof(T);
+std::ofstream text_file(args_info.OutputFile_arg, std::ios::out | std::ios::trunc);
+if(text_file)
+{
+    std::string stat="";
+    text_file << "COMPLETE_WAVE" << '\t' << "MASK"       << '\t' << "AQUISITION_PROFIL" << '\t' << "END-INHALE" << '\t' << "END-EXHALE" << '\t' << "AQUISITION_WAVE" << '\t' << "WAVE_STATISTICS" << '\t' << "MASK"        << std::endl;
+    for (int i=0;i<length-76;i+=2)
+    {
+           if ( i < 74 )
+           {
+                   switch(i)
+                   {
+                     case 68 :
+                       stat="Total points";
+                       break;
+                     case 70 :
+                       stat="Sampling rate (Hz)";
+                       break;
+                     default :
+                       stat="";
+                       break;
+                   }
+                     
+                   if (buffer[i+75] == 0)
+                       text_file << buffer[i+74]    << '\t' << buffer[i+75] << '\t' << 0                   << '\t' << "  "         << '\t' << "  "         << '\t' << "  "              << '\t' << buffer[i]         << '\t' << buffer[i+1] << '\t' << stat << std::endl;
+                   if (buffer[i+75] == 16384)
+                       text_file << buffer[i+74]    << '\t' << buffer[i+75] << '\t' << 0                   << '\t' << buffer[i+74] << '\t' << "  "         << '\t' << "  "              << '\t' << buffer[i]         << '\t' << buffer[i+1] << '\t' << stat << std::endl;
+                   if (buffer[i+75] == 256)
+                       text_file << buffer[i+74]    << '\t' << buffer[i+75] << '\t' << 0                   << '\t' << "  "         << '\t' << buffer[i+74] << '\t' << "  "              << '\t' << buffer[i]         << '\t' << buffer[i+1] << '\t' << stat << std::endl;
+                   if (buffer[i+75] == -32768)
+                       text_file << buffer[i+74]    << '\t' << buffer[i+75] << '\t' << 1                   << '\t' << "  "         << '\t' << "  "         << '\t' << buffer[i+74]      << '\t' << buffer[i]         << '\t' << buffer[i+1] << '\t' << stat << std::endl;
+                   if (buffer[i+75] == -16384)
+                       text_file << buffer[i+74]    << '\t' << buffer[i+75] << '\t' << 1                   << '\t' << buffer[i+74] << '\t' << "  "         << '\t' << buffer[i+74]      << '\t' << buffer[i]         << '\t' << buffer[i+1] << '\t' << stat << std::endl;
+                   if (buffer[i+75] == -32512)
+                       text_file << buffer[i+74]    << '\t' << buffer[i+75] << '\t' << 1                   << '\t' << "  "         << '\t' << buffer[i+74] << '\t' << buffer[i+74]      << '\t' << buffer[i]         << '\t' << buffer[i+1] << '\t' << stat << std::endl;
+           }
+           else
+           {
+                   if (buffer[i+75] == 0)
+                       text_file << buffer[i+74]    << '\t' << buffer[i+75] << '\t' << 0                   << '\t' << "  "         << '\t' << "  "         << '\t' << "  "              << '\t' << "  "              << '\t' << "  "        << std::endl;
+                   if (buffer[i+75] == 16384)
+                       text_file << buffer[i+74]    << '\t' << buffer[i+75] << '\t' << 0                   << '\t' << buffer[i+74] << '\t' << "  "         << '\t' << "  "              << '\t' << "  "              << '\t' << "  "        << std::endl;
+                   if (buffer[i+75] == 256)
+                       text_file << buffer[i+74]    << '\t' << buffer[i+75] << '\t' << 0                   << '\t' << "  "         << '\t' << buffer[i+74] << '\t' << "  "              << '\t' << "  "              << '\t' << "  "        << std::endl;
+                   if (buffer[i+75] == -32768)
+                       text_file << buffer[i+74]    << '\t' << buffer[i+75] << '\t' << 1                   << '\t' << "  "         << '\t' << "  "         << '\t' << buffer[i+74]      << '\t' << "  "              << '\t' << "  "        << std::endl;
+                   if (buffer[i+75] == -16384)
+                       text_file << buffer[i+74]    << '\t' << buffer[i+75] << '\t' << 1                   << '\t' << buffer[i+74] << '\t' << "  "         << '\t' << buffer[i+74]      << '\t' << "  "              << '\t' << "  "        << std::endl;
+                   if (buffer[i+75] == -32512)
+                       text_file << buffer[i+74]    << '\t' << buffer[i+75] << '\t' << 1                   << '\t' << "  "         << '\t' << buffer[i+74] << '\t' << buffer[i+74]      << '\t' << "  "              << '\t' << "  "        << std::endl;
+           }
+    }
+    text_file.close();
+}
+else
+    std::cerr << "Error openning "<< args_info.OutputFile_arg << std::endl;
+       
+}
diff --git a/tools/clitkDicomWave2Text.ggo b/tools/clitkDicomWave2Text.ggo
new file mode 100644 (file)
index 0000000..26542a0
--- /dev/null
@@ -0,0 +1,8 @@
+# file DicomWave2Text
+package "DicomWave2Text"
+version "1.0"
+purpose "Extract data from a Dicom wave file to a text file"
+option "config"         -    "config file"                     string  no
+option "InputFile"      i    "Dicom inputfile name"                       string  no
+option "OutputFile"     o   "Text outputfile name"                       string  no
+option "Verbose"        v    "verbose"                         int  no
diff --git a/tools/clitkDicomWave2Text.h b/tools/clitkDicomWave2Text.h
new file mode 100644 (file)
index 0000000..fa49267
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef CLITKDICOMWAVE2TEXT_H
+#define CLITKDICOMWAVE2TEXT_H
+
+#include "clitkCommon.h"
+//gdcm include
+#include "gdcmUtil.h"
+#include "gdcmFile.h"
+#include "gdcmValEntry.h"
+#include "gdcmSeqEntry.h"
+#include "gdcmSQItem.h"
+#include "gdcmSerieHelper.h"
+
+
+namespace clitk {
+
+  //---------------------------------------------------------------------
+  class DicomWave2Text
+  {
+
+      public:
+      //constructor;
+      DicomWave2Text();
+      //destructor;
+      ~DicomWave2Text();
+
+  };
+  
+} // end namespace
+
+#endif