Search in sources :

Example 6 with TransformGroup

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

the class RendererCache method createTransformGroup.

private static final TransformGroup createTransformGroup(Transform3D transform3D) {
    TransformGroup transformGroup;
    if (transform3D == null) {
        transformGroup = new TransformGroup();
    } else {
        transformGroup = new TransformGroup(transform3D);
    }
    transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    transformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
    return transformGroup;
}
Also used : TransformGroup(javax.media.j3d.TransformGroup)

Example 7 with TransformGroup

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

the class GraphicsEvents method systemTranslate.

private boolean systemTranslate() {
    TransformGroup tg = null;
    GraphicsCanvas.MouseMode mouseMode = graphics3D.getMouseMode();
    if ((mouseMode == GraphicsCanvas.MouseMode.SYSTEMBELOWMOUSE) && atom != null) {
        tg = (TransformGroup) pickResult.getNode(PickResult.TRANSFORM_GROUP);
    } else if (mouseMode == GraphicsCanvas.MouseMode.ACTIVESYSTEM) {
        if (mainPanel.getHierarchy().getActive() != null) {
            tg = mainPanel.getHierarchy().getActive().getTransformGroup();
        }
    }
    if ((tg != null) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))) {
        systemTranslate.setTransformGroup(tg);
        postId(TRANSLATEPOST);
        return true;
    }
    return false;
}
Also used : TransformGroup(javax.media.j3d.TransformGroup)

Example 8 with TransformGroup

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

the class MainPanel method merge.

/**
 * Merge two or more selected FSystem Nodes into one FSystem node. There are
 * a few gotchas that need to be fixed
 *
 * @param nodesToMerge a {@link java.util.ArrayList} object.
 */
public void merge(ArrayList<MSNode> nodesToMerge) {
    ArrayList<MSNode> activeNodes = new ArrayList<MSNode>();
    for (MSNode node : nodesToMerge) {
        if (node != null && !(node instanceof MSRoot)) {
            activeNodes.add(node);
        }
    }
    if (activeNodes.size() <= 1) {
        return;
    }
    // Set up a structure to hold the new system
    FFXSystem active = hierarchy.getActive();
    File file = SystemFilter.version(hierarchy.getActive().getFile());
    FFXSystem system = new FFXSystem(file, "Merge Result", active.getProperties());
    system.setKeyFile(active.getKeyFile());
    system.setKeywords(KeyFilter.open(active.getKeyFile()));
    // Fill arrays with the atoms and bonds from the systems to be combined
    ArrayList<Atom> mergedAtoms = new ArrayList<Atom>();
    ArrayList<Bond> mergedBonds = new ArrayList<Bond>();
    ArrayList<FFXSystem> systems = new ArrayList<FFXSystem>();
    TransformGroup parentTransformGroup = null;
    FFXSystem parentSystem;
    Transform3D parentTransform3D = new Transform3D();
    Vector3d parentPosition = new Vector3d();
    Vector3d atomPosition = new Vector3d();
    // TINKER Atom Numbers start at 1
    int atomNum = 1;
    Vector3d zero = new Vector3d(0.0, 0.0, 0.0);
    for (MSNode m : activeNodes) {
        parentSystem = (FFXSystem) m.getMSNode(FFXSystem.class);
        if (parentSystem == null) {
            return;
        }
        if (!systems.contains(parentSystem)) {
            graphicsCanvas.updateSceneWait(parentSystem, false, true, RendererCache.ViewModel.WIREFRAME, false, null);
            systems.add(parentSystem);
        }
        // Move each atom into the global frame by applying the System
        // Transform to
        // relative atomic position
        parentTransformGroup = parentSystem.getOriginToRot();
        parentTransformGroup.getTransform(parentTransform3D);
        parentTransform3D.get(parentPosition);
        parentTransform3D.setTranslation(zero);
        // parentTransform3D.setScale(1.0d);
        ArrayList<Atom> atoms = m.getAtomList();
        ArrayList<ROLS> bonds = m.getBondList();
        for (Atom atom : atoms) {
            atom.removeFromParent();
            atom.setXyzIndex(atomNum++);
            mergedAtoms.add(atom);
            atom.getV3D(atomPosition);
            parentTransform3D.transform(atomPosition);
            atomPosition.add(parentPosition);
            atom.moveTo(atomPosition);
        }
        for (ROLS msm : bonds) {
            Bond bond = (Bond) msm;
            bond.removeFromParent();
            mergedBonds.add((Bond) msm);
        }
    }
    for (FFXSystem sys : systems) {
        close(sys);
    }
    MergeFilter mergeFilter = new MergeFilter(system, mergedAtoms, mergedBonds);
    UIFileOpener fileOpener = new UIFileOpener(mergeFilter, this);
    if (fileOpenerThreads > 0) {
        fileOpener.setNThreads(fileOpenerThreads);
    }
    Thread thread = new Thread(fileOpener);
    thread.start();
}
Also used : ROLS(ffx.potential.bonded.ROLS) Transform3D(javax.media.j3d.Transform3D) ArrayList(java.util.ArrayList) MergeFilter(ffx.potential.parsers.MergeFilter) Atom(ffx.potential.bonded.Atom) TransformGroup(javax.media.j3d.TransformGroup) MSNode(ffx.potential.bonded.MSNode) MSRoot(ffx.potential.bonded.MSRoot) Vector3d(javax.vecmath.Vector3d) Bond(ffx.potential.bonded.Bond) File(java.io.File)

Example 9 with TransformGroup

use of javax.media.j3d.TransformGroup 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 10 with TransformGroup

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

the class MolecularAssembly method createScene.

/**
 * The MolecularAssembly BranchGroup has two TransformGroups between it and
 * the "base" node where geometry is attached. If the point between the two
 * transformations is where user rotation occurs. For example, if rotating
 * about the center of mass of the system, the RotToCOM transformation will
 * be an identity transformation (ie. none). If rotation is about some atom
 * or group of atoms within the system, then the RotToCOM transformation
 * will be a translation from that point to the COM.
 *
 * @param zero boolean
 * @return BranchGroup
 */
public BranchGroup createScene(boolean zero) {
    originToRotT3D = new Transform3D();
    originToRotV3D = new Vector3d();
    originToRot = new TransformGroup(originToRotT3D);
    branchGroup = new BranchGroup();
    rotToCOM = new TransformGroup();
    rotToCOMT3D = new Transform3D();
    rotToCOMV3D = new Vector3d();
    // Set capabilities needed for picking and moving the MolecularAssembly
    branchGroup.setCapability(BranchGroup.ALLOW_DETACH);
    originToRot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    originToRot.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    originToRot.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    rotToCOM.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    rotToCOM.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    // Put the MolecularAssembly in the middle of the scene
    if (zero) {
        originToRotV3D.set(0.0, 0.0, 0.0);
        originToRotT3D.set(originToRotV3D);
        originToRot.setTransform(originToRotT3D);
    }
    wire = renderWire();
    switchGroup = new Switch(Switch.CHILD_NONE);
    switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE);
    base = new BranchGroup();
    base.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    base.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    childNodes = new BranchGroup();
    childNodes.setCapability(BranchGroup.ALLOW_DETACH);
    childNodes.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    childNodes.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    switchGroup.addChild(base);
    if (wire != null) {
        base.addChild(wire);
    }
    vrml = loadVRML();
    if (vrml != null) {
        vrmlTG = new TransformGroup();
        vrmlTd = new Transform3D();
        vrmlTG.setTransform(vrmlTd);
        vrmlTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        vrmlTG.addChild(vrml);
        switchGroup.addChild(vrmlTG);
        setView(RendererCache.ViewModel.INVISIBLE, null);
    }
    switchGroup.setWhichChild(Switch.CHILD_ALL);
    rotToCOM.addChild(switchGroup);
    originToRot.addChild(rotToCOM);
    branchGroup.addChild(originToRot);
    branchGroup.compile();
    return branchGroup;
}
Also used : Switch(javax.media.j3d.Switch) Vector3d(javax.vecmath.Vector3d) BranchGroup(javax.media.j3d.BranchGroup) Transform3D(javax.media.j3d.Transform3D) TransformGroup(javax.media.j3d.TransformGroup)

Aggregations

TransformGroup (javax.media.j3d.TransformGroup)16 Transform3D (javax.media.j3d.Transform3D)6 BranchGroup (javax.media.j3d.BranchGroup)5 Vector3d (javax.vecmath.Vector3d)5 PickResult (com.sun.j3d.utils.picking.PickResult)4 Shape3D (javax.media.j3d.Shape3D)4 MSNode (ffx.potential.bonded.MSNode)2 Color3f (javax.vecmath.Color3f)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 MSGroup (ffx.potential.bonded.MSGroup)1 MSRoot (ffx.potential.bonded.MSRoot)1 ROLS (ffx.potential.bonded.ROLS)1 MergeFilter (ffx.potential.parsers.MergeFilter)1 Font (java.awt.Font)1 File (java.io.File)1