[vtkusers] Many vtkTexturedButtonRepresentation2D does not accept user interaction.

Jose Barreto jose.de.paula at live.com
Mon Jan 2 13:58:36 EST 2017


Hi,
I have two renderes added in the same renderwindow. Use viewerport to
separate them.

I have two vtkButtonWidget using vtkTexturedButtonRepresentation2D as
impersonation.

When I add the 2 vtkButtonWidget, one on each renderer, the object that goes
into the second renderer does not accept user interaction.

Note that the mouse on the second renderer does not even change.

Below the code for compilation.


#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkImageData.h>
#include <vtkCoordinate.h>
#include <vtkSphereSource.h>
#include <vtkButtonWidget.h>
#include <vtkTexturedButtonRepresentation2D.h>

static void CreateImage(vtkSmartPointer<vtkImageData> image, unsigned char
*color1, unsigned char *color2);

int main(int, char *[])
{
	// Create two images for texture
	auto image1 = vtkSmartPointer<vtkImageData>::New();
	auto image2 = vtkSmartPointer<vtkImageData>::New();
	unsigned char banana[3] = { 227, 207, 87 };
	unsigned char tomato[3] = { 255, 99, 71 };
	CreateImage(image1, banana, tomato);
	CreateImage(image2, tomato, banana);

	// Renderes and Window
	auto renderer1 = vtkSmartPointer<vtkRenderer>::New();
	renderer1->SetViewport(0, 0, 1, .5);

	auto renderer2 = vtkSmartPointer<vtkRenderer>::New();
	renderer2->SetViewport(0, .5, 1, 1);

	auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
	renderWindow->AddRenderer(renderer1);
	renderWindow->AddRenderer(renderer2);

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

	renderer1->SetBackground(.1, .2, .5);
	renderer2->SetBackground(0, 0, 0);

	renderWindow->SetSize(640, 480);
	renderWindow->Render();

	vtkButtonWidget* buttonWidget[2];
	buttonWidget[0] = vtkButtonWidget::New();
	buttonWidget[1] = vtkButtonWidget::New();

	for (int i = 0; i < 2; i++)
	{
		auto buttonRepresentation = vtkTexturedButtonRepresentation2D::New();
		buttonRepresentation->SetNumberOfStates(2);
		buttonRepresentation->SetButtonTexture(0, image1);
		buttonRepresentation->SetButtonTexture(1, image2);

		buttonWidget[i]->SetInteractor(renderWindowInteractor);
		buttonWidget[i]->SetRepresentation(buttonRepresentation);

		if (i == 0)
		{
			buttonWidget[i]->SetDefaultRenderer(renderer2);
		}
		else
		{
			buttonWidget[i]->SetDefaultRenderer(renderer1);
		}

		buttonWidget[i]->On();
	}


	renderWindow->Render();
	renderWindowInteractor->Start();

	return EXIT_SUCCESS;
}

void CreateImage(vtkSmartPointer<vtkImageData> image,
				 unsigned char* color1,
				 unsigned char* color2)
{
	// Specify the size of the image data
	image->SetDimensions(10, 10, 1);
#if VTK_MAJOR_VERSION <= 5
	image->SetNumberOfScalarComponents(3);
	image->SetScalarTypeToUnsignedChar();
#else
	image->AllocateScalars(VTK_UNSIGNED_CHAR, 3);
#endif
	int* dims = image->GetDimensions();

	// Fill the image with
	for (int y = 0; y < dims[1]; y++)
	{
		for (int x = 0; x < dims[0]; x++)
		{
			unsigned char* pixel =
				static_cast<unsigned char*>(image->GetScalarPointer(x, y, 0));
			if (x < 5)
			{
				pixel[0] = color1[0];
				pixel[1] = color1[1];
				pixel[2] = color1[2];
			}
			else
			{
				pixel[0] = color2[0];
				pixel[1] = color2[1];
				pixel[2] = color2[2];
			}
		}
	}
}





--
View this message in context: http://vtk.1045678.n5.nabble.com/Many-vtkTexturedButtonRepresentation2D-does-not-accept-user-interaction-tp5741673.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list