From f81c61f9ca9f0c33f35e04f2c1c1ffa11a09db59 Mon Sep 17 00:00:00 2001 From: regrain Date: Thu, 13 Jan 2005 16:35:36 +0000 Subject: [PATCH] * src/gdcmDictSet.h : set the default output to the os variable * src/gdcmDictEntry.[h|cxx] : add the Print method * gdcmPython/demo/ : add a new test -- BeNours --- ChangeLog | 5 ++++ gdcmPython/CMakeLists.txt | 20 -------------- gdcmPython/demo/CMakeLists.txt | 7 +++++ gdcmPython/demo/PrintDict.py.in | 49 +++++++++++++++++++++++++++++++++ src/gdcmDictEntry.cxx | 28 +++++++++++++++++-- src/gdcmDictEntry.h | 9 ++++-- src/gdcmDictSet.h | 6 ++-- 7 files changed, 97 insertions(+), 27 deletions(-) create mode 100644 gdcmPython/demo/PrintDict.py.in diff --git a/ChangeLog b/ChangeLog index 0f5443bd..724cba70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-01-13 Benoit Regrain + * src/gdcmDictSet.h : set the default output to the os variable + * src/gdcmDictEntry.[h|cxx] : add the Print method + * gdcmPython/demo/ : add a new test + 2005-01-13 Jean-Pierre Roux * merging of Test/PrintDicomDir and Test/TestDicomDir * removal of now redundant Test/PrintDicomDir diff --git a/gdcmPython/CMakeLists.txt b/gdcmPython/CMakeLists.txt index 91fe9c0d..ded39cb1 100644 --- a/gdcmPython/CMakeLists.txt +++ b/gdcmPython/CMakeLists.txt @@ -134,26 +134,6 @@ ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9) ${EXE_DIR}/${CMAKE_CFG_INTDIR}/_gdcm${CMAKE_SHARED_LIBRARY_SUFFIX} ) - # Remove temporary (lib)pygdcm(.so .dll) library: -# ADD_CUSTOM_COMMAND( -# TARGET pygdcm -# POST_BUILD -# COMMAND ${CMAKE_COMMAND} -# ARGS -E remove ${LIB_DIR}/${CMAKE_CFG_INTDIR}/${LIB_NAME} -# ) - - # where are library stored ? -# SET(GDCM_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) -# ADD_CUSTOM_COMMAND( -# TARGET pygdcm -# POST_BUILD -# COMMAND ${CMAKE_COMMAND} -# ARGS -E copy -# ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${MY_LIB_NAME}${CMAKE_SHLIB_SUFFIX} -# ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/vtkXY.pvm -# TARGET vtkXY -# ) - ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9) diff --git a/gdcmPython/demo/CMakeLists.txt b/gdcmPython/demo/CMakeLists.txt index 25428d4e..6cc55456 100644 --- a/gdcmPython/demo/CMakeLists.txt +++ b/gdcmPython/demo/CMakeLists.txt @@ -16,6 +16,9 @@ FIND_PROGRAM(PYTHON_EXECUTABLE MARK_AS_ADVANCED(PYTHON_EXECUTABLE) IF(PYTHON_EXECUTABLE) + ADD_TEST(Python-PrintDict ${PYTHON_EXECUTABLE} + ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintDict.py + ) ADD_TEST(Python-PrintHeader ${PYTHON_EXECUTABLE} ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintHeader.py ) @@ -40,3 +43,7 @@ CONFIGURE_FILE( ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintDicomDir.py ) +CONFIGURE_FILE( + ${GDCM_SOURCE_DIR}/gdcmPython/demo/PrintDict.py.in + ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintDict.py +) diff --git a/gdcmPython/demo/PrintDict.py.in b/gdcmPython/demo/PrintDict.py.in new file mode 100644 index 00000000..4a1eb84a --- /dev/null +++ b/gdcmPython/demo/PrintDict.py.in @@ -0,0 +1,49 @@ +import sys +import os + +sys.path.append('${GDCM_BINARY_DIR}') +if os.name == 'posix': + sys.path.append('${GDCM_BINARY_DIR}/bin') +else: + sys.path.append('${GDCM_BINARY_DIR}/bin/Release') + sys.path.append('${GDCM_BINARY_DIR}/bin/Debug') + +from gdcmPython.core import * + +print "#####################################################################" +# Print the DictSet +dicts=gdcm.Global.GetDicts() +if(not isinstance(dicts,gdcm.DictSet)): + raise RuntimeError,"The DictSet hasn't the good type (%s)" % type(dicts) +print "DictSet content :" +dicts.Print() + +print "#####################################################################" +# Print the Dict (public) +pubDict=dicts.GetDefaultPubDict() +if(not isinstance(pubDict,gdcm.Dict)): + raise RuntimeError,"The public Dict hasn't the good type (%s)" % type(dict) +print "Public Dict content :" +pubDict.Print() + +print "#####################################################################" +# Print the DictEntry (0010|0020) +ENTRY_GR = 0x10 +ENTRY_EL = 0x20 +entry=pubDict.GetDictEntry(ENTRY_GR,ENTRY_EL) +if(not isinstance(entry,gdcm.DictEntry)): + raise RuntimeError,"The entry (%04x|%04x) hasn't the good type (%s)" % \ + (ENTRY_GR,ENTRY_EL,type(entry)) +print "Entry (%04x|%04x) content :" % (ENTRY_GR,ENTRY_EL) +entry.Print() + +# Print the DictEntry (0010|0010) +ENTRY_GR = 0x10 +ENTRY_EL = 0x10 +entry=pubDict.GetDictEntry(ENTRY_GR,ENTRY_EL) +if(not isinstance(entry,gdcm.DictEntry)): + raise RuntimeError,"The entry (%04x|%04x) hasn't the good type (%s)" % \ + (ENTRY_GR,ENTRY_EL,type(entry)) +print "Entry (%04x|%04x) content :" % (ENTRY_GR,ENTRY_EL) +entry.Print() + diff --git a/src/gdcmDictEntry.cxx b/src/gdcmDictEntry.cxx index 886dd489..a4bb7060 100644 --- a/src/gdcmDictEntry.cxx +++ b/src/gdcmDictEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictEntry.cxx,v $ Language: C++ - Date: $Date: 2005/01/10 17:17:52 $ - Version: $Revision: 1.38 $ + Date: $Date: 2005/01/13 16:35:37 $ + Version: $Revision: 1.39 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,6 +20,9 @@ #include "gdcmDebug.h" #include "gdcmUtil.h" +#include // for std::ios::left, ... +#include + namespace gdcm { @@ -49,6 +52,27 @@ DictEntry::DictEntry(uint16_t group, uint16_t element, //----------------------------------------------------------------------------- // Print +void DictEntry::Print(std::ostream &os) +{ + std::string vr; + std::ostringstream s; + + vr = GetVR(); + if(vr==GDCM_UNKNOWN) + vr=" "; + + s << DictEntry::TranslateToKey(GetGroup(),GetElement()); + s << " [" << vr << "] "; + + if (PrintLevel >= 1) + { + s.setf(std::ios::left); + s << std::setw(66-GetName().length()) << " "; + } + + s << "[" << GetName()<< "]"; + os << s.str(); +} //----------------------------------------------------------------------------- // Public diff --git a/src/gdcmDictEntry.h b/src/gdcmDictEntry.h index 1658bb49..89a85c0c 100644 --- a/src/gdcmDictEntry.h +++ b/src/gdcmDictEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictEntry.h,v $ Language: C++ - Date: $Date: 2005/01/11 15:15:38 $ - Version: $Revision: 1.28 $ + Date: $Date: 2005/01/13 16:35:37 $ + Version: $Revision: 1.29 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -46,8 +46,13 @@ public: TagName const &vm = GDCM_UNKNOWN, TagName const &name = GDCM_UNKNOWN); +// Print + void Print(std::ostream &os = std::cout); + +// Key creation static TagKey TranslateToKey(uint16_t group, uint16_t element); +// Content of DictEntry void SetVR(TagName const &vr); void SetVM(TagName const &vm); diff --git a/src/gdcmDictSet.h b/src/gdcmDictSet.h index cb891b82..54c8b0fc 100644 --- a/src/gdcmDictSet.h +++ b/src/gdcmDictSet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictSet.h,v $ Language: C++ - Date: $Date: 2005/01/11 15:15:38 $ - Version: $Revision: 1.34 $ + Date: $Date: 2005/01/13 16:35:37 $ + Version: $Revision: 1.35 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -44,7 +44,7 @@ public: DictSet(); ~DictSet(); - void Print(std::ostream &os); + void Print(std::ostream &os = std::cout); // Probabely useless ! //EntryNamesList *GetPubDictEntryNames(); -- 2.45.1