Jamoma API  0.6.0.a19
OrientationDataspace.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationDataspaceLib
4  *
5  * @brief Unit tests for the #OrientationDataspace.
6  *
7  * @authors Trond Lossius, Tim Place, Nils Peters, ...
8  *
9  * @copyright Copyright © 2011 Trond Lossius @n
10  * This code is licensed under the terms of the "New BSD License" @n
11  * http://creativecommons.org/licenses/BSD/
12  */
13 
14 
15 
16 
17 // Dataspaces and Units employ C++ double-inheritance and are thus unsuitable for direct use
18 // through the usual TTObject API
19 #define TT_NO_DEPRECATION_WARNINGS
20 
21 #include "OrientationDataspace.h"
22 
23 
24 TTErr OrientationDataspace::test(TTValue& returnedTestInfo)
25 {
26  int errorCount = 0;
27  int testAssertionCount = 0;
28 
29  // Create dataspace object and set to angle
30  try {
31 
32  TTObject myDataspace("dataspace");
33  myDataspace.set(TT("dataspace"), TT("orientation"));
34 
35  TTValue v;
36  TTValue expected;
37 
38  // for comparison, test values were computed with the spincalc toolbox for matlab:
39  // http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors
40 
41  /************************************************/
42  /* */
43  /* Test conversions to neutral unit */
44  /* */
45  /************************************************/
46 
47 
48 
49  // yaw-pitch-roll to quaternion
50 
51  myDataspace.set(TT("inputUnit"), TT("euler"));
52  myDataspace.set(TT("outputUnit"), TT("quaternion"));
53 
54  v.resize(3);
55  v[0] = TTFloat64(90.0);
56  v[1] = TTFloat64(45.0);
57  v[2] = TTFloat64(-45.0);
58 
59  expected.resize(4);
60  expected[0] = TTFloat64(0.0);
61  expected[1] = TTFloat64(-0.5);
62  expected[2] = TTFloat64(-0.7071067811865475);
63  expected[3] = TTFloat64(0.5);
64 
65  myDataspace.send(TT("convert"), v, v);
66 
67  TTTestAssertion("yaw-pitch-roll to quaternion",
68  TTTestFloat64ArrayEquivalence(v, expected),
69  testAssertionCount,
70  errorCount);
71 
72  // angle-axis to quaternion
73 
74  myDataspace.set(TT("inputUnit"), TT("xyza"));
75  myDataspace.set(TT("outputUnit"), TT("quaternion"));
76 
77  v.resize(4);
78  v[0] = TTFloat64(0.0);
79  v[1] = TTFloat64(-0.5773502691896258);
80  v[2] = TTFloat64(-0.8164965809277260);
81  v[3] = TTFloat64(120.0);
82 
83 
84  expected.resize(4);
85  expected[0] = TTFloat64(0.0);
86  expected[1] = TTFloat64(-0.5);
87  expected[2] = TTFloat64(-0.7071067811865475);
88  expected[3] = TTFloat64(0.5);
89 
90  myDataspace.send(TT("convert"), v, v);
91 
92  TTTestAssertion("axis-angle to quaternion",
93  TTTestFloat64ArrayEquivalence(v, expected),
94  testAssertionCount,
95  errorCount);
96 
97 
98  /************************************************/
99  /* */
100  /* Test conversions from neutral unit */
101  /* */
102  /************************************************/
103 
104  // quaternion to yaw-pitch-roll
105 
106  myDataspace.set(TT("inputUnit"), TT("quat"));
107  myDataspace.set(TT("outputUnit"), TT("euler"));
108 
109  v.resize(4);
110  v[0] = TTFloat64(0.0);
111  v[1] = TTFloat64(-0.5);
112  v[2] = TTFloat64(-0.7071067811865475);
113  v[3] = TTFloat64(0.5);
114 
115  expected.resize(3);
116  expected[0] = TTFloat64(90);
117  expected[1] = TTFloat64(45);
118  expected[2] = TTFloat64(-45);
119 
120  myDataspace.send(TT("convert"), v, v);
121 
122  TTTestAssertion("quaternion to yaw-pitch-roll",
123  TTTestFloat64ArrayEquivalence(v, expected),
124  testAssertionCount,
125  errorCount);
126 
127  // quaternion to angle-axis
128 
129  myDataspace.set(TT("inputUnit"), TT("quat"));
130  myDataspace.set(TT("outputUnit"), TT("axis"));
131 
132  v.resize(4);
133  v[0] = TTFloat64(0.0);
134  v[1] = TTFloat64(-0.5);
135  v[2] = TTFloat64(-0.7071067811865475);
136  v[3] = TTFloat64(0.5);
137 
138  expected.resize(4);
139  expected[0] = TTFloat64(0.0);
140  expected[1] = TTFloat64(-0.5773502691896258);
141  expected[2] = TTFloat64(-0.8164965809277260);
142  expected[3] = TTFloat64(120.0);
143 
144  myDataspace.send(TT("convert"), v, v);
145 
146  TTTestAssertion("quaternion to axis-angle",
147  TTTestFloat64ArrayEquivalence(v, expected),
148  testAssertionCount,
149  errorCount);
150 
151  /************************************************/
152  /* */
153  /* conversions across neutral units */
154  /* */
155  /************************************************/
156 
157  myDataspace.set(TT("inputUnit"), TT("euler"));
158  myDataspace.set(TT("outputUnit"), TT("axis"));
159 
160  v.resize(3);
161  v[0] = TTFloat64(90.0);
162  v[1] = TTFloat64(45.0);
163  v[2] = TTFloat64(-45.0);
164 
165  expected.resize(4);
166  expected[0] = TTFloat64(0.0);
167  expected[1] = TTFloat64(-0.5773502691896258);
168  expected[2] = TTFloat64(-0.8164965809277260);
169  expected[3] = TTFloat64(120.0);
170 
171  myDataspace.send(TT("convert"), v, v);
172 
173  TTTestAssertion("euler to axis-angle",
174  TTTestFloat64ArrayEquivalence(v, expected),
175  testAssertionCount,
176  errorCount);
177 
178  /************************************************/
179  /* */
180  /* simple rotations to axis-angle */
181  /* */
182  /************************************************/
183 
184  myDataspace.set(TT("inputUnit"), TT("euler"));
185  myDataspace.set(TT("outputUnit"), TT("axis"));
186 
187  //yaw
188  v.resize(3);
189  v[0] = TTFloat64(45.0);
190  v[1] = TTFloat64(0.0);
191  v[2] = TTFloat64(0.0);
192 
193  expected.resize(4);
194  expected[0] = TTFloat64(0.0);
195  expected[1] = TTFloat64(0.0);
196  expected[2] = TTFloat64(-1.0);
197  expected[3] = TTFloat64(45.0);
198 
199  myDataspace.send(TT("convert"), v, v);
200 
201  TTTestAssertion("yaw rotation to axis-angle",
202  TTTestFloat64ArrayEquivalence(v, expected),
203  testAssertionCount, errorCount);
204  //pitch
205  v[0] = TTFloat64(0.0);
206  v[1] = TTFloat64(45.0);
207  v[2] = TTFloat64(0.0);
208 
209  expected[0] = TTFloat64(1.0);
210  expected[1] = TTFloat64(0.0);
211  expected[2] = TTFloat64(0.0);
212  expected[3] = TTFloat64(45.0);
213 
214  myDataspace.send(TT("convert"), v, v);
215 
216  TTTestAssertion("pitch rotation to axis-angle",
217  TTTestFloat64ArrayEquivalence(v, expected),
218  testAssertionCount, errorCount);
219 
220  //roll
221  v[0] = TTFloat64(0.0);
222  v[1] = TTFloat64(0.0);
223  v[2] = TTFloat64(45.0);
224 
225  expected[0] = TTFloat64(0.0);
226  expected[1] = TTFloat64(1.0);
227  expected[2] = TTFloat64(0.0);
228  expected[3] = TTFloat64(45.0);
229 
230  myDataspace.send(TT("convert"), v, v);
231 
232  TTTestAssertion("roll rotation to axis-angle",
233  TTTestFloat64ArrayEquivalence(v, expected),
234  testAssertionCount, errorCount);
235 
236  }
237  catch (...) {
238  TTLogMessage("OrientationDataspace::test TOTAL FAILURE");
239  errorCount = 1;
240  testAssertionCount = 1;
241  }
242 
243  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
244 }
Create and use Jamoma object instances.
Definition: TTObject.h:29
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
void set(const TTUInt16 index, const T &anElementValue)
DEPRECATED.
Definition: TTValue.h:569
void TTFOUNDATION_EXPORT TTLogMessage(TTImmutableCString message,...)
Platform and host independent method for posting log messages.
Definition: TTBase.cpp:534
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
The OrientationDataspace converts between different untis describing orientation. ...