FractalDimensionWrapper extends BoneJCommand { @Override public void run() { statusService.showStatus("Fractal dimension: initialising"); final List<Double> dimensions = new ArrayList<>(); final List<Double> rSquared = new ArrayList<>(); subspaces = find3DSubspaces(inputImage); matchOps(subspaces.get(0).interval); subspaces.forEach(subspace -> { final RandomAccessibleInterval<BitType> interval = subspace.interval; statusService.showProgress(0, 3); statusService.showStatus("Fractal dimension: hollowing bone"); final RandomAccessibleInterval<BitType> outlines = hollowOp.calculate( interval); statusService.showProgress(1, 3); statusService.showStatus("Fractal dimension: counting boxes"); final List<ValuePair<DoubleType, DoubleType>> pairs = boxCountOp .calculate(outlines); statusService.showProgress(2, 3); statusService.showStatus("Fractal dimension: fitting curve"); dimensions.add(fitCurve(pairs)[1]); rSquared.add(getRSquared(pairs)); if (showPoints) { writePoints(subspace.toString(), pairs); } statusService.showProgress(3, 3); }); fillResultsTable(subspaces, dimensions, rSquared); resultsTable = SharedTable.getTable(); reportUsage(); }  @Override void run();  }
@Test public void testPointResults() throws Exception { final double[] expectedSizes = new double[] { -Math.log(4), -Math.log(2) }; final double[] emptyCounts = new double[] { Math.log(0), Math.log(0) }; final double[] cubeCounts = new double[] { Math.log(1), Math.log(8) }; final ImgPlus<BitType> imgPlus = createTestHyperStack(); final CommandModule module = command().run( FractalDimensionWrapper.class, true, "inputImage", imgPlus, "startBoxSize", 4, "smallestBoxSize", 2, "scaleFactor", 2.0, "translations", 0L, "showPoints", true).get(); final GenericTable pointsTable = (GenericTable) module.getOutput("pointsTable"); assertNotNull("Command should have returned a point table", pointsTable); assertEquals("Table has wrong number of columns", 8, pointsTable.getColumnCount()); testColumn(pointsTable, "-log(size) Channel: 1, Time: 1", expectedSizes); testColumn(pointsTable, "log(count) Channel: 1, Time: 1", emptyCounts); testColumn(pointsTable, "-log(size) Channel: 1, Time: 2", expectedSizes); testColumn(pointsTable, "log(count) Channel: 1, Time: 2", cubeCounts); testColumn(pointsTable, "-log(size) Channel: 2, Time: 1", expectedSizes); testColumn(pointsTable, "log(count) Channel: 2, Time: 1", cubeCounts); testColumn(pointsTable, "-log(size) Channel: 2, Time: 2", expectedSizes); testColumn(pointsTable, "log(count) Channel: 2, Time: 2", emptyCounts); }
@Test public void testResults() throws Exception { final Iterator<String> expectedHeaders = Stream.of("Fractal dimension", "R²").iterator(); final Iterator<Double> expectedDimensions = Stream.of(0.0, 1.4999999999999998, 1.4999999999999998, 0.0).iterator(); final Iterator<Double> expectedRSquares = Stream.of(Double.NaN, 0.7500000000000002, 0.7500000000000002, Double.NaN).iterator(); final ImgPlus<BitType> imgPlus = createTestHyperStack(); final CommandModule module = command().run( FractalDimensionWrapper.class, true, "inputImage", imgPlus, "startBoxSize", 4, "smallestBoxSize", 1, "scaleFactor", 2.0, "translations", 0L).get(); @SuppressWarnings("unchecked") final Table<DefaultColumn<Double>, Double> table = (Table<DefaultColumn<Double>, Double>) module.getOutput("resultsTable"); assertEquals("Wrong number of columns", 2, table.size()); table.forEach(column -> assertEquals( "Column has an incorrect number of rows", 4, column.size())); table.stream().map(Column::getHeader).forEach(header -> assertEquals( "Column has an incorrect header", header, expectedHeaders.next())); table.get("Fractal dimension").forEach(dimension -> assertEquals( "Fractal dimension column has a wrong value", expectedDimensions.next(), dimension, 1e-12)); table.get("R²").forEach(r2 -> assertEquals("R² column has a wrong value", expectedRSquares.next(), r2, 1e-12)); }