[vtkusers] How to control zooming limits?

Ken Martin ken.martin at kitware.com
Thu Jan 28 08:36:35 EST 2016


You can use a startevent on the renderer and check what the camera's
settings are. The example below prints the camera's position before each
render but you could instead have it check the camera and adjust as
needed.  There are probably other ways to do it as well. This was just the
first that came to mind.

Thanks
Ken



/*=========================================================================

  Program:   Visualization Toolkit
  Module:    Cone2.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
//
// This example shows how to add an observer to a C++ program. It extends
// the Step1/Cxx/Cone.cxx C++ example (see that example for information on
// the basic setup).
//
// VTK uses a command/observer design pattern. That is, observers watch for
// particular events that any vtkObject (or subclass) may invoke on
// itself. For example, the vtkRenderer invokes a "StartEvent" as it begins
// to render. Here we add an observer that invokes a command when this event
// is observed.
//

// first include the required header files for the vtk classes we are using
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkCommand.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"

// Callback for the interaction
class vtkMyCallback : public vtkCommand
{
public:
  static vtkMyCallback *New()
    { return new vtkMyCallback; }
  virtual void Execute(vtkObject *caller, unsigned long, void*)
    {
      vtkRenderer *renderer = reinterpret_cast<vtkRenderer*>(caller);
      cout << renderer->GetActiveCamera()->GetPosition()[0] << " "
           << renderer->GetActiveCamera()->GetPosition()[1] << " "
           << renderer->GetActiveCamera()->GetPosition()[2] << "\n";
    }
};

int main()
{
  //
  // The pipeline creation is documented in Step1
  //
  vtkConeSource *cone = vtkConeSource::New();
  cone->SetHeight( 3.0 );
  cone->SetRadius( 1.0 );
  cone->SetResolution( 10 );

  vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
  coneMapper->SetInputConnection( cone->GetOutputPort() );
  vtkActor *coneActor = vtkActor::New();
  coneActor->SetMapper( coneMapper );

  vtkRenderer *ren1= vtkRenderer::New();
  ren1->AddActor( coneActor );
  ren1->SetBackground( 0.1, 0.2, 0.4 );
  ren1->ResetCamera();

  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer( ren1 );
  renWin->SetSize( 300, 300 );

  // Here is where we setup the observer, we do a new and ren1 will
  // eventually free the observer
  vtkMyCallback *mo1 = vtkMyCallback::New();
  ren1->AddObserver(vtkCommand::StartEvent,mo1);
  mo1->Delete();

  //
  // now we loop over 360 degrees and render the cone each time
  //
  int i;
  for (i = 0; i < 360; ++i)
    {
    // render the image
    renWin->Render();
    // rotate the active camera by one degree
    ren1->GetActiveCamera()->Azimuth( 1 );
    }

  //
  // Free up any objects we created
  //
  cone->Delete();
  coneMapper->Delete();
  coneActor->Delete();
  ren1->Delete();
  renWin->Delete();

  return 0;
}



On Thu, Jan 28, 2016 at 2:32 AM, Rakesh Patil <rakesh.p at tataelxsi.co.in>
wrote:

> Hello users,
>
>
> Is there any way to control zoom limits? Like I need to restrict zooming,
> in the range of say 5 miles to 10 miles. How can this be done? Kindly
> suggest some ideas/techniques.
>
>
> Warm Regards
>
>
> Rakesh Patil
>
>
> _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 
Ken Martin PhD
Chairman & CFO
Kitware Inc.
28 Corporate Drive
Clifton Park NY 12065
518 371 3971

This communication, including all attachments, contains confidential and
legally privileged information, and it is intended only for the use of the
addressee.  Access to this email by anyone else is unauthorized. If you are
not the intended recipient, any disclosure, copying, distribution or any
action taken in reliance on it is prohibited and may be unlawful. If you
received this communication in error please notify us immediately and
destroy the original message.  Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160128/3277645c/attachment.html>


More information about the vtkusers mailing list