]> 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 21315ed..c5488ec 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 b3bde10..f50976a 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 703ee20..4b016d4 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 82537d0..aca8f43 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 77b1058..007a3fa 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 587165c..aea5e5c 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 cdb94fd..c3f5809 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()