How to achieve the screen shot with VTK

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to achieve the screen shot with VTK

ljp19890525
Hi all,
I try to write the codes to shot the Screen with VTK, as I want to capture the results of visualization,and save as some image formats,such tiff,JEPG,bmp and so on. How should I do firstly?
I render the result in the vtkRenderWindow and vtkRenderWindowInteractor. How can I capture the rendering result in the vtkRenderWindow? I do not know when rendering where the data store. I think I should find the place and write the data there  to  other image format.
Please give me some advices,Thanks a lot!
 

ljp19890525

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: How to achieve the screen shot with VTK

Vladimir Dudnik
Hi,

to capture the content of vtkRenderWindow you can use vtkWindowToImageFilter function and then to store this to file you may call vtkBMPWriter/vtkJPEGWriter/vtkPNGWriter functions.

Below is an example of function which capture contnet of render window and stores it to image file

void 3DView::onWindowScreenshot(void)
{
  FileSaveDialog dlg;

  dlg.Init(".");

  if(QDialog::Accepted == dlg.exec())
  {
    QString saveFileName = dlg.selectedFiles().last();
    QFileInfo fi(saveFileName);

    vtkWindowToImageFilter* f = vtkWindowToImageFilter::New();

    f->Modified();
    f->SetInput(m_qvtkWidget->GetRenderWindow());
    f->SetInputBufferTypeToRGBA();
    f->Update();

    vtkImageData* data = f->GetOutput();

    if("png" == fi.suffix())
    {
      vtkPNGWriter* w = vtkPNGWriter::New();

      w->SetFileName(saveFileName.toAscii());
      w->SetInput(data);
      w->Write();
      w->Delete();
    }

    if("bmp" == fi.suffix())
    {
      vtkBMPWriter* w = vtkBMPWriter::New();
      w->SetFileName(saveFileName.toAscii());
      w->SetInput(data);
      w->Write();
      w->Delete();
    }

    if("jpg" == fi.suffix())
    {
      vtkJPEGWriter* w = vtkJPEGWriter::New();
      w->SetFileName(saveFileName.toAscii());
      w->SetInput(data);
      w->Write();
      w->Delete();
    }

    f->Delete();
  }

  return;
} // onWindowScreenshot()

Here, dialog provides user choosen name and format of file to store. The content of render window is taken from m_qvtkWidget (which is class variable of QVTKWidget type). The example is from Qt based application which renders 3D in VTK window.

Hope this helps.

Regards,
  Vladimir
Reply | Threaded
Open this post in threaded view
|

Re: How to achieve the screen shot with VTK

Bill Lorensen
In reply to this post by ljp19890525


On Mon, Apr 15, 2013 at 3:30 AM, ljp19890525 <[hidden email]> wrote:
Hi all,
I try to write the codes to shot the Screen with VTK, as I want to capture the results of visualization,and save as some image formats,such tiff,JEPG,bmp and so on. How should I do firstly?
I render the result in the vtkRenderWindow and vtkRenderWindowInteractor. How can I capture the rendering result in the vtkRenderWindow? I do not know when rendering where the data store. I think I should find the place and write the data there  to  other image format.
Please give me some advices,Thanks a lot!
 

ljp19890525

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers




--
Unpaid intern in BillsBasement at noware dot com

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: How to achieve the screen shot with VTK

vinmean
You can convert the image data into opencv Mat. Then you can save it in any
format.

cv::Mat screenshot()
{

        vtkSmartPointer<vtkWindowToImageFilter> wif =
vtkSmartPointer<vtkWindowToImageFilter>::New();
        wif->SetInput(renderWindow);
        wif->Update();
        vtkImageData* vtkRGBimage = wif->GetOutput();
        int dimsRGBImage[3];
        vtkRGBimage->GetDimensions(dimsRGBImage);
        cv::Mat cvImageRGB (dimsRGBImage[1], dimsRGBImage[0], CV_8UC3,
vtkRGBimage->GetScalarPointer());
        cv::cvtColor( cvImageRGB, cvImageRGB, CV_BGR2RGB); //convert color
        cv::flip( cvImageRGB, cvImageRGB, 0); //align axis with visualizer
        return cvImageRGB;
}



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers