[vtkusers] continuous rendering from vtkVideoSource

David Gobbi dgobbi at atamai.com
Fri Mar 30 21:04:40 EDT 2007


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
>
>   




More information about the vtkusers mailing list