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

Removed quarterion method, will add another instead.

Luka 2 місяців тому
батько
коміт
0fe3035226
1 змінених файлів з 9 додано та 48 видалено
  1. 9 48
      SeekTransformModule/SeekTransformModule.py

+ 9 - 48
SeekTransformModule/SeekTransformModule.py

@@ -33,7 +33,7 @@ class SeekTransformModuleWidget(ScriptedLoadableModuleWidget):
 
         # Dropdown menu za izbiro metode
         self.rotationMethodComboBox = qt.QComboBox()
-        self.rotationMethodComboBox.addItems(["Kabsch", "Horn", "Quaternion"])
+        self.rotationMethodComboBox.addItems(["Kabsch", "Horn"])
         self.layout.addWidget(self.rotationMethodComboBox)
         
         # Load button
@@ -215,47 +215,8 @@ class MyTransformModuleLogic(ScriptedLoadableModuleLogic):
 
             return Rotate_optimal
 
-        def compute_Horn_rotation(moving_points, fixed_points):
-            """
-            Computes the optimal rotation matrix using Horn's method.
 
-            Parameters:
-            moving_points (list or ndarray): List of points to be rotated, CBCT
-            fixed_points (list or ndarray): List of reference points, CT
-
-            Returns:
-            ndarray: Optimal rotation matrix.
-            """
-            assert len(moving_points) == len(fixed_points), "Point lists must be the same length."
-            
-            moving = np.array(moving_points)
-            fixed = np.array(fixed_points)
-            
-            # Compute centroids
-            centroid_moving = np.mean(moving, axis=0)
-            centroid_fixed = np.mean(fixed, axis=0)
-            
-            # Center the points
-            moving_centered = moving - centroid_moving
-            fixed_centered = fixed - centroid_fixed
-            
-            # Compute cross-dispersion matrix
-            H = np.dot(moving_centered.T, fixed_centered)
-            
-            # Compute SVD of H
-            U, _, Vt = np.linalg.svd(H)
-            
-            # Compute rotation matrix
-            R = np.dot(Vt.T, U.T)
-            
-            # Ensure a proper rotation (avoid reflection)
-            if np.linalg.det(R) < 0:
-                Vt[-1, :] *= -1
-                R = np.dot(Vt.T, U.T)
-            
-            return R
-
-        def compute_quaternion_rotation(moving_points, fixed_points):
+        def compute_Horn_rotation(moving_points, fixed_points):
             """
             Computes the optimal rotation matrix using quaternions.
 
@@ -428,7 +389,7 @@ class MyTransformModuleLogic(ScriptedLoadableModuleLogic):
                     # print("Translation Vector:\n", quaternion_translation_vector)
 
                     # Izberi metodo glede na uporabnikov izbor
-                    if selectedMethod == "SVD":
+                    if selectedMethod == "Kabsch":
                         chosen_rotation_matrix = compute_Kabsch_rotation(cbct_points, ct_points)
                         chosen_translation_vector = compute_translation(cbct_points, ct_points, chosen_rotation_matrix)
                         print("\nKabsch Method:")
@@ -440,12 +401,12 @@ class MyTransformModuleLogic(ScriptedLoadableModuleLogic):
                         print("\nHorn Method:")
                         print("Rotation Matrix:\n", chosen_rotation_matrix)
                         print("Translation Vector:\n", chosen_translation_vector)
-                    elif selectedMethod == "Quaternion":
-                        chosen_rotation_matrix = compute_quaternion_rotation(cbct_points, ct_points)
-                        chosen_translation_vector = compute_translation(cbct_points, ct_points, chosen_rotation_matrix)
-                        print("\nQuaternion Method:")
-                        print("Rotation Matrix:\n", chosen_rotation_matrix)
-                        print("Translation Vector:\n", chosen_translation_vector)
+                    # elif selectedMethod == "Quaternion":
+                    #     chosen_rotation_matrix = compute_quaternion_rotation(cbct_points, ct_points)
+                    #     chosen_translation_vector = compute_translation(cbct_points, ct_points, chosen_rotation_matrix)
+                    #     print("\nQuaternion Method:")
+                    #     print("Rotation Matrix:\n", chosen_rotation_matrix)
+                    #     print("Translation Vector:\n", chosen_translation_vector)
 
                     imeTransformNoda = cbct_volume_name + " Transform"
                     # Ustvari vtkTransformNode in ga poveži z CBCT volumenom