[vtkusers] continuous rendering from vtkVideoSource
Tim Soper
tim_d_soper at yahoo.com
Sat Mar 31 16:54:16 EDT 2007
David-
Thanks for the reply. It helps to have some options eliminated. The sample application I gave you was just a test program. In actuality I am integrating this into a Qt application with multiple windows each displaying different information. Only one of these windows contains the video source. My present plan is to create a global flag that gets set to true in the ModifiedEvent callback. Then I should only need some sort of timer to be integrated into the program which sends an event every so many milliseconds. When I originally wrote code to do this in C# they had a handy timer control for which the user could set a predetermined pause and a callback function in which I could place a call to Render( ). It sounds as though that is not possible in VTK (or that it is dependent on mouse interaction). If that's the case should it be possible to write a custom VTK command timer ? I may also investigate the possibility of using some sort of Qt based timer event through
SIGNAL/SLOT connections, although I find it best to separate GUI-dependent code from the VTK code. Thoughts?
Tim
----- Original Message ----
From: David Gobbi <dgobbi at atamai.com>
To: Tim Soper <tsoper at u.washington.edu>
Cc: vtkusers at vtk.org
Sent: Friday, March 30, 2007 6:04:40 PM
Subject: Re: [vtkusers] continuous rendering from vtkVideoSource
Hi Tim,
You are correct that the error occurs because the vtkVideoSource
"Modified" event is being called from a separate thread. The Render()
method should only be called from the main application thread, i.e. the
thread that the vtkRenderWindow and vtkRenderWindowInteractor are
running in. There isn't any way to make it work with a Mutex lock
unless you also modified all of the VTK pipeline code so that it checked
that mutex lock before executing any Updates, Renders, or other pipeline
methods.
When I use the vtkVideoSource, I usually use it in an application that
has a Tk interface, and I use a Tk "after" command to re-render the
window at the desired framerate. You should be able to do the same sort
of thing by setting a callback for timer events, but I remember trying
this once and having trouble because the timer events were only
generated when the mouse was moving in the window. Whichever way you
get it to work, though, the renders should not be called from a separate
thread.
- David
Tim Soper wrote:
> Hi-
> I'm having trouble with the rendering frames acquired from vtkVideoSource. For now, I am simply trying to continuously display the random noise generated by the InternalGrab( ) method. I wrote a basic program that links the vtkImageViewer class to the vtkVideoSource. A ModifiedEvent observer is linked to a custom command in which I make a call to Render( ). This produces an error in a call to wglMakeCurrent. How should I properly link the render window to the video source? My code is below:
>
> //CALLBACK
> class vtkMyCallback : public vtkCommand
> {
> public:
> void SetRenderWindow( vtkRenderWindow* rw )
> {
> renWin = rw;
> }
> static vtkMyCallback *New()
> { return new vtkMyCallback; }
> virtual void Execute(vtkObject *caller, unsigned long, void*)
> {
> renWin->Render(); //THIS GENERATES MY ERROR
> }
> private:
> vtkRenderWindow* renWin;
> };
>
> //MAIN
> int main(int argc, char *argv[])
> {
> ...
>
> //create the viewer and interactor
> vtkImageViewer* viewer = vtkImageViewer::New();
> vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
> iren->SetRenderWindow( viewer->GetRenderWindow() );
>
> //create the video source
> vtkVideoSource * source = vtkVideoSource::New();
> source->SetFrameSize( 640, 480, 1 );
> source->SetOutputFormatToLuminance();
> source->SetFrameRate(15);
> source->Initialize();
>
> //create the callback
> vtkMyCallback* callback = vtkMyCallback::New();
> callback->SetRenderWindow( viewer->GetRenderWindow() );
>
> //add an observer
> source->AddObserver( vtkCommand::ModifiedEvent, callback );
>
> //connect input to output
> viewer->SetInputConnection( source->GetOutputPort() );
> source->Record();
>
> iren->Initialize();
> iren->Start();
>
> iren->Delete();
> source->ReleaseSystemResources();
> source->Delete();
> viewer->Delete();
>
> }
>
> I believe my problem is that I am not calling Render from the main thread. I read a previous post (http://public.kitware.com/pipermail/vtkusers/2004-April/073478.html) that addressed a similar problem and the advised creating a new vtkMutexLock to communicate between main and the videoSource or "device" and the main thread. However, after reading this post I am unsure how to do this. Where should I create new vtkMutexLock? How do I connect it between the video source, the main thread, and say a interactor "Timer" Event observer. I guess I'm not sure where and how the threads change and where and how I should call the Render method forthe viewer. Please let me know if I am on the right track or if there is an easier way to do this.
>
> Thanks
>
> Tim
>
>
>
>
>
> ____________________________________________________________________________________
> Don't get soaked. Take a quick peek at the forecast
> with the Yahoo! Search weather shortcut.
> http://tools.search.yahoo.com/shortcuts/#loc_weather
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
____________________________________________________________________________________
Bored stiff? Loosen up...
Download and play hundreds of games for free on Yahoo! Games.
http://games.yahoo.com/games/front
More information about the vtkusers
mailing list