[vtkusers] How to update the renderer when the data is modified?

Obada Mahdi omahdi at gmx.de
Fri Nov 3 15:25:04 EST 2006


Ali,

actually I cannot tell from the code snippet whether there is more
than one thread involved in your solution or not.  Having
"UpdateRenderer" called indirectly via event callback does not
necessarily mean that it is called from a thread different from the
"main thread".  For example, if an event handler is invoked on a
keyboard event as observed by a vtkInteractorStyle, it is still
dispatched in the main thread (provided that
vtkRenderWindowInteractor::Start() has been called from the main
thread); the call chain would probably look something like:
vtkWin32RenderWindowInteractor::Start()
-> DispatchMessage()
-> vtkWin32RenderWindowInteractor::OnKeyDown()
-> vtkWin32RenderWindowInteractor::InvokeEvent(vtkCommand::KeyPressEvent, ...)
-> vtkInteractorStyle::OnKeyDown(),
which is then still executed in the main thread context.

So the question would be where "InvokeEvent" is issued, in your case
caused by a call to "vtkImageImport::Modified()".  Do you update your
image data (along with a call to "Modified()") based on such things
like keyboard interaction with vtkImageViewer2, or is there a separate
thread that does it, like a listener-thread that awaits commands from
somewhere else, or a separate event loop thread that handles events
for a different application window/dialog box etc.?

Anyway, if you do have multiple threads, I would suggest to have a
look at David Gobbi's suggestion from the message I mentioned earlier:
http://public.kitware.com/pipermail/vtkusers/2004-April/073478.html

If you only want a quick-n-dirty hack for testing, you can probably
get away with something like

----BEGIN----
#include "vtkWindows.h"
// Global variable, set it in e.g. main()
HWND vtkWindowId;
// ...
int
main()
{
  // ...
  vtkImageViewer2* viewer = ...;
  vtkWindowId =
vtkWin32OpenGLRenderWindow::SafeDownCast(viewer->GetRenderWindow())->GetWindowId();
  // ...
}

void
UpdateRenderer(...)
{
  // ...
  // If dispatched in vtkWin32RenderWindowInteractor, WM_PAINT will cause
  // a call to Render()
  PostMessage(vtkWindowId, WM_PAINT, 0, 0);
}
----END----

However, I am not actually developing stuff under Windows, so this
might just be rubbish :-)


Obada



More information about the vtkusers mailing list