Search in sources :

Example 6 with Color3f

use of javax.vecmath.Color3f 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 7 with Color3f

use of javax.vecmath.Color3f in project ffx by mjschnie.

the class RendererCache method getColor.

/**
 * <p>
 * getColor</p>
 *
 * @param a a {@link ffx.potential.bonded.Atom} object.
 * @param mode a {@link ffx.potential.bonded.RendererCache.ColorModel}
 * object.
 * @return a {@link javax.vecmath.Color3f} object.
 */
public static final Color3f getColor(Atom a, ColorModel mode) {
    switch(mode) {
        case CPK:
            return Atom.AtomColor.get(a.getAtomicNumber());
        case PICK:
            return pickingColor;
        case SELECT:
            return selectionColor;
        case PARTIALCHARGE:
            int index = 0;
            double charge = a.getCharge();
            if (charge < 0.0d) {
                float c = (float) (charge * 1000.0);
                index = -1 * Math.round(c);
                if (index > 999) {
                    index = 999;
                }
                if (negCharge[index] == null) {
                    float value = index * 0.001f;
                    negCharge[index] = new Color3f(1.0f, 1.0f - value, 1.0f - value);
                }
                return negCharge[index];
            } else if (charge == 0) {
                return WHITE;
            } else {
                float c = (float) (charge * 1000.0);
                index = Math.round(c);
                if (index > 999) {
                    index = 999;
                }
                if (posCharge[index] == null) {
                    float value = index * 0.001f;
                    posCharge[index] = new Color3f(1.0f - value, 1.0f - value, 1.0f);
                }
                return posCharge[index];
            }
        default:
            return NULLColor;
    }
}
Also used : Color3f(javax.vecmath.Color3f)

Example 8 with Color3f

use of javax.vecmath.Color3f in project ffx by mjschnie.

the class GraphicsAxis method createAxis.

/**
 * <p>
 * createAxis</p>
 */
public void createAxis() {
    Appearance ap = new Appearance();
    Color3f col = new Color3f(Color.lightGray);
    Color3f black = new Color3f(Color.black);
    Color3f white = new Color3f(Color.white);
    Material mat = new Material(col, black, col, white, 50.0f);
    mat.setLightingEnable(true);
    ap.setMaterial(mat);
    // X-Axis
    Cone xcone = new Cone(2.0f, 3.0f, ap);
    xcone.setUserData(this);
    Transform3D xconeT3d = new Transform3D();
    xconeT3d.setTranslation(new Vector3d(10.0f, 0.0f, 0.0f));
    xconeT3d.setRotation(new AxisAngle4f(0.0f, 0.0f, 1.0f, (float) Math.PI / -2.0f));
    TransformGroup xconeTG = new TransformGroup(xconeT3d);
    xconeTG.addChild(xcone);
    Cylinder xcylinder = new Cylinder(1.0f, 9.0f, ap);
    xcylinder.setUserData(this);
    Transform3D xcyT3d = new Transform3D();
    xcyT3d.setTranslation(new Vector3d(4.5, 0.0, 0.0));
    xcyT3d.setRotation(new AxisAngle4f(0.0f, 0.0f, 1.0f, (float) Math.PI / 2.0f));
    TransformGroup xcyTG = new TransformGroup(xcyT3d);
    xcyTG.addChild(xcylinder);
    setCapabilities(xcone, xcylinder);
    addChild(xconeTG);
    addChild(xcyTG);
    // Y-Axis
    Cone ycone = new Cone(2.0f, 3.0f, ap);
    ycone.setUserData(this);
    Transform3D yconeT3d = new Transform3D();
    yconeT3d.setTranslation(new Vector3d(0.0f, 10.0f, 0.0f));
    TransformGroup yconeTG = new TransformGroup(yconeT3d);
    yconeTG.addChild(ycone);
    Cylinder ycylinder = new Cylinder(1.0f, 9.0f, ap);
    ycylinder.setUserData(this);
    Transform3D ycyT3d = new Transform3D();
    ycyT3d.setTranslation(new Vector3d(0.0, 4.5, 0.0));
    TransformGroup ycyTG = new TransformGroup(ycyT3d);
    ycyTG.addChild(ycylinder);
    setCapabilities(ycone, ycylinder);
    addChild(yconeTG);
    addChild(ycyTG);
    // Z-Axis
    Cone zcone = new Cone(2.0f, 3.0f, ap);
    zcone.setUserData(this);
    Transform3D zconeT3d = new Transform3D();
    zconeT3d.setTranslation(new Vector3d(0.0f, 0.0f, 10.0f));
    zconeT3d.setRotation(new AxisAngle4f(1.0f, 0.0f, 0.0f, (float) Math.PI / 2.0f));
    TransformGroup zconeTG = new TransformGroup(zconeT3d);
    zconeTG.addChild(zcone);
    Cylinder zcylinder = new Cylinder(1.0f, 9.0f, ap);
    zcylinder.setUserData(this);
    Transform3D zcyT3d = new Transform3D();
    zcyT3d.setTranslation(new Vector3d(0.0, 0.0, 4.5));
    zcyT3d.setRotation(new AxisAngle4f(1.0f, 0.0f, 0.0f, (float) Math.PI / 2.0f));
    TransformGroup zcyTG = new TransformGroup(zcyT3d);
    zcyTG.addChild(zcylinder);
    setCapabilities(zcone, zcylinder);
    addChild(zconeTG);
    addChild(zcyTG);
    Sphere sphere = new Sphere(1.0f, ap);
    if (!sphere.getShape().getGeometry(0).isCompiled() && !sphere.getShape().getGeometry(0).isLive()) {
        PickTool.setCapabilities(sphere.getShape(), PickTool.INTERSECT_COORD);
    }
    addChild(sphere);
    // Labels
    ap = new Appearance();
    col = new Color3f(Color.green);
    mat = new Material(col, black, col, white, 50.0f);
    mat.setLightingEnable(true);
    ap.setMaterial(mat);
    Font font = new Font("Arial", Font.PLAIN, 4);
    Font3D font3d = new Font3D(font, new FontExtrusion());
    addChild(createAxisLabel("X", font3d, ap, 11.0, 0.0, 0.0));
    addChild(createAxisLabel("Y", font3d, ap, 0.0, 11.0, 0.0));
    addChild(createAxisLabel("Z", font3d, ap, 0.0, 0.0, 11.0));
}
Also used : Cone(com.sun.j3d.utils.geometry.Cone) Font3D(javax.media.j3d.Font3D) Color3f(javax.vecmath.Color3f) Transform3D(javax.media.j3d.Transform3D) Material(javax.media.j3d.Material) Appearance(javax.media.j3d.Appearance) FontExtrusion(javax.media.j3d.FontExtrusion) Font(java.awt.Font) TransformGroup(javax.media.j3d.TransformGroup) Sphere(com.sun.j3d.utils.geometry.Sphere) Cylinder(com.sun.j3d.utils.geometry.Cylinder) Vector3d(javax.vecmath.Vector3d) AxisAngle4f(javax.vecmath.AxisAngle4f)

Example 9 with Color3f

use of javax.vecmath.Color3f in project ffx by mjschnie.

the class GraphicsCanvas method setBackgroundColor.

/**
 * <p>
 * setBackgroundColor</p>
 */
public void setBackgroundColor() {
    Color3f col = new Color3f();
    background.getColor(col);
    Color newcolor = JColorChooser.showDialog(this, "Choose Background Color", col.get());
    if (newcolor != null && newcolor != col.get()) {
        background.setColor(new Color3f(newcolor));
    }
}
Also used : Color3f(javax.vecmath.Color3f) Color(java.awt.Color)

Example 10 with Color3f

use of javax.vecmath.Color3f in project ffx by mjschnie.

the class GraphicsCanvas method initialize.

/**
 * Initialization of the GraphisCanvas.
 */
private void initialize() {
    setBackground(Color.black);
    universe = new SimpleUniverse(this);
    SimpleUniverse.setJ3DThreadPriority(Thread.MAX_PRIORITY);
    universe.getViewingPlatform().setNominalViewingTransform();
    // Create the Scene Root BranchGroup
    BranchGroup objRoot = new BranchGroup();
    baseTransformGroup = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.1d);
    baseTransformGroup.setTransform(t3d);
    baseTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    baseTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    // Set the Background
    Color3f bgColor = new Color3f(RendererCache.BLACK);
    background = new Background(bgColor);
    background.setCapability(Background.ALLOW_COLOR_READ);
    background.setCapability(Background.ALLOW_COLOR_WRITE);
    bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 2000.0);
    background.setApplicationBounds(bounds);
    // Create lights
    AmbientLight aLgt = new AmbientLight(new Color3f(Color.darkGray));
    aLgt.setInfluencingBounds(bounds);
    Vector3f dir = new Vector3f(0.0f, -1.0f, -1.0f);
    Color3f dLgtColor = new Color3f(Color.lightGray);
    DirectionalLight dLgt = new DirectionalLight(dLgtColor, dir);
    dLgt.setInfluencingBounds(bounds);
    dir = new Vector3f(0.0f, 1.0f, -1.0f);
    dLgtColor = new Color3f(0.1f, 0.1f, 0.1f);
    DirectionalLight dLgt2 = new DirectionalLight(dLgtColor, dir);
    dLgt2.setInfluencingBounds(bounds);
    // Create the Base of the Molecular Scene
    baseBranchGroup = new BranchGroup();
    baseBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    baseBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
    baseBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    baseBranchGroup.setCapability(BranchGroup.ALLOW_BOUNDS_READ);
    // Add children created above to the base TransformGroup
    baseTransformGroup.addChild(background);
    baseTransformGroup.addChild(baseBranchGroup);
    objRoot.addChild(baseTransformGroup);
    // Position the view platmform and add lights
    View v = universe.getViewer().getView();
    v.setProjectionPolicy(View.PARALLEL_PROJECTION);
    v.setFrontClipPolicy(View.VIRTUAL_EYE);
    v.setFrontClipDistance(1.0);
    v.setBackClipPolicy(View.VIRTUAL_EYE);
    v.setBackClipDistance(10.0);
    v.setTransparencySortingPolicy(View.TRANSPARENCY_SORT_NONE);
    Transform3D trans = new Transform3D();
    trans.set(new Vector3d(0.0d, 0.0d, 2.0d));
    TransformGroup vptg = universe.getViewingPlatform().getViewPlatformTransform();
    vptg.setTransform(trans);
    BranchGroup viewBranch = new BranchGroup();
    viewBranch.addChild(aLgt);
    viewBranch.addChild(dLgt);
    viewBranch.addChild(dLgt2);
    vptg.addChild(viewBranch);
    // Initialize Behaviors
    graphicsAxis = new GraphicsAxis(universe.getViewingPlatform(), this, bounds);
    graphicsEvents = new GraphicsEvents(mainPanel, this, graphicsAxis, universe, bounds, baseBranchGroup, baseTransformGroup);
    baseBranchGroup.addChild(graphicsEvents);
    rendererPicking = new GraphicsPicking(baseBranchGroup, bounds, this, mainPanel);
    baseBranchGroup.addChild(rendererPicking);
    renderer = new ffx.potential.Renderer(bounds, mainPanel.getStatusBar());
    baseBranchGroup.addChild(renderer);
    // Compile the Root BranchGroup and add it to the Universe
    objRoot.compile();
    universe.addBranchGraph(objRoot);
}
Also used : Background(javax.media.j3d.Background) BoundingSphere(javax.media.j3d.BoundingSphere) BranchGroup(javax.media.j3d.BranchGroup) Transform3D(javax.media.j3d.Transform3D) Color3f(javax.vecmath.Color3f) SimpleUniverse(com.sun.j3d.utils.universe.SimpleUniverse) View(javax.media.j3d.View) TransformGroup(javax.media.j3d.TransformGroup) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d) Vector3f(javax.vecmath.Vector3f) DirectionalLight(javax.media.j3d.DirectionalLight) AmbientLight(javax.media.j3d.AmbientLight)

Aggregations

Color3f (javax.vecmath.Color3f)11 Color (java.awt.Color)6 Appearance (javax.media.j3d.Appearance)3 BoundingSphere (javax.media.j3d.BoundingSphere)3 Point3d (javax.vecmath.Point3d)3 Vector3d (javax.vecmath.Vector3d)3 ColoringAttributes (javax.media.j3d.ColoringAttributes)2 LineArray (javax.media.j3d.LineArray)2 LineAttributes (javax.media.j3d.LineAttributes)2 RenderingAttributes (javax.media.j3d.RenderingAttributes)2 Shape3D (javax.media.j3d.Shape3D)2 Transform3D (javax.media.j3d.Transform3D)2 TransformGroup (javax.media.j3d.TransformGroup)2 Cone (com.sun.j3d.utils.geometry.Cone)1 Cylinder (com.sun.j3d.utils.geometry.Cylinder)1 Sphere (com.sun.j3d.utils.geometry.Sphere)1 SimpleUniverse (com.sun.j3d.utils.universe.SimpleUniverse)1 Atom (ffx.potential.bonded.Atom)1 Bond (ffx.potential.bonded.Bond)1 ROLS (ffx.potential.bonded.ROLS)1