ThicknessWrapper extends BoneJCommand { @Override public void run() { final List<Boolean> mapOptions = getMapOptions(); createLocalThickness(); final Map<Boolean, ImagePlus> thicknessMaps = new HashMap<>(); mapOptions.forEach(foreground -> { prepareRun(foreground); statusService.showStatus("Thickness: creating thickness map"); final ImagePlus map = createMap(); statusService.showStatus("Thickness: calculating results"); addMapResults(map); thicknessMaps.put(foreground, map); }); resultsTable = SharedTable.getTable(); if (showMaps) { final LUT fire = Common.makeFire(); trabecularMap = thicknessMaps.get(true); if (trabecularMap != null) { final StackStatistics trabecularStats = new StackStatistics(trabecularMap); trabecularMap.setDisplayRange(0.0, trabecularStats.max); trabecularMap.setLut(fire); } spacingMap = thicknessMaps.get(false); if (spacingMap != null) { final StackStatistics spacingStats = new StackStatistics(spacingMap); spacingMap.setDisplayRange(0.0, spacingStats.max); spacingMap.setLut(fire); } } reportUsage(); }  @Override void run();  }
@Test public void testCompositeImageCancelsPlugin() throws Exception { final String expectedMessage = CommonMessages.HAS_CHANNEL_DIMENSIONS + ". Please split the channels."; final ImagePlus imagePlus = IJ.createHyperStack("test", 3, 3, 3, 3, 1, 8); final CommandModule module = command().run(ThicknessWrapper.class, true, "inputImage", imagePlus).get(); assertTrue("A composite image should have cancelled the plugin", module .isCanceled()); assertEquals("Cancel reason is incorrect", expectedMessage, module .getCancelReason()); verify(MOCK_UI, timeout(1000)).dialogPrompt(anyString(), anyString(), any(), any()); }
@Test public void testMapImageLUTs() throws ExecutionException, InterruptedException { final LUT fireLUT = Common.makeFire(); final ImagePlus imagePlus = NewImage.createByteImage("TinyTestImage", 2, 2, 2, 1); final CommandModule module = command().run(ThicknessWrapper.class, true, "inputImage", imagePlus, "mapChoice", "Both", "showMaps", true) .get(); final LUT trabecularMap = ((ImagePlus) module.getOutput("trabecularMap")) .getLuts()[0]; final LUT spacingMap = ((ImagePlus) module.getOutput("spacingMap")) .getLuts()[0]; assertArrayEquals("Trabecular map doesn't have the 'fire' LUT", fireLUT.getBytes(), trabecularMap.getBytes()); assertArrayEquals("Spacing map doesn't have the 'fire' LUT", fireLUT .getBytes(), spacingMap.getBytes()); }
@Test public void testMapImagesBoth() throws ExecutionException, InterruptedException { final ImagePlus imagePlus = NewImage.createByteImage("image", 2, 2, 2, 1); final CommandModule module = command().run(ThicknessWrapper.class, true, "inputImage", imagePlus, "mapChoice", "Both", "showMaps", true) .get(); assertNotNull(module.getOutput("trabecularMap")); assertNotNull(module.getOutput("spacingMap")); }
@Test public void testMapImagesShowMapsFalse() throws ExecutionException, InterruptedException { final ImagePlus imagePlus = NewImage.createByteImage("image", 2, 2, 2, 1); final CommandModule module = command().run(ThicknessWrapper.class, true, "inputImage", imagePlus, "mapChoice", "Both", "showMaps", false) .get(); assertNull(module.getOutput("trabecularMap")); assertNull(module.getOutput("spacingMap")); }
@Test public void testMapImagesTrabecularSpacing() throws ExecutionException, InterruptedException { final ImagePlus imagePlus = NewImage.createByteImage("image", 2, 2, 2, 1); final CommandModule module = command().run(ThicknessWrapper.class, true, "inputImage", imagePlus, "mapChoice", "Trabecular spacing", "showMaps", true).get(); final ImagePlus spacingMap = (ImagePlus) module.getOutput("spacingMap"); assertNotNull(spacingMap); assertNull(module.getOutput("trabecularMap")); assertNotSame("Original image should not have been overwritten", imagePlus, spacingMap); }
@Test public void testMapImagesTrabecularThickness() throws ExecutionException, InterruptedException { final ImagePlus imagePlus = NewImage.createByteImage("image", 2, 2, 2, 1); final CommandModule module = command().run(ThicknessWrapper.class, true, "inputImage", imagePlus, "mapChoice", "Trabecular thickness", "showMaps", true).get(); final ImagePlus trabecularMap = (ImagePlus) module.getOutput( "trabecularMap"); assertNotNull(trabecularMap); assertNull(module.getOutput("spacingMap")); assertNotSame("Original image should not have been overwritten", imagePlus, trabecularMap); }
@Test public void testResults() throws Exception { final ImagePlus imagePlus = NewImage.createByteImage("TinyTestImage", 2, 2, 2, 1); final Calibration calibration = new Calibration(); calibration.setUnit("mm"); imagePlus.setCalibration(calibration); final String[] expectedHeaders = { "Tb.Th Mean (mm)", "Tb.Th Std Dev (mm)", "Tb.Th Max (mm)", "Tb.Sp Mean (mm)", "Tb.Sp Std Dev (mm)", "Tb.Sp Max (mm)" }; final Double[][] expectedValues = { { Double.NaN }, { Double.NaN }, { Double.NaN }, { 10.392304420471191 }, { 0.0 }, { 10.392304420471191 } }; final CommandModule module = command().run(ThicknessWrapper.class, true, "inputImage", imagePlus, "mapChoice", "Both", "maskArtefacts", false, "showMaps", false).get(); @SuppressWarnings("unchecked") final List<DefaultColumn<Double>> table = (List<DefaultColumn<Double>>) module.getOutput("resultsTable"); assertNotNull(table); assertEquals("Results table has wrong number of columns", 6, table.size()); for (int i = 0; i < 6; i++) { final DefaultColumn<Double> column = table.get(i); assertEquals(expectedHeaders[i], column.getHeader()); assertEquals("Results table has wrong number of rows", 1, column.size()); final int j = 0; assertEquals("Cell at i=" + i + ", j=" + j + " has an incorrect value", expectedValues[i][j], column.getValue(j)); } }
@Test public void testTimeDimensionCancelsPlugin() throws Exception { final String expectedMessage = CommonMessages.HAS_TIME_DIMENSIONS + ". Please split the hyperstack."; final ImagePlus imagePlus = IJ.createHyperStack("test", 3, 3, 1, 3, 3, 8); final CommandModule module = command().run(ThicknessWrapper.class, true, "inputImage", imagePlus).get(); assertTrue("An image with time dimension should have cancelled the plugin", module.isCanceled()); assertEquals("Cancel reason is incorrect", expectedMessage, module .getCancelReason()); verify(MOCK_UI, timeout(1000)).dialogPrompt(anyString(), anyString(), any(), any()); }