VtkRenderWindowInteractor event loop and threads

What I am trying to do in an application using vtk for interaction and rendering is to have two different parts: 1 is the stream with rendering and vtkRenderWindowInteractor for mouse interaction. 2 is a thread that calls some of the data modifier functions defined in the VTK stream.

From what I've gotten so far in my research, it seems rather complicated and VTK is not thread safe. Now I came across this post ( http://vtk.1045678.n5.nabble.com/Multi-threaded-VTK-td4514620.html ) on the VTK mailing list that suggests using Qt Signals and Slots. The first question will be, what is still a good solution?

The second question that is still related to this and the problem I ran into before is what is start()

for vtkRenderWindowInteractor

blocking. And so far, no matter what I've tried, any changes made with the rotation or translation or scaling functions are not executed until the start () method is called (since I'm entering the render loop). Then my question is: If I am using Qt Signals and Slots, will this prevent me from solving this problem?

Here's the basic code I've done so far for rendering and greeting vtkRenderWindowInteractor:

std::string filename = BUNNY;
// Read all the data from the file
vtkSmartPointer<vtkXMLPolyDataReader> reader =vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(filename.c_str());
reader->Update();
inputPolyData = reader->GetOutput();

cout << "File Found and Loaded : " << filename << endl ;

vtkSmartPointer<vtkTransform> translation = vtkSmartPointer<vtkTransform>::New();
translation->Translate(0.3, -0.05, 0);
transformFilter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
//transformFilter->SetInputConnection(reader->GetOutputPort());
transformFilter->SetInputData(inputPolyData);
transformFilter->SetTransform(translation);
//transformFilter->Update();

vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformFilter->GetOutputPort());

mainActor = vtkSmartPointer<vtkActor>::New();
mainActor->SetMapper(mapper);

ren->AddActor(mainActor);

vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(win);
vtkInteractorStyleMultiTouchCamera *style =
vtkInteractorStyleMultiTouchCamera::New();
iren->SetInteractorStyle(style);

//Start the event loop
iren->Initialize();
iren->Start();

//defineClipping();
win->PolygonSmoothingOn();
win->Render();
win->Start();

ctxView->Render();

      

So, I could summarize by asking the question: will Qt be able to call transform functions and vtk rendering and interacting thread is done with a start()

blocking method start()

? If not, should I change my code and think about different possibilities for interacting with my objects in VTK?

+3


source to share


1 answer


I managed to do the rotations after the call start()

, but in my case from the same thread.

The trick is to use vtkCommand

and set the timer vtkRenderWindowInteractor

to invoke this command. This command is basically a callback that can modify your members.



You can see a working example of this in this thread .

As for the multi-threaded approach you are using, perhaps you can keep the render stream in vtkCommand::Execute

until the change stream is changed. If you can use C ++ 11, you can use the many new tools available in the STL.

+2


source







All Articles