From: regrain Date: Mon, 29 Aug 2005 12:29:47 +0000 (+0000) Subject: * Fix bug while wrapping python. The DicomDir SetStart/Progress/EndMethod are... X-Git-Tag: Version1.2.bp~184 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=278965e64eb49669b1a05493843f97144d8323b4;p=gdcm.git * Fix bug while wrapping python. The DicomDir SetStart/Progress/EndMethod are accessible in python -- BeNours --- diff --git a/Example/MakeDicomDir.cxx b/Example/MakeDicomDir.cxx index 33e67afe..b3465316 100644 --- a/Example/MakeDicomDir.cxx +++ b/Example/MakeDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: MakeDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/07/26 02:25:25 $ - Version: $Revision: 1.11 $ + Date: $Date: 2005/08/29 12:29:47 $ + Version: $Revision: 1.12 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) dcmdir = new gdcm::DicomDir( ); - dcmdir->SetStartMethod(StartMethod, (void *) NULL); + dcmdir->SetStartMethod(StartMethod); dcmdir->SetEndMethod(EndMethod); dcmdir->SetLoadMode(loadMode); diff --git a/Testing/TestMakeDicomDir.cxx b/Testing/TestMakeDicomDir.cxx index 3d6b1bc3..81c9219c 100644 --- a/Testing/TestMakeDicomDir.cxx +++ b/Testing/TestMakeDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestMakeDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/07/21 04:51:26 $ - Version: $Revision: 1.5 $ + Date: $Date: 2005/08/29 12:29:48 $ + Version: $Revision: 1.6 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -70,7 +70,7 @@ int TestMakeDicomDir(int argc, char *argv[]) dcmdir->SetDirectoryName(dirName); dcmdir->Load( ); - dcmdir->SetStartMethod(StartMethod, (void *) NULL); + dcmdir->SetStartMethod(StartMethod); dcmdir->SetEndMethod(EndMethod); if ( !dcmdir->GetFirstPatient() ) diff --git a/gdcmPython/demo/PrintDicomDir.py.in b/gdcmPython/demo/PrintDicomDir.py.in index a7694499..341df43d 100644 --- a/gdcmPython/demo/PrintDicomDir.py.in +++ b/gdcmPython/demo/PrintDicomDir.py.in @@ -12,6 +12,14 @@ def PrintUse(): print "" print "" +### Progress methods +def startMethod(): + print "Start" +def progressMethod(): + print "Progress",dicomdir.GetProgress() +def endMethod(): + print "End" + ### Get filename from command line or default it try: fileName = sys.argv[1] @@ -27,6 +35,11 @@ except IndexError: ### Build the DicomDir element list dicomdir = gdcm.DicomDir() + +dicomdir.SetStartMethod(startMethod) +dicomdir.SetProgressMethod(progressMethod) +dicomdir.SetEndMethod(endMethod) + dicomdir.SetFileName(fileName) dicomdir.Load() if not dicomdir.IsReadable(): @@ -60,3 +73,17 @@ while(patient): study=patient.GetNextStudy() patient=dicomdir.GetNextPatient() +dicomdir.SetDirectoryName(os.path.dirname(fileName)) +dicomdir.Load() +if not dicomdir.IsReadable(): + PrintUse() + raise RuntimeError,"The '%s' DicomDir is not readable with gdcm." % fileName + +print "DICOMDIR -->",fileName +print "##############################################################" +print "## Display all the elements and their respective values" +print "## found in the ", fileName, " file." +print "##############################################################" +dicomdir.SetPrintLevel(-1) +dicomdir.Print() + diff --git a/gdcmPython/gdcm.i b/gdcmPython/gdcm.i index ab1e4869..bb21af1b 100644 --- a/gdcmPython/gdcm.i +++ b/gdcmPython/gdcm.i @@ -128,9 +128,7 @@ typedef unsigned long long uint64_t; // Note: Uses gdcmPythonVoidFunc and gdcmPythonVoidFuncArgDelete defined // in the Swig verbatim section of this gdcm.i i.e. in the above section // enclosed within the %{ ... %} scope operator ). -%typemap(python, in) ( gdcm::DicomDir::Method *, - void * = NULL, - gdcm::DicomDir::Method * = NULL ) +%typemap(python, in) (void(*method)(void *),void *arg,void(*argDelete)(void *)) { if($input!=Py_None) { @@ -205,8 +203,9 @@ typedef unsigned long long uint64_t; %ignore gdcm::binary_write(std::ostream &,uint32_t const &); %ignore gdcm::binary_write(std::ostream &,uint16_t const &); -//%ignore gdcm::File::File(); -//%ignore gdcm::DicomDir::DicomDir(); +%ignore gdcm::DicomDir::SetStartMethod(DicomDir::Method *method,void *arg = NULL); +%ignore gdcm::DicomDir::SetProgressMethod(DicomDir::Method *method,void *arg = NULL); +%ignore gdcm::DicomDir::SetEndMethod(DicomDir::Method *method,void *arg = NULL); // Ignore all placed in gdcmCommon.h %ignore GDCM_UNKNOWN; diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index 6ffb4fdd..8be64395 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/08/29 09:41:22 $ - Version: $Revision: 1.154 $ + Date: $Date: 2005/08/29 12:29:50 $ + Version: $Revision: 1.155 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -159,9 +159,9 @@ DicomDir::DicomDir(std::string const &fileName, bool parseDir ): */ DicomDir::~DicomDir() { - SetStartMethod(NULL); - SetProgressMethod(NULL); - SetEndMethod(NULL); + SetStartMethod(NULL,NULL,NULL); + SetProgressMethod(NULL,NULL,NULL); + SetEndMethod(NULL,NULL,NULL); ClearPatient(); if ( MetaElems ) @@ -404,6 +404,21 @@ void DicomDir::ParseDirectory() CreateDicomDir(); } +void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg ) +{ + SetStartMethod(method,arg,NULL); +} + +void DicomDir::SetProgressMethod( DicomDir::Method *method, void *arg ) +{ + SetProgressMethod(method,arg,NULL); +} + +void DicomDir::SetEndMethod( DicomDir::Method *method, void *arg ) +{ + SetEndMethod(method,arg,NULL); +} + /** * \brief Set the start method to call when the parsing of the * directory starts. @@ -621,10 +636,10 @@ void DicomDir::CreateDicomDirChainedList(std::string const &path) break; } - f = new File( ); - f->SetLoadMode(LoadMode); // we allow user not to load Sequences, or Shadow - // groups, or ...... - f->SetFileName( it->c_str() ); + f = new File( ); + f->SetLoadMode(LoadMode); // we allow user not to load Sequences, or Shadow + // groups, or ...... + f->SetFileName( it->c_str() ); /*int res = */f->Load( ); // if ( !f ) diff --git a/src/gdcmDicomDir.h b/src/gdcmDicomDir.h index f51c9f4c..22ced06d 100644 --- a/src/gdcmDicomDir.h +++ b/src/gdcmDicomDir.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.h,v $ Language: C++ - Date: $Date: 2005/07/21 05:02:11 $ - Version: $Revision: 1.66 $ + Date: $Date: 2005/08/29 12:29:50 $ + Version: $Revision: 1.67 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -95,17 +95,25 @@ public: // following method declarations. Refer to gdcmPython/gdcm.i // for the reasons of this unnecessary notation at C++ level. void SetStartMethod( DicomDir::Method *method, - void *arg = NULL, - DicomDir::Method *argDelete = NULL ); - void SetProgressMethod( DicomDir::Method *method, - void *arg = NULL, - DicomDir::Method *argDelete = NULL ); + void *arg = NULL ); + void SetProgressMethod( DicomDir::Method *method, + void *arg = NULL ); void SetEndMethod( DicomDir::Method *method, - void *arg = NULL, - DicomDir::Method *argDelete = NULL ); - void SetStartMethodArgDelete ( DicomDir::Method *m ); - void SetProgressMethodArgDelete( DicomDir::Method *m ); - void SetEndMethodArgDelete ( DicomDir::Method *m ); + void *arg = NULL ); + // Note: replace DicomDir::Method *method to void(*method)(void *) to + // avoid wrapping problems with the typemap conversions + void SetStartMethod( void(*method)(void *), // DicomDir::Method *method + void *arg, + void(*argDelete)(void *)); + void SetProgressMethod( void(*method)(void *), // DicomDir::Method *method + void *arg, + void(*argDelete)(void *)); + void SetEndMethod( void(*method)(void *), // DicomDir::Method *method + void *arg, + void(*argDelete)(void *)); + void SetStartMethodArgDelete ( DicomDir::Method *method ); + void SetProgressMethodArgDelete( DicomDir::Method *method ); + void SetEndMethodArgDelete ( DicomDir::Method *method ); /// GetProgress GetProgress float GetProgress() { return Progress; }