use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog 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();
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class ImageJ3DResultsViewer method createMesh.
@SuppressWarnings("unused")
private static CustomMesh createMesh(final ImageJ3DResultsViewerSettingsOrBuilder settings, LocalList<Point3f> points, final Point3f[] sphereSize, float transparency, float[] alpha) {
// Coordinates + color
int stride = 3 + 3;
if (alpha != null) {
// add color alpha
stride++;
}
// Support drawing as points ...
if (settings.getRendering() == 0) {
final long arraySize = (long) points.size() * stride;
if (arraySize > CustomContentHelper.MAX_ARRAY_SIZE) {
final double capacity = (double) arraySize / CustomContentHelper.MAX_ARRAY_SIZE;
// @formatter:off
IJ.error(TITLE, TextUtils.wrap(String.format("The results will generate data of %d values. " + "This is amount of data is not supported (%.2fx capacity). " + "Please choose a different dataset with fewer points.", arraySize, capacity), 80));
// @formatter:on
return null;
}
CustomPointMesh mesh;
if (alpha != null) {
final TransparentItemPointMesh mesh2 = new TransparentItemPointMesh(points, null, transparency);
mesh = mesh2;
mesh2.setItemAlpha(alpha);
} else {
mesh = new ItemPointMesh(points, null, transparency);
}
mesh.setPointSize(sphereSize[0].x);
return mesh;
}
final Rendering r = Rendering.forNumber(settings.getRendering());
// Repeated mesh creation is much faster as the normals are cached.
// There does not appear to be a difference in the speed the image responds
// to user interaction between indexed or standard triangles.
// Currently the RepeatedIndexedTriangleMesh computes the normals a different way to
// the super class to preserve the orientation of the normals. So if the coordinates
// are modified through the mesh then the appearance will change. For now just use
// the RepeatedTriangleMesh.
// TODO - check this. It may not be true if the shading mode is flat...
// Also the IndexedTriangleMesh has one normal per vertex and this causes a colour fall-off
// on the triangle plane towards the edges. The TriangleMesh colours the entire surface
// of each triangle the same which looks 'normal'.
final List<Point3f> point = Shape3DHelper.createLocalisationObject(r);
// + normals
stride += 3;
final int singlePointSize = point.size();
final long size = (long) points.size() * singlePointSize;
final long arraySize = size * stride;
if (arraySize > CustomContentHelper.MAX_ARRAY_SIZE) {
final double capacity = (double) arraySize / CustomContentHelper.MAX_ARRAY_SIZE;
// @formatter:off
IJ.error(TITLE, TextUtils.wrap(String.format("The results will generate data of %d values. " + "This is amount of data is not supported (%.2fx capacity). " + "Please choose a different rendering model with fewer vertices.", arraySize, capacity), 80));
// @formatter:on
return null;
}
if (size > 10000000L) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE);
egd.addMessage("The results will generate a large mesh of " + size + " vertices.\nThis may take a long time to render and may run out of memory.");
egd.setOKLabel("Continue");
egd.showDialog();
if (egd.wasCanceled()) {
return null;
}
}
IJ.showStatus("Creating 3D mesh ...");
final double creaseAngle = (r.isHighResolution()) ? 44 : 0;
// Used for debugging construction time
final ImageJTrackProgress progress = null;
if (alpha != null) {
final TransparentItemTriangleMesh mesh = new TransparentItemTriangleMesh(point.toArray(new Point3f[singlePointSize]), points.toArray(new Point3f[0]), sphereSize, null, transparency, creaseAngle, progress);
mesh.setItemAlpha(alpha);
return mesh;
}
return new ItemTriangleMesh(point.toArray(new Point3f[singlePointSize]), points.toArray(new Point3f[0]), sphereSize, null, transparency, creaseAngle, progress);
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class GaussianFit method showDialog.
@Override
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
final double[] limits = getLimits(imp.getProcessor());
final double minValue = limits[0];
final double maxValue = limits[1];
settings = Settings.load();
if (settings.background > maxValue) {
settings.background = (int) maxValue;
}
if (settings.background < minValue) {
settings.background = (int) minValue;
}
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("gaussian-fit"));
gd.addMessage("Fit 2D Gaussian to identified maxima");
gd.addMessage("--- Image smoothing ---\n" + "- Within a 2n+1 box\n");
gd.addSlider("Smoothing", 0, 4.5, settings.smooth);
gd.addMessage("--- Maxima identification ---\n" + "- Within a 2n+1 box\n");
gd.addSlider("Box_size", 1, 15, settings.boxSize);
gd.addSlider("Background", minValue, maxValue, settings.background);
gd.addSlider("Min_height", 0, maxValue, settings.peakHeight);
gd.addSlider("Fraction_above_background", 0, 1.01, settings.fractionAboveBackground);
gd.addSlider("Min_width", 0, 20, settings.peakWidth);
gd.addSlider("Top_N", 0, 20, settings.topN);
gd.addCheckbox("Block_find_algorithm", settings.blockFindAlgorithm);
gd.addCheckbox("Neighbour_check", settings.neighbourCheck);
gd.addSlider("Border", 0, 15, settings.border);
gd.addMessage("--- Gaussian fitting ---");
gd.addChoice("PSF", getPsfTypeNames(), PsfProtosHelper.getName(getPsfType()));
gd.addCheckbox("Fit_background", settings.fitBackground);
gd.addNumericField("Max_iterations", settings.maxIterations, 0);
gd.addNumericField("Relative_threshold", settings.relativeThreshold, -3);
gd.addNumericField("Absolute_threshold", settings.absoluteThreshold, -3);
gd.addCheckbox("Single_fit", settings.singleFit);
gd.addNumericField("Single_region_size", settings.singleRegionSize, 0);
gd.addNumericField("Initial_StdDev", settings.initialPeakStdDev, 3);
gd.addCheckbox("Log_progress", settings.logProgress);
gd.addCheckbox("Show_deviations", settings.showDeviations);
gd.addCheckbox("Filter_results", settings.filterResults);
gd.addCheckbox("Show_fit", settings.showFit);
gd.addPreviewCheckbox(pfr);
gd.addDialogListener(this::dialogItemChanged);
gd.showDialog();
if (gd.wasCanceled() || !dialogItemChanged(gd, null)) {
imp.setOverlay(null);
return DONE;
}
return FLAGS;
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class Fire method showDialog.
private boolean showDialog() {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(pluginTitle);
gd.addMessage("Compute the resolution using Fourier Ring Correlation");
gd.addHelp(HelpUrls.getUrl("fourier-image-resolution"));
final boolean single = results2 == null;
gd.addMessage("Image construction options:");
gd.addChoice("Image_scale", Settings.scaleItems, settings.imageScaleIndex);
gd.addChoice("Auto_image_size", Settings.imageSizeItems, settings.imageSizeIndex);
if (extraOptions) {
gd.addCheckbox("Use_signal (if present)", settings.useSignal);
}
gd.addNumericField("Max_per_bin", settings.maxPerBin, 0);
gd.addMessage("Fourier options:");
final String[] fourierMethodNames = SettingsManager.getNames((Object[]) Frc.FourierMethod.values());
gd.addChoice("Fourier_method", fourierMethodNames, fourierMethodNames[settings.fourierMethodIndex]);
final String[] samplingMethodNames = SettingsManager.getNames((Object[]) Frc.SamplingMethod.values());
gd.addChoice("Sampling_method", samplingMethodNames, samplingMethodNames[settings.samplingMethodIndex]);
gd.addSlider("Sampling_factor", 0.2, 4, settings.perimeterSamplingFactor);
gd.addMessage("FIRE options:");
final String[] thresholdMethodNames = SettingsManager.getNames((Object[]) Frc.ThresholdMethod.values());
gd.addChoice("Threshold_method", thresholdMethodNames, thresholdMethodNames[settings.thresholdMethodIndex]);
gd.addCheckbox("Show_FRC_curve", settings.showFrcCurve);
if (single) {
gd.addMessage("For single datasets:");
gd.addNumericField("Block_size", settings.blockSize, 0);
gd.addCheckbox("Random_split", settings.randomSplit);
gd.addNumericField("Repeats", settings.repeats, 0);
gd.addCheckbox("Show_FRC_curve_repeats", settings.showFrcCurveRepeats);
gd.addCheckbox("Show_FRC_time_evolution", settings.showFrcTimeEvolution);
gd.addCheckbox("Spurious correlation correction", settings.spuriousCorrelationCorrection);
gd.addNumericField("Q-value", settings.qvalue, 3);
gd.addNumericField("Precision_Mean", settings.mean, 2, 6, "nm");
gd.addNumericField("Precision_Sigma", settings.sigma, 2, 6, "nm");
if (extraOptions) {
gd.addNumericField("Threads", getLastNThreads(), 0);
}
}
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
settings.imageScaleIndex = gd.getNextChoiceIndex();
settings.imageSizeIndex = gd.getNextChoiceIndex();
if (extraOptions) {
myUseSignal = settings.useSignal = gd.getNextBoolean();
}
settings.maxPerBin = Math.abs((int) gd.getNextNumber());
settings.fourierMethodIndex = gd.getNextChoiceIndex();
fourierMethod = FourierMethod.values()[settings.fourierMethodIndex];
settings.samplingMethodIndex = gd.getNextChoiceIndex();
samplingMethod = SamplingMethod.values()[settings.samplingMethodIndex];
settings.perimeterSamplingFactor = gd.getNextNumber();
settings.thresholdMethodIndex = gd.getNextChoiceIndex();
thresholdMethod = Frc.ThresholdMethod.values()[settings.thresholdMethodIndex];
settings.showFrcCurve = gd.getNextBoolean();
if (single) {
settings.blockSize = Math.max(1, (int) gd.getNextNumber());
settings.randomSplit = gd.getNextBoolean();
settings.repeats = Math.max(1, (int) gd.getNextNumber());
settings.showFrcCurveRepeats = gd.getNextBoolean();
settings.showFrcTimeEvolution = gd.getNextBoolean();
settings.spuriousCorrelationCorrection = gd.getNextBoolean();
settings.qvalue = Math.abs(gd.getNextNumber());
settings.mean = Math.abs(gd.getNextNumber());
settings.sigma = Math.abs(gd.getNextNumber());
if (extraOptions) {
setThreads((int) gd.getNextNumber());
setLastNThreads(this.numberOfThreads);
}
}
// Check arguments
try {
ParameterUtils.isAboveZero("Perimeter sampling factor", settings.perimeterSamplingFactor);
if (single && settings.spuriousCorrelationCorrection) {
ParameterUtils.isAboveZero("Q-value", settings.qvalue);
ParameterUtils.isAboveZero("Precision Mean", settings.mean);
ParameterUtils.isAboveZero("Precision Sigma", settings.sigma);
// Set these for use in FIRE computation
setCorrectionParameters(settings.qvalue, settings.mean, settings.sigma);
}
} catch (final IllegalArgumentException ex) {
IJ.error(pluginTitle, ex.getMessage());
return false;
}
return true;
}
use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.
the class ImageJ3DResultsViewer method createItemMesh.
private static ItemMesh createItemMesh(final ImageJ3DResultsViewerSettingsOrBuilder settings, LocalList<Point3f> points, final Point3f[] sphereSize, float transparency, float[] alpha) {
final Rendering rendering = Rendering.forNumber(settings.getRendering());
final int colorDepth = (alpha != null) ? 4 : 3;
final Shape3D shape = Shape3DHelper.createShape(rendering, colorDepth);
final GeometryArray ga = (GeometryArray) shape.getGeometry();
final Appearance appearance = shape.getAppearance();
// Estimate the largest array required for the data.
// The mesh is created by reference using an array for coords, normals and colors.
final int singlePointVertexSize = ga.getValidVertexCount();
int singlePointIndexSize = 0;
final int stride = Math.max(3, colorDepth);
if (ga instanceof IndexedGeometryArray) {
// Indexed arrays may have much larger index array than the vertex array
singlePointIndexSize = ((IndexedGeometryArray) ga).getIndexCount();
}
final int singlePointSize = Math.max(singlePointIndexSize, stride * singlePointVertexSize);
final long arraySize = (long) points.size() * singlePointSize;
if (arraySize > CustomContentHelper.MAX_ARRAY_SIZE) {
final double capacity = (double) arraySize / CustomContentHelper.MAX_ARRAY_SIZE;
// @formatter:off
IJ.error(TITLE, TextUtils.wrap(String.format("The results will generate data of %d values. " + "This is amount of data is not supported (%.2fx capacity). " + "Please choose a different dataset with fewer points or " + "different rendering model.", arraySize, capacity), 80));
// @formatter:on
return null;
}
// Support drawing as points ...
if (settings.getRendering() == 0) {
final ItemMesh mesh = new ReferenceItemMesh(points.toArray(new Point3f[0]), ga, appearance, null, null, transparency);
if (alpha != null) {
mesh.setItemAlpha(alpha);
}
mesh.getAppearance().getPointAttributes().setPointSize(sphereSize[0].x);
return mesh;
}
final int triangles = Shape3DHelper.getNumberOfTriangles(rendering);
final long size = (long) points.size() * triangles;
if (size > 10000000L) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE);
egd.addMessage("The results will generate a large mesh of " + size + " triangles.\nThis may take a long time to render and may run out of memory.");
egd.setOKLabel("Continue");
egd.showDialog();
if (egd.wasCanceled()) {
return null;
}
}
IJ.showStatus("Creating 3D mesh ...");
final ItemMesh mesh = new ReferenceItemMesh(points.toArray(new Point3f[0]), ga, appearance, sphereSize, null, transparency);
if (alpha != null) {
mesh.setItemAlpha(alpha);
}
return mesh;
}
Aggregations