INCLUDE_DIRECTORIES(
${GDCM_SOURCE_DIR}/src
+ ${GDCM_SOURCE_DIR}/gdcmPython
${PYTHON_INCLUDE_PATH}
${GDCM_BINARY_DIR}/
)
ADD_TEST(Python-PrintDicomDir ${PYTHON_EXECUTABLE}
${GDCM_BINARY_DIR}/gdcmPython/demo/PrintDicomDir.py
)
+ ADD_TEST(Python-MakeDicomDir ${PYTHON_EXECUTABLE}
+ ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintDicomDir.py
+ )
ELSE(PYTHON_EXECUTABLE)
MESSAGE(FATAL_ERROR "You requested testing for python, but python was not
found")
${GDCM_BINARY_DIR}/gdcmPython/demo/PrintDicomDir.py
)
+CONFIGURE_FILE(
+ ${GDCM_SOURCE_DIR}/gdcmPython/demo/MakeDicomDir.py.in
+ ${GDCM_BINARY_DIR}/gdcmPython/demo/MakeDicomDir.py
+)
+
CONFIGURE_FILE(
${GDCM_SOURCE_DIR}/gdcmPython/demo/PrintDict.py.in
${GDCM_BINARY_DIR}/gdcmPython/demo/PrintDict.py
--- /dev/null
+import sys
+import os.path
+from gdcmConfigDemo import *
+from gdcmPython.core import *
+
+def PrintUse():
+ print ""
+ print "Use :"
+ print "-----"
+ print "%s" % sys.argv[0]
+ print " Create the DicomDir from the GDCM_DATA_ROOT path"
+ 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]
+except IndexError:
+ fileName = os.path.join(GDCM_DATA_ROOT, "DICOMDIR")
+ if( not os.path.isfile(fileName) ):
+ fileName=os.path.join(os.path.split(sys.argv[0])[0],"DICOMDIR")
+
+try:
+ printLevel = int(sys.argv[2])
+except IndexError:
+ printLevel = 1
+
+### Build the DicomDir element list
+dicomdir = gdcm.DicomDir.New()
+
+cmd=gdcm.CommandPy.New()
+cmd.SetCallback(startMethod)
+gdcm.CommandManager.SetCommand(dicomdir,gdcm.CMD_STARTPROGRESS,cmd)
+cmd=gdcm.CommandPy.New()
+cmd.SetCallback(endMethod)
+gdcm.CommandManager.SetCommand(dicomdir,gdcm.CMD_ENDPROGRESS,cmd)
+cmd=gdcm.CommandPy.New()
+cmd.SetCallback(progressMethod)
+gdcm.CommandManager.SetCommand(dicomdir,gdcm.CMD_PROGRESS,cmd)
+
+dicomdir.SetDirectoryName(GDCM_DATA_ROOT)
+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()
+
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]
### Build the DicomDir element list
dicomdir = gdcm.DicomDir.New()
-dicomdir.SetStartMethod(startMethod)
-dicomdir.SetProgressMethod(progressMethod)
-dicomdir.SetEndMethod(endMethod)
-
dicomdir.SetFileName(fileName)
dicomdir.Load()
if not dicomdir.IsReadable():
#include "gdcmCommon.h"
#include "gdcmBase.h"
#include "gdcmRefCounter.h"
+#include "gdcmCommand.h"
+#include "gdcmCommandPy.h"
+#include "gdcmDebug.h"
+#include "gdcmCommandManager.h"
#include "gdcmTagKey.h"
#include "gdcmVRKey.h"
#include "gdcmDict.h"
#include "gdcmTS.h"
#include "gdcmDictGroupName.h"
-////////////////////////////////////////////////////////////////////////////
-/// Refer (below) to the definition of multi-argument typemap
-/// %typemap(python, in)
-/// ( gdcm::DicomDir::Method*, void*, gdcm::DicomDir::Method*)
-/// for detail on gdcmPythonVoidFunc() and gdcmPythonVoidFuncArgDelete().
-void gdcmPythonVoidFunc(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))
- {
- std::cerr << "Caught a Ctrl-C within python, exiting program.\n";
- Py_Exit(1);
- }
- PyErr_Print();
- }
-}
-
-void gdcmPythonVoidFuncArgDelete(void *arg)
-{
- PyObject *func = (PyObject *)arg;
- if (func)
- {
- Py_DECREF(func);
- }
-}
-
/// This is required in order to avoid %including all the gdcm include files.
using namespace gdcm;
%}
$result = newEntry;
}
-////////////////////////////////////////////////////////////////////////////
-// Multi-argument typemap designed for wrapping the progress related methods
-// in order to control from an external application the computation of
-// a DicomDir object (see DicomDir::SetStartMethod*,
-// DicomDir::SetProgressMethod* and DicomDir::SetEndMethod*).
-// Motivation: since DicomDir parsing can be quite long, a GUI application
-// needs to display the avancement and potentially offer a
-// cancel method to the user (when this one feels things are
-// longer than expected).
-// Example of usage: refer to demo/DicomDirProgressMethod.py
-// 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) (void(*method)(void *),void *arg,void(*argDelete)(void *))
-{
- if($input!=Py_None)
- {
- Py_INCREF($input);
- $1=gdcmPythonVoidFunc;
- $2=$input;
- $3=gdcmPythonVoidFuncArgDelete;
- }
- else
- {
- $1=NULL;
- $2=NULL;
- $3=NULL;
- }
-}
-
//////////////////// STL string versus Python str ////////////////////////
// Convertion returning a C++ string.
%typemap(out) std::string
%include "gdcmCommon.h"
%include "gdcmBase.h"
%include "gdcmRefCounter.h"
+%include "gdcmCommand.h"
+%include "gdcmCommandPy.h"
+%include "gdcmDebug.h"
+%include "gdcmCommandManager.h"
%include "gdcmTagKey.h"
%include "gdcmVRKey.h"
%include "gdcmDicomEntry.h"
--- /dev/null
+/*=========================================================================
+
+ Program: gdcm
+ Module: $RCSfile: gdcmCommandPy.h,v $
+ Language: C++
+ Date: $Date: 2005/11/28 17:47:38 $
+ Version: $Revision: 1.1 $
+
+ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+ l'Image). All rights reserved. See Doc/License.txt or
+ http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*/
+
+#ifndef GDCMCOMMANDPY_H
+#define GDCMCOMMANDPY_H
+
+#include "gdcmDebug.h"
+#include "gdcmCommand.h"
+#include "python.h"
+
+namespace gdcm
+{
+//-----------------------------------------------------------------------------
+/**
+ * \brief CommandPy base class to react on a gdcm event
+ *
+ * \remarks The execution parameter depends on the
+ */
+class CommandPy : public Command
+{
+ gdcmTypeMacro(CommandPy);
+
+public:
+ static CommandPy *New() {return new CommandPy(); }
+
+ void SetCallback(PyObject *callback)
+ {
+ Callback = callback;
+ Py_INCREF(Callback);
+ }
+
+ virtual void Execute()
+ {
+ PyObject *arglist = Py_BuildValue("()");
+ PyObject *result = PyEval_CallObject(Callback, arglist);
+ Py_DECREF(arglist);
+
+ if (result)
+ {
+ Py_XDECREF(result);
+ }
+ else
+ {
+ if (PyErr_ExceptionMatches(PyExc_KeyboardInterrupt))
+ {
+ std::cerr << "Caught a Ctrl-C within python, exiting program.\n";
+ Py_Exit(1);
+ }
+ PyErr_Print();
+ }
+ }
+
+protected:
+ CommandPy()
+ {
+ Callback = NULL;
+ }
+ virtual ~CommandPy()
+ {
+ if (Callback)
+ Py_DECREF(Callback);
+ }
+
+private:
+ /// pointer to the initialisation method for any progress bar
+ PyObject *Callback;
+};
+} // end namespace gdcm
+
+//-----------------------------------------------------------------------------
+#endif