[vtkusers] continuous rendering from vtkVideoSource
Tim Soper
tim_d_soper at yahoo.com
Fri Mar 30 18:14:14 EDT 2007
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
More information about the vtkusers
mailing list