Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import numpy as np
from rq_interfaces.msg import ProjectionGeometry
class PyProjectionGeometry():
def __init__(self, focal_spot_mm: np.ndarray, detector_postion_mm: np.ndarray, detector_orientation_quad: np.ndarray,
frame_id: str = 'object') -> None:
self.focal_spot_mm = focal_spot_mm
self.detector_postion_mm = detector_postion_mm
self.detector_orientation_quad = detector_orientation_quad
self.frame_id = frame_id
@classmethod
def dummy(cls):
return cls(np.array([1., 0., 0]),
np.array([-1., 0., 0]),
np.array([1., 0., 0, 1.]))
@classmethod
def from_message(cls, msg: ProjectionGeometry):
focal_spot_mm = np.array([msg.focal_spot_postion_mm.x,
msg.focal_spot_postion_mm.y,
msg.focal_spot_postion_mm.z,])
detector_center_mm = np.array([msg.detector_postion_mm.x,
msg.detector_postion_mm.y,
msg.detector_postion_mm.z,])
detector_orientation_quad = np.array([msg.detector_orientation_quad.x,
msg.detector_orientation_quad.y,
msg.detector_orientation_quad.z,
msg.detector_orientation_quad.w])
frame_id = msg.header.frame_id
return cls(focal_spot_mm, detector_center_mm, detector_orientation_quad, frame_id)
def as_message(self) -> ProjectionGeometry:
message = ProjectionGeometry()
message.focal_spot_postion_mm.x = self.focal_spot_mm[0]
message.focal_spot_postion_mm.y = self.focal_spot_mm[1]
message.focal_spot_postion_mm.z = self.focal_spot_mm[2]
message.detector_postion_mm.x = self.detector_postion_mm[0]
message.detector_postion_mm.y = self.detector_postion_mm[1]
message.detector_postion_mm.z = self.detector_postion_mm[2]
message.detector_orientation_quad.x = self.detector_orientation_quad[0]
message.detector_orientation_quad.y = self.detector_orientation_quad[1]
message.detector_orientation_quad.z = self.detector_orientation_quad[2]
message.detector_orientation_quad.w = self.detector_orientation_quad[3]
message.header.frame_id = self.frame_id
return message