SurfaceFractionWrapper extends BoneJCommand { @Override public void run() { statusService.showStatus("Surface fraction: initializing"); subspaces = find3DSubspaces(inputImage); matchOps(subspaces.get(0).interval); prepareResultDisplay(); for (int i = 0; i < subspaces.size(); i++) { calculateSubspaceVolumes(subspaces.get(i), i + 1); statusService.showProgress(i, subspaces.size()); } resultsTable = SharedTable.getTable(); reportUsage(); }  @Override void run();  }
@Test public void testResults() throws Exception { final int cubeDepth = 3; final int cubeHeight = 3; final int cubeWidth = 3; final long imgWidth = 5; final long imgHeight = 5; final long imgDepth = 5; final String unit = "mm"; final double scale = 0.25; final double scaleCubed = scale * scale * scale; final double cubeVolume = ((cubeWidth - 1) * (cubeHeight - 1) * (cubeDepth - 1)) * scaleCubed; final double totalVolume = ((imgWidth - 1) * (imgHeight - 1) * (imgDepth - 1)) * scaleCubed; final double ratio = cubeVolume / totalVolume; final String[] expectedHeaders = { "Bone volume (" + unit + "³)", "Total volume (" + unit + "³)", "Volume ratio" }; final double[][] expectedValues = { { 0.0, cubeVolume, cubeVolume, 0.0 }, { totalVolume, totalVolume, totalVolume, totalVolume }, { 0.0, ratio, ratio, 0.0 } }; 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(imgWidth, imgHeight, imgDepth, 2, 2); final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis, zAxis, cAxis, tAxis); final RandomAccess<BitType> access = imgPlus.randomAccess(); for (int z = 1; z <= cubeDepth; z++) { for (int y = 1; y <= cubeHeight; y++) { for (int x = 1; x <= cubeWidth; x++) { access.setPosition(new long[] { x, y, z, 1, 0 }); access.get().setOne(); access.setPosition(new long[] { x, y, z, 0, 1 }); access.get().setOne(); } } } final CommandModule module = command().run( SurfaceFractionWrapper.class, true, "inputImage", imgPlus).get(); @SuppressWarnings("unchecked") final List<DefaultColumn<Double>> table = (List<DefaultColumn<Double>>) module.getOutput("resultsTable"); assertNotNull(table); assertEquals("Wrong number of columns", 3, table.size()); for (int i = 0; i < 3; i++) { final DefaultColumn<Double> column = table.get(i); assertEquals("Wrong number of rows", 4, column.size()); assertEquals("Column has incorrect header", expectedHeaders[i], column .getHeader()); for (int j = 0; j < expectedValues.length; j++) { assertEquals("Incorrect value in table", expectedValues[i][j], column.get(j), 1e-12); } } }