]> Creatis software - gdcm.git/commitdiff
* Amelioration of the Python part concerning demos
authorregrain <regrain>
Thu, 17 Mar 2005 11:21:47 +0000 (11:21 +0000)
committerregrain <regrain>
Thu, 17 Mar 2005 11:21:47 +0000 (11:21 +0000)
   -- BeNours

gdcmPython/CMakeLists.txt
gdcmPython/demo/CMakeLists.txt
gdcmPython/demo/PrintDicomDir.py.in
gdcmPython/demo/PrintDict.py.in
gdcmPython/demo/PrintFile.py.in
gdcmPython/demo/gdcmConfigDemo.py.in [new file with mode: 0644]
gdcmPython/demo/vtkGdcmReader.py.in
gdcmPython/demo/vtkGdcmWriter.py.in

index 21315eddc4189c41fb7260c888ccbe5427bf27a5..c5488ece24e5a5e9eaa2aea9c49582b1c3766238 100644 (file)
@@ -208,7 +208,7 @@ FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py
 
 FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/core.py
     "import gdcm\n"
-    "GDCM_DATA_ROOT     =\"${GDCM_DATA_ROOT}\"\n"
+    "GDCM_DATA_ROOT \"${GDCM_DATA_ROOT}\"\n"
     )
 
 IF(GDCM_VTK)
@@ -218,7 +218,7 @@ IF(GDCM_VTK)
     "  from libvtkgdcmPython import *\n"
     "else:\n"
     "  from vtkgdcmPython import *\n"
-    "GDCM_DATA_ROOT     =\"${GDCM_DATA_ROOT}\"\n"
+    "GDCM_DATA_ROOT \"${GDCM_DATA_ROOT}\"\n"
     )
 ENDIF(GDCM_VTK)
 
index b3bde10cbae8e2db67c7cf2a9b14c45c32198f07..f50976ab9329b73bfbc16bd294ca0d3bc3e0bd09 100644 (file)
@@ -33,6 +33,11 @@ ENDIF(PYTHON_EXECUTABLE)
 #-----------------------------------------------------------------------------
 # Copy all the demo directory content to the cmake bin 
 # Without it, tests can't be launched
+CONFIGURE_FILE(
+    ${GDCM_SOURCE_DIR}/gdcmPython/demo/gdcmConfigDemo.py.in
+    ${GDCM_BINARY_DIR}/gdcmPython/demo/gdcmConfigDemo.py
+)
+
 CONFIGURE_FILE(
     ${GDCM_SOURCE_DIR}/gdcmPython/demo/PrintFile.py.in
     ${GDCM_BINARY_DIR}/gdcmPython/demo/PrintFile.py
index 703ee20ec7846354e50c9421832b5c910c1b2930..4b016d43037842c6537d315290154d69e22bfd7d 100644 (file)
@@ -1,15 +1,15 @@
-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 gdcmConfigDemo import *
 from gdcmPython.core import *
 
+def PrintUse():
+   print ""
+   print "Use :"
+   print "-----"
+   print "%s <dicomDir>" % sys.argv[0]
+   print "   dicomDir : path to the DICOMDIR to parse"
+   print ""
+   print ""
+
 ### Get filename from command line or default it
 try:
    fileName = sys.argv[1]
@@ -24,10 +24,10 @@ except IndexError:
 ### Build the DicomDir element list
 dicomdir = gdcm.DicomDir(fileName)
 if not dicomdir.IsReadable():
-   print
+   PrintUse()
    raise RuntimeError,"The '%s' DicomDir is not readable with gdcm." % fileName
-   #sys.exit()
 
+print "DICOMDIR -->",fileName
 print "##############################################################"
 print "## Display all the elements and their respective values"
 print "## found in the ", fileName, " file."
index 82537d05d6cc5bcb634ab0ed3057ee10077fb3d9..aca8f437b17e5809e259b35a854bcb2d1d51c11b 100644 (file)
@@ -1,13 +1,4 @@
-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 gdcmConfigDemo import *
 from gdcmPython.core import *
 
 print "#####################################################################"
index 77b1058c973ad20b40e4fd7b1a69f28b7c50dc13..007a3fa1bfc8422f39044e58c2c163d6649c9f78 100644 (file)
@@ -1,15 +1,16 @@
 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 gdcmConfigDemo import *
 from gdcmPython.core import *
 
+def PrintUse():
+   print ""
+   print "Use :"
+   print "-----"
+   print "%s <fileName>" % sys.argv[0]
+   print "   fileName : path to the DICOM file to parse"
+   print ""
+   print ""
+
 ### Get filename from command line or default it
 try:
    fileName = sys.argv[1]
@@ -22,11 +23,12 @@ except IndexError:
    printLevel = 1
 
 ### Build the file element list
-print fileName, type(fileName)
 file = gdcm.File(fileName)
 if not file.IsReadable():
+   PrintUse()
    raise RuntimeError,"The '%s' file is not readable with gdcm." % fileName
 
+print "File -->",fileName
 print "##############################################################"
 print "### Display all the elements and their respective values"
 print "## found in the ", fileName, " file."
diff --git a/gdcmPython/demo/gdcmConfigDemo.py.in b/gdcmPython/demo/gdcmConfigDemo.py.in
new file mode 100644 (file)
index 0000000..245b9c0
--- /dev/null
@@ -0,0 +1,45 @@
+# gdcmPython Demo configurer
+
+if __name__!="main":
+   import sys
+   import os
+   import inspect
+   import os.path
+
+   def FindPath():
+      try:
+         path=inspect.getsourcefile(FindPath)
+      except:
+         pass
+      else:
+         if( path ):
+            path=os.path.split(path)[0]
+            file=os.path.join(path,"..","__init__.py")
+            if( os.path.isfile(file) ):
+               gdcmPath=os.path.join(path,"..","..")
+               sys.path.append(gdcmPath)
+               sys.path.append(os.path.join(gdcmPath,"bin"))
+               if( os.name != 'posix' ):
+                  sys.path.append(os.path.join(gdcmPath,"bin","Release"))
+                  sys.path.append(os.path.join(gdcmPath,"bin","Debug"))
+
+   def UseCMakePath():
+      sys.path.append('${GDCM_BINARY_DIR}')
+      sys.path.append('${GDCM_BINARY_DIR}/bin')
+      if( os.name != 'posix' ):
+         sys.path.append('${GDCM_BINARY_DIR}/bin/Release')
+         sys.path.append('${GDCM_BINARY_DIR}/bin/Debug')
+
+   try:
+      mod=__import__("gdcmPython")
+   except:
+      FindPath()
+      try:
+         mod=__import__("gdcmPython")
+      except:
+         UseCMakePath()
+
+else:
+   print "Only a system configurer for gdcm Demos."
+   print "Can't be executed"
+
index 587165c06849ef6973bf3251f7fddcb695edc1de..aea5e5c879fda132c0fb83fa2faa3a4b2e78ef93 100644 (file)
@@ -1,22 +1,25 @@
-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 gdcmConfigDemo import *
 from gdcmPython.vtk import *
 from vtkpython import *
 
+def PrintUse():
+   print ""
+   print "Use :"
+   print "-----"
+   print "%s <fileName>" % sys.argv[0]
+   print "   fileName : path to the DICOM file to see"
+   print ""
+   print ""
+
 # Get the file names
 try:
    fileName = sys.argv[1]
 except IndexError:
    fileName = os.path.join(GDCM_DATA_ROOT, "test.acr")
+   
+if( not os.path.isfile(fileName) ):
+   PrintUse()
+   sys.exit(1)
 
 # read the image
 reader = vtkGdcmReader()
index cdb94fd7fe0566157e69af6b5bb11d302aa5c738..c3f5809ee53b99702f32b29fd9acc0390cb33dee 100644 (file)
@@ -1,21 +1,25 @@
-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 gdcmConfigDemo import *
 from gdcmPython.vtk import *
 from vtkpython import *
 
+def PrintUse():
+   print ""
+   print "Use :"
+   print "-----"
+   print "%s <fileName>" % sys.argv[0]
+   print "   fileName : path to the DICOM file to see"
+   print ""
+   print ""
+
 # Get the file names
 try:
    fileName = sys.argv[1]
 except IndexError:
    fileName = os.path.join(GDCM_DATA_ROOT, "test.acr")
+   
+if( not os.path.isfile(fileName) ):
+   PrintUse()
+   sys.exit(1)
 
 # read the image
 reader = vtkGdcmReader()