Jamoma API  0.6.0.a19
PositionDataspace.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationDataspaceLib
4  *
5  * @brief The #PositionDataspace converts between different untis describing position.
6  *
7  * @details The neutral unit of the position dataspace is 3-dimensional Cartesian coordinates.
8  *
9  * @authors Nils Peters, Trond Lossius, Jan Schacher, Tim Place, ...
10  *
11  * @copyright Copyright © 2007 by Nils Peters @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #include "PositionDataspace.h"
18 
19 
20 #define thisTTClass Cartesian3DUnit
21 #define thisTTClassName "unit.cart3d"
22 #define thisTTClassTags "dataspace.unit, position"
23 
25 TTDataspaceUnit(arguments)
26 {;}
27 
28 Cartesian3DUnit::~Cartesian3DUnit(){;}
29 
31 {
32  output.resize(3);
33  output = input;
34 }
35 
36 
38 {
39  output = input;
40  output.resize(3);
41 }
42 
43 
44 #undef thisTTClass
45 #undef thisTTClassName
46 #undef thisTTClassTags
47 
48 /***********************************************************************************************/
49 
50 #define thisTTClass Cartesian2DUnit
51 #define thisTTClassName "unit.cart2d"
52 #define thisTTClassTags "dataspace.unit, position"
53 
55 TTDataspaceUnit(arguments)
56 {;}
57 
58 Cartesian2DUnit::~Cartesian2DUnit(){;}
59 
61 {
62  TTFloat64 x;
63  TTFloat64 y;
64 
65  x = input[0];
66  y = input[1];
67 
68  output.resize(3);
69  output[0] = x;
70  output[1] = y;
71  output[2] = 0.0;
72 }
73 
75 {
76  output = input;
77  output.resize(2);
78 }
79 
80 
81 #undef thisTTClass
82 #undef thisTTClassName
83 #undef thisTTClassTags
84 
85 /***********************************************************************************************/
86 
87 #define thisTTClass SphericalUnit
88 #define thisTTClassName "unit.spherical"
89 #define thisTTClassTags "dataspace.unit, position"
90 
92 TTDataspaceUnit(arguments)
93 {;}
94 
95 SphericalUnit::~SphericalUnit(){;}
96 
97 void SphericalUnit::convertToNeutral(const TTValue& input, TTValue& output)
98 {
99  //TTFloat64 kTTDegreesToRadians = kTTDegreesToRadians;
100  TTFloat64 aa;//a
101  TTFloat64 ee;//e
102  TTFloat64 dd;//d
103  TTFloat64 temp;
104 
105  aa = input[0];
106  ee = input[1];
107  dd = input[2];
108 
109  aa *= kTTDegreesToRadians;
110  ee *= kTTDegreesToRadians;
111  temp = cos(ee) * dd;
112 
113  output.resize(3);
114  output[0] = sin(aa) * temp;
115  output[1] = cos(aa) * temp;
116  output[2] = sin(ee) * dd;
117 }
118 
119 
121 {
122  TTFloat64 xx;
123  TTFloat64 yy;
124  TTFloat64 zz;
125  TTFloat64 temp;
126 
127  xx = input[0];
128  yy = input[1];
129  zz = input[2];
130 
131  temp = (xx * xx) + (yy * yy);
132 
133  output.resize(3);
134  output[0] = atan2(xx, yy) * kTTRadiansToDegrees;
135  output[1] = atan2(zz, (pow((temp), 0.5))) * kTTRadiansToDegrees;
136  output[2] = pow((temp + (zz * zz)), 0.5);
137 }
138 
139 
140 #undef thisTTClass
141 #undef thisTTClassName
142 #undef thisTTClassTags
143 
144 /***********************************************************************************************/
145 
146 #define thisTTClass PolarUnit
147 #define thisTTClassName "unit.polar"
148 #define thisTTClassTags "dataspace.unit, position"
149 
151 TTDataspaceUnit(arguments)
152 {;}
153 
154 PolarUnit::~PolarUnit(){;}
155 
156 void PolarUnit::convertToNeutral(const TTValue& input, TTValue& output)
157 {
158  TTFloat64 aa;
159  TTFloat64 dd;
160 
161  aa = input[0];
162  dd = input[1];
163  aa *= kTTDegreesToRadians;
164 
165  output.resize(3);
166  output[0] = sin(aa) * dd; // x
167  output[1] = cos(aa) * dd; // y
168  output[2] = 0; // z
169 }
170 
171 
172 void PolarUnit::convertFromNeutral(const TTValue& input, TTValue& output)
173 {
174  TTFloat64 xx;
175  TTFloat64 yy;
176 
177  xx = input[0];
178  yy = input[1];
179 
180  output.resize(2);
181  output[0] = atan2(xx, yy) * kTTRadiansToDegrees; //a
182  output[1] = pow(((xx * xx) + (yy * yy)), 0.5); //distance
183 }
184 
185 
186 #undef thisTTClass
187 #undef thisTTClassName
188 #undef thisTTClassTags
189 
190 /***********************************************************************************************/
191 
192 #define thisTTClass OpenGlUnit
193 #define thisTTClassName "unit.openGL"
194 #define thisTTClassTags "dataspace.unit, position"
195 
197 TTDataspaceUnit(arguments)
198 {;}
199 
200 OpenGlUnit::~OpenGlUnit(){;}
201 
202 void OpenGlUnit::convertToNeutral(const TTValue& input, TTValue& output)
203 {
204  TTFloat64 x;
205  TTFloat64 y;
206  TTFloat64 z;
207 
208  x = input[0];
209  y = input[1];
210  z = input[2];
211 
212  output.resize(3);
213  output[0] = x;
214  output[1] = -1.0 * z;
215  output[2] = y;
216 }
217 
218 
219 void OpenGlUnit::convertFromNeutral(const TTValue& input, TTValue& output)
220 {
221  TTFloat64 x;
222  TTFloat64 y;
223  TTFloat64 z;
224 
225  x = input[0];
226  y = input[1];
227  z = input[2];
228 
229  output.resize(3);
230  output[0] = x;
231  output[1] = z;
232  output[2] = y * -1.0;
233 }
234 
235 
236 #undef thisTTClass
237 #undef thisTTClassName
238 #undef thisTTClassTags
239 
240 /***********************************************************************************************/
241 
242 #define thisTTClass CylindricalUnit
243 #define thisTTClassName "unit.cylindrical"
244 #define thisTTClassTags "dataspace.unit, position"
245 
247 TTDataspaceUnit(arguments)
248 {;}
249 
250 CylindricalUnit::~CylindricalUnit(){;}
251 
252 // Cylindrical coordinate System (according to ISO 31-11 http://en.wikipedia.org/wiki/ISO_31-11#Coordinate_systems ) = radius azimut hight
253 
255 {
256  TTFloat64 dd;
257  TTFloat64 aa;
258  TTFloat64 zz;
259 
260  dd = input[0];
261  aa = input[1];
262  zz = input[2];
263  aa *= kTTDegreesToRadians;
264 
265  output.resize(3);
266  output[0] = sin(aa) * dd; //x
267  output[1] = cos(aa) * dd; //y
268  output[2] = zz; //z
269 }
270 
271 
273 {
274  TTFloat64 xx;
275  TTFloat64 yy;
276  TTFloat64 zz;
277 
278  xx = input[0];
279  yy = input[1];
280  zz = input[2];
281 
282  // d a z
283  output.resize(3);
284  output[0] = pow(((xx * xx) + (yy * yy)), 0.5); //distance
285  output[1] = atan2(xx, yy) * kTTRadiansToDegrees; //a
286  output[2] = zz; //z
287 }
288 
289 
290 #undef thisTTClass
291 #undef thisTTClassName
292 #undef thisTTClassTags
293 
294 /***********************************************************************************************/
295 
296 #define thisTTClass PositionDataspace
297 #define thisTTClassName "dataspace.position"
298 #define thisTTClassTags "foundationDataspaceLib, dataspace, position"
299 
301 {
302  // Create one of each kind of unit, and cache them in a hash
303  registerUnit(TT("unit.cart3d"), TT("cart3D"));
304  registerUnit(TT("unit.cart3d"), TT("xyz"));
305  registerUnit(TT("unit.cart2d"), TT("cart2D"));
306  registerUnit(TT("unit.cart2d"), TT("xy"));
307  registerUnit(TT("unit.spherical"), TT("spherical"));
308  registerUnit(TT("unit.spherical"), TT("aed"));
309  registerUnit(TT("unit.polar"), TT("polar"));
310  registerUnit(TT("unit.polar"), TT("ad"));
311  registerUnit(TT("unit.openGL"), TT("openGL"));
312  registerUnit(TT("unit.cylindrical"), TT("cylindrical"));
313  registerUnit(TT("unit.cylindrical"), TT("daz"));
314 
315  // Set our neutral unit (the unit through which all conversions are made)
316  neutralUnit = TT("xyz");
317 
318  // Now that the cache is created, we can create a set of default units
319  setInputUnit(neutralUnit);
320  setOutputUnit(neutralUnit);
321 }
322 
323 
324 PositionDataspace::~PositionDataspace()
325 {
326  ;
327 }
328 
329 #undef thisTTClass
330 #undef thisTTClassName
331 #undef thisTTClassTags
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to polar coordinates.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from 2D Cartesian coordinates to neutral unit.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from 3D Cartesian coordinates to neutral unit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to cylindrical coordinates.
The PositionDataspace converts between different untis describing position.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to spherical coordinates.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from cylindrical coordinates to neutral unit.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to OpenGL coordinates.
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
TTFOUNDATION_EXPORT const TTFloat64 kTTRadiansToDegrees
Factor constant for converting radians to degrees.
Definition: TTBase.cpp:32
Specification for the base class of each DataspaceUnit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to 3D Cartesian coordinates.
TTFOUNDATION_EXPORT const TTFloat64 kTTDegreesToRadians
Factor constant for converting degrees to radians.
Definition: TTBase.cpp:33
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to 2D Cartesian coordinates.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from spherical coordinates to neutral unit.
TT_OBJECT_CONSTRUCTOR
Constructor macro.
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from polar coordinates to neutral unit.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from OpenGL coordinates to neutral unit.