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 &quot;apply_matrix\n&quot;;<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>