[vtkusers] Windows offscreen image rendering
John Biddiscombe
jbiddiscombe at skippingmouse.co.uk
Sat Sep 8 13:04:23 EDT 2001
renWin->SetupMemoryRendering(width, height,
(HDC)renWin->GetGenericContext());
renWin->Render();
// do stuff with bitmap
renWin->ResumeScreenRendering();
I have used this successfully, but note that it stopped working some time
(I don't know when - I didn't use it for months) and when I tried it last
week it gave an image of width & height of zero (ie nothing). I checked in
a fix a few days ago and my offscreen rendering is working fine again.
maybe you should try a nightly release from today or similar and give it a go.
If you're using an older vtk, you should probably just get
vtkWin32OpenGLRenderWindow from cvs
(Note that the above assumes you already have a compatible device context
on screen, if you are doing vtk without a window you might need something
else...)
JB
At 09:00 08/09/2001, =?utf-8?Q?Ermin_Hasi=C4=8Devi=C4=87?= wrote:
>Hi!
>
>I would like to render a sequence of images in offscreen mode
>using VTK on Windows platform. But it seems I can't just simply
>tell vtkWin32OpenGLImageWindow to render images offscreen.
>I have tried to set memory rendering by calling
>SetupMemoryRendering(xsize, ysize, NULL) but after calling
>Render method on image window I still get window opened
>and don't know how to prevent it's opening.
>
>What modifications should I make to following code to achieve
>offscreen rendering of images?
>
> vtkCellArray *segResCellArr = vtkCellArray::New();
> vtkPolyData *segResPD = vtkPolyData::New();
> //vtkExtentTranslator *segResExtTr = vtkExtentTranslator::New();
> vtkPolyDataMapper2D *segResMapper = vtkPolyDataMapper2D::New();
> vtkActor2D *segResActor = vtkActor2D::New();
> vtkImager *segResImager = vtkImager::New();
> vtkWin32OpenGLImageWindow *segResWnd =
>vtkWin32OpenGLImageWindow::New();
> vtkWindowToImageFilter *segResWnd2Img;
> vtkImageAppend *segResImgApp = vtkImageAppend::New();
> vtkImageBlend *segResImgBlend = vtkImageBlend::New();
> vtkBMPWriter *segResWriter = vtkBMPWriter::New();
> segResImgApp->SetAppendAxis(2);
> segResImgApp->Update();
> segResWnd->AddImager(segResImager);
> segResWnd->SetSize(MaxCoord[0] + 1, MaxCoord[1] + 1);
> segResWriter->SetFilePrefix((InputDirectory + "SEGRes" +
>BMPInputFilePrefix).c_str());
> segResWriter->SetFilePattern("%s_%03d.bmp");
> int n = VFTemplatesRadioGroup->ItemIndex;
> int contour_no = deformSurfsPD[n]->GetNumberOfCells();
> int segRes_point_no;
> int *segRes_ptIds;
> for(int i = 0; i < contour_no; i ++) {
> segRes_point_no =
>deformSurfsPD[n]->GetCell(i)->GetNumberOfPoints();
> segRes_ptIds = new int[segRes_point_no + 1];
> for(int j = 0; j < segRes_point_no; j ++) {
> segRes_ptIds[j] = j;
> }
> segRes_ptIds[segRes_point_no] = 0;
> segResCellArr->Initialize();
> segResCellArr->InsertNextCell(segRes_point_no + 1,
>segRes_ptIds);
>
>segResPD->SetPoints(deformSurfsPD[n]->GetCell(i)->GetPoints());
> segResPD->SetLines(segResCellArr);
> segResPD->Update();
> segResMapper->SetInput(segResPD);
> segResActor->SetMapper(segResMapper);
> segResImager->AddActor2D(segResActor);
> segResWnd->Render();
> segResWnd2Img = vtkWindowToImageFilter::New();
> segResWnd2Img->SetInput(segResWnd);
> segResWnd2Img->Update();
> segResImgApp->AddInput(segResWnd2Img->GetOutput());
> segResImgApp->Update();
> segResWnd2Img->Delete();
> segResImager->RemoveActor2D(segResActor);
> }
> segResImgBlend->SetInput(0, OrigImgData);
> segResImgBlend->SetInput(1, segResImgApp->GetOutput());
> segResImgBlend->SetOpacity(1, 0.2);
> segResImgBlend->Update();
> segResWriter->SetInput(segResImgBlend->GetOutput());
> segResWriter->Write();
> segResCellArr->Delete();
> segResPD->Delete();
> segResMapper->Delete();
> segResActor->Delete();
> segResImager->Delete();
> segResWnd->Delete();
> segResImgBlend->Delete();
> segResWriter->Delete();
>
>BTW. Does anybody know how to accelerate vtkBMPWriter. It takes him
>about 20 seconds
>for 20 50kB images.
>
>Thanks in advance.
>
>Ermin
>_______________________________________________
>This is the private VTK discussion list.
>Please keep messages on-topic. Check the FAQ at:
><http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list