Hi all,
       I am working on volume rendering. I have an
array of buffered Image objects and I am forming a
Texture3D object form those bImage objects. I am then
defining some quads with suitable texture coordinates
and attributes (like transparency, rendering, polygon
attributes etc. set) for each quad (or shape3D
object). I am using REPLACE for the texture mode and
BLEND, BLEND_ONE_MINUS_SRC_ALPHA for transparency
attr. This works fine, and I could see a 3D volume
(i.e, a front view of the image)
   My problem is: Now I am changing the number of
quads to be used in rendering. When I change the
number of quads used, I am detaching the current BG
(holding all the quads) and building a new BG(with new
quads and attributes set) into the scene. Now what I
see is that rendered image's transparency is changed
and the slices that are mapped front are becoming more
transparent, showing the slices that are mapped
behind, which changes the way the rendered image
looks.

Could anyone predict if I am doing any mistake. I am
working on this problem since 4 days but could not
find a solution. If you have time please see the
following sample code below:






/* Main Program with Gui */

class Gui
{

Gui();

/* Method invoked when a data set is loaded */
FirstTime Button pressed()
{
  /* Creating a constructor of scene3D */
  Scene3DTest scene3D = new Scene3DTest();

  /* Create a 3D TExture */
  scene3D.create3DTexture();

  /* Create the quads, with suitable tex coords */
  BranchGroup bGroup1=scene3D.createPlanes(numPlanes);

 /* Render the scene */
  Panel renderedPanel = scene3D.renderScene(bGroup1);

  /* add the panel for displaying */
  addPanel(....);
}


/* WHen a new value of quads are entered */
SecondTimeButton pressed()
{
  Enters number of planes;

/* Detach the current BG holding the quads */
  scene3D.detachBranchGroup();

/* Again create a 3D Texture -- This is not necessary
again but I am calling again. Not creating a texture
again is not making any difference */

  scene3D.create3DTexture();

/* Create new quads with the specified number of
planes */
  BranchGroup bGroup2=scene3D.createPlanes(numPlanes);

/* Render the scene */
Panel finalRenderedScene=scene3D.renderScene(bGroup2);
addPanel(...)
}


  public static void main(String args[])
  {
        Frame frame = new Gui();
        ....
   }
}




/* Scene3D Class */

class Scene3DTest
{


 Scene3DTest()
 {

/* Setting up the View, Simple Universe */

   config =
SimpleUniverse.getPreferredConfiguration();
   canvas3D = new Canvas3D(config);
   simpleU = new SimpleUniverse(canvas3D);
   int policy = 0;
   View myView = new View();
   myView.setProjectionPolicy(policy);
simpleU.getViewingPlatform().setNominalViewingTransform();

/* A BG which will be holding another BG havind quads
*/

        bgRoot = new BranchGroup();
bgRoot.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
bgRoot.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
bgRoot.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
}
  // End of constructor

// Method which returns a panel with the rendered
image
Panel renderScene(BranchGroup scene)
{
  renderPanel.add("Center", canvas3D);
  scene.compile();
  bgRoot.addChild(scene);

/* This if loop is entered only for the first time */
  if(For the first time)
        {
             bgRoot.compile();
            simpleU.addBranchGraph(bgRoot);
        }

        return renderPanel;
}


/* Method which creates a 3D Texture and sets its
attributes */

create3DTexture()
{
  setting buffered Images into ImageComponent3D;
  texture = Texture3D(.......);
  texture.setImage(0, ImageCOmponent3D);
  texture.setEnable(true);
                texAttr.setTextureMode(TextureAttributes.REPLACE);

renAttr.setAlphaTestFunction(RenderingAttributes.ALWAYS);
        transAttr.setTransparencyMode(transAttr.BLENDED);

transAttr.setDstBlendFunction(transAttr.BLEND_ONE_MINUS_SRC_ALPHA);

        appear = new Appearance();

/* Setting appearance node to the texture3D */
        appear.setTexture(texture);
}

/* Method which creates quads int the texture3D for
displaying */

public BranchGroup createPlanes(int numPlanes)
{

/* This branch group holds all the quads */

BranchGroup objRoot = new BranchGroup();

   for(i=0;i<numPlanes;i++)
        {
           QuadArray plane = new QuadArray(..,..,..);
           plane.setCoordinates(...);
           plane.setTextureCoordinates(...);

           Shape3D s3d = new Shape3D(plane, appear);
           app = s3d.getAppearance();
           app.setTextureAttributes(texAttr);
           app.setRenderingAttributes(renAttr);
           app.setTransparencyAttributes(transAttr);
           s3d.setAppearance(app);
           objRoot.addChild(s3d);
       }

   objRoot.setCapability(BranchGroup.ALLOW_DETACH);
objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
        return objRoot;
}

/* Method whichj detaches the BG whoch holds the quads
*/

 public void detachBranchGroup()
    {
        bgRoot.removeChild(0);
    }
} /* ENd of class Scene3DTest


Thanks for ur patience...

Sagar.

__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to