Last active
February 23, 2023 22:50
-
-
Save certik/5687727 to your computer and use it in GitHub Desktop.
Test offscreen rendering with VTK 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
set -e | |
g++ -o test_offscreen.o -c test_offscreen.cpp -I$PYTHONHPC/include/vtk-6.0 | |
g++ -o test_offscreen test_offscreen.o $PYTHONHPC/lib/libvtk*.so | |
LD_LIBRARY_PATH=$PYTHONHPC/lib/ ./test_offscreen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// These 2 lines are needed due to: | |
// http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Factories_now_require_defines | |
#define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL) | |
#define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL) | |
#include <vtkPolyDataMapper.h> | |
#include <vtkActor.h> | |
#include <vtkRenderWindow.h> | |
#include <vtkRenderer.h> | |
#include <vtkPolyData.h> | |
#include <vtkSmartPointer.h> | |
#include <vtkSphereSource.h> | |
#include <vtkWindowToImageFilter.h> | |
#include <vtkPNGWriter.h> | |
#include <vtkGraphicsFactory.h> | |
int main () | |
{ | |
//sphere 1 | |
vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New(); | |
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); | |
mapper->SetInputConnection(sphereSource->GetOutputPort()); | |
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); | |
actor->SetMapper(mapper); | |
// a renderer and render window | |
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); | |
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); | |
renderWindow->SetOffScreenRendering(1); | |
renderWindow->AddRenderer(renderer); | |
// add the actors to the scene | |
renderer->AddActor(actor); | |
renderer->SetBackground(1, 1, 1); // Background color white | |
renderWindow->Render(); | |
vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter = | |
vtkSmartPointer<vtkWindowToImageFilter>::New(); | |
windowToImageFilter->SetInput(renderWindow); | |
windowToImageFilter->Update(); | |
vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New(); | |
writer->SetFileName("sphere.png"); | |
writer->SetInputConnection(windowToImageFilter->GetOutputPort()); | |
writer->Write(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! ./local/bin/python | |
from vtk import (vtkSphereSource, vtkPolyDataMapper, vtkActor, vtkRenderer, | |
vtkRenderWindow, vtkWindowToImageFilter, vtkPNGWriter) | |
sphereSource = vtkSphereSource() | |
mapper = vtkPolyDataMapper() | |
mapper.SetInputConnection(sphereSource.GetOutputPort()) | |
actor = vtkActor() | |
actor.SetMapper(mapper) | |
renderer = vtkRenderer() | |
renderWindow = vtkRenderWindow() | |
renderWindow.SetOffScreenRendering(1) | |
renderWindow.AddRenderer(renderer) | |
renderer.AddActor(actor) | |
renderer.SetBackground(1, 1, 1) | |
renderWindow.Render() | |
windowToImageFilter = vtkWindowToImageFilter() | |
windowToImageFilter.SetInput(renderWindow) | |
windowToImageFilter.Update() | |
writer = vtkPNGWriter() | |
writer.SetFileName("sphere.png") | |
writer.SetInputConnection(windowToImageFilter.GetOutputPort()) | |
writer.Write() |
@Guptajakala I think it did, but this is a very old set of scripts, over 6 years old at this point, so it might not compile properly anymore.
I just compiled VTK-9.0.1 with OSMESA enabled.
Following the guide and replace the OffScreenRendering.cxx
file content with your test_offscreen.cpp
, it works.
@Guptajakala I think it did, but this is a very old set of scripts, over 6 years old at this point, so it might not compile properly anymore.
I just compiled VTK-9.0.1 with OSMESA enabled.
Following the guide and replace the
OffScreenRendering.cxx
file content with yourtest_offscreen.cpp
, it works.
thank you!
Perfect, I am glad it is still useful!
…On Wed, Jul 1, 2020, at 5:52 AM, Bingliang wrote:
***@***.**** commented on this gist.
> @Guptajakala <https://github.com/Guptajakala> I think it did, but this is a very old set of scripts, over 6 years old at this point, so it might not compile properly anymore.
I just compiled VTK-9.0.1 with OSMESA enabled.
Following the guide
<https://lorensen.github.io/VTKExamples/site/Cxx/Utilities/OffScreenRendering/> and replace the `OffScreenRendering.cxx` file content with your `test_offscreen.cpp`, it works.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/5687727#gistcomment-3360632>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAFAWAXCBPQJON6UM4PSWDRZMPPLANCNFSM4J2YBOVQ>.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Guptajakala I think it did, but this is a very old set of scripts, over 6 years old at this point, so it might not compile properly anymore.