Compute methods
 
 
 

The implementation of a dependency graph node is little more than assigning attributes and coding a compute method. The DG node is a C++ class, with the attributes being static class members. Instances of the class make up individual instances of the DG node in the graph. Plugs are separate objects which indicate the state of a particular attribute for a node.

The compute method takes its input from the attributes and plugs of an instance of the node (the default value of an attribute if there is no plug for it, or the specific value of the plug). When requesting information from a plug, the plug determines if it is in a proper state (for instance, clean). If it is not, it automatically asks the node to which it is connected to update itself. This can propagate all the way through the DG. Once all the plugs are clean, the node takes the data from the plugs (through the data blocks and data handles), computes its results and sends the output to its output attributes.

A node must not know anything outside of its attributes and plugs. For instance, it should not alter the DAG or other dependency graph nodes. Altering the DAG or another node in the DG could prompt a new DG evaluation which could cause your node to re-evaluate, causing you to alter again, which forces a new DG evaluation putting you in an infinite loop. If for some reason a node needs to know something about its environment, that knowledge should be provided as an attribute that can be connected to. Using any outside data will almost certainly violate one of the following:

The compute() method in every node must operate with only the data that is present in its parameters. If any other data is required then it should be made into an attribute. Even if it is only temporarily cached information to speed up computation, it could be useful as a hidden attribute to speed up the first refresh after file retrieval.

Also, a node must not save a reference to any of the data coming in on a plug. If, for example, surface geometry comes in on a plug, do not save a pointer to this geometry. The data coming in on a plug is transitory and may cease to exist without you knowing it. You are only guaranteed that it will exist during the execution of your node’s compute function.