Search in sources :

Example 11 with Content

use of ij3d.Content in project GDSC-SMLM by aherbert.

the class ImageJ3DResultsViewer method menuActionPerformed.

private void menuActionPerformed(ActionEvent event) {
    final Object src = event.getSource();
    ContentAction action = null;
    // Adapted from univ.resetView()
    if (src == resetRotation) {
        univ.fireTransformationStarted();
        // rotate so that y shows downwards
        final Transform3D t = new Transform3D();
        final AxisAngle4d aa = new AxisAngle4d(1, 0, 0, Math.PI);
        t.set(aa);
        univ.getRotationTG().setTransform(t);
        univ.fireTransformationUpdated();
        univ.fireTransformationFinished();
        return;
    }
    if (src == resetTranslation) {
        univ.fireTransformationStarted();
        final Transform3D t = new Transform3D();
        univ.getTranslateTG().setTransform(t);
        univ.recalculateGlobalMinMax();
        univ.getViewPlatformTransformer().centerAt(univ.getGlobalCenterPoint());
        univ.fireTransformationUpdated();
        univ.fireTransformationFinished();
        return;
    }
    if (src == resetZoom) {
        univ.fireTransformationStarted();
        final Transform3D t = new Transform3D();
        univ.getZoomTG().setTransform(t);
        final Point3d max = new Point3d();
        final Point3d min = new Point3d();
        univ.getGlobalMaxPoint(max);
        univ.getGlobalMinPoint(min);
        final float range = (float) (max.x - min.x);
        final double d = (range) / Math.tan(Math.PI / 8);
        univ.getViewPlatformTransformer().zoomTo(d);
        univ.fireTransformationUpdated();
        univ.fireTransformationFinished();
        return;
    }
    if (src == updateSettings) {
        final ImageJ3DResultsViewerSettings.Builder settings = SettingsManager.readImageJ3DResultsViewerSettings(0).toBuilder();
        final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
        final ResultsSettings.Builder s = ResultsSettings.newBuilder();
        ResultsTableSettings localResultsTableSettings = resultsTableSettings.get();
        s.setResultsTableSettings(localResultsTableSettings);
        gd.addMessage("Click on the image to view localisation data.\nCtrl/Alt key must be pressed.");
        final TextField[] tf = new TextField[1];
        gd.addStringField("Highlight_colour", settings.getHighlightColour(), new OptionListener<String>() {

            @Override
            public boolean collectOptions(String value) {
                createHighlightColour(value);
                int red;
                int green;
                int blue;
                final Color3f color = highlightColor.get();
                if (color == null) {
                    red = blue = 0;
                    green = 255;
                } else {
                    red = (int) (color.x * 255);
                    green = (int) (color.y * 255);
                    blue = (int) (color.z * 255);
                }
                final ExtendedGenericDialog egd = new ExtendedGenericDialog("Highlight colour", null);
                egd.addSlider("Red", 0, 255, red);
                egd.addSlider("Green", 0, 255, green);
                egd.addSlider("Blue", 0, 255, blue);
                egd.showDialog(true, gd);
                if (egd.wasCanceled()) {
                    return false;
                }
                red = (int) egd.getNextNumber();
                green = (int) egd.getNextNumber();
                blue = (int) egd.getNextNumber();
                final Color c = new Color(red, green, blue);
                final String cvalue = c.getRed() + "," + c.getGreen() + "," + c.getBlue();
                tf[0].setText(cvalue);
                return true;
            }

            @Override
            public boolean collectOptions() {
                return false;
            }
        });
        tf[0] = gd.getLastTextField();
        gd.addCheckbox("Add_to_selection", settings.getAddToSelection());
        ResultsManager.addTableResultsOptions(gd, s, ResultsManager.FLAG_NO_SECTION_HEADER);
        gd.addMessage("Allow the 'Find Eye Point' command to save to settings");
        gd.addCheckbox("Save_eye_point", settings.getSaveEyePoint());
        // Same as CropResults
        gd.addChoice("Crop_name_option", CropResults.NAME_OPTIONS, settings.getNameOption(), new OptionListener<Integer>() {

            @Override
            public boolean collectOptions(Integer value) {
                settings.setNameOption(value);
                final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE);
                if (settings.getNameOption() == CropResults.NAME_OPTION_NAME) {
                    return false;
                } else if (settings.getNameOption() == CropResults.NAME_OPTION_SUFFIX) {
                    final String name = (TextUtils.isNullOrEmpty(settings.getNameSuffix())) ? " Cropped" : settings.getNameSuffix();
                    egd.addStringField("Name_suffix", name, MathUtils.clip(20, 60, name.length()));
                } else if (settings.getNameOption() == CropResults.NAME_OPTION_SEQUENCE) {
                    final String name = settings.getNameSuffix();
                    egd.addStringField("Name_suffix", name, MathUtils.clip(20, 60, name.length()));
                    int counter = settings.getNameCounter();
                    if (counter < 1) {
                        counter = 1;
                    }
                    egd.addNumericField("Name_counter", counter, 0);
                } else {
                    throw new IllegalStateException("Unknown name option: " + settings.getNameOption());
                }
                egd.showDialog(true, gd);
                if (egd.wasCanceled()) {
                    return false;
                }
                if (settings.getNameOption() == CropResults.NAME_OPTION_SUFFIX) {
                    settings.setNameSuffix(egd.getNextString());
                } else if (settings.getNameOption() == CropResults.NAME_OPTION_SEQUENCE) {
                    settings.setNameSuffix(egd.getNextString());
                    settings.setNameCounter(Math.max(1, (int) egd.getNextNumber()));
                }
                return true;
            }

            @Override
            public boolean collectOptions() {
                return false;
            }
        });
        gd.addCheckbox("Update_existing_tables", localResultsTableSettings.getUpdateExistingTables());
        addHelp(gd);
        gd.showDialog();
        if (gd.wasCanceled()) {
            return;
        }
        settings.setHighlightColour(gd.getNextString());
        boolean add = gd.getNextBoolean();
        addToSelection.set(add);
        settings.setAddToSelection(add);
        final ResultsTableSettings.Builder resultsTableSettingsBuilder = s.getResultsTableSettingsBuilder();
        resultsTableSettingsBuilder.setShowTable(gd.getNextBoolean());
        settings.setSaveEyePoint(gd.getNextBoolean());
        settings.setNameOption(gd.getNextChoiceIndex());
        resultsTableSettingsBuilder.setUpdateExistingTables(gd.getNextBoolean());
        createHighlightColour(settings.getHighlightColour());
        // Save updated settings
        localResultsTableSettings = resultsTableSettingsBuilder.build();
        settings.setResultsTableSettings(localResultsTableSettings);
        SettingsManager.writeSettings(settings);
        // Update the table settings for all the selection models
        if (resultsTableSettingsBuilder.getUpdateExistingTables()) {
            for (final Triple<PeakResultTableModel, ?, ?> t : resultsTables.values()) {
                t.getLeft().setTableSettings(localResultsTableSettings);
            }
        }
        action = new UpdateHighlightColourAction();
    }
    if (src == toggleDynamicTransparency) {
        final long total = getTotalTransparentObjects(univ, "");
        final View view = univ.getViewer().getView();
        final boolean activate = view.getTransparencySortingPolicy() == View.TRANSPARENCY_SORT_NONE;
        activateDynamicTransparency(univ, total, activate);
        return;
    }
    // Actions to perform on content
    if (src == changeColour) {
        action = new ChangeColourContentAction();
    } else if (src == resetAll) {
        univ.resetView();
        univ.select(null);
        action = new ResetViewContentAction(false);
    } else if (src == resetSelectedView) {
        action = new ResetViewContentAction(true);
    } else if (src == findEyePoint) {
        action = new FindEyePointContentAction();
    } else if (src == sortBackToFront) {
        action = new SortContentAction(false);
    } else if (src == sortFrontToBack) {
        action = new SortContentAction(true);
    } else if (src == colourSurface) {
        action = new ColourSurfaceContentAction();
    } else if (src == toggleTransparent) {
        action = new ToggleTransparentAction();
    } else if (src == toggleShaded) {
        action = new ToggleShadedAction();
    } else if (src == changePointSize) {
        action = new ChangePointSizeContentAction();
    } else if (src == increasePointSize) {
        action = UpdatePointSizeContentAction.INCREASE;
    } else if (src == decreasePointSize) {
        action = UpdatePointSizeContentAction.DECREASE;
    } else if (src == cropResults) {
        action = new CropResultsAction();
    } else if (src == showHelp) {
        showHelp();
        return;
    }
    if (action == null) {
        return;
    }
    if (univ.getSelected() != null) {
        action.run(univ.getSelected());
    } else {
        for (final Iterator<Content> it = univ.contents(); it.hasNext(); ) {
            if (action.run(it.next()) < 0) {
                break;
            }
        }
    }
    action.finish();
}
Also used : ImageJ3DResultsViewerSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ImageJ3DResultsViewerSettings) Transform3D(org.scijava.java3d.Transform3D) Color3f(org.scijava.vecmath.Color3f) PeakResultTableModel(uk.ac.sussex.gdsc.smlm.ij.gui.PeakResultTableModel) Point3d(org.scijava.vecmath.Point3d) TextField(java.awt.TextField) Builder(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ImageJ3DResultsViewerSettings.Builder) ResultsTableSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsTableSettings) Color(java.awt.Color) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) ResultsSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsSettings) View(org.scijava.java3d.View) Content(ij3d.Content) CustomContent(uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContent) NamedObject(uk.ac.sussex.gdsc.smlm.data.NamedObject) AxisAngle4d(org.scijava.vecmath.AxisAngle4d)

Example 12 with Content

use of ij3d.Content 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)

Example 13 with Content

use of ij3d.Content in project TrakEM2 by trakem2.

the class Display3D method setTransparency.

public static Future<Boolean> setTransparency(final Displayable d, final float alpha) {
    if (null == d)
        return null;
    final Layer layer = d.getLayer();
    // some objects have no layer, such as the parent LayerSet.
    if (null == layer)
        return null;
    final Display3D d3d = ht_layer_sets.get(layer.getParent());
    if (null == d3d)
        return null;
    return d3d.executors.submit(new Callable<Boolean>() {

        @Override
        public Boolean call() {
            String title = makeTitle(d);
            Content content = d3d.universe.getContent(title);
            if (null == content)
                content = getProfileContent(d);
            if (null != content)
                content.setTransparency(1 - alpha);
            else if (null == content && d.getClass().equals(Patch.class)) {
                final Patch pa = (Patch) d;
                if (pa.isStack()) {
                    title = pa.getProject().getLoader().getFileName(pa);
                    for (final Display3D dd : ht_layer_sets.values()) {
                        for (final Iterator<?> cit = dd.universe.getContents().iterator(); cit.hasNext(); ) {
                            final Content c = (Content) cit.next();
                            if (c.getName().startsWith(title)) {
                                c.setTransparency(1 - alpha);
                            // no break, since there could be a volume and an orthoslice
                            }
                        }
                    }
                }
            }
            return true;
        }
    });
}
Also used : Content(ij3d.Content)

Example 14 with Content

use of ij3d.Content in project TrakEM2 by trakem2.

the class ControlClickBehavior method doProcess.

@Override
public void doProcess(final MouseEvent e) {
    if (!e.isControlDown() || e.getID() != MouseEvent.MOUSE_PRESSED) {
        super.doProcess(e);
        return;
    }
    final Picker picker = universe.getPicker();
    final Content content = picker.getPickedContent(e.getX(), e.getY());
    if (content == null)
        return;
    final Point3d p = picker.getPickPointGeometry(content, e);
    if (p == null) {
        Utils.log("No point was found on content " + content);
        return;
    }
    final Display display = Display.getFront(ls.getProject());
    if (display == null) {
        // If there's no Display, just return...
        return;
    }
    if (display.getLayerSet() != ls) {
        Utils.log("The LayerSet instances do not match");
        return;
    }
    if (ls == null) {
        Utils.log("No LayerSet was found for the Display");
        return;
    }
    final Calibration cal = ls.getCalibration();
    if (cal == null) {
        Utils.log("No calibration information was found for the LayerSet");
        return;
    }
    final double scaledZ = p.z / cal.pixelWidth;
    final Layer l = ls.getNearestLayer(scaledZ);
    if (l == null) {
        Utils.log("No layer was found nearest to " + scaledZ);
        return;
    }
    final Coordinate<?> coordinate = new Coordinate<Object>(p.x / cal.pixelWidth, p.y / cal.pixelHeight, l, null);
    display.center(coordinate);
}
Also used : Coordinate(ini.trakem2.display.Coordinate) Content(ij3d.Content) Point3d(org.scijava.vecmath.Point3d) Picker(ij3d.behaviors.Picker) Calibration(ij.measure.Calibration) Layer(ini.trakem2.display.Layer) Display(ini.trakem2.display.Display)

Example 15 with Content

use of ij3d.Content in project TrakEM2 by trakem2.

the class Display3DGUI method getOrderedContents.

/**
 * The {@link Image3DUniverse#getContents()} returns an unordered list, because the
 * list are the values of a {@link Map}; this method circumvents that by getting
 * the list from the enumeration of children elements in the scene of the {@code univ},
 * which is a {@link BranchGroup}.
 *
 * @param univ
 * @return
 */
private static final List<Content> getOrderedContents(final Image3DUniverse univ) {
    final ArrayList<Content> cs = new ArrayList<Content>();
    final Enumeration<?> seq = univ.getScene().getAllChildren();
    while (seq.hasMoreElements()) {
        final Object o = seq.nextElement();
        if (o instanceof Content)
            cs.add((Content) o);
    }
    return cs;
}
Also used : Content(ij3d.Content) ArrayList(java.util.ArrayList) DBObject(ini.trakem2.persistence.DBObject)

Aggregations

Content (ij3d.Content)18 Color3f (org.scijava.vecmath.Color3f)7 CustomContent (uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContent)5 ArrayList (java.util.ArrayList)4 ImagePlus (ij.ImagePlus)3 Color (java.awt.Color)3 Transform3D (org.scijava.java3d.Transform3D)3 CustomContentInstant (uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContentInstant)3 ItemGroupNode (uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemGroupNode)3 CustomMesh (customnode.CustomMesh)2 CustomMeshNode (customnode.CustomMeshNode)2 CustomTriangleMesh (customnode.CustomTriangleMesh)2 Calibration (ij.measure.Calibration)2 ContentInstant (ij3d.ContentInstant)2 Image3DUniverse (ij3d.Image3DUniverse)2 PatchStack (ini.trakem2.imaging.PatchStack)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2