neuray API Programmer's Manual

mi::neuraylib::IExpression_temporary Class Reference

[MDL type system]

Description

A temporary reference expression. Temporary reference expressions are used to make the structure of DAGs (directed acyclic graphs) more explicit. Consider a diamond-shaped graph with four nodes A, B, C, and D. Node A references nodes B and C, and both nodes B and C reference node D.

Figure 1. Diamond-shaped graph
Figure 2. Diamond-shaped graph
When traversing this graph starting at node A, it could be important to realize when the node D is visited a second time (to avoid double work for node D, or to avoid misinterpreting the graph as a tree).

Note that in this example we use letters to identify the nodes. But expressions themselves do not have names. And the neuray API does not guarantee identical pointer addresses for repeated accesses to the (logically) same object. For example, repeated calls of mi::neuraylib::IExpression_direct_call::get_arguments() followed by mi::neuraylib::IExpression_list::get_expression() result in different pointers, although logically the result is always the same (for the same input). Therefore, a different mechanism is needed to recognize nodes that can be visited several times in a traversal.

This is where temporary references come into play. In an expression graph for the example above, the nodes B and C do not point directly to node D, but to two temporary reference expressions, both with the same index. The node D can then be retrieved by passing that index to mi::neuraylib::IFunction_definition::get_temporary() or mi::neuraylib::ICompiled_material::get_temporary().

Figure 3. Same graph, but with temporary references
Figure 4. Same graph, but with temporary references
A common idiom is to traverse temporaries first, storing the result for each temporary, and to use them when encountering the corresponding temporary reference. Alternatively, one can traverse temporaries when encountered on-demand, store the result for each temporary, and reuse the result of the first encounter of a particular temporary on later encounters of that temporary.

Note that, despite the name mi::neuraylib::IExpression_temporary, expressions of this type are not the temporaries themselves, but references to temporaries. Temporaries can be nested, i.e., a temporary with index i might contain temporary references for other temporaries with indices up to i-1.

Temporary reference expressions appear in fields (and temporaries) of compiled materials, and in the bodies (and temporaries) of function and material definitions.

Public Member Functions

virtual Size get_index() const =0
Returns the index of the referenced temporary.
virtual void set_index( Size index) =0
Sets the index of the referenced temporary.

Static Public Variables

static const Kind s_kind = EK_TEMPORARY
The kind of this subclass.

Member Functions

virtual Size mi::​neuraylib::​IExpression_temporary::get_index() const [pure virtual]

Returns the index of the referenced temporary.

virtual void mi::​neuraylib::​IExpression_temporary::set_index( Size index) [pure virtual]

Sets the index of the referenced temporary.

Variables

const Kind mi::​neuraylib::​IExpression_temporary::s_kind = EK_TEMPORARY [static]

The kind of this subclass.