Hi all,<br><br>I just would like to update my question in case anyone also ever bumps into it.<br><br>Apparently, if I change the last but second line from <span style="color:rgb(0,153,0)"><font size="1"><span style="font-family:courier new,monospace">camera.SetUserTransform(T); </span></font></span>to <span style="color:rgb(0,153,0)"><font size="1"><span style="font-family:courier new,monospace">camera.SetUserViewTransform(T); </span></font></span>, the problem is solved.<br>
<br>Cheers,<br><br>Li<br><br><div class="gmail_quote">On Fri, Mar 1, 2013 at 3:11 PM, Li Guan <span dir="ltr"><<a href="mailto:li.9uan@gmail.com" target="_blank">li.9uan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi all,<br><br>I am trying to set up the camera view w.r.t. the camera matrix K in Paraview python shell. Basically, I create an <span style="color:rgb(0,153,0)"><font size="1"><span style="font-family:courier new,monospace">intrinsic </span></font></span>matrix to store the new projective matrix obtained from 3x3 camera intrinsic matrix K, get the current projection transform matrix <span style="color:rgb(0,153,0)"><font size="1"><span style="font-family:courier new,monospace">A</span></font></span>, and create a new matrix <span style="color:rgb(0,153,0)"><font size="1"><span style="font-family:courier new,monospace">apply_matrix<span style="font-family:arial,helvetica,sans-serif"><span style="color:rgb(0,0,0)"><font>, as </font></span></span></span></font></span><span style="color:rgb(0,153,0)"><font size="1"><span style="font-family:courier new,monospace">intrinsic/A</span></font></span>, and apply it to <span style="color:rgb(0,153,0)"><font size="1"><span style="font-family:courier new,monospace">vtk.vtkPerspectiveTransform() </span></font></span>The code is shown below. My question is if this code is correct? Because when I run the script twice, the rendered views are a little bit different. And the third time the view will become the same as the first time again. I wonder if this is some numerical error or what I have done wrong? Many thanks!<br>
<br>Li<br><br><div style="margin-left:40px"><span style="color:rgb(0,153,0)"><font size="1"><span style="font-family:courier new,monospace">RenderView1 = GetRenderView();<br>[w, h]=RenderView1.GetRenderer().GetSize();<br>
camera = RenderView1.GetActiveCamera();<br>[n, f] = camera.GetClippingRange();<br>print f,n;<br><br>A = camera.GetProjectionTransformMatrix(double(w)/double(h), -1.0, 1.0);<br><br>iIntrinsic = vtk.vtkMatrix4x4();<br>A.Invert(A, iIntrinsic);<br>
<br>intrinsic = vtk.vtkMatrix4x4();<br>intrinsic.SetElement(0,0,2.0*K.getA()[0][0]/double(w));<br>intrinsic.SetElement(0,1,-2.0*K.getA()[0][1]/double(w));<br>intrinsic.SetElement(0,2,-2.0*K.getA()[0][2]/double(w)+1.0);<br>
intrinsic.SetElement(0,3,0.0);<br>intrinsic.SetElement(1,0,0.0);<br>intrinsic.SetElement(1,1,2.0*K.getA()[1][1]/double(h));<br>intrinsic.SetElement(1,2,-2.0*(double(h)-K.getA()[1][2])/double(h)+1.0);<br>intrinsic.SetElement(1,3,0.0);<br>
intrinsic.SetElement(2,0,0.0);<br>intrinsic.SetElement(2,1,0.0);<br>intrinsic.SetElement(2,2,-(f+n)/(f-n));<br>intrinsic.SetElement(2,3,-2.0*f*n/(f-n));<br>intrinsic.SetElement(3,0,0.0);<br>intrinsic.SetElement(3,1,0.0);<br>
intrinsic.SetElement(3,2,-1.0);<br>intrinsic.SetElement(3,3,0.0);<br><br>apply_matrix = vtk.vtkMatrix4x4();<br>apply_matrix.Multiply4x4(intrinsic, iIntrinsic, apply_matrix);<br>print "apply_matrix\n";<br>print apply_matrix;<br>
T = vtk.vtkPerspectiveTransform();<br>T.SetMatrix(apply_matrix);<br><br>camera.SetUserTransform(T); <br>R<font size="1">ender()</font></span></font></span>;<br><br><br></div>
</blockquote></div><br>