]> Creatis software - gdcm.git/commitdiff
* ENH : add callback and methods to get the progression of dicomDir
authorregrain <regrain>
Tue, 10 Feb 2004 15:37:24 +0000 (15:37 +0000)
committerregrain <regrain>
Tue, 10 Feb 2004 15:37:24 +0000 (15:37 +0000)
       directory parsing
     -- BeNours

ChangeLog
gdcmPython/gdcm.i
gdcmPython/win32/_vtkGdcm.dsp
gdcmPython/win32/gdcmpyembedded.dsp
src/gdcmDicomDir.cxx
src/gdcmDicomDir.h
src/gdcmMeta.cxx
src/win32/gdcmdll.dsp
vtk/win32/vtkgdcm.dsp

index 6d73c866ea2b0929c2f3a80e372467f0c7e6bb4f..05fe4f15903baf6c1f421eb39c810c246b9d7f5a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 2004-02-10 Benoit Regrain
      * FIX : bug fix in the gdcmDirList for the recursivity in directories
      * FIX : in gdcmDicomDir when the directory is empty
+     * ENH : add callback and methods to get the progression of dicomDir
+       directory parsing
 
 2004-02-06 Jean-Pierre Roux
      * ENH : - now gdcmDicomDir::CreateDicomDir() returns also the meta elements
index 129a6f4253c81eac478c5c2fe1e346d92bfc7fe3..71b026def4a7056ae9a1a963fc3a89a3bf4fe704 100644 (file)
@@ -28,6 +28,41 @@ void EatLeadingAndTrailingSpaces(string & s) {
        while ( s.length() && (s[s.length()-1] == ' ') )
                s.erase(s.length()-1, 1);
 }
+
+void vtkPythonVoidFunc(void *arg)
+{
+  PyObject *arglist, *result;
+  PyObject *func = (PyObject *)arg;
+
+  arglist = Py_BuildValue("()");
+
+  result = PyEval_CallObject(func, arglist);
+  Py_DECREF(arglist);
+
+  if (result)
+    {
+    Py_XDECREF(result);
+    }
+  else
+    {
+    if (PyErr_ExceptionMatches(PyExc_KeyboardInterrupt))
+      {
+      cerr << "Caught a Ctrl-C within python, exiting program.\n";
+      Py_Exit(1);
+      }
+    PyErr_Print();
+    }
+}
+
+void vtkPythonVoidFuncArgDelete(void *arg)
+{
+  PyObject *func = (PyObject *)arg;
+  if (func)
+    {
+    Py_DECREF(func);
+    }
+}
+
 %}
 typedef  unsigned short guint16;
 typedef  unsigned int guint32;
@@ -179,6 +214,13 @@ extern gdcmGlobal gdcmGlob;
 }
 
 ////////////////////////////////////////////////////////////////////////////
+// Deals with function returning a C++ string.
+%typemap(python, in) (gdcmMethod *method,void *arg) {
+    Py_INCREF($input);
+    $1=vtkPythonVoidFunc;
+       $2=$input;
+}
+
 
 ////////////////////////////////////////////////////////////////////////////
 // Deals with function returning a C++ string.
index 5b67033327b90a49844f1c363b3f5b2579d76762..9f01c3f568dfe6ce95ae6e44662fed8e93b6e35e 100644 (file)
@@ -118,6 +118,10 @@ SOURCE=..\..\src\gdcmJpeg2000.cxx
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\..\src\gdcmMeta.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\..\src\gdcmObject.cxx\r
 # End Source File\r
 # Begin Source File\r
@@ -192,7 +196,7 @@ InputPath=.\init.h
 \r
 SOURCE=..\..\vtk\vtkGdcmReader.h\r
 # Begin Custom Build - Performing Custom Build Step on $(VTKPATH)\bin\vtkwrappython "$(InputDir)\$(InputName).h" $(VTKPATH)\Examples\Build\vtkMy\Wrapping\hints 1  $(ProjDir)\..\$(InputName)Python.cxx\r
-InputDir=\Projects\gdcm\VTK\r
+InputDir=\Projects\gdcm\vtk\r
 ProjDir=.\r
 InputPath=..\..\vtk\vtkGdcmReader.h\r
 InputName=vtkGdcmReader\r
index 5895fb2cda6c09c73ab637b047e486f8da8ab76c..3ed70645beea3b8ca1426545fef0bac7e57e6f53 100644 (file)
@@ -53,7 +53,7 @@ LINK32=link.exe
 # Begin Special Build Tool\r
 ProjDir=.\r
 SOURCE="$(InputPath)"\r
-PostBuild_Cmds=move                     $(ProjDir)\gdcm.py                     $(ProjDir)\..\ \r
+PostBuild_Cmds=move                      $(ProjDir)\gdcm.py                      $(ProjDir)\..\ \r
 # End Special Build Tool\r
 # Begin Target\r
 \r
@@ -140,6 +140,10 @@ SOURCE=..\..\src\gdcmJpeg2000.cxx
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\..\src\gdcmMeta.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\..\src\gdcmObject.cxx\r
 # End Source File\r
 # Begin Source File\r
index d4d6ad4fc7482c662bf10047233896b4be2bf02a..11223cd24ee410024ea2a1a4eb469dc2f9317102 100644 (file)
 
 #include <sys/types.h>
 #include <errno.h>
+
+void StartMethod(void * = NULL)
+{
+   std::cout<<"Start parsing"<<std::endl;
+}
+
+void EndMethod(void * = NULL)
+{
+   std::cout<<"End parsing"<<std::endl;
+}
+
 //-----------------------------------------------------------------------------
 //  For full DICOMDIR description, see:
 //  PS 3.3-2003, pages 731-750
@@ -27,6 +38,16 @@ gdcmDicomDir::gdcmDicomDir(const char *FileName, bool parseDir,
                            bool exception_on_error):
    gdcmParser(FileName,exception_on_error,true)
 {
+   startMethod=StartMethod;
+   progressMethod=NULL;
+   endMethod=EndMethod;
+   startArg=NULL;
+   progressArg=NULL;
+   endArg=NULL;
+
+   progress=NULL;
+   abort=false;
+
    metaElems=NULL;
 
    if( GetListEntry().begin()==GetListEntry().end() ) 
@@ -81,6 +102,37 @@ void gdcmDicomDir::Print(std::ostream &os)
 
 //-----------------------------------------------------------------------------
 // Public
+/*
+ * \ingroup gdcmDicomDir
+ * \brief  This predicate, based on hopefully reasonable heuristics,
+ *         decides whether or not the current gdcmParser was properly parsed
+ *         and contains the mandatory information for being considered as
+ *         a well formed and usable DicomDir.
+ * @return true when gdcmParser is the one of a reasonable DicomDir,
+ *         false otherwise. 
+ */
+bool gdcmDicomDir::IsReadable(void)
+{
+   if(!gdcmParser::IsReadable())
+      return(false);
+   if(!metaElems)
+      return(false);
+   if(patients.size()<=0)
+      return(false);
+
+   return(true);
+}
+
+/*
+ * \ingroup gdcmDicomDir
+ * \brief  fills whole the structure
+ */
+void gdcmDicomDir::ParseDirectory(void)
+{
+   NewDicomDir(GetPath());
+   CreateDicomDir();
+}
+
 /**
  * \ingroup gdcmDicomDir
  * \brief   writes on disc a DICOMDIR
@@ -113,16 +165,6 @@ bool gdcmDicomDir::Write(std::string fileName)
    return true;
 }
 
-/*
- * \ingroup gdcmDicomDir
- * \brief  fills whole the structure
- */
-void gdcmDicomDir::ParseDirectory(void)
-{
-   NewDicomDir(GetPath());
-   CreateDicomDir();
-}
-
 //-----------------------------------------------------------------------------
 // Protected
 /*
@@ -132,7 +174,10 @@ void gdcmDicomDir::ParseDirectory(void)
  */
 void gdcmDicomDir::NewDicomDir(std::string path)
 {
+   CallStartMethod();
+
    gdcmDirList fileList(path,1);
+   unsigned int count=0;
    ListHeader list;
    gdcmHeader *header;
 
@@ -142,17 +187,26 @@ void gdcmDicomDir::NewDicomDir(std::string path)
    for(gdcmDirList::iterator it=fileList.begin(); 
        it!=fileList.end(); ++it) 
    {
+      progress=(float)(count+1)/(float)fileList.size();
+      CallProgressMethod();
+      if(abort)
+         break;
+
       header=new gdcmHeader(it->c_str());
       if(header->IsReadable())
          list.push_back(header);
       else
          delete header;
+
+      count++;
    }
 
    std::sort(list.begin(),list.end(),gdcmDicomDir::HeaderLessThan);
 
    std::string tmp=fileList.GetDirName();
    SetElements(tmp,list);
+
+   CallEndMethod();
 }
 
 /*
@@ -174,6 +228,27 @@ std::string gdcmDicomDir::GetPath(void)
    return(path);
 }
 
+void gdcmDicomDir::CallStartMethod(void)
+{
+   progress=0.0f;
+   abort=false;
+   if(startMethod)
+      startMethod(startArg);
+}
+
+void gdcmDicomDir::CallProgressMethod(void)
+{
+   if(progressMethod)
+      progressMethod(progressArg);
+}
+
+void gdcmDicomDir::CallEndMethod(void)
+{
+   progress=1.0f;
+   if(endMethod)
+      endMethod(endArg);
+}
+
 //-----------------------------------------------------------------------------
 // Private
 /*
index e54995e3445a1d927dfbfd382e7d40bd13853e2e..ae675fb00ab6931b23f6955bc9a33c004f749435 100644 (file)
@@ -16,6 +16,7 @@
 typedef std::list<gdcmPatient *>   ListPatient;
 typedef std::vector<gdcmHeader *>  ListHeader;
 
+typedef GDCM_EXPORT void( gdcmMethod)(void * =NULL);
 //-----------------------------------------------------------------------------
 /*
  * \defgroup gdcmDicomDir
@@ -35,12 +36,25 @@ public:
    void SetPrintLevel(int level) { printLevel = level; };
    virtual void Print(std::ostream &os = std::cout);
 
+// Informations contained in the parser
+   virtual bool IsReadable(void);
    inline gdcmMeta   *GetMeta()      {return metaElems;};
    inline ListPatient &GetPatients() {return patients;};
 
+// Parsing
+   void ParseDirectory(void);
+
+   inline void SetStartMethod(gdcmMethod *method,void *arg=NULL)    {startMethod=method;startArg=arg;};
+   inline void SetProgressMethod(gdcmMethod *method,void *arg=NULL) {progressMethod=method;progressArg=arg;};
+   inline void SetEndMethod(gdcmMethod *method,void *arg=NULL)      {endMethod=method;endArg=arg;};
+
+   inline float GetProgress(void)                   {return(progress);};
+
+   inline void AbortProgress(void)                  {abort=true;};
+   inline bool IsAborted(void)                      {return(abort);};
+
 // Write
    bool Write(std::string fileName);
-   void ParseDirectory(void);
 
 // Types
    typedef enum
@@ -57,6 +71,10 @@ protected:
    void NewDicomDir(std::string path);
    std::string GetPath(void);
 
+   void CallStartMethod(void);
+   void CallProgressMethod(void);
+   void CallEndMethod(void);
+
 private:
    void CreateDicomDir(void);
    void AddObjectToEnd(gdcmDicomDirType type,
@@ -74,6 +92,16 @@ private:
 
    gdcmMeta *metaElems;
    ListPatient patients;
+
+   gdcmMethod *startMethod;
+   gdcmMethod *progressMethod;
+   gdcmMethod *endMethod;
+   void *startArg;
+   void *progressArg;
+   void *endArg;
+
+   float progress;
+   bool abort;
 };
 
 //-----------------------------------------------------------------------------
index aedc2a435a54c25f888ba54816d7b744f793e6c2..a9a0aa0da7f6707a001de31fe1d031ce4ab4bb48 100644 (file)
@@ -32,7 +32,7 @@ gdcmMeta::~gdcmMeta()
  */ 
 void gdcmMeta::Print(std::ostream &os)
 {
-   os<<"META :"<<std::endl;
+   os<<"META"<<std::endl;
    gdcmObject::Print(os);
 }
 
index 27dd687677f629c4412104c45e05a5c9dc299797..a1bff1e23d810ea7f0ecfefc209f040385d3647c 100644 (file)
@@ -58,7 +58,7 @@ LINK32=link.exe
 # Begin Special Build Tool\r
 SOURCE="$(InputPath)"\r
 PostBuild_Desc=Copy for test\r
-PostBuild_Cmds=copy                     ..\..\lib\gdcmdll.dll                     ..\..\gdcmPython\                    copy                     ..\..\lib\gdcmdll.dll                     ..\..\test\                  copy                  Release\gdcmdll.lib                  ..\..\lib\ \r
+PostBuild_Cmds=copy                      ..\..\lib\gdcmdll.dll                      ..\..\gdcmPython\                          copy                      ..\..\lib\gdcmdll.dll                      ..\..\test\                        copy                   Release\gdcmdll.lib                   ..\..\lib\ \r
 # End Special Build Tool\r
 \r
 !ELSEIF  "$(CFG)" == "gdcmdll - Win32 Debug"\r
@@ -90,7 +90,7 @@ LINK32=link.exe
 # Begin Special Build Tool\r
 SOURCE="$(InputPath)"\r
 PostBuild_Desc=Copy for test\r
-PostBuild_Cmds=copy                     ..\..\lib\gdcmdll.dll                     ..\..\gdcmPython\                    copy                     ..\..\lib\gdcmdll.dll                     ..\..\test\                  copy                  Debug\gdcmdll.lib                  ..\..\lib\ \r
+PostBuild_Cmds=copy                      ..\..\lib\gdcmdll.dll                      ..\..\gdcmPython\                          copy                      ..\..\lib\gdcmdll.dll                      ..\..\test\                        copy                   Debug\gdcmdll.lib                   ..\..\lib\ \r
 # End Special Build Tool\r
 \r
 !ENDIF \r
@@ -164,6 +164,10 @@ SOURCE=..\gdcmJpeg2000.cxx
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\gdcmMeta.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\gdcmObject.cxx\r
 # End Source File\r
 # Begin Source File\r
@@ -264,6 +268,10 @@ SOURCE=..\gdcmImage.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\gdcmMeta.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\gdcmObject.h\r
 # End Source File\r
 # Begin Source File\r
index 24e3a42b053cb3e740ff6388718df4278803a4d5..e6866198c0b095e56549a3e8336483919b207f6c 100644 (file)
@@ -140,6 +140,10 @@ SOURCE=..\..\src\gdcmHeaderHelper.cxx
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\..\src\gdcmImage.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\..\src\gdcmJpeg.cxx\r
 # End Source File\r
 # Begin Source File\r
@@ -152,6 +156,14 @@ SOURCE=..\..\src\gdcmJpeg2000.cxx
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\..\src\gdcmMeta.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\src\gdcmObject.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\..\src\gdcmParsePixels.cxx\r
 # End Source File\r
 # Begin Source File\r
@@ -160,10 +172,22 @@ SOURCE=..\..\src\gdcmParser.cxx
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\..\src\gdcmPatient.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\..\src\gdcmRLE.cxx\r
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\..\src\gdcmSerie.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\src\gdcmStudy.cxx\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\..\src\gdcmTS.cxx\r
 # End Source File\r
 # Begin Source File\r