Re: Problem with off-screen render


A quick update for any one else who may find themselves in the
same boat ... A poster on the Java3D list indicated that Java3D
does not work in the headless mode (my hack below produced
a GraphicsConfiguraiton that led to a ClassCastException deeper
down inside Java3D).

So, can you use VisAD from within servlets? Yes, but in a more
round-about way.  This is what I did:
 1) I created a Java application that had a visible JFrame. The
server dynamically creates images and writes them out to the
webserver directory.
2) The servlet opens up a socket connection to the application,
and passes on the request. The app creates the image, writes it
out, and notifies the servlet via the same socket.
3) The servlet returns an image tag back to the client.

This works, but as would be expected with off-screen rendering,
it is quite slow.

Lak


Valliappa Lakshmanan wrote:

Bill,

Here's a hack that works -- read an image, and use the
Graphics2D from that Image to get a GraphicsConfiguration.
Perhaps, you can change one of the APIs to accept
such a graphics configuration from the application,
since you probably don't want the VisAD classes reading local
files :)

Thanks for your help.

Lak


// run as:     java -Djava.awt.headless=true OffscreenImage

import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;

class OffscreenImage
{
 public static void main(String[] args) throws Exception
 {
    BufferedImage template = ImageIO.read( new File("test.jpg") );
    Graphics2D g = template.createGraphics();
    GraphicsConfiguration config = g.getDeviceConfiguration();
    if ( config != null )
       System.out.println( "Got valid GraphicsConfiguration" );
 }
}





Bill Hibbard wrote:

Hi Lak,

On Fri, 27 Aug 2004, Valliappa Lakshmanan wrote:

Thanks, Ugo. I was not aware that you could specify a headless
environment that way.
I think this is the right way to go, because ultimately, I want to
create images
using VisAD within a servlet, and servlets are headless.

I added -Djava.awt.headless=true to the invocation of the java VM
when I ran my test program.
I now get a InitializerException thrown from DisplayImplJ3D.initialize()
because
VisADConfig.makeConfig calls getDefaultScreenDevice() which throws
a java.awt.HeadlessException.
I'm thinking that:
   (a) if I'm creating an offscreen DisplayImplJ3D, it should not be
asking for a default screen device.
or (b) DisplayImplJ3D.initialize() should gracefully handle a headless case.


Good idea. However, the VisADCanvasJ3D constructor needs a
non-null GraphicsConfiguration to pass as an argument to
the super() constructor for its parent Canvas3D class. I
took a quick look at the GraphicsConfiguration, GraphicsDevice
and GraphicsEnvironment JavaDocs but couldn't see an obvious
way to construct a GraphicsConfiguration without a GraphicsDevice.
If you or someone else can suggest a way, we can catch the
java.awt.HeadlessException in VisADCanvasJ3D.makeConfig() and
use your alternative. There is hopefully an easy way to do this
that my quick look missed.

Thanks,
Bill