AnisotropyWrapper extends BoneJCommand { @Override public void run() { sections = (long) Math.sqrt(lines); statusService.showStatus("Anisotropy: initialising"); subspaces = find3DSubspaces(inputImage); calculateMILLength(subspaces.get(0).interval); matchOps(subspaces.get(0).interval); final List<Ellipsoid> ellipsoids = new ArrayList<>(); for (int i = 0; i < subspaces.size(); i++) { statusService.showStatus("Anisotropy: sampling subspace #" + (i + 1)); final RandomAccessibleInterval<BitType> interval = subspaces.get(i).interval; final Ellipsoid ellipsoid = milEllipsoid(interval); if (ellipsoid == null) { return; } ellipsoids.add(ellipsoid); } addResults(subspaces, ellipsoids); resultsTable = SharedTable.getTable(); reportUsage(); }  @Override void run();  }
@Test public void testAnisotropicCalibrationWithinToleranceDoesNotShowWarningDialog() throws ExecutionException, InterruptedException { final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, "", 1.0); final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, "", 1.01); final DefaultLinearAxis zAxis = new DefaultLinearAxis(Axes.Z, "", 1.0); final Img<BitType> img = ArrayImgs.bits(5, 5, 5); final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis, zAxis); final SwingDialogPrompt mockPrompt = mock(SwingDialogPrompt.class); when(mockPrompt.prompt()).thenReturn(Result.CANCEL_OPTION); final String expectedStart = "The voxels in the image are anisotropic"; when(MOCK_UI.dialogPrompt(startsWith(expectedStart), anyString(), eq( WARNING_MESSAGE), any())).thenReturn(mockPrompt); final CommandModule module = command().run(AnisotropyWrapper.class, true, "inputImage", imgPlus, "lines", 10, "directions", 10, "displayMILVectors", false).get(); assertFalse(module.isCanceled()); verify(MOCK_UI, timeout(1000).times(0)).dialogPrompt(startsWith( expectedStart), anyString(), eq(WARNING_MESSAGE), any()); }
@Test public void testAnisotropicCalibrationShowsWarningDialog() throws ExecutionException, InterruptedException { final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, "", 1.0); final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, "", 5.0); final DefaultLinearAxis zAxis = new DefaultLinearAxis(Axes.Z, "", 1.0); final Img<BitType> img = ArrayImgs.bits(5, 5, 5); final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis, zAxis); final SwingDialogPrompt mockPrompt = mock(SwingDialogPrompt.class); when(mockPrompt.prompt()).thenReturn(Result.CANCEL_OPTION); final String expectedStart = "The voxels in the image are anisotropic"; when(MOCK_UI.dialogPrompt(startsWith(expectedStart), anyString(), eq( WARNING_MESSAGE), any())).thenReturn(mockPrompt); final CommandModule module = command().run(AnisotropyWrapper.class, true, "inputImage", imgPlus, "lines", 10, "directions", 10).get(); assertTrue(module.isCanceled()); verify(MOCK_UI, timeout(1000).times(1)).dialogPrompt(startsWith( expectedStart), anyString(), eq(WARNING_MESSAGE), any()); }
@Test public void testEllipsoidFittingFailingCancelsPlugins() throws Exception { final CommandModule module = command().run(AnisotropyWrapper.class, true, "inputImage", hyperSheets, "lines", 1, "directions", 9).get(); assertTrue(module.isCanceled()); assertEquals( "Anisotropy could not be calculated - ellipsoid fitting failed", module .getCancelReason()); }
@Test public void testTooFewPointsCancelsPlugin() throws Exception { final CommandModule module = command().run(AnisotropyWrapper.class, true, "inputImage", hyperSheets, "lines", 1, "directions", 1).get(); assertTrue(module.isCanceled()); assertEquals("Anisotropy could not be calculated - too few points", module .getCancelReason()); }
@Test public void testMinimumIncrementIsEnforced() throws Exception { final double expectedIncrement = Math.round(Math.sqrt(3.0) * 100.0) / 100.0; final CommandModule module = command() .run(AnisotropyWrapper.class, true, "inputImage", hyperSheets, "lines", 1, "directions", 1, "samplingIncrement", 0).get(); final Double increment = (Double) module.getInput("samplingIncrement"); assertEquals(expectedIncrement, increment, 1e-12); }
@Test public void testIncrementGreaterThanMinimumIsAllowed() throws Exception { final double inputIncrement = 5.0; final CommandModule module = command() .run(AnisotropyWrapper.class, true, "inputImage", hyperSheets, "lines", 1, "directions", 1, "samplingIncrement", inputIncrement).get(); final Double increment = (Double) module.getInput("samplingIncrement"); assertEquals(increment, inputIncrement, 1e-12); }