Skip to content

Commit

Permalink
Merge origin/pierre into new-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
cmongis committed May 25, 2016
2 parents 6fc2c04 + 8579c58 commit e2961f1
Showing 1 changed file with 53 additions and 4 deletions.
57 changes: 53 additions & 4 deletions src/main/java/ijfx/service/overlay/OverlayStatCommandTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand All @@ -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> overlay = overlayService.getOverlays();

overlayService.addOverlays(display, overlay);

List<HashMap<String, Double>> 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);
}
}

0 comments on commit e2961f1

Please sign in to comment.