Search in sources :

Example 1 with BranchGroup

use of javax.media.j3d.BranchGroup in project ffx by mjschnie.

the class MolecularAssembly method recurseVRML.

private void recurseVRML(Node node) {
    if (node instanceof Shape3D) {
        Shape3D s3d = (Shape3D) node;
        PickTool.setCapabilities(s3d, PickTool.INTERSECT_COORD);
        return;
    } else if (node instanceof SharedGroup) {
        SharedGroup sg = (SharedGroup) node;
        for (Enumeration<Node> e = sg.getAllChildren(); e.hasMoreElements(); ) {
            recurseVRML(e.nextElement());
        }
        return;
    } else if (node instanceof BranchGroup) {
        BranchGroup bg = (BranchGroup) node;
        for (Enumeration<Node> e = bg.getAllChildren(); e.hasMoreElements(); ) {
            recurseVRML(e.nextElement());
        }
        return;
    } else if (node instanceof TransformGroup) {
        TransformGroup vrmlTG1 = (TransformGroup) node;
        for (Enumeration<Node> e = vrmlTG1.getAllChildren(); e.hasMoreElements(); ) {
            node = e.nextElement();
            recurseVRML(node);
        }
        return;
    } else if (node instanceof Link) {
        Link link = (Link) node;
        recurseVRML(link.getSharedGroup());
        return;
    } else if (node instanceof Group) {
        Group group = (Group) node;
        for (Enumeration<Node> e = group.getAllChildren(); e.hasMoreElements(); ) {
            Node n = e.nextElement();
            recurseVRML(n);
        }
    }
}
Also used : BranchGroup(javax.media.j3d.BranchGroup) Group(javax.media.j3d.Group) SharedGroup(javax.media.j3d.SharedGroup) MSGroup(ffx.potential.bonded.MSGroup) TransformGroup(javax.media.j3d.TransformGroup) Enumeration(java.util.Enumeration) BranchGroup(javax.media.j3d.BranchGroup) Node(javax.media.j3d.Node) MSNode(ffx.potential.bonded.MSNode) Shape3D(javax.media.j3d.Shape3D) SharedGroup(javax.media.j3d.SharedGroup) Link(javax.media.j3d.Link) TransformGroup(javax.media.j3d.TransformGroup)

Example 2 with BranchGroup

use of javax.media.j3d.BranchGroup in project ffx by mjschnie.

the class Renderer method processStimulus.

/**
 * {@inheritDoc}
 *
 * This method is called by the Java3D Behavior thread after the following
 * sequence of events: 1.) A graphics operation is loaded using the "arm"
 * method. 2.) The PostID call is processed by the Java3D Behavior Thread.
 */
@Override
public void processStimulus(Enumeration parm1) {
    // Do not perform two operations before the frame has be refreshed.
    if (getView().getFrameNumber() == frameNumber) {
        System.out.print(".");
        wakeupOn(postid);
        postId(1);
        return;
    }
    // Check that the requested View and Color Models are known.
    String viewString = null;
    String colorString = null;
    if (viewModel != null) {
        try {
            viewString = viewModel.toString();
        } catch (Exception e) {
            statusBar.setText("Unknown ViewModel: " + viewModel);
            return;
        }
    }
    if (colorModel != null) {
        try {
            colorString = colorModel.toString();
        } catch (Exception e) {
            statusBar.setText("Unknown ColorModel: " + colorModel);
            return;
        }
    }
    if (timer) {
        startTimer();
        if (viewString != null) {
            logger.info("Applying ViewModel Change: " + viewString);
        }
        if (colorString != null) {
            System.out.println("Applying ColorModel Change: " + colorString);
        }
    }
    // Perform the requested rendering operation
    ArrayList<ArrayList<BranchGroup>> newChildren = new ArrayList<ArrayList<BranchGroup>>();
    for (MSNode nodeToUpdate : nodesToUpdate) {
        if (nodeToUpdate == null) {
            continue;
        }
        if (doTransform) {
            nodeToUpdate.update();
        }
        if (doColor) {
            nodeToUpdate.setColor(colorModel, null, null);
            if (statusBar != null) {
                statusBar.setText("  Color by \"" + colorString + "\" applied to " + nodeToUpdate.toString());
            }
        }
        if (doView) {
            ArrayList<BranchGroup> newShapes = new ArrayList<BranchGroup>();
            newChildren.add(newShapes);
            nodeToUpdate.setView(viewModel, newShapes);
            if (statusBar != null) {
                statusBar.setText("  Style \"" + viewString + "\" applied to " + nodeToUpdate.toString());
            }
        }
    }
    // Wait for the parallel nodes to finish
    try {
        if (ROLSP.GO_PARALLEL && ROLSP.parallelNotDone > 0) {
            logger.info("Renderer waiting for " + ROLSP.parallelNotDone + " processes...");
        }
        while (ROLSP.GO_PARALLEL && ROLSP.parallelNotDone > 0) {
            synchronized (this) {
                wait(10);
            }
        }
    } catch (Exception e) {
        System.out.println("Exception Waiting for Parallel MultiScale Methods to Finish");
    } finally {
        // the MolecularAssembly.
        for (int i = 0; i < nodesToUpdate.size(); i++) {
            if (newChildren.isEmpty()) {
                break;
            }
            MSNode nodeToUpdate = nodesToUpdate.get(i);
            if (nodeToUpdate == null) {
                continue;
            }
            if (nodeToUpdate instanceof MolecularAssembly) {
                MolecularAssembly ma = (MolecularAssembly) nodeToUpdate;
                ma.sceneGraphChange(null);
            } else if (nodeToUpdate instanceof ROLSP) {
                MolecularAssembly ma = (MolecularAssembly) nodeToUpdate.getChildAt(0);
                ma.sceneGraphChange(null);
            } else if (nodeToUpdate instanceof MSRoot) {
                for (Enumeration e = nodeToUpdate.children(); e.hasMoreElements(); ) {
                    MSNode updatedNode = (MSNode) e.nextElement();
                    if (updatedNode instanceof ROLSP) {
                        MolecularAssembly ma = (MolecularAssembly) updatedNode.getChildAt(0);
                        ma.sceneGraphChange(null);
                    } else {
                        MolecularAssembly ma = (MolecularAssembly) updatedNode;
                        ma.sceneGraphChange(null);
                    }
                }
            } else {
                ArrayList<BranchGroup> newShapes = newChildren.get(i);
                if (!newShapes.isEmpty()) {
                    MolecularAssembly ma = (MolecularAssembly) nodeToUpdate.getMSNode(MolecularAssembly.class);
                    ma.sceneGraphChange(newShapes);
                }
            }
        }
    }
    if (timer) {
        stopTimer();
    }
    nodesToUpdate = null;
    wakeupOn(postid);
    if (nodesCache != null) {
        nodesToUpdate = nodesCache;
        doTransform = doTransformCache;
        doView = doViewCache;
        viewModel = viewModelCache;
        doColor = doColorCache;
        colorModel = colorModelCache;
        nodesCache = null;
        postId(1);
    }
}
Also used : MSNode(ffx.potential.bonded.MSNode) Enumeration(java.util.Enumeration) ROLSP(ffx.potential.bonded.ROLSP) BranchGroup(javax.media.j3d.BranchGroup) MSRoot(ffx.potential.bonded.MSRoot) ArrayList(java.util.ArrayList)

Example 3 with BranchGroup

use of javax.media.j3d.BranchGroup in project ffx by mjschnie.

the class RendererCache method doubleCylinderFactory.

/**
 * <p>
 * doubleCylinderFactory</p>
 *
 * @param a1 a {@link ffx.potential.bonded.Atom} object.
 * @param a2 a {@link ffx.potential.bonded.Atom} object.
 * @param div a int.
 * @return a {@link javax.media.j3d.BranchGroup} object.
 */
public static final BranchGroup doubleCylinderFactory(Atom a1, Atom a2, int div) {
    BranchGroup branchGroup;
    if (doubleCylinderPool.size() > 0) {
        branchGroup = doubleCylinderPool.remove(0);
        if (branchGroup != null) {
            TransformGroup cy1tg = (TransformGroup) branchGroup.getChild(0);
            Shape3D cy1 = (Shape3D) cy1tg.getChild(0);
            cy1.setAppearance(a1.getAtomAppearance());
            cy1.setUserData(a1);
            TransformGroup cy2tg = (TransformGroup) branchGroup.getChild(1);
            Shape3D cy2 = (Shape3D) cy2tg.getChild(0);
            cy2.setUserData(a2);
            cy2.setAppearance(a2.getAtomAppearance());
            return branchGroup;
        }
    }
    branchGroup = new BranchGroup();
    branchGroup.setCapability(BranchGroup.ALLOW_DETACH);
    branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
    branchGroup.setCapability(BranchGroup.ENABLE_PICK_REPORTING);
    TransformGroup cy1tg = createTransformGroup(null);
    Shape3D cy1 = createCylinder(a1.getAtomAppearance(), div);
    cy1.setUserData(a1);
    cy1tg.addChild(cy1);
    branchGroup.addChild(cy1tg);
    TransformGroup cy2tg = createTransformGroup(null);
    Shape3D cy2 = createCylinder(a2.getAtomAppearance(), div);
    cy2.setUserData(a2);
    cy2tg.addChild(cy2);
    branchGroup.addChild(cy2tg);
    branchGroup.compile();
    return branchGroup;
}
Also used : BranchGroup(javax.media.j3d.BranchGroup) Shape3D(javax.media.j3d.Shape3D) TransformGroup(javax.media.j3d.TransformGroup)

Example 4 with BranchGroup

use of javax.media.j3d.BranchGroup in project ffx by mjschnie.

the class MolecularAssembly method loadVRML.

/**
 * <p>
 * loadVRML</p>
 *
 * @return a {@link javax.media.j3d.BranchGroup} object.
 */
public BranchGroup loadVRML() {
    try {
        VrmlLoader loader = new VrmlLoader();
        VrmlScene scene = null;
        if (vrmlFile != null && vrmlFile.exists()) {
            scene = (VrmlScene) loader.load(vrmlFile.getAbsolutePath());
        } else if (vrmlURL != null) {
            scene = (VrmlScene) loader.load(vrmlURL);
        } else {
            return null;
        }
        BranchGroup bg = scene.getSceneGroup();
        recurseVRML(bg);
        bg.setCapability(BranchGroup.ALLOW_DETACH);
        bg.setCapability(BranchGroup.ALLOW_BOUNDS_READ);
        bg.compile();
        return bg;
    } catch (Exception e) {
        String message = "Fatal exception loading VRML.\n";
        logger.log(Level.SEVERE, message, e);
        System.exit(-1);
        return null;
    }
}
Also used : BranchGroup(javax.media.j3d.BranchGroup) VrmlScene(org.jdesktop.j3d.loaders.vrml97.VrmlScene) VrmlLoader(org.jdesktop.j3d.loaders.vrml97.VrmlLoader)

Example 5 with BranchGroup

use of javax.media.j3d.BranchGroup in project ffx by mjschnie.

the class MolecularAssembly method sceneGraphChange.

/**
 * <p>
 * sceneGraphChange</p>
 *
 * @param newShapes a {@link java.util.List} object.
 */
public void sceneGraphChange(List<BranchGroup> newShapes) {
    if (newShapes == null) {
        newShapes = myNewShapes;
    }
    if (newShapes.isEmpty()) {
        return;
    }
    boolean reCompile = false;
    // MolecularAssembly
    for (ListIterator<BranchGroup> li = newShapes.listIterator(); li.hasNext(); ) {
        BranchGroup group = li.next();
        li.remove();
        // This is code for cycling between two MolecularAssemblies
        if (group.getUserData() != null) {
            logger.info(format("%s %s", group.toString(), group.getUserData().toString()));
        /*
                 * Object userData = group.getUserData(); if (userData!=this) {
                 * // The appearance has already been set during a recursive
                 * call to setView, // although we need to turn back on
                 * Pickablility. TransformGroup tg = (TransformGroup)
                 * group.getChild(0); Shape3D shape = (Shape3D) tg.getChild(0);
                 * shape.setPickable(true); group.setUserData(this); if
                 * (!reCompile) { if (childNodes.isLive()) {
                 * childNodes.detach(); } reCompile = true; }
                 * childNodes.moveTo(group);
                 */
        } else {
            // This is a new group since it has no userData.
            // We can not query for the identity of its parent later, so
            // we will store it as a userData reference.
            group.setUserData(this);
            if (!reCompile) {
                if (childNodes.isLive()) {
                    childNodes.detach();
                }
                reCompile = true;
            }
            childNodes.addChild(group);
        }
    }
    if (reCompile) {
        childNodes.compile();
        base.addChild(childNodes);
    }
}
Also used : BranchGroup(javax.media.j3d.BranchGroup)

Aggregations

BranchGroup (javax.media.j3d.BranchGroup)9 TransformGroup (javax.media.j3d.TransformGroup)5 Shape3D (javax.media.j3d.Shape3D)3 MSNode (ffx.potential.bonded.MSNode)2 Enumeration (java.util.Enumeration)2 Transform3D (javax.media.j3d.Transform3D)2 Vector3d (javax.vecmath.Vector3d)2 SimpleUniverse (com.sun.j3d.utils.universe.SimpleUniverse)1 MSGroup (ffx.potential.bonded.MSGroup)1 MSRoot (ffx.potential.bonded.MSRoot)1 ROLSP (ffx.potential.bonded.ROLSP)1 ArrayList (java.util.ArrayList)1 AmbientLight (javax.media.j3d.AmbientLight)1 Background (javax.media.j3d.Background)1 BoundingSphere (javax.media.j3d.BoundingSphere)1 DirectionalLight (javax.media.j3d.DirectionalLight)1 Group (javax.media.j3d.Group)1 Link (javax.media.j3d.Link)1 Node (javax.media.j3d.Node)1 SharedGroup (javax.media.j3d.SharedGroup)1