[vtkusers] Widget interaction in multiple viewports

Timothee Evain tevain at telecom-paristech.fr
Fri Feb 3 07:58:17 EST 2017


Hello everybody,

I want to use widgets in a multiple viewport/renderer configuration.
Alas, when widgets are set up in any other renderer than the first in term of world coordinates, it is not possible to interact with them anymore.
I can't find the reason of this behavior, and need some insight on what's going on since I'm clueless for the moment.

Here a minimal working example with 2 renderers and 2 button widgets, only one working (I use VTK 6.3.0):

   vtkSmartPointer<vtkRenderer> Ren1 = vtkSmartPointer<vtkRenderer>::New();
   vtkSmartPointer<vtkRenderer> Ren2 = vtkSmartPointer<vtkRenderer>::New();
   vtkSmartPointer<vtkRenderWindow> renwin = vtkSmartPointer<vtkRenderWindow>::New();
   vtkSmartPointer<vtkRenderWindowInteractor> interact = vtkSmartPointer<vtkRenderWindowInteractor>::New();

   vtkSmartPointer<vtkTexturedButtonRepresentation2D> Butrep1 = vtkSmartPointer<vtkTexturedButtonRepresentation2D>::New();
   vtkSmartPointer<vtkButtonWidget> Butwid1 = vtkSmartPointer<vtkButtonWidget>::New();

   vtkSmartPointer<vtkTexturedButtonRepresentation2D> Butrep2 = vtkSmartPointer<vtkTexturedButtonRepresentation2D>::New();
   vtkSmartPointer<vtkButtonWidget> Butwid2 = vtkSmartPointer<vtkButtonWidget>::New();

   //Generate image texture
   vtkSmartPointer<vtkImageData> TextureOff = vtkSmartPointer<vtkImageData>::New();
   vtkSmartPointer<vtkImageData> TextureOn = vtkSmartPointer<vtkImageData>::New();
   int extent[6] = { 0, 50, 0, 50, 0, 0 };
   TextureOff->SetExtent(extent);
   TextureOff->AllocateScalars(VTK_UNSIGNED_CHAR, 3);
   TextureOn->SetExtent(extent);
   TextureOn->AllocateScalars(VTK_UNSIGNED_CHAR, 3);

   for (int i = 0; i <= extent[1]; i++)
   {
      for (int j = 0; j <= extent[3]; j++)
      {
         TextureOff->SetScalarComponentFromFloat(i, j, 0, 0, 255);
         TextureOff->SetScalarComponentFromFloat(i, j, 0, 1, 255);
         TextureOff->SetScalarComponentFromFloat(i, j, 0, 2, 255);
         if (i <= 10 || i >= 40 || j <= 10 || j >= 40)
         {
            TextureOn->SetScalarComponentFromFloat(i, j, 0, 0, 255);
            TextureOn->SetScalarComponentFromFloat(i, j, 0, 1, 255);
            TextureOn->SetScalarComponentFromFloat(i, j, 0, 2, 255);
         }
         else
         {
            TextureOn->SetScalarComponentFromFloat(i, j, 0, 0, 50);
            TextureOn->SetScalarComponentFromFloat(i, j, 0, 1, 255);
            TextureOn->SetScalarComponentFromFloat(i, j, 0, 2, 50);
         }
      }
   }

   Butrep1->SetNumberOfStates(2);
   Butrep1->SetDragable(false);
   Butrep1->SetButtonTexture(0, TextureOff);
   Butrep1->SetButtonTexture(1, TextureOn);
   double bounds[6] = { 50, 70, 50, 70, 0, 0 };
   Butrep1->PlaceWidget(bounds);
   Butwid1->SetCurrentRenderer(Ren1);
   Butwid1->SetInteractor(interact);
   Butwid1->SetRepresentation(Butrep1);
   Butwid1->EnabledOn();

   Butrep2->SetNumberOfStates(2);
   Butrep2->SetDragable(false);
   Butrep2->SetButtonTexture(0, TextureOff);
   Butrep2->SetButtonTexture(1, TextureOn);
   double bounds2[6] = { 50, 70, 50, 70, 0, 0 };
   Butrep2->PlaceWidget(bounds2);
   Butwid2->SetCurrentRenderer(Ren2);
   Butwid2->SetInteractor(interact);
   Butwid2->SetRepresentation(Butrep2);
   Butwid2->EnabledOn();

   Ren1->SetRenderWindow(renwin);  
   Ren1->SetBackground(0.7, 0.7, 0.7);
   Ren1->SetViewport(0, 0, 0.5, 1);
   Ren2->SetRenderWindow(renwin);
   Ren2->SetBackground(0.6, 0.6, 0.6);
   Ren2->SetViewport(0.5, 0, 1, 1);
   
   interact->SetRenderWindow(renwin);
   renwin->SetInteractor(interact);
   renwin->AddRenderer(Ren1);
   renwin->AddRenderer(Ren2);
   renwin->SetSize(800, 600);
   renwin->Render();
   
   interact->Start();


More information about the vtkusers mailing list