Commit 9a970652 authored by Purves, Murray's avatar Purves, Murray
Browse files

Adding screenshot output to vtkchartwidget

parent 5cc877f9
Pipeline #44107 passed with stages
in 16 minutes and 13 seconds
......@@ -4,6 +4,9 @@ VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
#include <vtkPNGWriter.h>
#include <vtkWindowToImageFilter.h>
#include "radixwidgets/vtkchartwidget.hh"
namespace radix
......@@ -33,4 +36,19 @@ vtkSmartPointer<vtkContextView> VTKChartWidget::contextView()
return mContextView;
}
void VTKChartWidget::savePNG(QString outputFile)
{
// Save the current view as a PNG file
vtkSmartPointer<vtkWindowToImageFilter> filter =
vtkSmartPointer<vtkWindowToImageFilter>::New();
filter->SetInput(mContextView->GetRenderWindow());
filter->ReadFrontBufferOff();
filter->Update();
vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New();
writer->SetFileName(outputFile.toStdString().c_str());
writer->SetInputConnection(filter->GetOutputPort());
writer->Write();
}
} // namespace radix
......@@ -10,6 +10,8 @@
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <QString>
#include "radixcore/visibility.hh"
namespace radix
......@@ -32,6 +34,10 @@ class RADIX_PUBLIC VTKChartWidget : public QVTKOpenGLWidget
// Default values
static double mDefaultBackground[3];
public slots:
// Save the current chart image as a PNG
void savePNG(QString outputFile);
signals:
}; // class VTKChartWidget
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment