Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Visualization Toolkit, which types of objects need Update() and Modified() to be called and when?

Tags:

vtk

I'm looking at some VTK code which may not be working correctly. Here's a snippet:

vtkSmartPointer<vtkCamera> cam = vtkSmartPointer<vtkCamera>::New();
cam->SetFocalPoint(0, 0, 0);
cam->SetViewUp(perp[0], perp[1], perp[2]);

cam->SetPosition(first_cam_pos);
cam->SetViewAngle(20);
cam->Modified();

It seems to me that the call to Modified() shouldn't be necessary, that calling the four Set functions should automatically signal that the camera has been modified.

Indeed, the Kitware VTK camera example doesn't use Modified() for the camera.

vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
camera->SetPosition(0, 0, 20);
camera->SetFocalPoint(0, 0, 0);

// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();

renderer->SetActiveCamera(camera);

In other cases, the potentially not-working VTK code I'm looking at uses Update() to manually update — not for the camera object, but elsewhere. Again, I think this is probably not necessary; but clearly Update() and Modified() are there for some reason.

Is there some rule for determining when Modified() and Update() need to be called and when they don't? Are there certain types of objects that need them and certain types that don't? Or is it related to the types of functions that are called on them?

I'm using VTK 6.1, but I'd love to get a general answer if there's some historical context here.

like image 602
Translunar Avatar asked Jun 05 '14 16:06

Translunar


1 Answers

Update() is required when you want to use an object before the pipeline updates it for you. An example is:

vtkSmartPointer<vtkXMLPolyDataReader> reader = \
        vtkSmartPointer<vtkPolyDataReader>::New();

reader->SetFileName("myfile.vtp");

// At this point, the reader hasn't yet read the file, so the
// following line with result in polydata being null (or 
// something like that)

vtkPolyData* badPolydata = reader->GetOutput();

// However, once you tell the reader "update right now, don't wait
// for the pipeline to update you" with:

reader->Update();

// you can now get access to the data it has read:

vtkPolyData* goodPolydata = reader->GetOutput();

If, on the other hand, you are going to take the reader, attach it to a mapper, attach the mapper to an actor, and display the actor in the renderwindow, then at the time when the renderer says "Ok, now I need the data that drives this whole chain", the pipeline will go back and call Update() on the reader. This is the whole reason for/benefit of the pipeline execution model.


Modified() is required when you want to inform the pipeline "on the next pass, you need to re-process this object". This is done internally by most of the Set* functions, so I guess you just have to look at the implementation to see if Modified() is getting called or not by whatever function you've called that you expect to take effect the next pass through the pipeline.

like image 112
David Doria Avatar answered Sep 20 '22 02:09

David Doria