[vtkusers] Win32 OffScreen Rendering and Visibility cell selector

David E DeMarle dave.demarle at kitware.com
Thu Mar 22 15:12:48 EDT 2007


I've just committed a change to vtkOpenGLRenderWindow which appears to fix
it. The change is to return default values if the window isn't mapped like
getColorDepth does.

cheers
Dave DeMarle

On 3/22/07, David E DeMarle <dave.demarle at kitware.com> wrote:
>
> Hmmm, the program looks ok to me, with the exception of two calls to a
> "render" instead of "ofsrender".
> I will try cell selection with offscreen rendering on windows and see if I
> can reproduce the problem.
>
> cheers
> Dave DeMarle
>
>
> On 3/20/07, Lim, Theodore <T.Lim at hw.ac.uk> wrote:
>
> >  Hi,
> >
> > Not sure how to put this but here goes...
> >
> > I'm trying to get get visible cell data for a series of camera positions
> > and would like to do this using the Win32 offscreen rendering capabilities.
> >
> > However, i discovered that the offscreen render window color buffer size
> > returns all 0 values. This seems to be the reason why the visible cell
> > selector fails. Is there a way to set (or force) values into it?
> >
> > Or rather, can the new class vtkVisibilityCellSelector be used in
> > Offscreen rendering mode? And if so, how can this be achieved. I've attached
> > the code which i'm testing below.
> >
> > One note: i compiled with cmake option VTK_USE_OFFSCREEN set to 'Off' as
> > this caused the vtkMFC examples (i.e. vtkDLG, vtkSDI, vtkMDI) to crash.
> > It also caused the same response to my own VTK-MFC app. Not sure if this has
> > anything to do with it not being able to use Offscreen. In the test code
> > below, i use the vtkWindowToImageFilter to grab a snapshot of the offscreen
> > render window and the results was as expected.
> >
> > Any help would be greatly appreciated.
> >
> > Many thanks, Theo.
> >
> >
> > /**************************************************************************************************/
> > int main()
> > {
> >  //Load model
> >  vtkSmartPointer<vtkSTLReader> reader =
> > vtkSmartPointer<vtkSTLReader>::New();
> >  reader->SetFileName("C:/Model/Data/MillCut.stl");
> >  vtkSmartPointer<vtkPolyDataMapper> map1 =
> > vtkSmartPointer<vtkPolyDataMapper>::New();
> >  map1->SetInput(reader->GetOutput());
> >
> >  // set up offscreen renderer
> >  vtkSmartPointer<vtkRenderer> ofsrenderer =
> > vtkSmartPointer<vtkRenderer>::New();
> >  ofsrenderer->SetBackground(0.0,0.0,0.0);
> >  vtkSmartPointer<vtkRenderWindow> ofsrenWin =
> > vtkSmartPointer<vtkRenderWindow>::New();
> >  ofsrenWin->AddRenderer(ofsrenderer);
> >  ofsrenWin->SetSize(800,800);
> >  ofsrenWin->SetOffScreenRendering(1);
> >  // set interactor
> >  vtkSmartPointer<vtkRenderWindowInteractor> iren =
> > vtkSmartPointer<vtkRenderWindowInteractor>::New();
> >  iren->SetRenderWindow(ofsrenWin);
> >
> >  //set up the view
> >  renderer->GetActiveCamera()->SetViewUp(0, 1, 0);
> >  renderer->SetBackground(0.0,0.0,0.0);
> >
> >
> >  // set actor
> >  vtkSmartPointer<vtkActor> act1 = vtkSmartPointer<vtkActor>::New();
> >  act1->SetMapper(map1);
> >  // add actor to renderer
> >  double diagonal = act1->GetLength();
> >  double *center = act1->GetCenter();
> >  ofsrenderer->AddActor(act1);
> >  ofsrenderer->GetActiveCamera()->SetFocalPoint(center);
> >  ofsrenderer->GetActiveCamera()->SetPosition(20, -20, -27);
> >  ofsrenderer->ResetCamera();
> >
> >  ofsrenWin->Render();
> >  //-----------------------------------------------
> >  // check offscreen render window...
> >  int rgba[4];
> >  ofsrenWin->GetColorBufferSizes(rgba);
> >  vtkSmartPointer<vtkWindowToImageFilter> wif =
> > vtkSmartPointer<vtkWindowToImageFilter>::New();//
> >  wif->SetInput(ofsrenWin);
> >  wif->Update();
> >  vtkSmartPointer<vtkJPEGWriter> jpgw =
> > vtkSmartPointer<vtkJPEGWriter>::New();
> >  jpgw->SetInput(wif->GetOutput());
> >  jpgw->SetQuality(100);
> >  jpgw->SetFileName("D:/Projects/VTK/testoffscreen.jpg");
> >  jpgw->Write();
> >  //-----------------------------------------------
> >
> >  // get visible cells
> >  vtkSmartPointer<vtkVisibleCellSelector> sel1 =
> > vtkSmartPointer<vtkVisibleCellSelector>::New();
> >  sel1->SetRenderer(ofsrenderer);
> >         // grab everything in the render window viewport
> >  int *size = ofsrenderer->GetRenderWindow()->GetSize();
> >  sel1->SetRenderPasses(0,1,0,1,1);
> >  sel1->SetArea(size[0],size[1],size[2],size[3]);
> >  sel1->Select();
> >  vtkSmartPointer<vtkSelection> res1 =
> > vtkSmartPointer<vtkSelection>::New();
> >  sel1->GetSelectedIds(res1);
> >  vtkSmartPointer<vtkSelection> cellids = res1->GetChild(0);
> >  vtkSmartPointer<vtkExtractSelectedPolyDataIds> extr =
> > vtkSmartPointer<vtkExtractSelectedPolyDataIds>::New();
> >         if (cellids)
> >          {
> >           extr->SetInput(1, act1->GetMapper()->GetInput());
> >           extr->SetInput(0, cellids);
> >           extr->Update();
> >           sMap->SetInput(extr->GetOutput());
> >          }
> >         else
> >          {
> >           cerr << "Empty color buffer selection -" << endl;
> >           cerr << "Check display color depth. Must be at least 24 bit."
> > << endl;
> >           sMap->SetInput(emptyPD);
> >          }
> >  ////////////////////////////////////////////////////////////
> >  ofsrenWin->Render();
> >
> >  // Set the user method (bound to key 'u')
> >  iren->Initialize();
> >  iren->Start();
> >
> >  return 0;
> > }
> >
> >
> >
> > _______________________________________________
> > 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
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070322/0da88229/attachment.htm>


More information about the vtkusers mailing list