]> Creatis software - gdcm.git/blobdiff - gdcmPython/demo/vtkGdcmDemo.py
* Remove useless methods added by JPR for Python users. All was already
[gdcm.git] / gdcmPython / demo / vtkGdcmDemo.py
index 142066a1b8d650b999ddb193cc759a735a567998..128029604bfc319c885ac428e009e2c78e79e1c9 100644 (file)
@@ -1,4 +1,11 @@
-## A small demo that displays with VTK an image parsed with gdcm.
+## A small demo that displays with VTK a dicom image parsed with gdcm.
+## Warning: the parsing of header of the dicom file is done with gdcm
+##          but the process of in-memory loading of the image is performed
+##          by vtkImageReader (classical vtk operator). Since vtkImageReader
+##          has no special knowledge of Dicom file format, this demo
+##          will only work for a restrained sub-set of Dicom files (basically
+##          non compressed and with "HighBit + 1 != BitsStored").
+##          When those conditions are not met try using vtkgdcmReader.py...
 import sys
 import vtk
 from gdcmPython import gdcmHeader
@@ -33,9 +40,9 @@ class vtkHistogram:
          self.ComputeHisto()
       self.__CumulHisto = []
       histo = self.__Histo.GetOutput()
-      self.__CumulHisto.append(int(histo.GetScalarComponentAsFloat(0,0,0,0)))
+      self.__CumulHisto.append(int(histo.GetScalarComponentAsDouble(0,0,0,0)))
       for i in range(1, self.__NumberOfBins):
-         value = int(histo.GetScalarComponentAsFloat(i,0,0,0))
+         value = int(histo.GetScalarComponentAsDouble(i,0,0,0))
          self.__CumulHisto.append( self.__CumulHisto[i-1] + value)
 
    def GetTruncateLevels(self, LostPercentage):
@@ -172,10 +179,10 @@ if not check.IsReadable():
    print "The ", FileName, " file is not "
    print "   readable with gdcm. Sorry."
    sys.exit()
-check = check.GetPubElVal()
+check = check.GetEntry()
 try:
-   BitsAlloc = check["Bits Allocated"]
-   if len(BitsAlloc) == 0 or BitsAlloc == "gdcm::Unfound":
+   HighBit = check["High Bit"]
+   if len(HighBit) == 0 or HighBit == "gdcm::Unfound":
       raise KeyError
 except KeyError:
    print "Gdcm couldn't find the Bits Allocated Dicom tag in file ", FileName
@@ -187,9 +194,12 @@ try:
 except KeyError:
    print "Gdcm couldn't find the Bits Stored Dicom tag in file ", FileName
    sys.exit()
-if BitsAlloc != BitsStored:
+if int(HighBit) + 1 != int(BitsStored):
    print "vtkImageReader cannot read the file ", FileName
-   print "  because the Bits Allocated and the Bits stored don't match."
+   print "  because the High Bit is offseted from the BitsStored."
+   print "  You should consider using vtkGdcmReader as opposed to the"
+   print "  vtkImageReader python class present in this demo. Please"
+   print "  see gdcmPython/demo/vtkGdcmReader.py for a demo."
    sys.exit()
 
 ### Display in a vtk RenderWindow