[vtkusers] Correctly apply camera matrix

Ken Martin ken.martin at kitware.com
Mon Jul 16 12:12:47 EDT 2018


The best approach in VTK is to save the key variables, camera position,
focal point, vup, dop, view angle. This is because the interaction methods
directly adjust those parameters, not the computed matrix.

On Mon, Jul 16, 2018 at 4:13 AM, andyjk <andrewkeeling at hotmail.com> wrote:

> I am trying to save a particular camera view, then reapply it later (ie be
> able to reset the the view to a previous position)
>
> I see from here (
> http://vtk.1045678.n5.nabble.com/How-to-restore-a-camera-
> view-td5728916.html
> ) that I can do this by saving  position, focal_point, View-up and
> view_angle,
>
> but I am trying to do this more neatly by saving just the 4x4
> transformation
> matrix of the camera (and assuming view angle is unchanged).
>
> How can I grab the current camera transformation matrix, and later re-apply
> it ?
>
> I have tried :
>
> 1) GRAB
> vtkSmartPointer<vtkMatrix4x4> mat;
>                 mat =
> iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->
> GetActiveCamera()->GetModelViewTransformMatrix();
>
>                 saveVTKMat4x4(mat, "VTKCamera.vmx");
>
> 2) LOAD and APPLY
> loadVTKMat4x4(mat, "VTKCamera.vmx");
>                 mat->Print(std::cout);
>
>
>                 vtkSmartPointer<vtkMatrix4x4> mat_inverse =
> vtkSmartPointer<vtkMatrix4x4>::New();
>                 vtkMatrix4x4::Invert(mat, mat_inverse);
>                 vtkSmartPointer<vtkTransform> transform =
> vtkSmartPointer<vtkTransform>::New();
>                 transform->SetMatrix(mat);
>                 transform->Update();
>
>
>                 vtkSmartPointer<vtkMatrix4x4> current_mat;
>                 current_mat = custom_camera->GetViewTransformMatrix();
>
>                 vtkSmartPointer<vtkMatrix4x4> current_mat_inverse =
> vtkSmartPointer<vtkMatrix4x4>::New();
>                 vtkMatrix4x4::Invert(current_mat, current_mat_inverse);
>
>                 vtkSmartPointer<vtkTransform> transformInv =
> vtkSmartPointer<vtkTransform>::New();
>                 transformInv->SetMatrix(current_mat_inverse);
>                 transformInv->Update();
>
>
>                 custom_camera->ApplyTransform(transformInv);
>                 custom_camera->Modified();
>                 custom_camera->ApplyTransform(transform);
>
>
> [Where the save/load functions have been verified using vtk::print and are
> working fine]
>
> I presume when loading, I have to move the camera back to identity (via an
> inverse transform) before applying the new transform because I think
> ApplyTransform concatenates.
>
> I find that if I don't move the camera at all between saving and loading,
> it
> works.
> If I nudge the camera a tiny bit between loading and saving, the new view
> is
> displaced a bit more when loading, so I think I must be getting some
> inverse
> transforms muddled up?
>
> Is there a neat way to the current camera matrix then reapply it later ?
>
>
>
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
>



-- 
Ken Martin PhD
Distinguished Engineer
Kitware Inc.
101 East Weaver Street
Carrboro, North Carolina
27510 USA

This communication, including all attachments, contains confidential and
legally privileged information, and it is intended only for the use of the
addressee.  Access to this email by anyone else is unauthorized. If you are
not the intended recipient, any disclosure, copying, distribution or any
action taken in reliance on it is prohibited and may be unlawful. If you
received this communication in error please notify us immediately and
destroy the original message.  Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180716/7a771179/attachment.html>


More information about the vtkusers mailing list