1SoCalculator(3IV)() SoCalculator(3IV)()
2
3
4
6 SoCalculator — a general-purpose calculator
7
9 SoBase > SoFieldContainer > SoEngine > SoCalculator
10
12 #include <Inventor/engines/SoCalculator.h>
13
14 Inputs from class SoCalculator:
15
16 SoMFFloat a
17 SoMFFloat b
18 SoMFFloat c
19 SoMFFloat d
20 SoMFFloat e
21 SoMFFloat f
22 SoMFFloat g
23 SoMFFloat h
24 SoMFVec3f A
25 SoMFVec3f B
26 SoMFVec3f C
27 SoMFVec3f D
28 SoMFVec3f E
29 SoMFVec3f F
30 SoMFVec3f G
31 SoMFVec3f H
32 SoMFString expression
33
34 Outputs from class SoCalculator:
35
36 (SoMFFloat) oa
37 (SoMFFloat) ob
38 (SoMFFloat) oc
39 (SoMFFloat) od
40 (SoMFVec3f) oA
41 (SoMFVec3f) oB
42 (SoMFVec3f) oC
43 (SoMFVec3f) oD
44
45 Methods from class SoCalculator:
46
47 SoCalculator()
48
49 Methods from class SoEngine:
50
51 static SoType getClassTypeId()
52 virtual int getOutputs(SoEngineOutputList &list) const
53 SoEngineOutput * getOutput(const SbName &outputName) const
54 SbBool getOutputName(const SoEngineOutput *output, SbName
55 &outputName) const
56 SoEngine * copy() const
57 static SoEngine * getByName(const SbName &name)
58 static int getByName(const SbName &name, SoEngineList &list)
59
60 Methods from class SoFieldContainer:
61
62 void setToDefaults()
63 SbBool hasDefaultValues() const
64 SbBool fieldsAreEqual(const SoFieldContainer *fc) const
65 void copyFieldValues(const SoFieldContainer *fc, SbBool
66 copyConnections = FALSE)
67 SbBool set(const char *fieldDataString)
68 void get(SbString &fieldDataString)
69 virtual int getFields(SoFieldList &resultList) const
70 virtual SoField * getField(const SbName &fieldName) const
71 SbBool getFieldName(const SoField *field, SbName &fieldName)
72 const
73 SbBool isNotifyEnabled() const
74 SbBool enableNotify(SbBool flag)
75
76 Methods from class SoBase:
77
78 void ref()
79 void unref() const
80 void unrefNoDelete() const
81 void touch()
82 virtual SoType getTypeId() const
83 SbBool isOfType(SoType type) const
84 virtual void setName(const SbName &name)
85 virtual SbName getName() const
86
87
89 This engine is a general-purpose calculator. The calculator operates on
90 floating-point values and 3D floating-point vectors. The engine takes
91 up to eight inputs of each type (SoMFFloat and SoMFVec3f), and produces
92 up to four outputs of each type.
93
94 Each input field (a-h, A-H) can have multiple values, allowing the
95 engine to evaluate the expression with different values in parallel.
96 Some inputs may have more values than others. In such cases, the last
97 value of the shorter inputs will be repeated as necessary.
98
99 The expression input string specifies the expression to be evaluated.
100 An expression can consist of multiple subexpressions. Several subex‐
101 pressions can be specified in one string, separated by semicolons (;).
102 Alternatively, the subexpressions can be stored in separate strings in
103 the multiple-valued input field.
104
105 Each subexpression is of the form:
106
107 <lhs> = <rhs>
108
109 The <lhs> can be any one of the outputs or a temporary variable. The
110 engine provides 8 temporary floating-point variables (ta, tb, tc, td, te,
111 tf, tg, and th), and 8 temporary vector variables (tA, tB, tC, tD, tE,
112 tF, tG, and tH). You can assign a value to one component of a vector out‐
113 put (A-H) or a vector variable (tA-tH) by using the [] operator. For
114 example, oA[0] = <rhs>, will evaluate the right hand side and assign the
115 value to the first component of the output vector oA.
116
117 The <rhs> supports arithmetic, logical and conditional operators. They
118 are:
119
120 (unary) !, -
121 (binary) +, -, *, /, %, <, > <=, >=, ==, !=, &&, ||
122 (ternary) ? :
123
124 The ternary operator is a conditional operator. For example, a ? b : c
125 evaluates to b if a != 0, and to c if a==0.
126
127 Valid operands for the <rhs> include the inputs, outputs, temporary vari‐
128 ables, and their components (e.g. oA[0]). Operands can also be numeric
129 constants (e.g. 1.0), pre-defined named constants, or pre-defined func‐
130 tions.
131
132 The named constants are:
133
134 MAXFLOAT
135 MINFLOAT
136 M_E
137 M_LOG2E
138 M_LOG10E
139 M_LN2
140 M_LN10
141 M_PI
142 M_SQRT2 = sqrt(2)
143 M_SQRT1_2 = sqrt(1/2)
144
145 Most of the pre-defined functions come from the math library:
146
147 cos, sin, tan,
148 acos, asin, atan, atan2,
149 cosh, sinh, tanh,
150 sqrt, pow, exp, log, log10,
151 ceil, floor, fabs, fmod.
152
153 Other functions are defined by SoCalculator. They are:
154
155 rand(f) - Random number generator
156 cross(v1, v2) - Vector cross product
157 dot(v1, v2) - Vector dot product
158 length(v) - Vector length
159 normalize(v) - Normalize vector
160 vec3f(f1, f2, f3) - Generate a vector from 3 floats
161
162 The subexpressions are evaluated in order, so a variable set in the <lhs>
163 of an earlier expression may be used in the <rhs> of a later expression.
164
165 Note, when the input has multiple values, all the subexpressions speci‐
166 fied in the expression are applied to all the multiple input values. This
167 is unlike the SoBoolOperation engine, where each operation is applied
168 only to the corresponding entries of the input data. Note also, that even
169 though the inputs and outputs can have multiple values the [] operator is
170 only for indexing into the values of a single vector. It does not index
171 into the multiple values of a field. For example, if the floating-point
172 input field a has two values: 1.0, and 2.0, then the expression
173
174 "oA[0]=a; oA[1]=a; oA[2]=0.0"
175
176 will produce two output vectors in oA: (1.0, 1.0, 0.0) and (2.0, 2.0,
177 0.0).
178
179 Examples of expressions:
180
181 "ta = oA[0]*floor(a)"
182 "tb = (a+b)*sin(M_PI)"
183 "oA = vec3f(ta, tb, ta+tb)"
184 "oB = normalize(oA)"
185 "ta = a; tb = sin(ta); oA = vec3f(ta, tb, 0)"
186
187
189 SoMFFloat a
190 SoMFFloat b
191 SoMFFloat c
192 SoMFFloat d
193 SoMFFloat e
194 SoMFFloat f
195 SoMFFloat g
196 SoMFFloat h
197 Inputs a-h are the floating-point values.
198
199 SoMFVec3f A
200 SoMFVec3f B
201 SoMFVec3f C
202 SoMFVec3f D
203 SoMFVec3f E
204 SoMFVec3f F
205 SoMFVec3f G
206 SoMFVec3f H
207 Inputs A-H are the vectors.
208
209 SoMFString expression
210 The expression to be evaluated.
211
212
214 (SoMFFloat) oa
215 (SoMFFloat) ob
216 (SoMFFloat) oc
217 (SoMFFloat) od
218 Outputs oa-od are the floating-point values.
219
220 (SoMFVec3f) oA
221 (SoMFVec3f) oB
222 (SoMFVec3f) oC
223 (SoMFVec3f) oD
224 Outputs oA-oD are the vectors.
225
226
228 SoCalculator()
229 Constructor
230
231
233 Calculator {
234 a 0
235 b 0
236 c 0
237 d 0
238 e 0
239 f 0
240 g 0
241 h 0
242 A 0 0 0
243 B 0 0 0
244 C 0 0 0
245 D 0 0 0
246 E 0 0 0
247 F 0 0 0
248 G 0 0 0
249 H 0 0 0
250 expression ""
251 }
252
254 SoEngineOutput, SoBoolOperation
255
256
257
258
259 SoCalculator(3IV)()