Example usage for javax.media.j3d ImageComponent2D ImageComponent2D

List of usage examples for javax.media.j3d ImageComponent2D ImageComponent2D

Introduction

In this page you can find the example usage for javax.media.j3d ImageComponent2D ImageComponent2D.

Prototype

public ImageComponent2D(int format, RenderedImage image) 

Source Link

Document

Constructs a 2D image component object using the specified format and RenderedImage.

Usage

From source file:RasterTest.java

public void updateRenderRaster() {
    // takes the Depth Raster and updates 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 ints to store the depth components from the
    // Depth Raster
    if (m_DepthData == null)
        m_DepthData = new int[m_DepthRaster.getDepthComponent().getWidth()
                * m_DepthRaster.getDepthComponent().getHeight()];

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

    // assign the depth values to the temporary image, the integer depths
    // will be//ww  w.j  a va 2s  .  c o  m
    // 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);

    // because the Depth Raster is a different size to the Render Raster,
    // i.e. the Depth Raster is canvas width by canvas height and the Render
    // Raster
    // is of aritrary 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
    m_RenderRaster.setImage(new ImageComponent2D(BufferedImage.TYPE_INT_RGB, tempBufferedImage));
}

From source file:HiResCoordTest.java

private Shape3D createLabel(String szText, float x, float y, float z) {
    BufferedImage bufferedImage = new BufferedImage(50, 20, BufferedImage.TYPE_INT_RGB);
    Graphics g = bufferedImage.getGraphics();
    g.setColor(Color.white);//w w  w  . j  a  v a 2 s .c o  m
    g.drawString(szText, 10, 10);

    ImageComponent2D imageComponent2D = new ImageComponent2D(ImageComponent2D.FORMAT_RGB, bufferedImage);
    imageComponent2D.setCapability(ImageComponent.ALLOW_IMAGE_READ);
    imageComponent2D.setCapability(ImageComponent.ALLOW_SIZE_READ);

    // create the Raster for the image
    javax.media.j3d.Raster renderRaster = new javax.media.j3d.Raster(new Point3f(x, y, z),
            javax.media.j3d.Raster.RASTER_COLOR, 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(),
            imageComponent2D, null);

    return new Shape3D(renderRaster);
}

From source file:PrintCanvas3D.java

BufferedImage doRender(int width, int height) {

    BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage);

    setOffScreenBuffer(buffer);/*from  w  ww.  j a  v a  2s  .  co m*/
    renderOffScreenBuffer();
    waitForOffScreenRendering();
    bImage = getOffScreenBuffer().getImage();

    return bImage;
}

From source file:PlatformTest.java

private Shape3D createLabel(String szText, float x, float y, float z) {
    BufferedImage bufferedImage = new BufferedImage(25, 14, BufferedImage.TYPE_INT_RGB);
    Graphics g = bufferedImage.getGraphics();
    g.setColor(Color.white);// w  ww  .  j a  v  a2 s .  com
    g.drawString(szText, 2, 12);

    ImageComponent2D imageComponent2D = new ImageComponent2D(ImageComponent2D.FORMAT_RGB, bufferedImage);

    // create the Raster for the image
    javax.media.j3d.Raster renderRaster = new javax.media.j3d.Raster(new Point3f(x, y, z),
            javax.media.j3d.Raster.RASTER_COLOR, 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(),
            imageComponent2D, null);

    return new Shape3D(renderRaster);
}

From source file:J3dSwingFrame.java

/**
 * Set the texture on our goemetry/*  www .ja  v  a  2  s  .co  m*/
 * <P>
 * Always specified as a URL so that we may fetch it from anywhere.
 * 
 * @param url
 *            The url to the image.
 */
public void setTexture(URL url) {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image src_img = tk.createImage(url);
    BufferedImage buf_img = null;

    if (!(src_img instanceof BufferedImage)) {
        // create a component anonymous inner class to give us the image
        // observer we need to get the width and height of the source image.
        Component obs = new Component() {
        };

        int width = src_img.getWidth(obs);
        int height = src_img.getHeight(obs);

        // construct the buffered image from the source data.
        buf_img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics g = buf_img.getGraphics();
        g.drawImage(src_img, 0, 0, null);
        g.dispose();
    } else
        buf_img = (BufferedImage) src_img;

    src_img.flush();

    ImageComponent img_comp = new ImageComponent2D(ImageComponent.FORMAT_RGB, buf_img);

    texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, img_comp.getWidth(), img_comp.getHeight());

    appearance.setTexture(texture);

    buf_img.flush();
}

From source file:Human1.java

private BufferedImage doRender(int width, int height) {

    BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGB, bImage);
    //buffer.setYUp(true);

    setOffScreenBuffer(buffer);//from   w  w  w .  j a va2s .c  o  m
    renderOffScreenBuffer();
    waitForOffScreenRendering();
    bImage = getOffScreenBuffer().getImage();
    return bImage;
}

From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java

public void setBackgroundGradient(Color c0, Color c1, Color c2) {
    bgColor = new Color3f(c0.getColorComponents(null));
    myFog.setColor(bgColor);//from  ww w .j a va 2  s  .  com
    fireBgrColorChanged();
    int r0 = c0.getRed(), r1 = c1.getRed(), r2 = c2.getRed();
    int g0 = c0.getGreen(), g1 = c1.getGreen(), g2 = c2.getGreen();
    int b0 = c0.getBlue(), b1 = c1.getBlue(), b2 = c2.getBlue();
    int[] bgrData = new int[256 * 256];
    int k = 0;
    for (int i = 0; i < 128; i++) {
        float t = i / 127.f;
        int r = (int) (t * r1 + (1 - t) * r0);
        int g = (int) (t * g1 + (1 - t) * g0);
        int b = (int) (t * b1 + (1 - t) * b0);
        int c = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
        for (int j = 0; j < 256; j++, k++) {
            bgrData[k] = c;
        }
    }
    for (int i = 0; i < 128; i++) {
        float t = i / 127.f;
        int r = (int) (t * r2 + (1 - t) * r1);
        int g = (int) (t * g2 + (1 - t) * g1);
        int b = (int) (t * b2 + (1 - t) * b1);
        int c = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
        for (int j = 0; j < 256; j++, k++) {
            bgrData[k] = c;
        }
    }
    BufferedImage bgrImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
    bgrImage.setRGB(0, 0, 256, 256, bgrData, 0, 256);
    ImageComponent2D bgrImageComponent = new ImageComponent2D(ImageComponent2D.FORMAT_RGBA, bgrImage);
    bg.setImage(bgrImageComponent);
}

From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java

public void setBgrImageBrightness(float t) {
    if (baseBgrImage == null) {
        return;//w w  w  . j  a  va 2s  .c  o m
    }
    int w = baseBgrImage.getWidth();
    int h = baseBgrImage.getHeight();
    int[] bgrData = baseBgrImage.getRGB(0, 0, w, h, null, 0, w);
    for (int i = 0; i < bgrData.length; i++) {
        int imc = bgrData[i];
        int r = (int) (t * ((imc >> 16) & 0xff));
        int g = (int) (t * ((imc >> 8) & 0xff));
        int b = (int) (t * (imc & 0xff));
        bgrData[i] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
    }
    BufferedImage bgrImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    bgrImage.setRGB(0, 0, w, h, bgrData, 0, w);
    ImageComponent2D bgrImageComponent = new ImageComponent2D(ImageComponent2D.FORMAT_RGBA, bgrImage);
    bg.setImage(bgrImageComponent);
}