From: regrain Date: Tue, 10 Feb 2004 15:37:24 +0000 (+0000) Subject: * ENH : add callback and methods to get the progression of dicomDir X-Git-Tag: Version0.5.bp~312 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=a919b2ba053a046eb268658ba81ad1bb1ddcd686;p=gdcm.git * ENH : add callback and methods to get the progression of dicomDir directory parsing -- BeNours --- diff --git a/ChangeLog b/ChangeLog index 6d73c866..05fe4f15 100644 --- 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 diff --git a/gdcmPython/gdcm.i b/gdcmPython/gdcm.i index 129a6f42..71b026de 100644 --- a/gdcmPython/gdcm.i +++ b/gdcmPython/gdcm.i @@ -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. diff --git a/gdcmPython/win32/_vtkGdcm.dsp b/gdcmPython/win32/_vtkGdcm.dsp index 5b670333..9f01c3f5 100644 --- a/gdcmPython/win32/_vtkGdcm.dsp +++ b/gdcmPython/win32/_vtkGdcm.dsp @@ -118,6 +118,10 @@ SOURCE=..\..\src\gdcmJpeg2000.cxx # End Source File # Begin Source File +SOURCE=..\..\src\gdcmMeta.cxx +# End Source File +# Begin Source File + SOURCE=..\..\src\gdcmObject.cxx # End Source File # Begin Source File @@ -192,7 +196,7 @@ InputPath=.\init.h SOURCE=..\..\vtk\vtkGdcmReader.h # 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 -InputDir=\Projects\gdcm\VTK +InputDir=\Projects\gdcm\vtk ProjDir=. InputPath=..\..\vtk\vtkGdcmReader.h InputName=vtkGdcmReader diff --git a/gdcmPython/win32/gdcmpyembedded.dsp b/gdcmPython/win32/gdcmpyembedded.dsp index 5895fb2c..3ed70645 100644 --- a/gdcmPython/win32/gdcmpyembedded.dsp +++ b/gdcmPython/win32/gdcmpyembedded.dsp @@ -53,7 +53,7 @@ LINK32=link.exe # Begin Special Build Tool ProjDir=. SOURCE="$(InputPath)" -PostBuild_Cmds=move $(ProjDir)\gdcm.py $(ProjDir)\..\ +PostBuild_Cmds=move $(ProjDir)\gdcm.py $(ProjDir)\..\ # End Special Build Tool # Begin Target @@ -140,6 +140,10 @@ SOURCE=..\..\src\gdcmJpeg2000.cxx # End Source File # Begin Source File +SOURCE=..\..\src\gdcmMeta.cxx +# End Source File +# Begin Source File + SOURCE=..\..\src\gdcmObject.cxx # End Source File # Begin Source File diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index d4d6ad4f..11223cd2 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -12,6 +12,17 @@ #include #include + +void StartMethod(void * = NULL) +{ + std::cout<<"Start parsing"<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 /* diff --git a/src/gdcmDicomDir.h b/src/gdcmDicomDir.h index e54995e3..ae675fb0 100644 --- a/src/gdcmDicomDir.h +++ b/src/gdcmDicomDir.h @@ -16,6 +16,7 @@ typedef std::list ListPatient; typedef std::vector 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; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmMeta.cxx b/src/gdcmMeta.cxx index aedc2a43..a9a0aa0d 100644 --- a/src/gdcmMeta.cxx +++ b/src/gdcmMeta.cxx @@ -32,7 +32,7 @@ gdcmMeta::~gdcmMeta() */ void gdcmMeta::Print(std::ostream &os) { - os<<"META :"<