c++ SOP: managing persistent data on the node

   878   2   1
User Avatar
Member
2 posts
Joined: Dec. 2022
Offline
Hello, I'm pretty new to Houdini and experimenting with writing my own c++ sop node. I have some questions I'm having trouble finding answers for. Say my sop takes in two inputs. input0 = the mesh to deform. input1 = A "reference" mesh. input1 is used to compute some quantities that are used in deforming input0. The SOP will be time dependent and deform input0 on frame changes.

Now, say that computing these quantities from input1 is heavy enough such that they should really only be re-computed when input1 changes. First question is, is there a way to detect/track when an input changes? And, is there any granularity to the changes that can be detected? e.g. the points value has changed. vs the connection has been re-wired to different geometry etc?

int changed;
duplicateChangedSource(1, context, &changed);

The above apparently allows me to know when input1 has changed (btw, what is the definition of "changed"?) but I don't actually want to have the node output input1's geometry - the SOP just wants to deform input0. Is there a better way?


Second question is, say my computed quantities from input2 are wrapped in my own custom class FooData. It is data that doesn't need to persist across houdini sessions - no need to record it as an attribute the node. Imagine it's something like an octree. Is it kosher to have my SOP just keep a handle to an instance of that class? e.g.

class SOP_Foo
{
public:
...

private:
   FooData *m_data;   // some data that needs be re-computed whenever input2 changes. 
                      // should NOT be recomputed each time sop is cooked.
}

Sop_Foo::cookMySop(OP_Context &context)
{
    ...
    if (!m_data) {
        m_data = new FooData();
        m_data->doSomeHeavyComputation();
    }
}


Is it fine during the cooking of my SOP to read/write that m_data member? Or does houdini do multi-threaded(across points?) cooking and this is a race condition? Thank you in advance.
User Avatar
Staff
733 posts
Joined: Oct. 2012
Offline
For more fine-grained tracking of geometry changes, you probably want to use data ids [www.sidefx.com] to see whether the attributes or topology you're using have changed

For the second question, that approach is safe. The same SOP_Node instance will not be cooked from multiple threads at the same time.
Note that if you implement a verbified SOP (like the SOP_Star example) the verb can be executed in parallel with different inputs, e.g. in a foreach loop, but in that case you'd use SOP_NodeVerb::CookParms::cache() (after implementing SOP_NodeVerb::allocCache()) to get a unique instance of your cached data as required
User Avatar
Member
2 posts
Joined: Dec. 2022
Offline
Great, thank you.
  • Quick Links