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;
}
}
}
}
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;
}
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);
}
}
}
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;
}
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;
}
Aggregations