Are there any specific requirements to observe vtkMRMLCameraNode events in C++ module logic?
Python code works as it should, and i can see “update beam” message
def updateBeamFromCamera(caller=None, event=None):
print("update beam")
cameraObs = threeDcamera.AddObserver( vtk.vtkCommand.ModifiedEvent, updateBeamFromCamera)
But i can’t observe any camera node events in C++ module.
Did i miss something obvious?
Here is a part of C++ code
//-----------------------------------------------------------------------------
void vtkSlicerSomeLogic::RegisterNodes()
{
vtkMRMLScene* scene = this->GetMRMLScene();
if (!scene)
{
vtkErrorMacro("RegisterNodes: Invalid MRML scene");
return;
}
if (!scene->IsNodeClassRegistered("vtkMRMLCameraNode"))
{
vtkWarningMacro("OnMRMLSceneNodeAdded: camera registered");
scene->RegisterNodeClass(vtkSmartPointer<vtkMRMLCameraNode>::New());
}
}
//---------------------------------------------------------------------------
void vtkSlicerSomeLogic::OnMRMLSceneNodeAdded(vtkMRMLNode* node)
{
if (!node || !this->GetMRMLScene())
{
vtkErrorMacro("OnMRMLSceneNodeAdded: Invalid MRML scene or input node");
return;
}
if (node->IsA("vtkMRMLCameraNode"))
{
vtkWarningMacro("OnMRMLSceneNodeAdded: Observe camera events");
// Observe camera events
vtkNew<vtkIntArray> events;
events->InsertNextValue(vtkCommand::ModifiedEvent);
vtkObserveMRMLNodeEventsMacro(node, events);
}
}
//----------------------------------------------------------------------------
void vtkSlicerSomeLogic::ProcessMRMLNodesEvents(vtkObject* caller, unsigned long event, void* callData)
{
Superclass::ProcessMRMLNodesEvents(caller, event, callData);
vtkMRMLScene* mrmlScene = this->GetMRMLScene();
if (!mrmlScene)
{
vtkErrorMacro("ProcessMRMLNodesEvents: Invalid MRML scene");
return;
}
if (mrmlScene->IsBatchProcessing())
{
return;
}
if (caller->IsA("vtkMRMLCameraNode"))
{
vtkMRMLCameraNode* cameraNode = vtkMRMLCameraNode::SafeDownCast(caller);
if (event == vtkCommand::ModifiedEvent)
{
vtkWarningMacro("ProcessMRMLNodesEvents: Camera modified");
}
else
{
vtkWarningMacro("ProcessMRMLNodesEvents: Other events");
}
}
}