Search in sources :

Example 1 with Switch

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;
}
Also used : Switch(org.scijava.java3d.Switch) Point3d(org.scijava.vecmath.Point3d) CoordinateSystem(ij3d.shapes.CoordinateSystem) ContentNode(ij3d.ContentNode) CustomMeshNode(customnode.CustomMeshNode) Node(org.scijava.java3d.Node) BoundingBox(ij3d.shapes.BoundingBox) Color3f(org.scijava.vecmath.Color3f)

Example 2 with Switch

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);
}
Also used : Switch(org.scijava.java3d.Switch)

Example 3 with Switch

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;
}
Also used : Switch(org.scijava.java3d.Switch) BranchGroup(org.scijava.java3d.BranchGroup)

Aggregations

Switch (org.scijava.java3d.Switch)3 CustomMeshNode (customnode.CustomMeshNode)1 ContentNode (ij3d.ContentNode)1 BoundingBox (ij3d.shapes.BoundingBox)1 CoordinateSystem (ij3d.shapes.CoordinateSystem)1 BranchGroup (org.scijava.java3d.BranchGroup)1 Node (org.scijava.java3d.Node)1 Color3f (org.scijava.vecmath.Color3f)1 Point3d (org.scijava.vecmath.Point3d)1