Hi all, I am trying to set up the camera view w.r.t. the camera matrix K in Paraview python shell. Basically, I create an intrinsic matrix to store the new projective matrix obtained from 3x3 camera intrinsic matrix K, get the current projection transform matrix A, and create a new matrix apply_matrix, as intrinsic/A, and apply it to vtk.vtkPerspectiveTransform() 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!
Li RenderView1 = GetRenderView(); [w, h]=RenderView1.GetRenderer().GetSize(); camera = RenderView1.GetActiveCamera(); [n, f] = camera.GetClippingRange(); print f,n; A = camera.GetProjectionTransformMatrix(double(w)/double(h), -1.0, 1.0); iIntrinsic = vtk.vtkMatrix4x4(); A.Invert(A, iIntrinsic); intrinsic = vtk.vtkMatrix4x4(); intrinsic.SetElement(0,0,2.0*K.getA()[0][0]/double(w)); intrinsic.SetElement(0,1,-2.0*K.getA()[0][1]/double(w)); intrinsic.SetElement(0,2,-2.0*K.getA()[0][2]/double(w)+1.0); intrinsic.SetElement(0,3,0.0); intrinsic.SetElement(1,0,0.0); intrinsic.SetElement(1,1,2.0*K.getA()[1][1]/double(h)); intrinsic.SetElement(1,2,-2.0*(double(h)-K.getA()[1][2])/double(h)+1.0); intrinsic.SetElement(1,3,0.0); intrinsic.SetElement(2,0,0.0); intrinsic.SetElement(2,1,0.0); intrinsic.SetElement(2,2,-(f+n)/(f-n)); intrinsic.SetElement(2,3,-2.0*f*n/(f-n)); intrinsic.SetElement(3,0,0.0); intrinsic.SetElement(3,1,0.0); intrinsic.SetElement(3,2,-1.0); intrinsic.SetElement(3,3,0.0); apply_matrix = vtk.vtkMatrix4x4(); apply_matrix.Multiply4x4(intrinsic, iIntrinsic, apply_matrix); print "apply_matrix\n"; print apply_matrix; T = vtk.vtkPerspectiveTransform(); T.SetMatrix(apply_matrix); camera.SetUserTransform(T); Render();
_______________________________________________ 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 ParaView Wiki at: http://paraview.org/Wiki/ParaView Follow this link to subscribe/unsubscribe: http://www.paraview.org/mailman/listinfo/paraview