Search in sources :

Example 6 with Shape3D

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

the class RendererCache method createSphere.

/**
 * This method creates a single Sphere from the given appearance
 */
private static Shape3D createSphere(Appearance ap, int div) {
    Shape3D shape3d = new Shape3D();
    shape3d.setAppearance(ap);
    shape3d.addGeometry(getSphereGeom(div));
    shape3d.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    shape3d.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape3d.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    shape3d.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    shape3d.setCapability(Shape3D.ENABLE_PICK_REPORTING);
    shape3d.setCapability(Shape3D.ALLOW_PICKABLE_WRITE);
    return shape3d;
}
Also used : Shape3D(javax.media.j3d.Shape3D)

Example 7 with Shape3D

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

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

the class GraphicsAxis method createAxisLabel.

@SuppressWarnings("unchecked")
private TransformGroup createAxisLabel(String letter, Font3D font3d, Appearance ap, double x, double y, double z) {
    Text3D text = new Text3D(font3d, letter);
    text.setUserData(this);
    Transform3D t3D = new Transform3D();
    t3D.setTranslation(new Vector3d(x, y, z));
    TransformGroup tg = new TransformGroup(t3D);
    Shape3D text3d = new Shape3D(text, ap);
    text3d.setUserData(this);
    for (Enumeration<Geometry> e = text3d.getAllGeometries(); e.hasMoreElements(); ) {
        Geometry g = e.nextElement();
        g.setCapability(Geometry.ALLOW_INTERSECT);
    }
    text3d.setCapability(Shape3D.ENABLE_PICK_REPORTING);
    text3d.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    tg.addChild(text3d);
    return tg;
}
Also used : Text3D(javax.media.j3d.Text3D) Geometry(javax.media.j3d.Geometry) Vector3d(javax.vecmath.Vector3d) Transform3D(javax.media.j3d.Transform3D) Shape3D(javax.media.j3d.Shape3D) TransformGroup(javax.media.j3d.TransformGroup)

Example 9 with Shape3D

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

the class MolecularAssembly method renderWire.

private Shape3D renderWire() {
    ArrayList<ROLS> bonds = getBondList();
    int numbonds = bonds.size();
    if (numbonds < 1) {
        return null;
    }
    Vector3d bondmidpoint = new Vector3d();
    double[] mid = { 0, 0, 0 };
    Vector3d v1 = new Vector3d();
    Vector3d v2 = new Vector3d();
    float[] a1 = { 0, 0, 0 };
    float[] a2 = { 0, 0, 0 };
    float[] col = new float[4];
    Bond bond;
    Atom atom1, atom2;
    LineArray la = new LineArray(4 * numbonds, 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);
    atomLookUp = new Atom[4 * numbonds];
    int i = 0;
    col[3] = 0.9f;
    for (ListIterator<ROLS> li = bonds.listIterator(); li.hasNext(); ) {
        bond = (Bond) li.next();
        bond.setWire(la, i);
        atom1 = bond.getAtom(0);
        atom2 = bond.getAtom(1);
        atom1.getV3D(v1);
        atom2.getV3D(v2);
        a1[0] = (float) v1.x;
        a1[1] = (float) v1.y;
        a1[2] = (float) v1.z;
        a2[0] = (float) v2.x;
        a2[1] = (float) v2.y;
        a2[2] = (float) v2.z;
        // Find the bond center
        bondmidpoint.add(v1, v2);
        bondmidpoint.scale(0.5d);
        bondmidpoint.get(mid);
        // Atom #1
        Atom.AtomColor.get(atom1.getAtomicNumber()).get(col);
        atomLookUp[i] = atom1;
        la.setCoordinate(i, a1);
        la.setColor(i, col);
        la.setNormal(i, a2);
        i++;
        atomLookUp[i] = atom1;
        la.setCoordinate(i, mid);
        la.setColor(i, col);
        la.setNormal(i, a2);
        i++;
        // Atom #2
        Atom.AtomColor.get(atom2.getAtomicNumber()).get(col);
        atomLookUp[i] = atom2;
        la.setCoordinate(i, a2);
        la.setColor(i, col);
        la.setNormal(i, a1);
        i++;
        atomLookUp[i] = atom2;
        la.setCoordinate(i, mid);
        la.setColor(i, col);
        la.setNormal(i, a1);
        i++;
    }
    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), 1000.0));
    try {
        wireframe.setBoundsAutoCompute(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    wireframe.setCapability(Shape3D.ALLOW_LOCAL_TO_VWORLD_READ);
    return wireframe;
}
Also used : ROLS(ffx.potential.bonded.ROLS) BoundingSphere(javax.media.j3d.BoundingSphere) Color3f(javax.vecmath.Color3f) RenderingAttributes(javax.media.j3d.RenderingAttributes) ColoringAttributes(javax.media.j3d.ColoringAttributes) Appearance(javax.media.j3d.Appearance) Atom(ffx.potential.bonded.Atom) LineAttributes(javax.media.j3d.LineAttributes) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d) LineArray(javax.media.j3d.LineArray) Shape3D(javax.media.j3d.Shape3D) Bond(ffx.potential.bonded.Bond)

Example 10 with Shape3D

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

the class RendererCache method sphereFactory.

/**
 * <p>
 * sphereFactory</p>
 *
 * @param ap a {@link javax.media.j3d.Appearance} object.
 * @param div a int.
 * @param transform3D a {@link javax.media.j3d.Transform3D} object.
 * @return a {@link javax.media.j3d.BranchGroup} object.
 */
public static final BranchGroup sphereFactory(Appearance ap, int div, Transform3D transform3D) {
    BranchGroup branchGroup;
    if (spherePool.size() > 0) {
        branchGroup = spherePool.remove(0);
        if (branchGroup != null) {
            TransformGroup transformGroup = (TransformGroup) branchGroup.getChild(0);
            transformGroup.setTransform(transform3D);
            Shape3D sphere = (Shape3D) transformGroup.getChild(0);
            sphere.setAppearance(ap);
            return branchGroup;
        }
    }
    branchGroup = new BranchGroup();
    branchGroup.setCapability(BranchGroup.ALLOW_DETACH);
    branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
    branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    TransformGroup transformGroup = createTransformGroup(transform3D);
    Shape3D sphere = createSphere(ap, div);
    transformGroup.addChild(sphere);
    branchGroup.addChild(transformGroup);
    branchGroup.compile();
    return branchGroup;
}
Also used : BranchGroup(javax.media.j3d.BranchGroup) Shape3D(javax.media.j3d.Shape3D) TransformGroup(javax.media.j3d.TransformGroup)

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