[vtkusers] VtkCamera -- Zoom method

Gerrick Bivins gbivins at objectreservoir.com
Mon Sep 15 18:26:23 EDT 2008


Hi All, Long email but please bear with me.
;)
I have had this problem of zooming in with vtkInteractorStyleRubberBandZoom.
Today was the day to tackle is and eventually I realized that zoom works
fine when I use parallel projection but not perspective.
When I switch to perspective projection and zoom in, at some point the view
angle gets set to 0 (1e-8).

I¹ve dug down into the code and ran across this implementation for Zoom in
vtkCamera which is being called by vtkInteractorStyleRubberBandZoom:

//--------------------------------------------------------------------------
--
// Change the ViewAngle (for perspective) or the ParallelScale (for
parallel)
// so that more or less of a scene occupies the viewport.  A value > 1 is a
// zoom-in. A value < 1 is a zoom-out.
void vtkCamera::Zoom(double amount)
{
  if (amount <= 0.0)
    {
    return;
    }

  if (this->ParallelProjection)
    {
    this->SetParallelScale(this->ParallelScale/amount);
    }
  else
    {
    this->SetViewAngle(this->ViewAngle/amount);//<==Why is zoom implemented
like this? Why isn¹t it a function of translation?
    }
}

Which is defined here:
void vtkCamera::SetViewAngle(double angle)
{
  double min = 0.00000001;
  double max = 179.0;

  if ( this->ViewAngle != angle )
    {
    this->ViewAngle = (angle<min?min:(angle>max?max:angle));
    this->Modified();
    this->ViewingRaysModified();
    }
}

At this point(when min is set ), rendering becomes messed up (backfaces and
bad z-fighting) and the only way to fix things is to restart the
application.
This 0 can be seen as problematic in functions like

 vktRenderer::ResetCamera(double bounds[6])
{
...
  //around line 990
  distance = 
radius/sine(this->ActiveCamera()->GetViewAngle()*vtkMath::Pi()/360.0);//<==
(radius/some really small number if view angle is small) == some really big
number(e12)!!!!!
...
//around line 1004
  this->ActiveCamera->SetPosition(center[0]+distance*vn[0],
center[1]+distance*vn[1], center[2]+distance*vn[2]); //<==Uh Oh distance is
a really big number(e12)!!
}
So finally, my question deals with trying to get a better understanding of
the ³Zoom² method in vtkCamera.
I don¹t understand why zoom is implemented by changing the view angle.
Why isn¹t it a function of translating the camera along it¹s view vector
toward or away from it¹s lookAt point?

Hopefully someone made it this far and can shed some light here.
;)
Gerrick






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080915/3b6403f5/attachment.htm>


More information about the vtkusers mailing list