[vtkusers] problem in having two Widgets with the same interactor

David Doria daviddoria+vtk at gmail.com
Fri Feb 12 11:26:35 EST 2010


On Thu, Feb 11, 2010 at 3:01 AM, satyanarayana reddy
<satyajanga at gmail.com>wrote:

> Hi,
>
> I want to have two sphere widgets with the same interactor. The code I have
> written like this..
>
> iren->SetInteractorStyle(vtkInteractorStyleTerrain::New());
>
> // pointwidget1->SetInteractor(iren);
>
> // pointwidget1->PlaceWidget();
>
> // pointwidget2->SetInteractor(iren);
>
> // pointwidget2->PlaceWidget();
>
> // linewidget1->SetInteractor(iren);
>
> // linewidget1->PlaceWidget();
>
> // linewidget2->SetInteractor(iren);
>
> // linewidget2->PlaceWidget();
>
> spherewidget1->SetInteractor(iren);
>
> spherewidget1->PlaceWidget();
>
> spherewidget1->SetCenter(10,10,-100);
>
> spherewidget1->SetPriority(0.2);
>
> spherewidget2->SetInteractor(iren);
>
> spherewidget2->PlaceWidget();
>
> spherewidget2->SetCenter(0,0,-100);
>
> spherewidget2->SetPriority(0.5);
>
> iren->Initialize();
>
> iren->Start();
>
>
> Each sphere widget is working fine when used individually. But when I tried
> to have both of them only one is coming. And it is the same for point and
> line widgets also..
>
> Some one plz help on this. Thanx in advance..
>
>
> Regards,
>
> Satya..
>
>
>
The following works fine for me - can you explain the problem in more
detail?

#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkSphereWidget.h>
#include <vtkSphereRepresentation.h>
#include <vtkBoxWidget2.h>
#include <vtkCommand.h>

int main(int argc, char *argv[])
{
  // a renderer and render window
  vtkSmartPointer<vtkRenderer> renderer =
      vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
      vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);

  // an interactor
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
      vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  vtkSmartPointer<vtkSphereWidget> sphereWidget1 =
      vtkSmartPointer<vtkSphereWidget>::New();
  sphereWidget1->SetInteractor(renderWindowInteractor);
  sphereWidget1->SetRepresentationToSurface();

   vtkSmartPointer<vtkSphereWidget> sphereWidget2 =
      vtkSmartPointer<vtkSphereWidget>::New();
  sphereWidget2->SetInteractor(renderWindowInteractor);
  sphereWidget2->SetRepresentationToSurface();
  sphereWidget2->SetCenter(2.0, 0.0, 0.0);

  sphereWidget1->On();
  sphereWidget2->On();
  renderWindow->Render();
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100212/e04832ce/attachment.htm>


More information about the vtkusers mailing list