use of org.scijava.java3d.Switch in project GDSC-SMLM by aherbert.
the class CustomContentInstant method display.
@Override
public void display(final ContentNode node) {
// Remove everything if possible
for (final Enumeration<Node> e = ordered.getAllChildren(); e.hasMoreElements(); ) {
final Switch s = (Switch) e.nextElement();
s.removeAllChildren();
}
// Remove custom switch objects
while (ordered.numChildren() > 5) {
ordered.removeChild(ordered.numChildren() - 1);
}
customBefore = 0;
if (switchMap != null) {
switchMap.clear();
}
// Create content node and add it to the switch
contentNode = node;
((Switch) ordered.getChild(CO)).addChild(contentNode);
// Create the bounding box and add it to the switch
final Point3d min = new Point3d();
contentNode.getMin(min);
final Point3d max = new Point3d();
contentNode.getMax(max);
BoundingBox bb = new BoundingBox(min, max);
bb.setPickable(false);
((Switch) ordered.getChild(BS)).addChild(bb);
bb = new BoundingBox(min, max, new Color3f(0, 1, 0));
bb.setPickable(false);
((Switch) ordered.getChild(BB)).addChild(bb);
// Create coordinate system and add it to the switch
final float cl = (float) Math.abs(max.x - min.x) / 5f;
final CoordinateSystem cs = new CoordinateSystem(cl, new Color3f(0, 1, 0));
cs.setPickable(false);
((Switch) ordered.getChild(CS)).addChild(cs);
// Create point list and add it to the switch
((Switch) ordered.getChild(PL)).addChild(plShape);
// Adjust the landmark point size properly
plShape.setRadius((float) min.distance(max) / 100f);
// Initialize child mask of the switch
setSwitchValue(BS, selected);
setSwitchValue(CS, coordVisible);
setSwitchValue(CO, visible);
setSwitchValue(PL, showPl);
// Update type
this.type = CUSTOM;
}
use of org.scijava.java3d.Switch in project GDSC-SMLM by aherbert.
the class CustomContentInstant method setCustomSwitch.
/**
* Sets the custom switch content.
*
* @param which the which
* @param on the on
*/
public void setCustomSwitch(int which, final boolean on) {
if (switchMap == null) {
return;
}
final Switch s = switchMap.get(which);
if (s == null) {
return;
}
s.setWhichChild(on ? Switch.CHILD_ALL : Switch.CHILD_NONE);
}
use of org.scijava.java3d.Switch in project GDSC-SMLM by aherbert.
the class CustomContentInstant method addCustomSwitch.
/**
* Adds a custom switchable item to the content. The content can be optionally displayed.
*
* <p>The before flag species if the switch should be inserted into the group before the standard
* content, or added after. This is relevant if using an ordered group and transparent objects.
* Any transparent object must be drawn after non-transparent objects.
*
* @param node the node
* @param before the before flag
* @return the switch number
*/
public int addCustomSwitch(Node node, boolean before) {
if (switchMap == null) {
switchMap = new TIntObjectHashMap<>();
}
final int index = switchMap.size();
final Switch s = new Switch();
switchMap.put(index, s);
s.setCapability(Switch.ALLOW_SWITCH_WRITE);
s.setCapability(Switch.ALLOW_SWITCH_READ);
s.setCapability(Group.ALLOW_CHILDREN_WRITE);
s.setCapability(Group.ALLOW_CHILDREN_EXTEND);
s.addChild(node);
// Only a branch group can be added to a live scene
final BranchGroup bg = new BranchGroup();
bg.addChild(s);
if (before) {
ordered.insertChild(bg, 0);
customBefore++;
} else {
ordered.addChild(bg);
}
// Account for the standard switches
return index;
}
Aggregations