From 9fa652361f83211bf271393ab7ec55c55f7e839f Mon Sep 17 00:00:00 2001
From: Aju George <aju.george@fau.de>
Date: Sun, 22 Oct 2023 11:59:51 +0200
Subject: [PATCH] feat : added python code for ReadDICOMSeries.cxx

---
 src/Python.md                                 |  2 +
 src/Python/IO/ReadDICOMSeries.md              |  7 +++
 src/Python/IO/ReadDicomSeries.py              | 47 ++++++++++++-------
 .../Python/IO/TestReadDICOMSeries.png         |  3 ++
 4 files changed, 42 insertions(+), 17 deletions(-)
 create mode 100644 src/Python/IO/ReadDICOMSeries.md
 create mode 100644 src/Testing/Baseline/Python/IO/TestReadDICOMSeries.png

diff --git a/src/Python.md b/src/Python.md
index ab45fd8fdc9..0830555dcef 100644
--- a/src/Python.md
+++ b/src/Python.md
@@ -89,6 +89,8 @@ If you are new to VTK then these [tutorials](#tutorial) will help to get you sta
 | -------------- | ------------- | ------- |
 [HDRReader](/Python/IO/HDRReader) | Read a high-dynamic-range imaging file.
 [ReadDICOM](/Python/IO/ReadDICOM) | Read DICOM file.
+[ReadDICOMSeries](/Python/IO/ReadDICOMSeries) | This example demonstrates how to read a series of DICOM images and scroll through slices
+
 
 
 #### Output
diff --git a/src/Python/IO/ReadDICOMSeries.md b/src/Python/IO/ReadDICOMSeries.md
new file mode 100644
index 00000000000..43e11e10c22
--- /dev/null
+++ b/src/Python/IO/ReadDICOMSeries.md
@@ -0,0 +1,7 @@
+### Description
+
+This example demonstates how to read a series of DICOM images and how to scroll with the mousewheel or the up/down keys through all slices.
+Sample data are available as a zipped file (977 kB, 40 slices): <a id="raw-url" href="https://raw.githubusercontent.com/Kitware/vtk-examples/gh-pages/src/SupplementaryData/Cxx/IO/DicomTestImages.zip">DicomTestImages</a>
+
+!!! seealso
+    [ReadDICOM](../ReadDICOM).
\ No newline at end of file
diff --git a/src/Python/IO/ReadDicomSeries.py b/src/Python/IO/ReadDicomSeries.py
index f0c03991f26..d36fa8c2fd1 100644
--- a/src/Python/IO/ReadDicomSeries.py
+++ b/src/Python/IO/ReadDicomSeries.py
@@ -14,13 +14,15 @@ from vtk import vtkTextMapper
 from vtk import vtkTextProperty
 from vtk import vtkInteractorStyleTrackballCamera
 
+
+#Helper class to format slice status message
 class StatusMessage:
     @staticmethod
     def format(slice:int,max_slice:int):
         return f"Slice Number {(slice+1)/(max_slice+1)}"
     
 
-
+#Define own interaction style
 class MyVtkInteractorStyleImage(vtkInteractorStyleImage):
     def __init__(self,parent=None):
         super().__init__()
@@ -66,8 +68,7 @@ class MyVtkInteractorStyleImage(vtkInteractorStyleImage):
             self.move_slice_forward
         elif key=="Down":
             self.move_slice_backward
-        #forward event
-        #super(MyVtkInteractorStyleImage, self).OnKeyDown()
+
 
     def mouseWheelForwardEvent(self,obj,event):
         if self.slice<self.max_slice:
@@ -80,15 +81,27 @@ class MyVtkInteractorStyleImage(vtkInteractorStyleImage):
 
 
 #Read all the DICOM files in the specified directory.
-folder=r"src/Python/IO/matlab/examples/sample_data/DICOM/digest_article"
+#folder=r"src/Python/IO/matlab/examples/sample_data/DICOM/digest_article"
+#/Users/ajugeorge/Documents/Python Programs/vtk-examples/src/Python/IO/matlab/examples/sample_data/DICOM/digest_article
+
+def get_program_parameters():
+    import argparse
+    description = 'Read DICOM series data'
+    epilogue = ''''''
+    parser = argparse.ArgumentParser(description=description, epilog=epilogue,
+                                     formatter_class=argparse.RawDescriptionHelpFormatter)
+    parser.add_argument('dirname', help='DicomTestImages.zip')
+    args = parser.parse_args()
+    return args.dirname
+
+
 
-class DicomViewer():
-    def __init__(self):
-        self.main()
 
 def main():
     colors=vtkNamedColors()
     reader=vtkDICOMImageReader()
+    folder=get_program_parameters()
+    #Read DICOM files in the specified directory
     reader.SetDirectoryName(folder)
     reader.Update()
     #Visualilze
@@ -101,7 +114,7 @@ def main():
     slice_text_prop.SetFontSize(20)
     slice_text_prop.SetVerticalJustificationToBottom()
     slice_text_prop.SetJustificationToLeft()
-
+    #Slice status message
     slice_text_mapper=vtkTextMapper()
     msg=StatusMessage.format(image_viewer.GetSliceMin(),image_viewer.GetSliceMax())
     slice_text_mapper.SetInput(msg)
@@ -136,26 +149,26 @@ def main():
 
 
     #Create an interactor with our own style (inherit from
-    #vtkInteractorStyleImage) in order to catch mousewheel and key events.
+    #vtkInteractorStyleImage in order to catch mousewheel and key events.
 
     render_window_interactor= vtkRenderWindowInteractor()
     my_interactor_style=MyVtkInteractorStyleImage()
+  
+   #Make imageviewer2 and sliceTextMapper visible to our interactorstyle
+   #to enable slice status message updates when  scrolling through the slices.
 
     my_interactor_style.set_imageviewer(image_viewer)
     my_interactor_style.set_status_mapper(slice_text_mapper)
 
-
-    image_viewer.SetupInteractor(render_window_interactor)
-    render_window_interactor.SetInteractorStyle(my_interactor_style)
-    render_window_interactor.Render()
-
-    
     #Make the interactor use our own interactorstyle
     #cause SetupInteractor() is defining it's own default interatorstyle
     #this must be called after SetupInteractor().
+    #renderWindowInteractor.SetInteractorStyle(myInteractorStyle);
+    image_viewer.SetupInteractor(render_window_interactor)
+    render_window_interactor.SetInteractorStyle(my_interactor_style)
+    render_window_interactor.Render()
 
-
-
+    #Add slice status message and usage hint message to the renderer.
     image_viewer.GetRenderer().AddActor2D(slice_text_actor)
     image_viewer.GetRenderer().AddActor2D(usage_text_actor)
 
diff --git a/src/Testing/Baseline/Python/IO/TestReadDICOMSeries.png b/src/Testing/Baseline/Python/IO/TestReadDICOMSeries.png
new file mode 100644
index 00000000000..c10bf1d9d03
--- /dev/null
+++ b/src/Testing/Baseline/Python/IO/TestReadDICOMSeries.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:9abfef71e88a2dc08e8d4097bda52a16a1758aaf8b6edf6df7031270e0a129fc
+size 128807
-- 
GitLab