<div dir="ltr">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.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 16, 2018 at 4:13 AM, andyjk <span dir="ltr"><<a href="mailto:andrewkeeling@hotmail.com" target="_blank">andrewkeeling@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am trying to save a particular camera view, then reapply it later (ie be<br>
able to reset the the view to a previous position)<br>
<br>
I see from here (<br>
<a href="http://vtk.1045678.n5.nabble.com/How-to-restore-a-camera-view-td5728916.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.<wbr>com/How-to-restore-a-camera-<wbr>view-td5728916.html</a><br>
) that I can do this by saving position, focal_point, View-up and<br>
view_angle,<br>
<br>
but I am trying to do this more neatly by saving just the 4x4 transformation<br>
matrix of the camera (and assuming view angle is unchanged).<br>
<br>
How can I grab the current camera transformation matrix, and later re-apply<br>
it ?<br>
<br>
I have tried :<br>
<br>
1) GRAB<br>
vtkSmartPointer<vtkMatrix4x4> mat;<br>
mat =<br>
iren->GetRenderWindow()-><wbr>GetRenderers()-><wbr>GetFirstRenderer()-><wbr>GetActiveCamera()-><wbr>GetModelViewTransformMatrix();<br>
<br>
saveVTKMat4x4(mat, "VTKCamera.vmx");<br>
<br>
2) LOAD and APPLY<br>
loadVTKMat4x4(mat, "VTKCamera.vmx");<br>
mat->Print(std::cout);<br>
<br>
<br>
vtkSmartPointer<vtkMatrix4x4> mat_inverse =<br>
vtkSmartPointer<vtkMatrix4x4>:<wbr>:New();<br>
vtkMatrix4x4::Invert(mat, mat_inverse);<br>
vtkSmartPointer<vtkTransform> transform =<br>
vtkSmartPointer<vtkTransform>:<wbr>:New();<br>
transform->SetMatrix(mat);<br>
transform->Update();<br>
<br>
<br>
vtkSmartPointer<vtkMatrix4x4> current_mat;<br>
current_mat = custom_camera-><wbr>GetViewTransformMatrix();<br>
<br>
vtkSmartPointer<vtkMatrix4x4> current_mat_inverse =<br>
vtkSmartPointer<vtkMatrix4x4>:<wbr>:New();<br>
vtkMatrix4x4::Invert(current_<wbr>mat, current_mat_inverse);<br>
<br>
vtkSmartPointer<vtkTransform> transformInv =<br>
vtkSmartPointer<vtkTransform>:<wbr>:New();<br>
transformInv->SetMatrix(<wbr>current_mat_inverse);<br>
transformInv->Update();<br>
<br>
<br>
custom_camera->ApplyTransform(<wbr>transformInv);<br>
custom_camera->Modified();<br>
custom_camera->ApplyTransform(<wbr>transform);<br>
<br>
<br>
[Where the save/load functions have been verified using vtk::print and are<br>
working fine]<br>
<br>
I presume when loading, I have to move the camera back to identity (via an<br>
inverse transform) before applying the new transform because I think<br>
ApplyTransform concatenates.<br>
<br>
I find that if I don't move the camera at all between saving and loading, it<br>
works.<br>
If I nudge the camera a tiny bit between loading and saving, the new view is<br>
displaced a bit more when loading, so I think I must be getting some inverse<br>
transforms muddled up?<br>
<br>
Is there a neat way to the current camera matrix then reapply it later ?<br>
<br>
<br>
<br>
<br>
<br>
<br>
--<br>
Sent from: <a href="http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.<wbr>com/VTK-Users-f1224199.html</a><br>
______________________________<wbr>_________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_<wbr>FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=<wbr>vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">https://public.kitware.com/<wbr>mailman/listinfo/vtkusers</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Ken Martin PhD<div>Distinguished Engineer<br><span style="font-size:12.8px">Kitware Inc.</span><br></div><div>101 East Weaver Street<br>Carrboro, North Carolina<br>
27510 USA<br><br><div><span style="font-size:10pt;font-family:Tahoma,sans-serif">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.</span></div></div></div></div></div></div></div>
</div>