Hi Sebastien,<div><br></div><div>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?<div>
<br></div><div>I chose to create an alternative implementation. I uploaded it to GitHub: <a href="http://miho.github.com/JVTK/">http://miho.github.com/JVTK/</a></div><div><br></div><div>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.</div>
<div><br></div><div>The project contains a sample application that demonstrates its features.</div><div><br></div><div>It would be nice if you could check my implementation. Maybe there is a better way to convert pixeldata...</div>
<div><br></div><div>Regards,</div><div>Michael</div></div><br><div class="gmail_quote">2012/5/28 Sebastien Jourdain <span dir="ltr"><<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think you have a better solution on your end since you are using Java.<br>
The idea is to use a vtkPanel or vtkCanvas directly without inserting<br>
it in a graphical component. Somehow, it will be offscreen and you<br>
will keep the GPU acceleration.<br>
<br>
Let me know how it goes.<br>
<br>
Seb<br>
<div><div class="h5"><br>
On Sun, May 27, 2012 at 3:48 PM, Michael Hoffer <<a href="mailto:info@michaelhoffer.de">info@michaelhoffer.de</a>> wrote:<br>
> Hello,<br>
><br>
> i am totally new to VTK. First of all, I was really surprised how easy it is<br>
> to setup VTK with Java. I compiled it on Linux and OS X. Well done!<br>
><br>
> Now my question: as I am interested in offscreen rendering I tried the<br>
> example below. It worked but unfortunately an empty window was shown. I<br>
> didn't expect a window. Do I really have to completely switch hardware<br>
> acceleration off by using VTK_OPENGL_HAS_OSMESA? Couldn't I just hide the<br>
> window? If it is possible, how do I do that?<br>
><br>
> My intention is to write a pure Swing component that uses offscreen<br>
> rendering. I know that this will slow down everything. But my views will be<br>
> relatively small in size (e.g. 300x200 pixel). Thus, the performance should<br>
> be ok as long as getting the native memory isn't too time consuming. I have<br>
> seen that there are some approaches that also tried that. But all code<br>
> samples I have seen looped over the vtk array to copy it to an image. This<br>
> is definitely too slow. But using WritableRaster, DataBuffer etc. should<br>
> help.<br>
><br>
> Thanks for your help!<br>
><br>
> Regards,<br>
> Michael<br>
><br>
> //<br>
> // code originally<br>
> from <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/OffScreenRendering" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/OffScreenRendering</a><br>
> //<br>
> import vtk.*;<br>
><br>
> /**<br>
> *<br>
> * @author Michael Hoffer <a href="mailto:info@michaelhoffer.de">info@michaelhoffer.de</a><br>
> */<br>
> public class VTKOffscreenSample {<br>
><br>
> public static void main(String[] args) {<br>
><br>
> loadLibraries();<br>
><br>
> // Setup offscreen rendering<br>
> vtkGraphicsFactory graphics_factory = new vtkGraphicsFactory();<br>
> graphics_factory.SetOffScreenOnlyMode(1);<br>
> graphics_factory.SetUseMesaClasses(1);<br>
><br>
> vtkImagingFactory imaging_factory = new vtkImagingFactory();<br>
> imaging_factory.SetUseMesaClasses(1);<br>
><br>
> // Create a sphere<br>
> vtkSphereSource sphereSource = new vtkSphereSource();<br>
><br>
> // Create a mapper and actor<br>
> vtkPolyDataMapper mapper = new vtkPolyDataMapper();<br>
> mapper.SetInputConnection(sphereSource.GetOutputPort());<br>
><br>
> vtkActor actor = new vtkActor();<br>
> actor.SetMapper(mapper);<br>
><br>
> // A renderer and render window<br>
> vtkRenderer renderer = new vtkRenderer();<br>
> vtkRenderWindow renderWindow = new vtkRenderWindow();<br>
> renderWindow.SetOffScreenRendering(1);<br>
> renderWindow.AddRenderer(renderer);<br>
><br>
> // Add the actors to the scene<br>
> renderer.AddActor(actor);<br>
> renderer.SetBackground(1, 1, 1); // Background color white<br>
><br>
> renderWindow.Render();<br>
><br>
> vtkWindowToImageFilter windowToImageFilter = new<br>
> vtkWindowToImageFilter();<br>
> windowToImageFilter.SetInput(renderWindow);<br>
> windowToImageFilter.Update();<br>
><br>
> vtkPNGWriter writer = new vtkPNGWriter();<br>
> writer.SetFileName("screenshot.png");<br>
> writer.SetInputConnection(windowToImageFilter.GetOutputPort());<br>
> writer.Write();<br>
> }<br>
><br>
> private static void loadLibraries() {<br>
><br>
> if (!vtkNativeLibrary.LoadAllNativeLibraries()) {<br>
> for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {<br>
> if (!lib.IsLoaded()) {<br>
> System.out.println(lib.GetLibraryName() + " not<br>
> loaded");<br>
> }<br>
> }<br>
><br>
> System.out.println("Make sure the search path is correct: ");<br>
> System.out.println(System.getProperty("java.library.path"));<br>
> }<br>
><br>
> vtkNativeLibrary.DisableOutputWindow(null);<br>
> }<br>
> }<br>
><br>
><br>
</div></div>> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at:<br>
> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Dipl.-Math. Michael Hoffer<br><br>Goethe-Zentrum für Wissenschaftliches Rechnen (G-CSC)<br>Goethe-Universität<br>Kettenhofweg 139<br>60325 Frankfurt am Main<br>
Tel.: +49 69 798 25254<br><a href="mailto:michael.hoffer@gcsc.uni-frankfurt.de" target="_blank">michael.hoffer@gcsc.uni-frankfurt.de</a><br>