Search in sources :

Example 1 with Shape3D

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

the class GraphicsPicking method updateScene.

/**
 * {@inheritDoc}
 *
 * Called by Java3D when an atom is picked
 */
public void updateScene(int xpos, int ypos) {
    if (picking == false) {
        return;
    }
    // Determine what FNode was picked
    pickCanvas.setShapeLocation(xpos, ypos);
    PickResult result = pickCanvas.pickClosest();
    if (result != null) {
        SceneGraphPath sceneGraphPath = result.getSceneGraphPath();
        Node node = sceneGraphPath.getObject();
        if (!(node instanceof Shape3D)) {
            return;
        }
        Shape3D pickedShape3D = (Shape3D) node;
        Object userData = pickedShape3D.getUserData();
        if (userData instanceof MolecularAssembly) {
            FFXSystem sys = (FFXSystem) userData;
            if (result.numIntersections() > 0) {
                PickIntersection pickIntersection = result.getIntersection(0);
                int[] coords = pickIntersection.getPrimitiveCoordinateIndices();
                userData = sys.getAtomFromWireVertex(coords[0]);
            } else {
                return;
            }
        }
        if (userData instanceof Atom) {
            Atom a = (Atom) userData;
            // Check to see if the pickLevel has changed
            if (!(pickLevel == newPickLevel)) {
                pickLevel = newPickLevel;
                pickNumber = 0;
            }
            // Clear selections between measurements
            String pickLevelString = pickLevel.toString();
            boolean measure = pickLevelString.startsWith("MEASURE");
            if (!measure || count == 0) {
                for (Atom matom : atomCache) {
                    matom.setSelected(false);
                    matom.setColor(RendererCache.ColorModel.SELECT, null, null);
                }
                atomCache.clear();
                count = 0;
            }
            // If measuring, select the current atom and add it to the cache
            if (measure && !atomCache.contains(a)) {
                atomCache.add(0, a);
                a.setSelected(true);
                a.setColor(RendererCache.ColorModel.PICK, null, null);
                count++;
                measure();
            }
            if (!measure) {
                // This allows iteration through the atom's terms
                if (a == previousAtom) {
                    pickNumber++;
                } else {
                    previousAtom = a;
                    pickNumber = 0;
                }
                MSNode currentPick = null;
                switch(pickLevel) {
                    case PICKATOM:
                        currentPick = a;
                        break;
                    case PICKBOND:
                    case PICKANGLE:
                    case PICKDIHEDRAL:
                        ArrayList terms = null;
                        if (pickLevel == PickLevel.PICKBOND) {
                            terms = a.getBonds();
                        } else if (pickLevel == PickLevel.PICKANGLE) {
                            terms = a.getAngles();
                        } else if (pickLevel == PickLevel.PICKDIHEDRAL) {
                            terms = a.getTorsions();
                        }
                        if (terms == null) {
                            return;
                        }
                        int num = terms.size();
                        if (pickNumber >= num) {
                            pickNumber = 0;
                        }
                        currentPick = (BondedTerm) terms.get(pickNumber);
                        break;
                    case PICKRESIDUE:
                    case PICKPOLYMER:
                    case PICKMOLECULE:
                    case PICKSYSTEM:
                        MSNode dataNode = null;
                        if (pickLevel == PickLevel.PICKRESIDUE) {
                            dataNode = (MSNode) a.getMSNode(Residue.class);
                        } else if (pickLevel == PickLevel.PICKPOLYMER) {
                            dataNode = (MSNode) a.getMSNode(Polymer.class);
                        } else if (pickLevel == PickLevel.PICKSYSTEM) {
                            dataNode = (MSNode) a.getMSNode(MolecularAssembly.class);
                        } else if (pickLevel == PickLevel.PICKMOLECULE) {
                            dataNode = (MSNode) a.getMSNode(Molecule.class);
                            if (dataNode == null) {
                                dataNode = (MSNode) a.getMSNode(Polymer.class);
                            }
                        }
                        currentPick = dataNode;
                        break;
                    case MEASUREANGLE:
                    case MEASUREDIHEDRAL:
                    case MEASUREDISTANCE:
                        break;
                }
                // Add the selected node to the Tree View
                if (currentPick != null) {
                    if (controlButton) {
                        mainPanel.getHierarchy().toggleSelection(currentPick);
                    } else if (currentPick != previousPick) {
                        mainPanel.getHierarchy().onlySelection(currentPick);
                    }
                    // Color the Current Pick by Picking Color
                    mainPanel.getGraphics3D().updateScene(currentPick, false, false, null, true, RendererCache.ColorModel.PICK);
                }
                // Remove picking color from the previousPick
                if (previousPick != null && previousPick != currentPick) {
                    previousPick.setColor(RendererCache.ColorModel.REVERT, null, null);
                }
                previousPick = currentPick;
            }
        }
    }
}
Also used : SceneGraphPath(javax.media.j3d.SceneGraphPath) MSNode(ffx.potential.bonded.MSNode) Node(javax.media.j3d.Node) ArrayList(java.util.ArrayList) Polymer(ffx.potential.bonded.Polymer) PickIntersection(com.sun.j3d.utils.picking.PickIntersection) Atom(ffx.potential.bonded.Atom) Molecule(ffx.potential.bonded.Molecule) MolecularAssembly(ffx.potential.MolecularAssembly) MSNode(ffx.potential.bonded.MSNode) PickResult(com.sun.j3d.utils.picking.PickResult) Shape3D(javax.media.j3d.Shape3D)

Example 2 with Shape3D

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

the class MolecularAssembly method createBox.

/**
 * <p>
 * createBox</p>
 */
public void createBox() {
    int vertices = 8;
    LineArray la = new LineArray(4 * vertices, GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS);
    la.setCapability(LineArray.ALLOW_COORDINATE_WRITE);
    la.setCapability(LineArray.ALLOW_COORDINATE_READ);
    la.setCapability(LineArray.ALLOW_COLOR_WRITE);
    la.setCapability(LineArray.ALLOW_COUNT_READ);
    la.setCapability(LineArray.ALLOW_INTERSECT);
    la.setCapability(LineArray.ALLOW_FORMAT_READ);
    // Create a normal
    // for (ListIterator<MSNode> li = bondlist.listIterator(); li.hasNext(); ){
    // la.setCoordinate(i, a1);
    // la.setColor(i, col);
    // la.setNormal(i++, a1);
    // }
    ColoringAttributes cola = new ColoringAttributes(new Color3f(), ColoringAttributes.SHADE_GOURAUD);
    Appearance app = new Appearance();
    lineAttributes = new LineAttributes();
    lineAttributes.setLineWidth(RendererCache.bondwidth);
    lineAttributes.setCapability(LineAttributes.ALLOW_WIDTH_WRITE);
    lineAttributes.setLineAntialiasingEnable(true);
    app.setLineAttributes(lineAttributes);
    app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ);
    app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE);
    RenderingAttributes ra = new RenderingAttributes();
    ra.setAlphaTestValue(0.1f);
    ra.setAlphaTestFunction(RenderingAttributes.GREATER);
    ra.setDepthBufferEnable(true);
    ra.setDepthBufferWriteEnable(true);
    app.setRenderingAttributes(ra);
    app.setColoringAttributes(cola);
    Shape3D wireframe = new Shape3D(la, app);
    // PickTool.setCapabilities(wire, PickTool.INTERSECT_COORD);
    wireframe.setUserData(this);
    wireframe.setBounds(new BoundingSphere(new Point3d(0, 0, 0), 10.0));
    try {
        wireframe.setBoundsAutoCompute(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
// return wire;
}
Also used : BoundingSphere(javax.media.j3d.BoundingSphere) Point3d(javax.vecmath.Point3d) Color3f(javax.vecmath.Color3f) RenderingAttributes(javax.media.j3d.RenderingAttributes) LineArray(javax.media.j3d.LineArray) ColoringAttributes(javax.media.j3d.ColoringAttributes) Shape3D(javax.media.j3d.Shape3D) Appearance(javax.media.j3d.Appearance) LineAttributes(javax.media.j3d.LineAttributes)

Example 3 with Shape3D

use of javax.media.j3d.Shape3D 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 4 with Shape3D

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

the class RendererCache method createCylinder.

/**
 * This method creates a Cylinder
 *
 * @param ap a {@link javax.media.j3d.Appearance} object.
 * @param res a int.
 * @return a {@link javax.media.j3d.Shape3D} object.
 */
protected static final Shape3D createCylinder(Appearance ap, int res) {
    if (res < 0) {
        res = 0;
    }
    if (res > 10) {
        res = 10;
    }
    final Shape3D cyl = new Shape3D();
    cyl.setAppearance(ap);
    cyl.addGeometry(getCylinderGeom(0, res));
    cyl.addGeometry(getCylinderGeom(1, res));
    cyl.addGeometry(getCylinderGeom(2, res));
    cyl.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    cyl.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    cyl.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    cyl.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    cyl.setCapability(Shape3D.ENABLE_PICK_REPORTING);
    cyl.setCapability(Shape3D.ALLOW_PICKABLE_WRITE);
    return cyl;
}
Also used : Shape3D(javax.media.j3d.Shape3D)

Example 5 with Shape3D

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

the class RendererCache method coneFactory.

/**
 * <p>
 * coneFactory</p>
 *
 * @param ap a {@link javax.media.j3d.Appearance} object.
 * @param res a int.
 * @return a {@link javax.media.j3d.Shape3D} object.
 */
protected static Shape3D coneFactory(Appearance ap, int res) {
    if (res > 3) {
        res = 3;
    }
    Shape3D cone = new Shape3D();
    cone.setAppearance(ap);
    cone.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    cone.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    cone.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    cone.setCapability(Shape3D.ALLOW_PICKABLE_WRITE);
    cone.addGeometry(getConeGeom(0, res));
    cone.addGeometry(getConeGeom(1, res));
    return cone;
}
Also used : Shape3D(javax.media.j3d.Shape3D)

Aggregations

Shape3D (javax.media.j3d.Shape3D)11 TransformGroup (javax.media.j3d.TransformGroup)4 Atom (ffx.potential.bonded.Atom)3 BranchGroup (javax.media.j3d.BranchGroup)3 Node (javax.media.j3d.Node)3 PickIntersection (com.sun.j3d.utils.picking.PickIntersection)2 MolecularAssembly (ffx.potential.MolecularAssembly)2 MSNode (ffx.potential.bonded.MSNode)2 Appearance (javax.media.j3d.Appearance)2 BoundingSphere (javax.media.j3d.BoundingSphere)2 ColoringAttributes (javax.media.j3d.ColoringAttributes)2 LineArray (javax.media.j3d.LineArray)2 LineAttributes (javax.media.j3d.LineAttributes)2 RenderingAttributes (javax.media.j3d.RenderingAttributes)2 SceneGraphPath (javax.media.j3d.SceneGraphPath)2 Color3f (javax.vecmath.Color3f)2 Point3d (javax.vecmath.Point3d)2 Vector3d (javax.vecmath.Vector3d)2 PickResult (com.sun.j3d.utils.picking.PickResult)1 Bond (ffx.potential.bonded.Bond)1