I'm not able to get off-screen rendering to work consistently.
I modified the main() method in the 3D canvas class.
The following code hangs on the line "display.getImage(true)".
Interestingly, it worked once, and then started to hang on subsequent
runs of the same program, so I'm wondering if there is some
resource that I need to get rid of properly.
I'm doing this on Windows with Java 1.4 and Java3D 1.3.1 and
the latest pre-compiled visad.jar file from the SSEC website.
thanks
Lak
package gov.noaa.nssl.wdssii.display;
import visad.*;
import visad.java3d.DisplayImplJ3D;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
public class TestOffScreen {
public static void main(String[] args) throws Exception {
DisplayImplJ3D display = new DisplayImplJ3D("offscreen", 300, 300);
RealType[] types = {RealType.Latitude, RealType.Longitude};
RealTupleType earth_location = new RealTupleType(types);
RealType vis_radiance = RealType.getRealType("vis_radiance");
RealType ir_radiance = RealType.getRealType("ir_radiance");
RealType[] types2 = {vis_radiance, ir_radiance};
RealTupleType radiance = new RealTupleType(types2);
FunctionType image_tuple = new FunctionType(earth_location,
radiance);
int size = 32;
FlatField imaget1 = FlatField.makeField(image_tuple, size, false);
display.addMap(new ScalarMap(RealType.Latitude, Display.YAxis));
display.addMap(new ScalarMap(RealType.Longitude, Display.XAxis));
display.addMap(new ScalarMap(vis_radiance, Display.RGB));
DataReferenceImpl ref_imaget1 = new
DataReferenceImpl("ref_imaget1");
ref_imaget1.setData(imaget1);
display.addReference(ref_imaget1, null);
System.out.println("set up the display okay");
// get image with sync
BufferedImage image = display.getImage(true);
System.out.println("Got image from display");
// write image
ImageWriter writer = (ImageWriter)
ImageIO.getImageWritersByFormatName("jpg").next();
java.io.FileOutputStream of = new
java.io.FileOutputStream("test.jpg");
writer.setOutput( ImageIO.createImageOutputStream(of) );
writer.write(image);
of.close();
System.out.println("File test.jpg written out.");
}
}