[Paraview] Set up camera intrinsic matrix in python Paraview

Li Guan li.9uan at gmail.com
Mon Mar 4 16:17:48 EST 2013


Hi all,

I just would like to update my question in case anyone also ever bumps into
it.

Apparently, if I change the last but second line from
camera.SetUserTransform(T);
to camera.SetUserViewTransform(T); , the problem is solved.

Cheers,

Li

On Fri, Mar 1, 2013 at 3:11 PM, Li Guan <li.9uan at gmail.com> wrote:

> 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();
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20130304/d8ddfdaf/attachment.htm>


More information about the ParaView mailing list