HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Abusing SOP Cook Mechanism

You can override the SOP cook mechanism to compute whatever type of data you wish, not just GU_Detail.

The first step is how to attach your custom data to a GU_Detail. One approach is with a very large detail integer attribute. Being a detail attribute, only one copy will exist regardless of the number of other regular primitives and points added. Being integer, it can hold any valid byte string. Finally, being an attribute, you know it will be freed when the GU_Detail is. The disadvantage is that the structure has to be flat, not having any pointers, which may require difficult marshalling.

Another approach is to just store a handle to your geometry in the GU_Detail. Again, a detail integer attribute could be used to store the unique index to your object. One issue with this approach is that you are not alerted when GU_Detail are destroyed so it can be difficult to properly reference count. A good first approximation can be had by having the SOP_Node own a copy, but this can run into issues if you pass through SOPs that are not aware of your structure.

The SOP_Node::cookMySop can then load the data, either from the input detail attribute or from using the input's handle to lookup your structure. After relevant computation, the result can be stored in the local gdp for other SOPs to see.

The euclid/SOP_Euclid.C example demonstrates the handle based approach. A roughly external euclid/EUC_Expression.C, euclid/EUC_Expression.h, euclid/EUC_Object.C, and euclid/EUC_Object.h represent a simple geometry library using only points, lines, and circles. The euclid/SOP_Euclid.C then defines a series of SOPs that are aware of these expressions and perform intersections, line construction, etc, based on them. The actual data in the GU_Detail is only a single integer detail attribute giving the handle number. To properly free unused handles, the SOP_Node itself uses reference counting to track the lifetime of the handle.

Not only does one gain the advantage of the SOP cook mechanism, Houdini parameters, and Houdini handles, one also gains the ability to build digital assets out of your new operators.

Finally, to see anything in the viewport you need to override the display of the relevant GU_Detail. This is done in euclid/GR_Euclid.C