[vtk-developers] vtkPropPicker is unable to pick vtkActor2D when display location is set to backgorund

Tharun tharun160190 at gmail.com
Tue Sep 5 22:57:05 EDT 2017


Hi all,

vtkPropPicker is unable to pick vtkActor2D when the actor display location
is set to background.

In VTK 5.8, it was working. I am using VTK 7.1.1 now. Is this a bug or a
deliberate upgrade?

Sample code. Press middle button for screenshot and left button to check
issue.

#include <vtkAutoInit.h> 
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType);
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkPolyDataMapper.h>
#include <vtkSmartPointer.h>
#include <vtkPointPicker.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkObjectFactory.h>
#include <vtkRendererCollection.h>
#include <vtkPropPicker.h>
#include <vtkImageMapper.h>
#include <vtkActor2D.h>
#include <vtkWindowToImageFilter.h>
#include <vtkInteractorStyleImage.h>
#include <vtkProperty2D.h>

vtkSmartPointer<vtkPropPicker> propPicker =
vtkSmartPointer<vtkPropPicker>::New();
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor
=vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow
=vtkSmartPointer<vtkRenderWindow>::New();

class customMouseInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
	static customMouseInteractorStyle* New();
	vtkTypeMacro(customMouseInteractorStyle,
vtkInteractorStyleTrackballCamera);

	virtual void OnLeftButtonDown()
	{
		int X = renderWindowInteractor->GetEventPosition()[0];
		int Y = renderWindowInteractor->GetEventPosition()[1];
		vtkRenderer* renderer =
renderWindowInteractor->GetRenderWindow()->GetRenderers()->GetFirstRenderer();
		// Forward events
		int picked = propPicker->PickProp(X, Y, renderer);
		vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
	}

	virtual void OnMiddleButtonDown()
	{
		vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter =
vtkSmartPointer<vtkWindowToImageFilter>::New();
		windowToImageFilter->SetInput(renderWindow);
		windowToImageFilter->SetMagnification(1);
		windowToImageFilter->SetInputBufferTypeToRGBA();
		windowToImageFilter->ReadFrontBufferOff(); // read from the back buffer
		windowToImageFilter->Update();
	
		vtkSmartPointer<vtkImageMapper> imageMapper =
vtkSmartPointer<vtkImageMapper>::New();
		imageMapper->SetInputConnection(windowToImageFilter->GetOutputPort());
		imageMapper->SetColorWindow(255);
		imageMapper->SetColorLevel(127.5);

		vtkSmartPointer<vtkActor2D> actor = vtkSmartPointer<vtkActor2D>::New();
		actor->SetMapper(imageMapper);
		actor->SetPosition(0, 0);
		actor->GetProperty()->SetDisplayLocationToBackground(); // does not work
when this is used
		vtkRenderer* renderer =
renderWindowInteractor->GetRenderWindow()->GetRenderers()->GetFirstRenderer();
		renderer->AddActor(actor);

		propPicker->PickFromListOn();
		propPicker->AddPickList(actor);


		vtkInteractorStyleTrackballCamera::OnMiddleButtonDown();
	}

};

vtkStandardNewMacro(customMouseInteractorStyle);

int main(int argc, char* argv[])
{
	vtkSmartPointer<vtkRenderer> renderer =	
vtkSmartPointer<vtkRenderer>::New();
	renderer->SetBackground(1, 1, 1); // Background color white
	renderWindow->AddRenderer(renderer);
	renderWindowInteractor->SetRenderWindow(renderWindow);
	
	vtkSmartPointer<customMouseInteractorStyle> style =
vtkSmartPointer<customMouseInteractorStyle>::New();
	renderWindowInteractor->SetInteractorStyle(style);

	renderWindowInteractor->Initialize();
	renderWindowInteractor->Start();

	return EXIT_SUCCESS;
}



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Dev-f1251487.html


More information about the vtk-developers mailing list