diff --git a/src/main/java/ijfx/service/overlay/OverlayStatCommandTester.java b/src/main/java/ijfx/service/overlay/OverlayStatCommandTester.java index 59bb3655..bc077412 100644 --- a/src/main/java/ijfx/service/overlay/OverlayStatCommandTester.java +++ b/src/main/java/ijfx/service/overlay/OverlayStatCommandTester.java @@ -19,15 +19,24 @@ */ package ijfx.service.overlay; +import ijfx.plugins.commands.BinaryToOverlay; +import ijfx.service.batch.BatchSingleInput; +import ijfx.service.batch.ImageDisplayBatchInput; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; import net.imagej.display.ImageDisplay; import net.imagej.display.ImageDisplayService; import net.imagej.display.OverlayService; import net.imagej.overlay.Overlay; -import org.scijava.SciJava; +import net.imagej.table.DefaultGenericTable; +import org.scijava.Context; import org.scijava.command.Command; import org.scijava.plugin.Parameter; import org.scijava.plugin.Plugin; +import org.scijava.ui.UIService; /** * @@ -46,12 +55,52 @@ public class OverlayStatCommandTester implements Command{ @Parameter OverlayStatService overlayStatService; + @Parameter + Context context; + + @Parameter + private UIService uiService; + @Override public void run(){ ImageDisplay display = imageDisplayService.getActiveImageDisplay(); - Overlay overlay = overlayService.getActiveOverlay(display); - OverlayStatistics overlayStatistics = overlayStatService.getOverlayStatistics(display, overlay); - System.out.println(overlayStatistics.toString()); + + List overlay = overlayService.getOverlays(); + + overlayService.addOverlays(display, overlay); + + List> map = overlay.stream() + .map(o -> { + try { + + return overlayStatService.getStatistics(overlayStatService.getOverlayStatistics(display, o)); + } catch (Exception e) { + return null; + } + }) + .filter(o -> o != null) + .collect(Collectors.toList()); + + DefaultGenericTable resultTable = new DefaultGenericTable(); + if (map.size() > 0) { + int headerNumber = map.get(0).keySet().size(); + + String[] headers = map.get(0).keySet().toArray(new String[headerNumber]); + resultTable.insertColumns(0, headers); + + for (int rowNumber = 0; rowNumber != map.size(); rowNumber++) { + final int finalRowNumber = rowNumber; + resultTable.insertRow(finalRowNumber); + map.get(rowNumber).forEach((key, value) -> { + System.out.println(String.format("Setting the value %s to %.3f (%d)", key, value, finalRowNumber)); + + resultTable.set(key, finalRowNumber, value); + }); + } + + } + + uiService.show(resultTable); } }