Search in sources :

Example 1 with PickInfo

use of org.scijava.java3d.PickInfo in project GDSC-SMLM by aherbert.

the class ImageJ3DResultsViewer method getPickedContent.

/**
 * Get the Content and closest intersection point at the specified canvas position.
 *
 * <p>Adapted from Picker.getPickedContent(...).
 *
 * @param canvas the canvas
 * @param scene the scene
 * @param x the x
 * @param y the y
 * @return the Content and closest intersection point
 */
private static Pair<Content, IntersectionInfo> getPickedContent(Canvas3D canvas, BranchGroup scene, final int x, final int y) {
    final PickCanvas pickCanvas = new PickCanvas(canvas, scene);
    pickCanvas.setMode(PickInfo.PICK_GEOMETRY);
    pickCanvas.setFlags(PickInfo.SCENEGRAPHPATH | PickInfo.CLOSEST_GEOM_INFO);
    pickCanvas.setTolerance(3);
    pickCanvas.setShapeLocation(x, y);
    try {
        final PickInfo[] result = pickCanvas.pickAllSorted();
        if (result == null) {
            return null;
        }
        for (int i = 0; i < result.length; i++) {
            final SceneGraphPath path = result[i].getSceneGraphPath();
            Content content = null;
            for (int j = path.nodeCount(); j-- > 0; ) {
                if (path.getNode(j) instanceof Content) {
                    content = (Content) path.getNode(j);
                }
            }
            if (content == null) {
                continue;
            }
            return Pair.of(content, result[i].getIntersectionInfos()[0]);
        }
        return null;
    } catch (final Exception ex) {
        return null;
    }
}
Also used : SceneGraphPath(org.scijava.java3d.SceneGraphPath) Content(ij3d.Content) CustomContent(uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContent) PickCanvas(org.scijava.java3d.utils.pickfast.PickCanvas) PickInfo(org.scijava.java3d.PickInfo) ExecutionException(java.util.concurrent.ExecutionException) DataException(uk.ac.sussex.gdsc.core.data.DataException)

Aggregations

Content (ij3d.Content)1 ExecutionException (java.util.concurrent.ExecutionException)1 PickInfo (org.scijava.java3d.PickInfo)1 SceneGraphPath (org.scijava.java3d.SceneGraphPath)1 PickCanvas (org.scijava.java3d.utils.pickfast.PickCanvas)1 DataException (uk.ac.sussex.gdsc.core.data.DataException)1 CustomContent (uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContent)1