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
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;
}
////////////////////////////////////////////////////////////////////////////
+// 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.
# 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=..\..\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
# 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
# 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
#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
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() )
//-----------------------------------------------------------------------------
// 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
return true;
}
-/*
- * \ingroup gdcmDicomDir
- * \brief fills whole the structure
- */
-void gdcmDicomDir::ParseDirectory(void)
-{
- NewDicomDir(GetPath());
- CreateDicomDir();
-}
-
//-----------------------------------------------------------------------------
// Protected
/*
*/
void gdcmDicomDir::NewDicomDir(std::string path)
{
+ CallStartMethod();
+
gdcmDirList fileList(path,1);
+ unsigned int count=0;
ListHeader list;
gdcmHeader *header;
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();
}
/*
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
/*
typedef std::list<gdcmPatient *> ListPatient;
typedef std::vector<gdcmHeader *> ListHeader;
+typedef GDCM_EXPORT void( gdcmMethod)(void * =NULL);
//-----------------------------------------------------------------------------
/*
* \defgroup gdcmDicomDir
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
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,
gdcmMeta *metaElems;
ListPatient patients;
+
+ gdcmMethod *startMethod;
+ gdcmMethod *progressMethod;
+ gdcmMethod *endMethod;
+ void *startArg;
+ void *progressArg;
+ void *endArg;
+
+ float progress;
+ bool abort;
};
//-----------------------------------------------------------------------------
*/
void gdcmMeta::Print(std::ostream &os)
{
- os<<"META :"<<std::endl;
+ os<<"META"<<std::endl;
gdcmObject::Print(os);
}
# 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
# 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
# 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
# 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
# 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
# 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
# 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