[vtkusers] Offscreen Rendering
Michael Hoffer
info at michaelhoffer.de
Mon May 28 14:56:54 EDT 2012
Hi Sebastien,
thanks for your answer. I have checked vtkPanel. But it seems to be a
heavyweight AWT component. Java 7 is currently no option for me and I need
real transparency etc. There is no easy way to access the pixel data from
Java and it seems like vtkPanel only works if it is atached to a JFrame. Is
that correct?
I chose to create an alternative implementation. I uploaded it to GitHub:
http://miho.github.com/JVTK/
The project contains a pure lightweight Swing panel that uses a vtkPanel
internally. The panel converts the native pixel data to an AWT image that
is used to paint the Swing panel. I implemented basic fullscreen support.
In fullscreen mode the internal vtkPanel is used. This allows full render
performance.
The project contains a sample application that demonstrates its features.
It would be nice if you could check my implementation. Maybe there is a
better way to convert pixeldata...
Regards,
Michael
2012/5/28 Sebastien Jourdain <sebastien.jourdain at kitware.com>
> 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
> >
>
--
Dipl.-Math. Michael Hoffer
Goethe-Zentrum für Wissenschaftliches Rechnen (G-CSC)
Goethe-Universität
Kettenhofweg 139
60325 Frankfurt am Main
Tel.: +49 69 798 25254
michael.hoffer at gcsc.uni-frankfurt.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120528/aebd567f/attachment.htm>
More information about the vtkusers
mailing list