genre | Fields |
author | Florian Link |
package | MeVisLab/Standard |
dll | SoUtils |
definition | utils.def |
see also | SoClipBox, ComposePlane, CalculateAngle, ComposeMatrix, ComposeMatrix, ComposePlane, ComposeVector, DecomposeMatrix, DecomposeVector |
keywords | iv, compute, calculate, plane, synchronized, distance, parallel |
The module SoCalculator calculates by evaluating expressions (with access to input/output fields) and writing the result to the output fields.
The SoCalculator has 7 input float fields named a-g and 7 input vectors named va-vg. It has 4 output float fields named oa-ad and 4 output vectors named ova-ovd.
The expression input string specifies the expression to be evaluated. An expression can consist of multiple subexpressions. Several subexpressions can be specified in one string, separated by semicolons (;) (newline characters are filtered automatically).
Each subexpression is of the form:
<lhs> = <rhs>
The <lhs> can be any one of the outputs (oa-ad, ova-ovd) or a temporary variable. The engine provides 8 temporary floating-point variables (ta, tb, tc, td, te, tf, tg, and th), and 8 temporary vector variables (tA, tB, tC, tD, tE, tF, tG, and tH). You can assign a value to one component of a vector output (ova-ovd) or a vector variable (tA-tH) by using the [ ] operator. For example, ova[0] = <rhs>, will evaluate the right hand side and assign the value to the first component of the output vector ova.
The <rhs> supports arithmetic, logical and conditional operators. They are:
(unary) !, -
(binary) +, -, *, /, %, <, > <=, >=, ==, !=, &&, ||
(ternary) ? :
The ternary operator is a conditional operator. For example, a ? b : c evaluates to b if a != 0, and to c if a==0.
Valid operands for the <rhs> include the inputs, outputs, temporary variables, and their components (e.g. oA[0]). Operands can also be numeric constants (e.g. 1.0), pre-defined named constants, or pre-defined functions.
The named constants are:
MAXFLOAT
MINFLOAT
M_E
M_LOG2E
M_LOG10E
M_LN2
M_LN10
M_PI
M_SQRT2 = sqrt(2)
M_SQRT1_2 = sqrt(1/2)
Most of the pre-defined functions come from the math library:
cos, sin, tan,
acos, asin, atan, atan2,
cosh, sinh, tanh,
sqrt, pow, exp, log, log10,
ceil, floor, fabs, fmod.
Other functions are defined by SoCalculator. They are:
rand(f) - Random number generator
cross(v1, v2) - Vector cross product
dot(v1, v2) - Vector dot product
length(v) - Vector length
normalize(v) - Normalize vector
vec3f(f1, f2, f3) - Generate a vector from 3 floats
The subexpressions are evaluated in order, so a variable set in the <lhs> of an earlier expression may be used in the <rhs> of a later expression. Comments can be inserted with #.