Hi,
From module widget (qSlicerMyModuleWidget.cxx
) I was trying to get active camera of a 3D view and apply transform to it.
The only two working ways to do that were:
qMRMLThreeDWidget* threeDWidget = app->layoutManager()->threeDWidget('View1');
vtkCamera* camera =
threeDWidget->threeDView()->renderer()->GetActiveCamera();
and
qMRMLThreeDWidget* threeDWidget = app->layoutManager()->threeDWidget('View1');
vtkCamera* camera =
threeDWidget->threeDView()->activeCamera();
But there are other high level ways to get camera from vtkMRMLCameraNode.
For example:
vtkMRMLCameraNode* cameraNode =
threeDWidget->threeDView()->cameraNode();
if (!cameraNode)
qCritical() << Q_FUNC_INFO << ": No active camera node found";
vtkCamera* camera = cameraNode->GetCamera(); // there I get an exception "read access violation" even the exception abovev was not triggered
I get an exception on line where I’m trying to get vtkCamera*
. Is it normal behaviour?
Also I’ve tried to get comeras’s logic and then retrieve from that camera and apply transform to camera (preliminary I linked to the vtkSlicerCamerasModuleLogic
):
vtkSlicerCamerasModuleLogic* camerasLogic =
vtkSlicerCamerasModuleLogic::SafeDownCast(this->moduleLogic("Cameras"));
if (!camerasLogic)
qCritical() << Q_FUNC_INFO << ": Cameras module is not found";
vtkMRMLCameraNode* cameraNode =
camerasLogic->GetViewActiveCameraNode(viewNode);
if (!cameraNode)
qCritical() << Q_FUNC_INFO << ": No active camera node found";
vtkCamera* camera = cameraNode->GetCamera();
if (!camera)
qCritical() << Q_FUNC_INFO << ": No active camera found";
vtkNew<vtkTransform> transform;
transform->Scale(2, 1, 1);
camera->SetModelTransformMatrix(transform->GetMatrix()); // here I gen an exception read access violation: `vtkObject::GetDebug()`
I get an exception now only when I try to apply transform.
All of this seemed to me strange so I decided to ask here… perhaps I don’t understand how vtkMRMLCameraNode
is initialized?
By the way python example script works fine