[vtkusers] Offscreen Rendering

Sebastien Jourdain sebastien.jourdain at kitware.com
Mon May 28 09:00:44 EDT 2012


I think you have a better solution on your end since you are using Java.
The idea is to use a vtkPanel or vtkCanvas directly without inserting
it in a graphical component. Somehow, it will be offscreen and you
will keep the GPU acceleration.

Let me know how it goes.

Seb

On Sun, May 27, 2012 at 3:48 PM, Michael Hoffer <info at michaelhoffer.de> wrote:
> Hello,
>
> i am totally new to VTK. First of all, I was really surprised how easy it is
> to setup VTK with Java. I compiled it on Linux and OS X. Well done!
>
> Now my question: as I am interested in offscreen rendering I tried the
> example below. It worked but unfortunately an empty window was shown. I
> didn't expect a window. Do I really have to completely switch hardware
> acceleration off by using VTK_OPENGL_HAS_OSMESA? Couldn't I just hide the
> window? If it is possible, how do I do that?
>
> My intention is to write a pure Swing component that uses offscreen
> rendering. I know that this will slow down everything. But my views will be
> relatively small in size (e.g. 300x200 pixel). Thus, the performance should
> be ok as long as getting the native memory isn't too time consuming. I have
> seen that there are some approaches that also tried that. But all code
> samples I have seen looped over the vtk array to copy it to an image. This
> is definitely too slow. But using WritableRaster, DataBuffer etc. should
> help.
>
> Thanks for your help!
>
> Regards,
> Michael
>
> //
> // code originally
> from http://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/OffScreenRendering
> //
> import vtk.*;
>
> /**
>  *
>  * @author Michael Hoffer info at michaelhoffer.de
>  */
> public class VTKOffscreenSample {
>
>     public static void main(String[] args) {
>
>         loadLibraries();
>
>         // Setup offscreen rendering
>         vtkGraphicsFactory graphics_factory = new vtkGraphicsFactory();
>         graphics_factory.SetOffScreenOnlyMode(1);
>         graphics_factory.SetUseMesaClasses(1);
>
>         vtkImagingFactory imaging_factory = new vtkImagingFactory();
>         imaging_factory.SetUseMesaClasses(1);
>
>         // Create a sphere
>         vtkSphereSource sphereSource = new vtkSphereSource();
>
>         // Create a mapper and actor
>         vtkPolyDataMapper mapper = new vtkPolyDataMapper();
>         mapper.SetInputConnection(sphereSource.GetOutputPort());
>
>         vtkActor actor = new vtkActor();
>         actor.SetMapper(mapper);
>
>         // A renderer and render window
>         vtkRenderer renderer = new vtkRenderer();
>         vtkRenderWindow renderWindow = new vtkRenderWindow();
>         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();
>
>         vtkWindowToImageFilter windowToImageFilter = new
> vtkWindowToImageFilter();
>         windowToImageFilter.SetInput(renderWindow);
>         windowToImageFilter.Update();
>
>         vtkPNGWriter writer = new vtkPNGWriter();
>         writer.SetFileName("screenshot.png");
>         writer.SetInputConnection(windowToImageFilter.GetOutputPort());
>         writer.Write();
>     }
>
>     private static void loadLibraries() {
>
>         if (!vtkNativeLibrary.LoadAllNativeLibraries()) {
>             for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {
>                 if (!lib.IsLoaded()) {
>                     System.out.println(lib.GetLibraryName() + " not
> loaded");
>                 }
>             }
>
>             System.out.println("Make sure the search path is correct: ");
>             System.out.println(System.getProperty("java.library.path"));
>         }
>
>         vtkNativeLibrary.DisableOutputWindow(null);
>     }
> }
>
>
> _______________________________________________
> 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
>



More information about the vtkusers mailing list