55from dataclasses import asdict , dataclass , field
66from datetime import datetime
77from pathlib import Path
8- from typing import Dict , List , Tuple
8+ from typing import Dict , List , Tuple , Optional
99
1010import numpy as np
1111
@@ -28,6 +28,26 @@ class ArrayTransform:
2828 (In order to apply the transform to transducer points,
2929 first represent the points in these units.)"""
3030
31+ @dataclass
32+ class TransducerTrackingResult :
33+ """
34+ Class representing the results of running the transducer tracking
35+ algorithm.
36+ """
37+
38+ photoscan_id : str
39+ """ID of the photoscan object used for transducer tracking"""
40+
41+ transducer_to_photoscan_transform : ArrayTransform
42+ """Transform output by transducer tracking algorithm to register the transducer surface to the photoscan model"""
43+
44+ photoscan_to_volume_transform : ArrayTransform
45+ """Transform output by the transducer tracking algorithm to register the photoscan model the volume's skin segmentation"""
46+
47+ transducer_tracking_approved : Optional [bool ] = False
48+ """Approval state of transducer tracking result. `True` means the user has provided some kind of
49+ confirmation that the transducer transforms in this result agrees with reality."""
50+
3151@dataclass
3252class Session :
3353 """
@@ -83,9 +103,8 @@ class Session:
83103 only. None of the other transforms in the list are considered to be approved.
84104 """
85105
86- transducer_tracking_approved : bool | None = False
87- """Approval state of transducer tracking. `True` means the user has provided some kind of
88- confirmation that the transducer transform in this session agrees with reality."""
106+ transducer_tracking_results : Optional [List [TransducerTrackingResult ]] = field (default_factory = list )
107+ """List of any transducer tracking results"""
89108
90109 def __post_init__ (self ):
91110 if self .id is None and self .name is None :
@@ -130,6 +149,11 @@ def from_dict(d:Dict):
130149 raise ValueError ("Sessions no longer recognize a volume attribute -- it is now volume_id." )
131150 if 'array_transform' in d :
132151 d ['array_transform' ] = ArrayTransform (np .array (d ['array_transform' ]['matrix' ]), d ['array_transform' ]['units' ])
152+ if 'transducer_tracking_results' in d :
153+ d ['transducer_tracking_results' ] = [TransducerTrackingResult (t ['photoscan_id' ],
154+ ArrayTransform (np .array (t ['transducer_to_photoscan_transform' ]['matrix' ]),t ['transducer_to_photoscan_transform' ]['units' ]),
155+ ArrayTransform (np .array (t ['photoscan_to_volume_transform' ]['matrix' ]), t ['photoscan_to_volume_transform' ]['units' ]),
156+ t ['transducer_tracking_approved' ]) for t in d ['transducer_tracking_results' ]]
133157 if isinstance (d ['targets' ], list ):
134158 if len (d ['targets' ])> 0 and isinstance (d ['targets' ][0 ], dict ):
135159 d ['targets' ] = [Point .from_dict (p ) for p in d ['targets' ]]
@@ -165,12 +189,13 @@ def to_dict(self):
165189 d ['markers' ] = [p .to_dict () for p in d ['markers' ]]
166190
167191 d ['array_transform' ] = asdict (d ['array_transform' ])
168-
169192 for target_id ,(approval ,transforms ) in d ['virtual_fit_results' ].items ():
170193 d ['virtual_fit_results' ][target_id ] = (
171194 approval ,
172195 [asdict (t ) for t in transforms ],
173196 )
197+
198+ d ['transducer_tracking_results' ] = [asdict (t ) for t in d ['transducer_tracking_results' ]]
174199
175200 return d
176201
0 commit comments