ConnectivityWrapper extends BoneJCommand { @Override public void run() { statusService.showStatus("Connectivity: initialising"); final String name = inputImage.getName(); subspaces = find3DSubspaces(inputImage); determineResultUnit(); matchOps(subspaces.get(0).interval); subspaces.forEach(subspace -> { progress = 0; statusService.showProgress(progress, PROGRESS_STEPS); progress++; final String suffix = subspace.toString(); final String label = suffix.isEmpty() ? name : name + " " + suffix; subspaceConnectivity(label, subspace.interval); }); resultsTable = SharedTable.getTable(); reportUsage(); }  @Override void run();  }
@Test public void testNegativeConnectivityShowsInfoDialog() throws Exception { final SwingDialogPrompt mockPrompt = mock(SwingDialogPrompt.class); when(MOCK_UI.dialogPrompt(eq(NEGATIVE_CONNECTIVITY), anyString(), eq( INFORMATION_MESSAGE), any())).thenReturn(mockPrompt); final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, "mm"); final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, "mm"); final DefaultLinearAxis zAxis = new DefaultLinearAxis(Axes.Z, "mm"); final DefaultLinearAxis cAxis = new DefaultLinearAxis(Axes.CHANNEL); final Img<BitType> img = ArrayImgs.bits(5, 5, 5, 2); final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis, zAxis, cAxis); final RandomAccess<BitType> access = imgPlus.randomAccess(); access.setPosition(new long[] { 1, 1, 1, 0 }); access.get().setOne(); access.setPosition(new long[] { 3, 3, 3, 0 }); access.get().setOne(); access.setPosition(new long[] { 1, 1, 1, 1 }); access.get().setOne(); access.setPosition(new long[] { 3, 3, 3, 1 }); access.get().setOne(); command().run(ConnectivityWrapper.class, true, "inputImage", imgPlus).get(); verify(MOCK_UI, timeout(1000).times(1)).dialogPrompt(eq( NEGATIVE_CONNECTIVITY), anyString(), eq(INFORMATION_MESSAGE), any()); }
@Test public void testResults() throws Exception { final String unit = "mm"; final List<String> expectedHeaders = Arrays.asList("Euler char. (χ)", "Corrected Euler (χ + Δχ)", "Connectivity", String.format( "Conn. density (%s³)", unit)); final long size = 3; final double scale = 0.9; final long spaceSize = size * size * size; final double elementSize = scale * scale * scale; final double[] expectedChis = { 0.0, 1.0, 1.0, 0.0 }; final double[] expectedDeltaChis = { 0.0, 1.0, 1.0, 0.0 }; final double[] expectedConnectivities = { 1.0, 0.0, 0.0, 1.0 }; final double expectedDensity = 1.0 / (spaceSize * elementSize); final double[] expectedDensities = { expectedDensity, 0.0, 0.0, expectedDensity }; final double[][] expectedValues = { expectedChis, expectedDeltaChis, expectedConnectivities, expectedDensities }; final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, unit, scale); final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, unit, scale); final DefaultLinearAxis zAxis = new DefaultLinearAxis(Axes.Z, unit, scale); final DefaultLinearAxis cAxis = new DefaultLinearAxis(Axes.CHANNEL); final DefaultLinearAxis tAxis = new DefaultLinearAxis(Axes.TIME); final Img<BitType> img = ArrayImgs.bits(size, size, size, 2, 2); final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis, zAxis, cAxis, tAxis); final RandomAccess<BitType> access = imgPlus.randomAccess(); access.setPosition(new long[] { 1, 1, 1, 1, 0 }); access.get().setOne(); access.setPosition(new long[] { 1, 1, 1, 0, 1 }); access.get().setOne(); final CommandModule module = command().run( ConnectivityWrapper.class, true, "inputImage", imgPlus).get(); @SuppressWarnings("unchecked") final List<DefaultColumn<Double>> table = (List<DefaultColumn<Double>>) module.getOutput("resultsTable"); assertNotNull(table); assertEquals("Results table has wrong number of columns", 4, table.size()); for (int i = 0; i < 4; i++) { final DefaultColumn<Double> column = table.get(i); assertEquals("A column has wrong number of rows", 4, column.size()); final String header = column.getHeader(); assertEquals("A column has an incorrect header", expectedHeaders.get(i), header); for (int j = 0; j < column.size(); j++) { assertEquals(expectedValues[i][j], column.get(j), 1e-12); } } }