How to set camera so that the image fill up the screen horizontally

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to set camera so that the image fill up the screen horizontally

chrisyeshi
So, I need the image the fit the width of the screen. It doesn't matter if the image is too high for the screen.
It needs to be done both in Parallel and Perspective modes.

I have read the vtkRenderer::ResetCamera() method. There are two places I don't understand.

1)   double w1 = bounds[1] - bounds[0];
  double w2 = bounds[3] - bounds[2];
  double w3 = bounds[5] - bounds[4];
  w1 *= w1;
  w2 *= w2;
  w3 *= w3;
  double radius = w1 + w2 + w3;

Why do we get the radius this way? What is it?

2) this->ActiveCamera->SetParallelScale(radius);

Why is the radius the ParallelScale? And why there is no perspective zoom settings?

Thanks in advance!
Reply | Threaded
Open this post in threaded view
|

Re: How to set camera so that the image fill up the screen horizontally

David Gobbi
Hi Chris,

The ResetCamera method is only meant to be approximate.
Do not use it if you need to exactly fit an image to the window,
that is not what it is for.

To fit an image to the window, compute the height of the
image, and use that to set the ParallelScale.  Or if you need
to fit the width, then use the aspect ratio to compute the
ParallelScale you need from the width.

If you need to do the same thing for perspective, then you
can use a bit of trigonometry and compute the ViewAngle
that is needed to exactly fit the image.

  - David


On Wed, Mar 9, 2011 at 10:31 AM, chrisyeshi <[hidden email]> wrote:

> So, I need the image the fit the width of the screen. It doesn't matter if
> the image is too high for the screen.
> It needs to be done both in Parallel and Perspective modes.
>
> I have read the vtkRenderer::ResetCamera() method. There are two places I
> don't understand.
>
> 1)   double w1 = bounds[1] - bounds[0];
>  double w2 = bounds[3] - bounds[2];
>  double w3 = bounds[5] - bounds[4];
>  w1 *= w1;
>  w2 *= w2;
>  w3 *= w3;
>  double radius = w1 + w2 + w3;
>
> Why do we get the radius this way? What is it?
>
> 2) this->ActiveCamera->SetParallelScale(radius);
>
> Why is the radius the ParallelScale? And why there is no perspective zoom
> settings?
>
> Thanks in advance!
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/How-to-set-camera-so-that-the-image-fill-up-the-screen-horizontally-tp3415966p3415966.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> 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 VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
_______________________________________________
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 VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: How to set camera so that the image fill up the screen horizontally

chrisyeshi
Thanks for your reply, it's alot clearer now!

So, for perspective, it's better to SetViewAngle rather than calculating the camera distance?
By the way, how to determine the camera distance? Right now I am just using bounding box radius * 2.
Reply | Threaded
Open this post in threaded view
|

Re: How to set camera so that the image fill up the screen horizontally

David Gobbi
On Wed, Mar 9, 2011 at 10:57 AM, chrisyeshi <[hidden email]> wrote:
> Thanks for your reply, it's alot clearer now!
>
> So, for perspective, it's better to SetViewAngle rather than calculating the
> camera distance?

That's up to you.  I use a parallel projection when viewing images.  But if you
want to keep the perspective constant, then you should keep the ViewAngle
the same and modify the Distance.

> By the way, how to determine the camera distance? Right now I am just using
> bounding box radius * 2.

Compute the distance from your ViewAngle and your image height.  The equation
is something like  Height*0.5/Distance = tan(0.5*ViewAngle)

 - David
_______________________________________________
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 VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers