Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro fixes #210

Merged
merged 6 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Modern/wrapperPlugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@
<dependency><!-- Needed for legacy UI. Do not remove. -->
<groupId>net.imagej</groupId>
<artifactId>imagej-legacy</artifactId>
<scope>runtime</scope>
<optional>true</optional>
<!-- Try removing after pom-scijava 29.x.x -->
<exclusions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static org.bonej.wrapperPlugins.CommonMessages.NOT_8_BIT_BINARY_IMAGE;
import static org.bonej.wrapperPlugins.CommonMessages.NO_IMAGE_OPEN;
import static org.bonej.wrapperPlugins.CommonMessages.NO_SKELETONS;
import static org.bonej.wrapperPlugins.wrapperUtils.Common.cancelMacroSafe;

import ij.ImagePlus;
import ij.ImageStack;
Expand All @@ -50,6 +51,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import org.bonej.utilities.AxisUtils;
import org.bonej.utilities.ImagePlusUtil;
import org.bonej.utilities.SharedTable;
import org.bonej.wrapperPlugins.wrapperUtils.Common;
import org.bonej.wrapperPlugins.wrapperUtils.UsageReporter;
import org.scijava.ItemIO;
import org.scijava.ItemVisibility;
Expand Down Expand Up @@ -99,7 +101,7 @@ public class AnalyseSkeletonWrapper extends ContextCommand {
persist = false)
private ImagePlus inputImage;

@Parameter(visibility = ItemVisibility.MESSAGE, columns = 1)
@Parameter(visibility = ItemVisibility.MESSAGE, columns = 1, persist = false)
private String loopSection = "-- LOOPS --";

@Parameter(label = "Cycle pruning method",
Expand All @@ -108,7 +110,7 @@ public class AnalyseSkeletonWrapper extends ContextCommand {
"Shortest branch", "Lowest intensity voxel", "Lowest intensity branch" })
private String pruneCycleMethod = "None";

@Parameter(visibility = ItemVisibility.MESSAGE)
@Parameter(visibility = ItemVisibility.MESSAGE, persist = false)
private String endPointSection = "-- END-POINTS --";

@Parameter(label = "Prune ends",
Expand All @@ -117,10 +119,10 @@ public class AnalyseSkeletonWrapper extends ContextCommand {

@Parameter(label = "Exclude ROI from pruning",
description = "Exclude the current selection from pruning",
required = false, visibility = ItemVisibility.INVISIBLE)
required = false, visibility = ItemVisibility.INVISIBLE, persist = false)
private boolean excludeRoi;

@Parameter(visibility = ItemVisibility.MESSAGE)
@Parameter(visibility = ItemVisibility.MESSAGE, persist = false)
private String resultSection = "-- RESULTS AND OUTPUT --";

@Parameter(label = "Calculate largest shortest paths",
Expand Down Expand Up @@ -213,7 +215,7 @@ public void run() {
final SkeletonResult results = analyzeSkeleton_.run(pruneIndex, pruneEnds,
calculateShortestPaths, intensityImage, true, verbose, roi);
if (hasNoSkeletons(analyzeSkeleton_)) {
cancel(NO_SKELETONS);
cancelMacroSafe(this, NO_SKELETONS);
return;
}
showResults(results);
Expand Down Expand Up @@ -260,21 +262,21 @@ private boolean isValidIntensityImage(final Dataset dataset) {
// image
final int compositeChannelCount = dataset.getCompositeChannelCount();
if (compositeChannelCount != 1 || dataset.getValidBits() != 8) {
cancel("The intensity image needs to be 8-bit greyscale");
cancelMacroSafe(this, "The intensity image needs to be 8-bit greyscale");
return false;
}
if (AxisUtils.hasTimeDimensions(dataset)) {
cancel("The intensity image can't have a time dimension");
cancelMacroSafe(this, "The intensity image can't have a time dimension");
return false;
}
if (AxisUtils.hasChannelDimensions(dataset)) {
cancel("The intensity image can't have a channel dimension");
cancelMacroSafe(this, "The intensity image can't have a channel dimension");
return false;
}
if (AxisUtils.countSpatialDimensions(dataset) != inputImage
.getNDimensions())
{
cancel(
cancelMacroSafe(this,
"The intensity image should match the dimensionality of the input image");
return false;
}
Expand Down Expand Up @@ -312,17 +314,17 @@ private void openIntensityImage() {
return;
}
if (!convertService.supports(dataset, ImagePlus.class)) {
cancel("Intensity image could not be converted into an ImagePlus");
cancelMacroSafe(this, "Intensity image could not be converted into an ImagePlus");
return;
}
intensityImage = convertService.convert(dataset, ImagePlus.class);
}
catch (final FormatException e) {
cancel("Image format is not recognized");
cancelMacroSafe(this, "Image format is not recognized");
logService.trace(e);
}
catch (final IOException | NullPointerException e) {
cancel("An error occurred while opening the image");
cancelMacroSafe(this, "An error occurred while opening the image");
logService.trace(e);
}
}
Expand Down Expand Up @@ -433,7 +435,7 @@ private ImagePlus skeletonise(final ImagePlus inputImage) {
@SuppressWarnings("unused")
private void validateImage() {
if (inputImage == null) {
cancel(NO_IMAGE_OPEN);
cancelMacroSafe(this, NO_IMAGE_OPEN);
return;
}

Expand All @@ -442,16 +444,16 @@ private void validateImage() {
{
// AnalyzeSkeleton_ and Skeletonize_ cast to byte[], anything else than
// 8-bit will crash
cancel(NOT_8_BIT_BINARY_IMAGE);
cancelMacroSafe(this, NOT_8_BIT_BINARY_IMAGE);
return;
}

if (inputImage.getNChannels() > 1) {
cancel(HAS_CHANNEL_DIMENSIONS + ". Please split the channels.");
cancelMacroSafe(this, HAS_CHANNEL_DIMENSIONS + ". Please split the channels.");
return;
}
if (inputImage.getNFrames() > 1) {
cancel(HAS_TIME_DIMENSIONS + ". Please split the hyperstack.");
cancelMacroSafe(this, HAS_TIME_DIMENSIONS + ". Please split the hyperstack.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static org.bonej.wrapperPlugins.CommonMessages.NOT_3D_IMAGE;
import static org.bonej.wrapperPlugins.CommonMessages.NOT_BINARY;
import static org.bonej.wrapperPlugins.CommonMessages.NO_IMAGE_OPEN;
import static org.bonej.wrapperPlugins.wrapperUtils.Common.cancelMacroSafe;
import static org.scijava.ui.DialogPrompt.MessageType.WARNING_MESSAGE;
import static org.scijava.ui.DialogPrompt.OptionType.OK_CANCEL_OPTION;
import static org.scijava.ui.DialogPrompt.Result.OK_OPTION;
Expand Down Expand Up @@ -364,12 +365,12 @@ private Ellipsoid milEllipsoid(final RandomAccessibleInterval<BitType> interval)
try {
pointCloud = runDirectionsInParallel(interval);
if (pointCloud.size() < Quadric.MIN_DATA) {
cancel("Anisotropy could not be calculated - too few points");
cancelMacroSafe(this, "Anisotropy could not be calculated - too few points");
return null;
}
final Optional<Ellipsoid> ellipsoid = fitEllipsoid(pointCloud);
if (!ellipsoid.isPresent()) {
cancel("Anisotropy could not be calculated - ellipsoid fitting failed");
cancelMacroSafe(this, "Anisotropy could not be calculated - ellipsoid fitting failed");
return null;
}
if (displayMILVectors) {
Expand All @@ -379,7 +380,7 @@ private Ellipsoid milEllipsoid(final RandomAccessibleInterval<BitType> interval)
}
catch (final ExecutionException | InterruptedException e) {
logService.trace(e.getMessage());
cancel("The plug-in was interrupted");
cancelMacroSafe(this, "The plug-in was interrupted");
}
return null;
}
Expand Down Expand Up @@ -441,15 +442,15 @@ private void shutdownAndAwaitTermination(final ExecutorService executor) {
@SuppressWarnings("unused")
private void validateImage() {
if (inputImage == null) {
cancel(NO_IMAGE_OPEN);
cancelMacroSafe(this, NO_IMAGE_OPEN);
return;
}
if (AxisUtils.countSpatialDimensions(inputImage) != 3) {
cancel(NOT_3D_IMAGE);
cancelMacroSafe(this, NOT_3D_IMAGE);
return;
}
if (!ElementUtil.isBinary(inputImage)) {
cancel(NOT_BINARY);
cancelMacroSafe(this, NOT_BINARY);
return;
}
if (!isSpatialCalibrationsIsotropic(inputImage, 0.01, unitService) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static org.bonej.wrapperPlugins.CommonMessages.NOT_3D_IMAGE;
import static org.bonej.wrapperPlugins.CommonMessages.NOT_BINARY;
import static org.bonej.wrapperPlugins.CommonMessages.NO_IMAGE_OPEN;
import static org.bonej.wrapperPlugins.wrapperUtils.Common.cancelMacroSafe;
import static org.scijava.ui.DialogPrompt.MessageType.INFORMATION_MESSAGE;

import java.util.List;
Expand Down Expand Up @@ -213,17 +214,17 @@ private void subspaceConnectivity(final String label,
@SuppressWarnings("unused")
private void validateImage() {
if (inputImage == null) {
cancel(NO_IMAGE_OPEN);
cancelMacroSafe(this, NO_IMAGE_OPEN);
return;
}

if (AxisUtils.countSpatialDimensions(inputImage) != 3) {
cancel(NOT_3D_IMAGE);
cancelMacroSafe(this, NOT_3D_IMAGE);
return;
}

if (!ElementUtil.isBinary(inputImage)) {
cancel(NOT_BINARY);
cancelMacroSafe(this, NOT_BINARY);
}
}
// endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static org.bonej.wrapperPlugins.CommonMessages.NOT_BINARY;
import static org.bonej.wrapperPlugins.CommonMessages.NO_IMAGE_OPEN;
import static org.bonej.wrapperPlugins.CommonMessages.WEIRD_SPATIAL;
import static org.bonej.wrapperPlugins.wrapperUtils.Common.cancelMacroSafe;

import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -178,17 +179,17 @@ private void prepareResultDisplay() {
@SuppressWarnings("unused")
private void validateImage() {
if (inputImage == null) {
cancel(NO_IMAGE_OPEN);
cancelMacroSafe(this, NO_IMAGE_OPEN);
return;
}

if (!ElementUtil.isBinary(inputImage)) {
cancel(NOT_BINARY);
cancelMacroSafe(this, NOT_BINARY);
}

final long spatialDimensions = AxisUtils.countSpatialDimensions(inputImage);
if (spatialDimensions < 2 || spatialDimensions > 3) {
cancel(WEIRD_SPATIAL);
cancelMacroSafe(this, WEIRD_SPATIAL);
}
}
// endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static net.imagej.ops.stats.regression.leastSquares.Quadric.MIN_DATA;
import static org.bonej.wrapperPlugins.CommonMessages.NOT_3D_IMAGE;
import static org.bonej.wrapperPlugins.CommonMessages.NO_IMAGE_OPEN;
import static org.bonej.wrapperPlugins.wrapperUtils.Common.cancelMacroSafe;

import ij.ImagePlus;
import ij.measure.Calibration;
Expand Down Expand Up @@ -113,8 +114,8 @@ public class FitEllipsoidWrapper extends ContextCommand {
@Override
public void run() {
if (!initPointROIs()) {
cancel("Please populate ROI Manager with at least " + MIN_DATA +
" point ROIs");
cancelMacroSafe(this, "Please populate ROI Manager with at least "
+ MIN_DATA + " point ROIs");
return;
}
statusService.showStatus("Fit ellipsoid: solving ellipsoid equation");
Expand All @@ -126,7 +127,7 @@ public void run() {
final Optional<Ellipsoid> result = (Optional<Ellipsoid>) opService.run(
QuadricToEllipsoid.class, quadric);
if (!result.isPresent()) {
cancel("Can't fit ellipsoid to points.\n" +
cancelMacroSafe(this, "Can't fit ellipsoid to points.\n" +
"Try adding more point ROIs to the ROI Manager and try again.");
return;
}
Expand Down Expand Up @@ -181,11 +182,11 @@ private boolean initPointROIs() {
@SuppressWarnings("unused")
private void validateImage() {
if (inputImage == null) {
cancel(NO_IMAGE_OPEN);
cancelMacroSafe(this, NO_IMAGE_OPEN);
return;
}
if (!ImagePlusUtil.is3D(inputImage)) {
cancel(NOT_3D_IMAGE);
cancelMacroSafe(this, NOT_3D_IMAGE);
return;
}
if (!Common.warnAnisotropy(inputImage, uiService)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

import static org.bonej.wrapperPlugins.CommonMessages.NOT_BINARY;
import static org.bonej.wrapperPlugins.CommonMessages.NO_IMAGE_OPEN;
import static org.bonej.wrapperPlugins.wrapperUtils.Common.cancelMacroSafe;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -322,11 +323,11 @@ private WeightedObservedPoints toWeightedObservedPoints(
@SuppressWarnings("unused")
private void validateImage() {
if (inputImage == null) {
cancel(NO_IMAGE_OPEN);
cancelMacroSafe(this, NO_IMAGE_OPEN);
return;
}
if (!ElementUtil.isBinary(inputImage)) {
cancel(NOT_BINARY);
cancelMacroSafe(this, NOT_BINARY);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import static org.bonej.wrapperPlugins.CommonMessages.HAS_TIME_DIMENSIONS;
import static org.bonej.wrapperPlugins.CommonMessages.NOT_8_BIT_BINARY_IMAGE;
import static org.bonej.wrapperPlugins.CommonMessages.NO_SKELETONS;
import static org.bonej.wrapperPlugins.wrapperUtils.Common.cancelMacroSafe;
import static org.scijava.ui.DialogPrompt.MessageType.WARNING_MESSAGE;

import ij.ImagePlus;
Expand Down Expand Up @@ -180,7 +181,7 @@ public void run() {
statusService.showProgress(0, PROGRESS_STEPS);
final Graph[] graphs = analyzeSkeleton(skeleton);
if (graphs == null || graphs.length == 0) {
cancel(NO_SKELETONS);
cancelMacroSafe(this, NO_SKELETONS);
return;
}
warnMultipleGraphs(graphs);
Expand Down Expand Up @@ -226,7 +227,7 @@ private void addResults(final Map<Integer, DoubleStream> anglesMap) {
anglesTable = SharedTable.getTable();
}
else {
cancel(NO_RESULTS_MSG);
cancelMacroSafe(this, NO_RESULTS_MSG);
}
}

Expand Down Expand Up @@ -277,23 +278,23 @@ private List<Vertex> filterBoundaryVertices(
@SuppressWarnings("unused")
private void imageValidater() {
if (inputImage == null) {
cancel(CommonMessages.NO_IMAGE_OPEN);
cancelMacroSafe(this, CommonMessages.NO_IMAGE_OPEN);
return;
}
if (inputImage.getBitDepth() != 8 || !ImagePlusUtil.isBinaryColour(
inputImage))
{
cancel(NOT_8_BIT_BINARY_IMAGE);
cancelMacroSafe(this, NOT_8_BIT_BINARY_IMAGE);
return;
}

if (inputImage.getNChannels() > 1) {
cancel(HAS_CHANNEL_DIMENSIONS + ". Please split the channels.");
cancelMacroSafe(this, HAS_CHANNEL_DIMENSIONS + ". Please split the channels.");
return;
}

if (inputImage.getNFrames() > 1) {
cancel(HAS_TIME_DIMENSIONS + ". Please split the hyperstack.");
cancelMacroSafe(this, HAS_TIME_DIMENSIONS + ". Please split the hyperstack.");
}
// Without anisotropyWarned the warning is shown twice
if (!anisotropyWarned) {
Expand Down
Loading