From d24a4150db8e1c04392eece82119098276713d46 Mon Sep 17 00:00:00 2001 From: regrain Date: Mon, 17 Jan 2005 14:20:29 +0000 Subject: [PATCH] * gdcmPython/demo : add python demos using VTK -- BeNours --- ChangeLog | 9 ++++- gdcmPython/CMakeLists.txt | 1 + gdcmPython/demo/CMakeLists.txt | 25 +++++++++++- gdcmPython/demo/vtkGdcmReader.py.in | 43 +++++++++++++++++++++ gdcmPython/demo/vtkGdcmWriter.py.in | 52 +++++++++++++++++++++++++ src/gdcmUtil.cxx | 60 +++++++++++++++++++---------- 6 files changed, 166 insertions(+), 24 deletions(-) create mode 100644 gdcmPython/demo/vtkGdcmReader.py.in create mode 100644 gdcmPython/demo/vtkGdcmWriter.py.in diff --git a/ChangeLog b/ChangeLog index 5d1bab0f..a598438f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ -2005-01-16 Jean-Pierre Roux +2005-01-17 Benoit Regrain + * src/gdcmUtil.cxx : bug fix to find the Windows MAC address. Now, there + is no memory access violation + * gdcmPython/demo : add python demos using VTK + +2005-01-16 Jean-Pierre Roux * FIX 'Dictionnary' is now spelt 'Dictionary' 'wether' is now spelt 'whether' 'archieve' is now spelt 'archive' ;-) @@ -7,7 +12,7 @@ * ADD DicomDir, DicomDirPatient, DicomDirStudy, DicomDirSerie, DicomDirImage related methods, in order not to expose internal mechanisms InitTraversal(); - GetNextEntry(); + GetNextEntry(); * REM methods that exposed internal mechanisms : DicomDir::GetDicomDirPatients() DicomDirPatient::GetDicomDirStudies() diff --git a/gdcmPython/CMakeLists.txt b/gdcmPython/CMakeLists.txt index ded39cb1..9e85703c 100644 --- a/gdcmPython/CMakeLists.txt +++ b/gdcmPython/CMakeLists.txt @@ -150,6 +150,7 @@ IF(GDCM_VTK) SET(vtkgdcmPython_la_SOURCES ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx + ${GDCM_SOURCE_DIR}/vtk/vtkGdcmWriter.cxx ) SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED) diff --git a/gdcmPython/demo/CMakeLists.txt b/gdcmPython/demo/CMakeLists.txt index 6cc55456..66da5850 100644 --- a/gdcmPython/demo/CMakeLists.txt +++ b/gdcmPython/demo/CMakeLists.txt @@ -3,7 +3,7 @@ #----------------------------------------------------------------------------- # DOH! python is not found by default FIND_PROGRAM(PYTHON_EXECUTABLE - NAMES python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5 python + NAMES python python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5 PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath] [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath] @@ -47,3 +47,26 @@ CONFIGURE_FILE( ${GDCM_SOURCE_DIR}/gdcmPython/demo/PrintDict.py.in ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintDict.py ) + +#----------------------------------------------------------------------------- +# Same but for VTK +IF(GDCM_VTK) + IF(PYTHON_EXECUTABLE) + ADD_TEST(Python-VTK-Reader ${PYTHON_EXECUTABLE} + ${GDCM_BINARY_DIR}/gdcmPython/demo/vtkGdcmReader.py + ) + ADD_TEST(Python-VTK-Writer ${PYTHON_EXECUTABLE} + ${GDCM_BINARY_DIR}/gdcmPython/demo/vtkGdcmWriter.py + ) + ENDIF(PYTHON_EXECUTABLE) + + CONFIGURE_FILE( + ${GDCM_SOURCE_DIR}/gdcmPython/demo/vtkGdcmReader.py.in + ${GDCM_BINARY_DIR}/gdcmPython/demo/vtkGdcmReader.py + ) + + CONFIGURE_FILE( + ${GDCM_SOURCE_DIR}/gdcmPython/demo/vtkGdcmWriter.py.in + ${GDCM_BINARY_DIR}/gdcmPython/demo/vtkGdcmWriter.py + ) +ENDIF(GDCM_VTK) diff --git a/gdcmPython/demo/vtkGdcmReader.py.in b/gdcmPython/demo/vtkGdcmReader.py.in new file mode 100644 index 00000000..70670b2b --- /dev/null +++ b/gdcmPython/demo/vtkGdcmReader.py.in @@ -0,0 +1,43 @@ +import sys +import os + +# All paths must be added without system tests, because of ctest... +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.vtk import * +from vtkpython import * + +# Get the file names +try: + fileName = sys.argv[1] +except IndexError: + fileName = os.path.join(GDCM_DATA_PATH, "test.acr") + +# read the image +reader = vtkGdcmReader() +reader.SetFileName(fileName) +reader.Update() + +# show the image +viewer = vtkImageViewer() +viewer.SetInput(reader.GetOutput()) +rng = reader.GetOutput().GetScalarRange() +viewer.SetColorWindow(rng[1] - rng[0]) +viewer.SetColorLevel(0.5 * (rng[1] + rng[0])) + +dim = reader.GetOutput().GetDimensions() +viewer.SetSize(dim[0],dim[1]) +if(dim[2] != 1): + # For multifame dicom, take a snapshot of the center slice (+/- 1) + viewer.SetZSlice(dim[2] / 2) +else: + viewer.SetZSlice(0) +viewer.Render() + +# sys.stdin.read(1) + diff --git a/gdcmPython/demo/vtkGdcmWriter.py.in b/gdcmPython/demo/vtkGdcmWriter.py.in new file mode 100644 index 00000000..845243f7 --- /dev/null +++ b/gdcmPython/demo/vtkGdcmWriter.py.in @@ -0,0 +1,52 @@ +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.vtk import * +from vtkpython import * + +# Get the file names +try: + fileName = sys.argv[1] +except IndexError: + fileName = os.path.join(GDCM_DATA_PATH, "test.acr") + +# read the image +reader = vtkGdcmReader() +reader.SetFileName(fileName) + +# write the image +writer = vtkGdcmWriter() +writer.SetInput(reader.GetOutput()) +writer.SetFileName("outputPy.dcm") +writer.Write() + +# re-read the image +reader2 = vtkGdcmReader() +reader2.SetFileName("outputPy.dcm") +reader2.Update() + +# show the image +viewer = vtkImageViewer() +viewer.SetInput(reader2.GetOutput()) +rng = reader.GetOutput().GetScalarRange() +viewer.SetColorWindow(rng[1] - rng[0]) +viewer.SetColorLevel(0.5 * (rng[1] + rng[0])) + +dim = reader.GetOutput().GetDimensions() +viewer.SetSize(dim[0],dim[1]) +if(dim[2] != 1): + # For multifame dicom, take a snapshot of the center slice (+/- 1) + viewer.SetZSlice(dim[2] / 2) +else: + viewer.SetZSlice(0) +viewer.Render() + +# sys.stdin.read(1) + diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index dee613e5..b8a06b66 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.cxx,v $ Language: C++ - Date: $Date: 2005/01/17 13:55:26 $ - Version: $Revision: 1.100 $ + Date: $Date: 2005/01/17 14:20:30 $ + Version: $Revision: 1.101 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -40,45 +40,45 @@ // For GetMACAddress #ifdef _WIN32 -#include -#include + #include + #include #else -#include -#include -#include -#include + #include + #include + #include + #include #endif // How do I do that in CMake ? #ifdef __APPLE__ -#define HAVE_SA_LEN -#define CMAKE_HAVE_NET_IF_DL_H -#define CMAKE_HAVE_NETINET_IN_H -#define CMAKE_HAVE_NET_IF_H + #define HAVE_SA_LEN + #define CMAKE_HAVE_NET_IF_DL_H + #define CMAKE_HAVE_NETINET_IN_H + #define CMAKE_HAVE_NET_IF_H #endif //APPLE #ifdef CMAKE_HAVE_SYS_IOCTL_H -#include // For SIOCGIFCONF on Linux + #include // For SIOCGIFCONF on Linux #endif #ifdef CMAKE_HAVE_SYS_SOCKET_H -#include + #include #endif #ifdef CMAKE_HAVE_SYS_SOCKIO_H -#include // For SIOCGIFCONF on SunOS + #include // For SIOCGIFCONF on SunOS #endif #ifdef CMAKE_HAVE_NET_IF_H -#include + #include #endif #ifdef CMAKE_HAVE_NETINET_IN_H -#include //For IPPROTO_IP + #include //For IPPROTO_IP #endif #ifdef CMAKE_HAVE_NET_IF_DL_H -#include + #include #endif #ifdef __sun -//#if defined(CMAKE_HAVE_NET_IF_ARP_H) && defined(__sun) -// This is absolutely necesseray on SunOS -#include + //#if defined(CMAKE_HAVE_NET_IF_ARP_H) && defined(__sun) + // This is absolutely necesseray on SunOS + #include #endif namespace gdcm @@ -516,6 +516,24 @@ int GetMacAddrSys ( unsigned char *addr ) // Free the bindings SNMP_FreeVarBind(&varBind[0]); SNMP_FreeVarBind(&varBind[1]); + + + +/* IP_ADAPTER_INFO AdapterInfo[2]; + DWORD dwBufSize = sizeof(AdapterInfo); + + DWORD dwStatus = GetAdaptersInfo(AdapterInfo, &dwBufSize); + + PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; + do + { + unsigned char *MAC=pAdapterInfo->Address; + printf("Your MAC Address Is: %02X-%02X-%02X-%02X-%02X-%02X", MAC[0], MAC[1], MAC[2], MAC[3], MAC[4], MAC[5]); + pAdapterInfo = pAdapterInfo->Next; + } + while(pAdapterInfo); */ + + return 0; #endif //Win32 version -- 2.45.1