7
7
import numpy as np
8
8
from dynamic_graph .sot .core .op_point_modifier import OpPointModifier
9
9
10
- gaze = tuple (((1.0 , 0.0 , 0.0 , 0.025000000000000001 ), (0.0 , 1.0 , 0.0 , 0.0 ),
11
- (0.0 , 0.0 , 1.0 , 0.64800000000000002 ), (0.0 , 0.0 , 0.0 , 1.0 )))
10
+ gaze = np .array ((((1.0 , 0.0 , 0.0 , 0.025 ), (0.0 , 1.0 , 0.0 , 0.0 ), (0.0 , 0.0 , 1.0 , 0.648 ), (0.0 , 0.0 , 0.0 , 1.0 ))))
12
11
13
- Jgaze = tuple (
14
- ((1.0 , 0.0 , 0.0 , 0.0 , 0.64800000000000002 ,
15
- 0.0 ), (0.0 , 1.0 , 0.0 , - 0.64800000000000002 , 0.0 ,
16
- 0.025000000000000001 ), (0.0 , 0.0 , 1.0 , 0.0 , - 0.025000000000000001 ,
17
- 0.0 ), (0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 ),
18
- (0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 ), (0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 )))
12
+ Jgaze = np .array (
13
+ (((1.0 , 0.0 , 0.0 , 0.0 , 0.648 , 0.0 ), (0.0 , 1.0 , 0.0 , - 0.648 , 0.0 , 0.025 ), (0.0 , 0.0 , 1.0 , 0.0 , - 0.025 , 0.0 ),
14
+ (0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 ), (0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 ), (0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 ))))
19
15
20
- I4 = (( 1. , 0. , 0. , 0. ), (0. , 1. , 0. , 0. ), (0. , 0. , 1. , 0. ), (0. , 0. , 0. , 1. ))
16
+ I4 = np . array ((( 1. , 0. , 0. , 0. ), (0. , 1. , 0. , 0. ), (0. , 0. , 1. , 0. ), (0. , 0. , 0. , 1. ) ))
21
17
22
- I6 = ((1. , 0. , 0. , 0. , 0. , 0. ), (0. , 1. , 0. , 0. , 0. , 0. ),
23
- (0. , 0. , 1. , 0. , 0. , 0. ), (0. , 0. , 0. , 1. , 0. , 0. ),
24
- (0. , 0. , 0. , 0. , 1. , 0. ), (0. , 0. , 0. , 0. , 0. , 1. ))
18
+ I6 = np .array (((1. , 0. , 0. , 0. , 0. , 0. ), (0. , 1. , 0. , 0. , 0. , 0. ), (0. , 0. , 1. , 0. , 0. , 0. ), (0. , 0. , 0. , 1. , 0. , 0. ),
19
+ (0. , 0. , 0. , 0. , 1. , 0. ), (0. , 0. , 0. , 0. , 0. , 1. )))
25
20
26
21
27
22
class OpPointModifierTest (unittest .TestCase ):
@@ -33,17 +28,16 @@ def test_simple(self):
33
28
op .position .recompute (0 )
34
29
op .jacobian .recompute (0 )
35
30
36
- self .assertEqual ( op .getTransformation (), I4 )
37
- self .assertEqual ( op .position .value , I4 )
38
- self .assertEqual ( op .jacobian .value , I6 )
31
+ self .assertTrue (( op .getTransformation () == I4 ). all () )
32
+ self .assertTrue (( op .position .value == I4 ). all () )
33
+ self .assertTrue (( op .jacobian .value == I6 ). all () )
39
34
40
35
def test_translation (self ):
41
36
tx = 11.
42
37
ty = 22.
43
38
tz = 33.
44
39
45
- T = ((1. , 0. , 0. , tx ), (0. , 1. , 0. , ty ), (0. , 0. , 1. , tz ), (0. , 0. , 0. ,
46
- 1. ))
40
+ T = np .array (((1. , 0. , 0. , tx ), (0. , 1. , 0. , ty ), (0. , 0. , 1. , tz ), (0. , 0. , 0. , 1. )))
47
41
48
42
op = OpPointModifier ('op2' )
49
43
op .setTransformation (T )
@@ -52,31 +46,28 @@ def test_translation(self):
52
46
op .position .recompute (1 )
53
47
op .jacobian .recompute (1 )
54
48
55
- self .assertEqual ( op .getTransformation (), T )
49
+ self .assertTrue (( op .getTransformation () == T ). all () )
56
50
57
51
# w_M_s = w_M_g * g_M_s
58
- w_M_g = np . asmatrix ( gaze )
59
- g_M_s = np . asmatrix ( T )
60
- w_M_s_ref = w_M_g * g_M_s
61
- w_M_s = np . asmatrix ( op .position .value )
52
+ w_M_g = gaze
53
+ g_M_s = T
54
+ w_M_s_ref = w_M_g . dot ( g_M_s )
55
+ w_M_s = op .position .value
62
56
63
57
# Check w_M_s == w_M_s_ref
64
- self .assertEqual ( np . equal (w_M_s , w_M_s_ref ).all (), True )
58
+ self .assertTrue ( (w_M_s == w_M_s_ref ).all ())
65
59
66
- twist = np .matrix ([[1. , 0. , 0. , 0. , tz ,
67
- - ty ], [0. , 1. , 0. , - tz , 0. , tx ],
68
- [0. , 0. , 1. , ty , - tx , 0. ], [0. , 0. , 0. , 1. , 0. , 0. ],
69
- [0. , 0. , 0. , 0. , 1. , 0. ], [0. , 0. , 0. , 0. , 0. , 1. ]])
60
+ twist = np .array ([[1. , 0. , 0. , 0. , tz , - ty ], [0. , 1. , 0. , - tz , 0. , tx ], [0. , 0. , 1. , ty , - tx , 0. ],
61
+ [0. , 0. , 0. , 1. , 0. , 0. ], [0. , 0. , 0. , 0. , 1. , 0. ], [0. , 0. , 0. , 0. , 0. , 1. ]])
70
62
71
- J = np . asmatrix ( op .jacobian .value )
72
- J_ref = twist * Jgaze
63
+ J = op .jacobian .value
64
+ J_ref = twist . dot ( Jgaze )
73
65
74
66
# Check w_M_s == w_M_s_ref
75
- self .assertEqual ( np . equal ( J , J_ref ).all (), True )
67
+ self .assertTrue (( J == J_ref ).all ())
76
68
77
69
def test_rotation (self ):
78
- T = ((0. , 0. , 1. , 0. ), (0. , - 1. , 0. , 0. ), (1. , 0. , 0. , 0. ), (0. , 0. ,
79
- 0. , 1. ))
70
+ T = np .array (((0. , 0. , 1. , 0. ), (0. , - 1. , 0. , 0. ), (1. , 0. , 0. , 0. ), (0. , 0. , 0. , 1. )))
80
71
81
72
op = OpPointModifier ('op3' )
82
73
op .setTransformation (T )
@@ -85,35 +76,32 @@ def test_rotation(self):
85
76
op .position .recompute (1 )
86
77
op .jacobian .recompute (1 )
87
78
88
- self .assertEqual ( op .getTransformation (), T )
79
+ self .assertTrue (( op .getTransformation () == T ). all () )
89
80
90
81
# w_M_s = w_M_g * g_M_s
91
- w_M_g = np . asmatrix ( gaze )
92
- g_M_s = np . asmatrix ( T )
93
- w_M_s_ref = w_M_g * g_M_s
94
- w_M_s = np . asmatrix ( op .position .value )
82
+ w_M_g = gaze
83
+ g_M_s = T
84
+ w_M_s_ref = w_M_g . dot ( g_M_s )
85
+ w_M_s = op .position .value
95
86
96
87
# Check w_M_s == w_M_s_ref
97
- self .assertEqual ( np . equal (w_M_s , w_M_s_ref ).all (), True )
88
+ self .assertTrue ( (w_M_s == w_M_s_ref ).all ())
98
89
99
- twist = np .matrix ([[0. , 0. , 1. , 0. , 0. , 0. ], [0. , - 1. , 0. , 0. , 0. , 0. ],
100
- [1. , 0. , 0. , 0. , 0. , 0. ], [0. , 0. , 0. , 0. , 0. , 1. ],
101
- [0. , 0. , 0. , 0. , - 1. , 0. ], [0. , 0. , 0. , 1. , 0. ,
102
- 0. ]])
90
+ twist = np .array ([[0. , 0. , 1. , 0. , 0. , 0. ], [0. , - 1. , 0. , 0. , 0. , 0. ], [1. , 0. , 0. , 0. , 0. , 0. ],
91
+ [0. , 0. , 0. , 0. , 0. , 1. ], [0. , 0. , 0. , 0. , - 1. , 0. ], [0. , 0. , 0. , 1. , 0. , 0. ]])
103
92
104
- J = np . asmatrix ( op .jacobian .value )
105
- J_ref = twist * Jgaze
93
+ J = op .jacobian .value
94
+ J_ref = twist . dot ( Jgaze )
106
95
107
96
# Check w_M_s == w_M_s_ref
108
- self .assertEqual ( np . equal ( J , J_ref ).all (), True )
97
+ self .assertTrue (( J == J_ref ).all ())
109
98
110
99
def test_rotation_translation (self ):
111
100
tx = 11.
112
101
ty = 22.
113
102
tz = 33.
114
103
115
- T = ((0. , 0. , 1. , tx ), (0. , - 1. , 0. , ty ), (1. , 0. , 0. , tz ), (0. , 0. ,
116
- 0. , 1. ))
104
+ T = np .array (((0. , 0. , 1. , tx ), (0. , - 1. , 0. , ty ), (1. , 0. , 0. , tz ), (0. , 0. , 0. , 1. )))
117
105
118
106
op = OpPointModifier ('op4' )
119
107
op .setTransformation (T )
@@ -122,27 +110,25 @@ def test_rotation_translation(self):
122
110
op .position .recompute (1 )
123
111
op .jacobian .recompute (1 )
124
112
125
- self .assertEqual ( op .getTransformation (), T )
113
+ self .assertTrue (( op .getTransformation () == T ). all () )
126
114
127
115
# w_M_s = w_M_g * g_M_s
128
- w_M_g = np . asmatrix ( gaze )
129
- g_M_s = np . asmatrix ( T )
130
- w_M_s_ref = w_M_g * g_M_s
131
- w_M_s = np . asmatrix ( op .position .value )
116
+ w_M_g = gaze
117
+ g_M_s = T
118
+ w_M_s_ref = w_M_g . dot ( g_M_s )
119
+ w_M_s = op .position .value
132
120
133
121
# Check w_M_s == w_M_s_ref
134
- self .assertEqual ( np . equal (w_M_s , w_M_s_ref ).all (), True )
122
+ self .assertTrue ( (w_M_s == w_M_s_ref ).all ())
135
123
136
- twist = np .matrix (
137
- [[0. , 0. , 1. , ty , - tx , 0. ], [0. , - 1. , 0. , tz , 0. , - tx ],
138
- [1. , 0. , 0. , 0. , tz , - ty ], [0. , 0. , 0. , 0. , 0. , 1. ],
139
- [0. , 0. , 0. , 0. , - 1. , 0. ], [0. , 0. , 0. , 1. , 0. , 0. ]])
124
+ twist = np .array ([[0. , 0. , 1. , ty , - tx , 0. ], [0. , - 1. , 0. , tz , 0. , - tx ], [1. , 0. , 0. , 0. , tz , - ty ],
125
+ [0. , 0. , 0. , 0. , 0. , 1. ], [0. , 0. , 0. , 0. , - 1. , 0. ], [0. , 0. , 0. , 1. , 0. , 0. ]])
140
126
141
- J = np . asmatrix ( op .jacobian .value )
142
- J_ref = twist * Jgaze
127
+ J = op .jacobian .value
128
+ J_ref = twist . dot ( Jgaze )
143
129
144
130
# Check w_M_s == w_M_s_ref
145
- self .assertEqual ( np . equal ( J , J_ref ).all (), True )
131
+ self .assertTrue (( J == J_ref ).all ())
146
132
147
133
148
134
if __name__ == '__main__' :
0 commit comments