Class SoCalculator
- java.lang.Object
-
- com.openinventor.inventor.Inventor
-
- com.openinventor.inventor.misc.SoBase
-
- com.openinventor.inventor.fields.SoFieldContainer
-
- com.openinventor.inventor.engines.SoEngine
-
- com.openinventor.inventor.engines.SoCalculator
-
- All Implemented Interfaces:
SafeDisposable
public class SoCalculator extends SoEngine
A general-purpose calculator. This engine is a general-purpose calculator. The calculator operates on floating-point values and 3D floating-point vectors. The engine takes up to eight inputs of each type (SoMFFloat
andSoMFVec3f
), and produces up to four outputs of each type.Each input field (
a
-h
,A
-H
) can have multiple values, allowing the engine to evaluate the expression with different values in parallel. Some inputs may have more values than others. In such cases, the last value of the shorter inputs will be repeated as necessary.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 (;). Alternatively, the subexpressions can be stored in separate strings in the multiple-valued input field.Each subexpression is of the form:
The <lhs> can be any one of the outputs 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 (\<lhs\> = \<rhs\> A
-H
) or a vector variable ( tA - tH ) by using the [ ] operator. For example, oA[0] = <rhs>, will evaluate the right hand side and assign the value to the first component of the output vectoroA
.The <rhs> supports arithmetic, logical and conditional operators. They are:
The ternary operator is a conditional operator. For example, a ? b : c evaluates to b if a != 0, and to c if a==0.(unary) !, - (binary) +, -, *, /, \%, <, > <=, >=, ==, !=, &&, || (ternary) ? : 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:
Most of the pre-defined functions come from the math library:MAXFLOAT MINFLOAT M_E M_LOG2E M_LOG10E M_LN2 M_LN10 M_PI M_SQRT2 = sqrt(2) M_SQRT1_2 = sqrt(1/2)
Other functions are defined bycos, sin, tan, acos, asin, atan, atan2, cosh, sinh, tanh, sqrt, pow, exp, log, log10, ceil, floor, fabs, fmod. SoCalculator
. They are:
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.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 Note, when the input has multiple values, all the subexpressions specified in the
expression
are applied to all the multiple input values. This is unlike theSoBoolOperation
engine, where each operation is applied only to the corresponding entries of the input data. Note also, that even though the inputs and outputs can have multiple values the [ ] operator is only for indexing into the values of a single vector. It does not index into the multiple values of a field. For example, if the floating-point input fielda
has two values: 1.0, and 2.0, then the expression
will produce two output vectors in"oA[0]=a; oA[1]=a; oA[2]=0.0" oA
: (1.0, 1.0, 0.0) and (2.0, 2.0, 0.0).Examples of expressions:
"ta = oA[0]*floor(a)" "tb = (a+b)*sin(M_PI)" "oA = vec3f(ta, tb, ta+tb)" "oB = normalize(oA)" "ta = a; tb = sin(ta); oA = vec3f(ta, tb, 0)" File format/default:
Calculator {
a 0 b 0 c 0 d 0 e 0 f 0 g 0 h 0 A 0 0 0 B 0 0 0 C 0 0 0 D 0 0 0 E 0 0 0 F 0 0 0 G 0 0 0 H 0 0 0 expression "" - See Also:
SoEngineOutput
,SoBoolOperation
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand
-
-
Field Summary
Fields Modifier and Type Field Description SoMFFloat
a
Floating point input.SoMFVec3f
A
Vector input.SoMFFloat
b
Floating point input.SoMFVec3f
B
Vector input.SoMFFloat
c
Floating point input.SoMFVec3f
C
Vector input.SoMFFloat
d
Floating point input.SoMFVec3f
D
Vector input.SoMFFloat
e
Floating point input.SoMFVec3f
E
Vector input.SoMFString
expression
Expressions to be evaluated.SoMFFloat
f
Floating point input.SoMFVec3f
F
Vector input.SoMFFloat
g
Floating point input.SoMFVec3f
G
Vector input.SoMFFloat
h
Floating point input.SoMFVec3f
H
Vector input.SoEngineOutput
oa
(SoMFFloat
) Outputs oa-od are the floating-point values.SoEngineOutput
oA
(SoMFVec3f
) Outputs oA-oD are the vectors.SoEngineOutput
ob
(SoMFFloat
) Outputs oa-od are the floating-point values.SoEngineOutput
oB
(SoMFVec3f
) Outputs oA-oD are the vectors.SoEngineOutput
oc
(SoMFFloat
) Outputs oa-od are the floating-point values.SoEngineOutput
oC
(SoMFVec3f
) Outputs oA-oD are the vectors.SoEngineOutput
od
(SoMFFloat
) Outputs oa-od are the floating-point values.SoEngineOutput
oD
(SoMFVec3f
) Outputs oA-oD are the vectors.-
Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle
-
-
Constructor Summary
Constructors Constructor Description SoCalculator()
Constructor.
-
Method Summary
-
Methods inherited from class com.openinventor.inventor.engines.SoEngine
copy, getByName, getOutput, getOutputName
-
Methods inherited from class com.openinventor.inventor.fields.SoFieldContainer
copyFieldValues, copyFieldValues, enableNotify, fieldsAreEqual, get, getAllFields, getEventIn, getEventOut, getField, getFieldName, hasDefaultValues, isNotifyEnabled, set, setToDefaults
-
Methods inherited from class com.openinventor.inventor.misc.SoBase
dispose, getName, isDisposable, isSynchronizable, setName, setSynchronizable, touch
-
Methods inherited from class com.openinventor.inventor.Inventor
getNativeResourceHandle
-
-
-
-
Field Detail
-
a
public final SoMFFloat a
Floating point input.
-
b
public final SoMFFloat b
Floating point input.
-
c
public final SoMFFloat c
Floating point input.
-
d
public final SoMFFloat d
Floating point input.
-
e
public final SoMFFloat e
Floating point input.
-
f
public final SoMFFloat f
Floating point input.
-
g
public final SoMFFloat g
Floating point input.
-
h
public final SoMFFloat h
Floating point input.
-
A
public final SoMFVec3f A
Vector input.
-
B
public final SoMFVec3f B
Vector input.
-
C
public final SoMFVec3f C
Vector input.
-
D
public final SoMFVec3f D
Vector input.
-
E
public final SoMFVec3f E
Vector input.
-
F
public final SoMFVec3f F
Vector input.
-
G
public final SoMFVec3f G
Vector input.
-
H
public final SoMFVec3f H
Vector input.
-
expression
public final SoMFString expression
Expressions to be evaluated.
-
oa
public final SoEngineOutput oa
(SoMFFloat
) Outputs oa-od are the floating-point values.
-
ob
public final SoEngineOutput ob
(SoMFFloat
) Outputs oa-od are the floating-point values.
-
oc
public final SoEngineOutput oc
(SoMFFloat
) Outputs oa-od are the floating-point values.
-
od
public final SoEngineOutput od
(SoMFFloat
) Outputs oa-od are the floating-point values.
-
oA
public final SoEngineOutput oA
(SoMFVec3f
) Outputs oA-oD are the vectors.
-
oB
public final SoEngineOutput oB
(SoMFVec3f
) Outputs oA-oD are the vectors.
-
oC
public final SoEngineOutput oC
(SoMFVec3f
) Outputs oA-oD are the vectors.
-
oD
public final SoEngineOutput oD
(SoMFVec3f
) Outputs oA-oD are the vectors.
-
-