[vtkusers] Re: Some question of the using of vtkWin32VideoSource

zhangzhijun zjzhang at ee.cuhk.edu.hk
Tue May 22 11:55:48 EDT 2001


David:
          Now my program are working very well when I add
ReleaseSystemResources()
in the Delete() functions of my class. But I don't know why before I use the
~vtkWin32VideoSource()
function to do this, it doesnt' work. Maybe in the ~vtkWin32VideoSource()
the
ReleaseSystemResource() fuction is not called. Here is my MFC code for the
video display:
In the Document class I opened a serial port and read the Fastrak 3D sensor
data. and
when the serial port is opened , a working thread is also created to read
data. and
every time a serial data is read the update function of the view class will
refresh the view window
and show the video frame.
          Also I dont' know whether there will be some space to optimise the
display of the windows
cos I dont' know very well how the parameters in the functions like
SetFrameBufferSize,
SerNumberOfOutputFrames ,SetFrameRate ,SetFrameSize will be set. So I want
to know
how to make best use of these parameters.

void CCalibDoc::OnFileOpenport()
{
 ... ... // open the serial port

    videoSource->SetFrameBufferSize(60);
    videoSource->SetNumberOfOutputFrames(1);
    videoSource->SetFrameRate(60);
    videoSource->SetFrameSize(320,240,1);
    videoSource->Play();

    vtkImageViewer *imageViewer=vtkImageViewer::New();
    imageViewer->SetInput(videoSource->GetOutput());
    imageViewer->GetImageWindow()->DoubleBufferOn();
    imageViewer->SetColorWindow(255);
    imageViewer->SetColorLevel(127.5);
    imageViewer->SetZSlice(0);
    vtkImageData* imageData=vtkImageData::New();
    imageData=imageViewer->GetInput();
    vtkImageMapper* imageMapper=vtkImageMapper::New();
    imageMapper->SetInput(imageData);
    imageMapper->SetColorWindow(100);
    imageMapper->SetColorLevel(100);
    vtkImageActor *actor=vtkImageActor::New();
    actor->SetInput(imageData);
    Props1->AddItem(actor);
    winthread=AfxBeginThread(MyProc, NULL ,THREAD_PRIORITY_IDLE);
}

// in the multithread a message for update view window will be sent
// when the data is read
UINT MyProc(LPVOID pParam)
{  
// every time a serial data is read, this will be called, and the view window will  redraw
    pDoc->pView1->InvalidateRect(NULL,FALSE);
 
 return 0;
}
// and here is the video display window
// every time a update message is received, the window will be updated
// so a frame will be grabbed
void CVideoView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
 // TODO: Add your specialized code here and/or call the base class

  vtkPropCollection *propc;
  vtkProp *prop;
  // first remove any old actors
  this->Renderer->GetProps()->RemoveAllItems();

  this->GetDocument()->videoSource->Grab();  
  
propc = this->GetDocument()->GetProps1();
  propc->InitTraversal();
  while (prop = propc->GetNextProp())
    {
    this->Renderer->AddProp(prop);
 this->Renderer->ResetCamera();
 this->Renderer->SetBackground(0.2,0.3,0.4);
    }
  this->vtkMFCRenderView::OnUpdate(pSender, lHint, pHint); 
}

regards,
zj zhang








More information about the vtkusers mailing list