Example usage for javax.media.j3d Raster RASTER_COLOR

List of usage examples for javax.media.j3d Raster RASTER_COLOR

Introduction

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

Prototype

int RASTER_COLOR

To view the source code for javax.media.j3d Raster RASTER_COLOR.

Click Source Link

Document

Specifies a Raster object with color data.

Usage

From source file:ReadRaster.java

public BranchGroup createSceneGraph(BufferedImage bImage, Raster readRaster) {

    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a Raster shape. Add it to the root of the subgraph

    ImageComponent2D drawImageComponent = new ImageComponent2D(ImageComponent.FORMAT_RGB, bImage);

    Raster drawRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, bImage.getWidth(),
            bImage.getHeight(), drawImageComponent, null);
    Shape3D shape = new Shape3D(drawRaster);
    drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE);
    objRoot.addChild(shape);/*from www. j  a  v a 2  s  .c  om*/

    // Ceate the transform greup node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    TransformGroup cubeScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(-0.5, 0.5, 0.0));
    cubeScale.setTransform(t3d);

    cubeScale.addChild(objTrans);
    objRoot.addChild(cubeScale);

    // Create a simple shape leaf node, add it to the scene graph.
    objTrans.addChild(new ColorCube(0.3));

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);
    myRotationInterpolator rotator = new myRotationInterpolator(drawRaster, readRaster, rotationAlpha, objTrans,
            yAxis, 0.0f, (float) Math.PI * 2.0f);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);

    // Have Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:PrintFromButton.java

public void init() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    BufferedImage bImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);

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

    Raster drawRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, 200, 200, buffer,
            null);//  w w  w  .j  a  va 2  s.  c  o m

    drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE);

    // create the main scene graph
    BranchGroup scene = createSceneGraph(drawRaster);

    // create the on-screen canvas
    Canvas3D d = new Canvas3D(config, false);
    add("Center", d);

    // create a simple universe
    u = new SimpleUniverse(d);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();

    // create an off Screen Buffer

    c = new OffScreenCanvas3D(config, true, drawRaster);

    // set the offscreen to match the onscreen
    Screen3D sOn = d.getScreen3D();
    Screen3D sOff = c.getScreen3D();
    sOff.setSize(sOn.getSize());
    sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth());
    sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight());

    // attach the same view to the offscreen canvas
    u.getViewer().getView().addCanvas3D(c);

    // create the gui
    Button b = new Button("Print");
    b.addActionListener(this);
    Panel p = new Panel();
    p.add(b);
    add("North", p);

    u.addBranchGraph(scene);
}

From source file:OffScreenTest.java

public void init() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    BufferedImage bImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);

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

    Raster drawRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, 200, 200, buffer,
            null);//  w  w w  .  ja  v  a 2s .c  o  m

    drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE);

    // create the main scene graph
    BranchGroup scene = createSceneGraph(drawRaster);

    // create the on-screen canvas
    OnScreenCanvas3D d = new OnScreenCanvas3D(config, false);
    add("Center", d);

    // create a simple universe
    u = new SimpleUniverse(d);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();

    // create an off Screen Canvas

    OffScreenCanvas3D c = new OffScreenCanvas3D(config, true, drawRaster);

    // set the offscreen to match the onscreen
    Screen3D sOn = d.getScreen3D();
    Screen3D sOff = c.getScreen3D();
    sOff.setSize(sOn.getSize());
    sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth());
    sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight());

    // attach the same view to the offscreen canvas
    View v = u.getViewer().getView();
    v.addCanvas3D(c);

    // tell onscreen about the offscreen so it knows to
    // render to the offscreen at postswap
    d.setOffScreenCanvas(c);

    u.addBranchGraph(scene);
    v.stopView();
    // Make sure that image are render completely
    // before grab it in postSwap().
    d.setImageReady();
    v.startView();

}

From source file:RasterTest.java

public RasterTest() {
    // 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);/*from www.j a  v  a2 s . c o m*/

    initJava3d();
}

From source file:ReadRaster.java

public void init() {

    int width = 128;
    int height = 128;

    ImageComponent2D readImageComponent = new ImageComponent2D(ImageComponent.FORMAT_RGB, width, height);

    Raster readRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, width, height,
            readImageComponent, null);/*w w w . j  a  v a  2s.  com*/

    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    Canvas3D c = new myCanvas3D(config, readRaster);
    add("Center", c);

    // Create a simple scene and attach it to the virtual universe
    BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    BranchGroup scene = createSceneGraph(bImage, readRaster);
    u = new SimpleUniverse(c);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();

    u.addBranchGraph(scene);
}

From source file:ExRaster.java

public Group buildScene() {
    // Turn on the headlight
    setHeadlightEnable(true);/*from   w w w .  ja  v a 2  s . co m*/

    // Default to examine navigation
    setNavigationType(Examine);

    // Build the scene root
    Group scene = new Group();

    if (debug)
        System.err.println("  rasters...");

    // BEGIN EXAMPLE TOPIC
    // Create three raster geometry shapes, each with a
    // different annotation text image

    // Load the texture images
    TextureLoader texLoader = new TextureLoader("one.jpg", this);
    ImageComponent2D oneImage = texLoader.getImage();
    if (oneImage == null) {
        System.err.println("Cannot load 'one.jpg'");
    }

    texLoader = new TextureLoader("two.jpg", this);
    ImageComponent2D twoImage = texLoader.getImage();
    if (twoImage == null) {
        System.err.println("Cannot load 'two.jpg'");
    }

    texLoader = new TextureLoader("three.jpg", this);
    ImageComponent2D threeImage = texLoader.getImage();
    if (threeImage == null) {
        System.err.println("Cannot load 'three.jpg'");
    }

    // Create raster geometries and shapes
    Vector3f trans = new Vector3f();
    Transform3D tr = new Transform3D();
    TransformGroup tg;

    // Left
    Raster raster = new Raster();
    raster.setPosition(new Point3f(-2.0f, 0.75f, 0.0f));
    raster.setType(Raster.RASTER_COLOR);
    raster.setOffset(0, 0);
    raster.setSize(64, 32);
    raster.setImage(oneImage);
    Shape3D sh = new Shape3D(raster, new Appearance());
    scene.addChild(sh);

    // Middle-back
    raster = new Raster();
    raster.setPosition(new Point3f(0.0f, 0.75f, -2.0f));
    raster.setType(Raster.RASTER_COLOR);
    raster.setOffset(0, 0);
    raster.setSize(64, 32);
    raster.setImage(twoImage);
    sh = new Shape3D(raster, new Appearance());
    scene.addChild(sh);

    // Right
    raster = new Raster();
    raster.setPosition(new Point3f(2.0f, 0.75f, 0.0f));
    raster.setType(Raster.RASTER_COLOR);
    raster.setOffset(0, 0);
    raster.setSize(64, 32);
    raster.setImage(threeImage);
    sh = new Shape3D(raster, new Appearance());
    scene.addChild(sh);
    // END EXAMPLE TOPIC

    // Build foreground geometry including a floor and
    // cones on which the raster images sit
    if (debug)
        System.err.println("  cones...");
    Appearance app0 = new Appearance();
    Material mat0 = new Material();
    mat0.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat0.setDiffuseColor(1.0f, 0.0f, 0.0f);
    mat0.setSpecularColor(0.7f, 0.7f, 0.7f);
    app0.setMaterial(mat0);

    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3f(-2.0f, 0.0f, 0.0f));
    TransformGroup tg0 = new TransformGroup(t3d);
    Cone cone0 = new Cone(0.5f, // radius
            1.5f, // height
            Primitive.GENERATE_NORMALS, // flags
            16, // x division
            16, // y division
            app0); // appearance
    tg0.addChild(cone0);
    scene.addChild(tg0);

    Appearance app1 = new Appearance();
    Material mat1 = new Material();
    mat1.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat1.setDiffuseColor(0.0f, 1.0f, 0.0f);
    mat1.setSpecularColor(0.7f, 0.7f, 0.7f);
    app1.setMaterial(mat1);

    t3d = new Transform3D();
    t3d.setTranslation(new Vector3f(0.0f, 0.0f, -2.0f));
    TransformGroup tg1 = new TransformGroup(t3d);
    Cone cone1 = new Cone(0.5f, // radius
            1.5f, // height
            Primitive.GENERATE_NORMALS, // flags
            16, // x division
            16, // y division
            app1); // appearance
    tg1.addChild(cone1);
    scene.addChild(tg1);

    Appearance app2 = new Appearance();
    Material mat2 = new Material();
    mat2.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat2.setDiffuseColor(0.0f, 0.6f, 1.0f);
    mat2.setSpecularColor(0.7f, 0.7f, 0.7f);
    app2.setMaterial(mat2);

    t3d = new Transform3D();
    t3d.setTranslation(new Vector3f(2.0f, 0.0f, 0.0f));
    TransformGroup tg2 = new TransformGroup(t3d);
    Cone cone2 = new Cone(0.5f, // radius
            1.5f, // height
            Primitive.GENERATE_NORMALS, // flags
            16, // x division
            16, // y division
            app2); // appearance
    tg2.addChild(cone2);
    scene.addChild(tg2);

    return scene;
}