Переглянути джерело

Added checkmark for file write and notification that file has been written at location. Modified statistical output and more code cleanup

Luka 1 місяць тому
батько
коміт
c7c7dd498e
1 змінених файлів з 24 додано та 19 видалено
  1. 24 19
      SeekTransformModule/SeekTransformModule.py

+ 24 - 19
SeekTransformModule/SeekTransformModule.py

@@ -50,6 +50,10 @@ class SeekTransformModuleWidget(ScriptedLoadableModuleWidget):
         self.scalingCheckBox = qt.QCheckBox("Scaling")
         self.scalingCheckBox.setChecked(True)
         self.layout.addWidget(self.scalingCheckBox)
+        
+        self.writefileCheckBox = qt.QCheckBox("Write distances to csv file")
+        self.writefileCheckBox.setChecked(True)
+        self.layout.addWidget(self.writefileCheckBox)
 
         # Load button
         self.applyButton = qt.QPushButton("Find markers and transform")
@@ -70,9 +74,10 @@ class SeekTransformModuleWidget(ScriptedLoadableModuleWidget):
         applyRotation = self.rotationCheckBox.isChecked()
         applyTranslation = self.translationCheckBox.isChecked()
         applyScaling = self.scalingCheckBox.isChecked()
+        writefilecheck = self.writefileCheckBox.isChecked()
 
         # Pokliči logiko z izbranimi nastavitvami
-        logic.run(selectedMethod, applyRotation, applyTranslation, applyScaling)
+        logic.run(selectedMethod, applyRotation, applyTranslation, applyScaling, writefilecheck)
 
 
 class MyTransformModuleLogic(ScriptedLoadableModuleLogic):
@@ -81,7 +86,7 @@ class MyTransformModuleLogic(ScriptedLoadableModuleLogic):
     """
     
     
-    def run(self, selectedMethod, applyRotation, applyTranslation, applyScaling):
+    def run(self, selectedMethod, applyRotation, applyTranslation, applyScaling, writefilecheck):
         print("Calculating...")
         
         def group_points(points, threshold):
@@ -457,11 +462,6 @@ class MyTransformModuleLogic(ScriptedLoadableModuleLogic):
         for i in range(studyItems.GetNumberOfIds()):
             studyItem = studyItems.GetId(i)
             
-            # Dodamo ime študije v statistiko
-            studyName = shNode.GetItemName(studyItem)
-            prostate_size_est.append({"Study": studyName})
-            ctcbct_distance.append({"Study": studyName})
-            
             # **LOKALNI** seznami, resetirajo se pri vsakem study-ju
             cbct_list = []
             ct_list = []
@@ -605,7 +605,10 @@ class MyTransformModuleLogic(ScriptedLoadableModuleLogic):
                         distances_internal["A-B"].append(sorted_distances[0])
                         distances_internal["B-C"].append(sorted_distances[1])
                         distances_internal["C-A"].append(sorted_distances[2])
-
+                        
+                        # Dodamo ime študije za v statistiko
+                        studyName = shNode.GetItemName(studyItem)
+                        
                         # **Shrani razdalje v globalne sezname**
                         prostate_size_est.append({"Study": studyName, "Distances": sorted_distances})
                         ctcbct_distance.append({"Study": studyName, "Distances": list(distances_ct_cbct[-1])})  # Pretvorimo v seznam
@@ -655,15 +658,17 @@ class MyTransformModuleLogic(ScriptedLoadableModuleLogic):
         print("Razdalje med CT in CBCTji: ", ctcbct_distance)
         print("Razdalje med markerji: ", prostate_size_est)
         
-        # Define the file path for the CSV file
-        file_path = os.path.join(os.path.dirname(__file__), "study_data.csv")
-
-        # Write lists to the CSV file
-        with open(file_path, mode='w', newline='') as file: #w za write, a za append
-            writer = csv.writer(file)
-            # Write headers
-            writer.writerow(["Prostate Size", "CT-CBCT Distance"])
-            # Write data rows
-            for i in range(len(prostate_size_est)):
-                writer.writerow([prostate_size_est[i], ctcbct_distance[i]])
+        if(writefilecheck):
+            # Define the file path for the CSV file
+            file_path = os.path.join(os.path.dirname(__file__), "study_data.csv")
+
+            # Write lists to the CSV file
+            with open(file_path, mode='w', newline='') as file: #w za write, a za append
+                writer = csv.writer(file)
+                # Write headers
+                writer.writerow(["Prostate Size", "CT-CBCT Distance"])
+                # Write data rows
+                for i in range(len(prostate_size_est)):
+                    writer.writerow([prostate_size_est[i], ctcbct_distance[i]])
+                print("File written at ", file_path)