H3D API
2.4.1
|
The function node implements a general function R^n -> R by specifying it by a string. More...
#include <H3D/GeneralFunction.h>
Classes | |
class | SFFunctionObject |
Class for updating an HAPI::ParsedFunction depending on field input value. More... | |
Public Member Functions | |
GeneralFunction (Inst< SFNode > _metadata=0, Inst< SFString > _function=0, Inst< SFString > _params=0, Inst< SFFunctionObject > _functionObject=0) | |
Constructor. | |
virtual unsigned int | nrInputValues () |
Returns the number of input values the function takes. | |
virtual HAPI::HAPIFunctionObject * | getAsHAPIFunctionObject () |
Returns the function as a HAPIFunctionObject. More... | |
H3DDouble | evaluate (H3DDouble *x) |
Evaluate the function. | |
![]() | |
H3DFunctionNode (Inst< SFNode > _metadata=0, Inst< MFDouble > _input=0, Inst< Value > _output=0) | |
Constructor. | |
H3DDouble | evaluate (H3DDouble _input) |
Shortcut for functions just taking one input. | |
H3DDouble | get (H3DDouble _input) |
Same as evaluate(). For backwards compatability. | |
virtual string | defaultXMLContainerField () |
Returns the default xml containerField attribute value. More... | |
![]() | |
X3DNode (Inst< SFNode > _metadata=0) | |
Constructor. | |
X3DMetadataObject * | getMetadataByName (const string &_name) |
Given a name, the first X3DMetadataObject in the metadata field that matches that name is returned. More... | |
![]() | |
Node () | |
Constructor. | |
virtual Node * | clone (bool deepCopy=true, DeepCopyMap *deepCopyMap=NULL) |
Returns a new instance of this node type with the same state as this one. More... | |
virtual | ~Node () |
Destructor. | |
X3DPrototypeInstance * | getProtoInstanceParent () |
If this node is the root node in the proto body of a X3DPrototypeInstance then this will return that node. More... | |
void | setProtoInstanceParent (X3DPrototypeInstance *p) |
Set the X3DPrototypeInstance this node is the the root node if applicaple. | |
virtual void | render () |
the render() function is used for the depth-first rendering traversal of the scene-graph. More... | |
virtual void | traverseSG (TraverseInfo &ti) |
traverseSG is called once per scenegraph loop on the scene in order to traverse the scenegraph. More... | |
virtual bool | lineIntersect (const Vec3f &from, const Vec3f &to, LineIntersectResult &result) |
Detect intersection between a line segment and the Node. More... | |
virtual void | closestPoint (const Vec3f &p, NodeIntersectResult &result) |
Find closest point on Node to p. More... | |
virtual bool | movingSphereIntersect (H3DFloat radius, const Vec3f &from, const Vec3f &to, NodeIntersectResult &result) |
Detect collision between a moving sphere and the Node. More... | |
virtual Field * | getField (const string &_name) const |
return a pointer to the field specified by name within this instance | |
int | addDestructCallback (void(*func)(Node *, void *), void *args) |
Add a callback function to be run on destruction of node. More... | |
int | removeDestructCallback (void(*func)(Node *, void *), void *args) |
Add a callback function to be run on destruction of node. More... | |
Public Attributes | |
H3DUniquePtr< SFString > | function |
The function string. More... | |
H3DUniquePtr< SFString > | params |
The function parameter string. More... | |
![]() | |
H3DUniquePtr< MFDouble > | input |
Input value to the function to evaluate. | |
H3DUniquePtr< Value > | output |
Output value from the function when evaluated for the input values given in the input field. | |
H3DUniquePtr< Field > | functionChanged |
Field that indicated whether the function has changed. More... | |
![]() | |
H3DUniquePtr< SFNode > | metadata |
Meta data about the node. More... | |
Static Public Attributes | |
static H3DNodeDatabase | database |
The H3DNodeDatabase for this object. | |
![]() | |
static H3DNodeDatabase | database |
The H3DNodeDatabase for this node. | |
Protected Attributes | |
H3DUniquePtr< SFFunctionObject > | functionObject |
Field with the function object to use to evaluate the function. | |
Additional Inherited Members | |
![]() | |
typedef std::map< Node *, Node * > | DeepCopyMap |
A map type used during a deep copy clone() to map from original nodes to cloned nodes. | |
![]() | |
static unsigned int | nrNodesAlive () |
Returns the nr of nodes currently alive, i.e. nodes created but not destructed. | |
static int | nrNodesCreated () |
Returns the number of nodes created in total since the start of the program. | |
![]() | |
void | cloneFieldValue (Field &_from, Field &_to, bool deepCopy, DeepCopyMap &deepCopyMap) |
A helper function for the clone() method. More... | |
![]() | |
static Node * | getClonedInstance (Node *original, bool deepCopy, DeepCopyMap &deepCopyMap) |
A helper function for nodes that implement clone() More... | |
The function node implements a general function R^n -> R by specifying it by a string.
The function string understood by the class is very similar to the C-syntax. Arithmetic float expressions can be created from float literals, variables or functions using the following operators in this order of precedence:
() expressions in parentheses first A^B exponentiation (A raised to the power B) -A unary minus !A unary logical not (result is 1 if int(A) is 0, else 0) A*B A/B AB multiplication, division and modulo A+B A-B addition and subtraction A=B A!=B A<B A<=B A>B A>=B comparison between A and B (result is either 0 or 1) A&B result is 1 if int(A) and int(B) differ from 0, else 0 A|B result is 1 if int(A) or int(B) differ from 0, else 0
Since the unary minus has higher precedence than any other operator, for example the following expression is valid: x*-y
The class supports these functions:
abs(A) : Absolute value of A. If A is negative, returns -A otherwise returns A. acos(A) : Arc-cosine of A. Returns the angle, measured in radians, whose cosine is A. acosh(A) : Same as acos() but for hyperbolic cosine. asin(A) : Arc-sine of A. Returns the angle, measured in radians, whose sine is A. asinh(A) : Same as asin() but for hyperbolic sine. atan(A) : Arc-tangent of (A). Returns the angle, measured in radians, whose tangent is (A). atan2(A,B): Arc-tangent of A/B. The two main differences to atan() is that it will return the right angle depending on the signs of A and B (atan() can only return values betwen -pi/2 and pi/2), and that the return value of pi/2 and -pi/2 are possible. atanh(A) : Same as atan() but for hyperbolic tangent. ceil(A) : Ceiling of A. Returns the smallest integer greater than A. Rounds up to the next higher integer. cos(A) : Cosine of A. Returns the cosine of the angle A, where A is measured in radians. cosh(A) : Same as cos() but for hyperbolic cosine. cot(A) : Cotangent of A (equivalent to 1/tan(A)). csc(A) : Cosecant of A (equivalent to 1/sin(A)). eval(...) : This a recursive call to the function to be evaluated. The number of parameters must be the same as the number of parameters taken by the function. Must be called inside if() to avoid infinite recursion. exp(A) : Exponential of A. Returns the value of e raised to the power A where e is the base of the natural logarithm, i.e. the non-repeating value approximately equal to 2.71828182846. floor(A) : Floor of A. Returns the largest integer less than A. Rounds down to the next lower integer. if(A,B,C) : If int(A) differs from 0, the return value of this function is B, else C. Only the parameter which needs to be evaluated is evaluated, the other parameter is skipped; this makes it safe to use eval() in them. int(A) : Rounds A to the closest integer. 0.5 is rounded to 1. log(A) : Natural (base e) logarithm of A. log10(A) : Base 10 logarithm of A. max(A,B) : If A>B, the result is A, else B. min(A,B) : If A<B, the result is A, else B. sec(A) : Secant of A (equivalent to 1/cos(A)). sin(A) : Sine of A. Returns the sine of the angle A, where A is measured in radians. sinh(A) : Same as sin() but for hyperbolic sine. sqrt(A) : Square root of A. Returns the value whose square is A. tan(A) : Tangent of A. Returns the tangent of the angle A, where A is measured in radians. tanh(A) : Same as tan() but for hyperbolic tangent.
Examples of function string understood by the class:
"1+2" "x-1" "-sin(sqrt(x^2+y^2))" "sqrt(x*x + y*y)"
An example of a recursive function is the factorial function:
"if(n>1, n*eval(n-1), 1)"
Below are some examples for how to specify fields for some functions: Function Function field Params field f(x) = 2*x "2*x" "x" f(s,t) = s + t "s+t" "s,t" f(a) = cos(a) "cos(a)" "a"
Examples:
|
virtual |
Returns the function as a HAPIFunctionObject.
Should return a new copy if the H3DFunctionNode stores a copy of HAPIFunctionObject since owner ship of the returned HAPIFunctionObject should be considered to belong to the caller of the function. Returns NULL if the H3DFunctionNode can not be represented as a HAPIFunctionObject.
Reimplemented from H3D::H3DFunctionNode.
References function, H3DUtil::RefCountedClass::getName(), and params.
H3DUniquePtr< SFString > H3D::GeneralFunction::function |
The function string.
E.g. Function Function string f(x) = 2*x "2*x"
f(s,t) = s + t "s+t"
Access type: inputOutput
Default value: "x"
Referenced by getAsHAPIFunctionObject().
H3DUniquePtr< SFString > H3D::GeneralFunction::params |
The function parameter string.
Decides the order of the unknowns when evaluating the function E.g.
f(x) = 2*x "x"
f(s,t) = s + t "s,t"
Access type: inputOutput
Default value: 1
Referenced by GeneralFunction(), getAsHAPIFunctionObject(), and nrInputValues().