Observing modification of table node from the other node and logic

Greetings,

A couple of questions of loadable module development, some general stuff.

  1. What king of event generated when cells in table node are modified
    via “Tables” module or in table viewer?
    vtkCommand::ModifiedEvent,
    vtkMRMLTableNode::ReferencedNodeModifiedEvent,
    vtkMRMLTableNode::ReferenceModifiedEvent

  2. What overridden methods in logic must be modified to process a table node modifications?
    vtkMyModuleLogic::ProcessMRMLNodesEvents,
    vtkMyModuleLogic::OnMRMLSceneNodeAdded,
    vtkMyModuleLogic::SetMRMLSceneInternal

  3. When module logic is ready to process table node events, and table node on the same scene with other node , how should i observe table node from other node?
    other_node->SetNodeReferenceID( "Role", tableNode->GetID());
    or
    other_node->SetAndObserveNodeReferenceID( "Role", tableNode->GetID());

Best regards,
Mikhail

When you modify a cell in a table, it invokes vtkCommand::ModifiedEvent event on the vtkMRMLTableNode.

vtkMRMLNode::ReferencedNodeModifiedEvent and vtkMRMLNode::ReferenceModifiedEvent invoked on a node that references another node. If you reference a table node from node A, then ReferencedNodeModifiedEvent will be invoked on A if the table is modified; and ReferenceModifiedEvent will be invoked if you switch which table node you reference.

If you want to observe all changes of all table nodes in the scene then you need to observe all scene setting and scene node added/removed/batch update events so that you can add observer to all table nodes, and then override ProcessMRMLNodesEvents to get notification about changes in any nodes. See for example vtkSlicerBreachWarningLogic.

You observe changes of another node from a module logic as I described above.

If you want to observe referenced node changes from another node then you need to declare the node reference role in the constructor (specifying which events you want to observe) and add node reference using SetAndObserveNodeReferenceID. See for example vtkMRMLTransformableNode.

1 Like

Thank you for explanation!

The easiest method was using logic class by adding observer to table node modified event in
OnMRMLSceneNodeAdded, and then process table node events in ProcessMRMLNodesEvents.

Offtopic: The developer manual doesn’t recommend using C++11 elements, but many modules have override, default keywords, std::array variables and nullptr. What about using java-like cycles, auto, lambda expressions and initializer lists?

The developer manual has not been updated. I would say Slicer follows VTK conventions in this (which is now accepts usage of most C++11 features).