< Zurück | Inhalt | Weiter >

From RasterTest.java

//size of the window, and hence size of the depth component array private static int m_kWidth = 300;

private static int m_kHeight = 300;

//the Raster used to store depth components private Raster m_DepthRaster = null;

//the Raster used to render an image into the 3D view private Raster m_RenderRaster = null;

//an array of integer values for the depth components private int[] m_DepthData = null;

//create the image to be rendered using a Raster

BufferedImage bufferedImage = new BufferedImage( 128, 128, BufferedImage.TYPE_INT_RGB ); ImageComponent2D imageComponent2D = new ImageComponent2D( ImageComponent2D.FORMAT_RGB, bufferedImage );

imageComponent2D.setCapability( ImageComponent.ALLOW_IMAGE_READ ); imageComponent2D.setCapability( ImageComponent.ALLOW_SIZE_READ );

//create the depth component to store the 3D depth values

DepthComponentInt depthComponent = new DepthComponentInt( m_kWidth, m_kHeight );

depthComponent.setCapability( DepthComponent.ALLOW_DATA_READ );

//create the Raster for the image

m_RenderRaster = new Raster( new Point3f( 0.0f, 0.0f, 0.0f ), Raster.RASTER_COLOR,

0, 0,

bufferedImage.getWidth(), bufferedImage.getHeight(), imageComponent2D,

null );

m_RenderRaster.setCapability( Raster.ALLOW_IMAGE_WRITE ); m_RenderRaster.setCapability( Raster.ALLOW_SIZE_READ );

//create the Raster for the depth components

m_DepthRaster = new Raster( new Point3f( 0.0f, 0.0f, 0.0f ), Raster.RASTER_DEPTH,

0, 0,

m_kWidth, m_kHeight, null,

depthComponent );

//create a custom Canvas3D with postSwap overridden GraphicsConfigTemplate3D gc3D = new GraphicsConfigTemplate3D(); gc3D.setSceneAntialiasing( GraphicsConfigTemplate.PREFERRED );

GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); RasterCanvas3D c3d =

new RasterCanvas3D( this, gd[0].getBestConfiguration( gc3D) ); c3d.setSize( getCanvas3dWidth( c3d ), getCanvas3dHeight( c3d ) );

//create a Shape3D object for the Raster containing the Image Shape3D shape = new Shape3D( m_RenderRaster );

//add the Raster’s Shape3D to the Scenegraph objRoot.addChild( shape );

//take the Depth Raster and update the Render Raster containing

//the image based on the depth values stored in the Depth Raster.

//create a temporary BufferedImage for the depth components BufferedImage tempBufferedImage =

new BufferedImage( m_DepthRaster.getDepthComponent().getWidth(), m_DepthRaster.getDepthComponent().getHeight(), BufferedImage.TYPE_INT_RGB );

//allocate an array of integers to store the depth components

//from the Depth Raster m_DepthData =

new int[ m_DepthRaster.getDepthComponent().getWidth() * m_DepthRaster.getDepthComponent().getHeight () ];

//copy the depth values from the Raster into the integer array ((DepthComponentInt) m_DepthRaster.getDepthComponent()). getDepthData( m_DepthData);

//assign the depth values to the temporary image. the integer

//depths will be interpreted as integer rgb values. tempBufferedImage.setRGB(

0, 0,

m_DepthRaster.getDepthComponent().getWidth (), m_DepthRaster.getDepthComponent().getHeight(), m_DepthData, 0, m_DepthRaster.getDepthComponent().getWidth() );

//get a graphics device for the image

Graphics g = tempBufferedImage.getGraphics(); Dimension size = new Dimension(); m_RenderRaster.getSize( size );

//The Depth Raster is a different size than the Render Raster.

//i.e., if the Depth Raster is canvas width by canvas height and

//the Render Raster is of arbitrary size, we rescale the image here. g.drawImage( tempBufferedImage,

0, 0,

(int) size.getWidth(),

(int) size.getHeight(), null);

//finally, assign the scaled image to the RenderRaster


new ImageComponent2D( BufferedImage.TYPE_INT_RGB, tempBufferedImage) );

//Canvas3D overridden method to read the depth components

// of the 3D view into a Raster object and notify the Applet class RasterCanvas3D extends Canvas3D


RasterTest m_RasterTest = null;

public RasterCanvas3D( RasterTest rasterTest,

GraphicsConfiguration gc)


super( gc );

m_RasterTest = rasterTest;


public void postSwap()


super.postSwap(); getGraphicsContext3D().readRaster( m_RasterTest.getDepthRaster() );

//notify the applet to update the render object used

//to display the depth values m_RasterTest.updateRenderRaster();