1212from ..utils .c3d_data import C3dData
1313from ..utils .linear_algebra import (
1414 RotoTransMatrix ,
15- get_closest_rt_matrix ,
1615 mean_unit_vector ,
1716 RotoTransMatrixTimeSeries ,
1817 point_from_local_to_global ,
2726class RigidSegmentIdentification :
2827 def __init__ (
2928 self ,
30- filepath : str ,
29+ functional_c3d : C3dData ,
3130 parent_name : str ,
3231 child_name : str ,
3332 parent_marker_names : list [str ],
3433 child_marker_names : list [str ],
35- first_frame : int = None ,
36- last_frame : int = None ,
3734 initialize_whole_trial_reconstruction : bool = False ,
3835 animate_rt : bool = False ,
3936 ):
4037 """
4138 Parameters
4239 ----------
43- filepath
44- The path to the .c3d file containing the functional trial.
40+ functional_c3d
41+ The .c3d file containing the functional trial.
4542 parent_name
4643 The name of the joint's parent segment.
4744 child_name
@@ -50,24 +47,18 @@ def __init__(
5047 The name of the markers in the parent segment to consider during the SCoRE algorithm.
5148 child_marker_names
5249 The name of the markers in the child segment to consider during the SCoRE algorithm.
53- first_frame
54- The first frame to consider in the functional trial.
55- last_frame
56- The last frame to consider in the functional trial.
5750 initialize_whole_trial_reconstruction
5851 If True, the whole trial is reconstructed using whole body inverse kinematics to initialize the segments' rt in the global reference frame.
5952 animate_rt
6053 If True, it animates the segment rt reconstruction using pyomeca and pyorerun.
6154 """
6255
6356 # Original attributes
64- self .filepath = filepath
57+ self .c3d_data = functional_c3d
6558 self .parent_name = parent_name
6659 self .child_name = child_name
6760 self .parent_marker_names = parent_marker_names
6861 self .child_marker_names = child_marker_names
69- self .first_frame = first_frame
70- self .last_frame = last_frame
7162 self .initialize_whole_trial_reconstruction = initialize_whole_trial_reconstruction
7263 self .animate_rt = animate_rt
7364
@@ -78,7 +69,6 @@ def __init__(
7869 self .child_static_markers_in_local : np .ndarray = None
7970 self .parent_markers_global : np .ndarray = None
8071 self .child_markers_global : np .ndarray = None
81- self .c3d_data : C3dData = None
8272 self .marker_name : list [str ] = None
8373 self .marker_positions : np .ndarray = None
8474
@@ -101,22 +91,15 @@ def _check_c3d_functional_trial_file(self):
10191 """
10292 Check that the file format is appropriate and that there is a functional movement in the trial (aka the markers really move).
10393 """
104- # Check file format
105- if self .filepath .endswith (".c3d" ):
106- # Load the c3d file
107- self .c3d_data = C3dData (self .filepath , self .first_frame , self .last_frame )
108- self .marker_names = self .c3d_data .marker_names
109- self .marker_positions = self .c3d_data .all_marker_positions [:3 , :, :]
110- else :
111- if self .filepath .endswith (".trc" ):
112- raise NotImplementedError (".trc files cannot be read yet." )
113- else :
114- raise RuntimeError ("The filepath (static trial) must be a .c3d file in a static posture." )
94+ self .marker_names = self .c3d_data .marker_names
95+ self .marker_positions = self .c3d_data .all_marker_positions [:3 , :, :]
11596
11697 # Check that the markers move
11798 std = []
11899 for marker_name in self .parent_marker_names + self .child_marker_names :
119100 std += self .c3d_data .std_marker_position (marker_name )
101+ if len (std ) == 0 :
102+ raise RuntimeError ("There are no markers in the functional trial. Please check the trial again." )
120103 if all (np .array (std ) < 0.01 ):
121104 raise RuntimeError (
122105 f"The markers { self .parent_marker_names + self .child_marker_names } are not moving in the functional trial (markers std = { std } ). "
@@ -676,28 +659,24 @@ def perform_task(
676659class Sara (RigidSegmentIdentification ):
677660 def __init__ (
678661 self ,
679- filepath : str ,
662+ functional_c3d : C3dData ,
680663 parent_name : str ,
681664 child_name : str ,
682665 parent_marker_names : list [str ],
683666 child_marker_names : list [str ],
684667 joint_center_markers : list [str ],
685668 distal_markers : list [str ],
686669 is_longitudinal_axis_from_jcs_to_distal_markers : bool ,
687- first_frame : int = None ,
688- last_frame : int = None ,
689670 initialize_whole_trial_reconstruction : bool = False ,
690671 animate_rt : bool = False ,
691672 ):
692673
693674 super (Sara , self ).__init__ (
694- filepath = filepath ,
675+ functional_c3d = functional_c3d ,
695676 parent_name = parent_name ,
696677 child_name = child_name ,
697678 parent_marker_names = parent_marker_names ,
698679 child_marker_names = child_marker_names ,
699- first_frame = first_frame ,
700- last_frame = last_frame ,
701680 animate_rt = animate_rt ,
702681 initialize_whole_trial_reconstruction = initialize_whole_trial_reconstruction ,
703682 )
0 commit comments