public void generateTestSet() {

    List<ImageDisplay> displays = imageDisplayService.getImageDisplays();
    imgDatasets = new ArrayList<>(displays.size());
    List<Dataset> labeledDs = new ArrayList<>(displays.size());
    List<List<Overlay>> overlaySet = new ArrayList<>();

    displays
        .stream()
        .forEach(
            id -> {
              imgDatasets.add(imageDisplayService.getActiveDataset(id));
              overlaySet.add(overlayService.getOverlays(id));
            });

    List<List<Point2D>> seeds = seeding();
    int numProfiles = 0;
    for (int ds = 0; ds < imgDatasets.size(); ds++) {

      List<Point2D> centers = seeds.get(ds);

      ProfilesSet profiles = new DefaultProfilesSet(centers, searchRadius.getValue(), context);
      numProfiles += profiles.size();
      testData.add(profiles);
    }
    eventService.publish(new ProfileEvent(ProfileType.TEST, numProfiles));
  }
  public List<List<Point2D>> seeding() {
    // TODO seeding algorithm. Temp manual alternative

    List<List<Point2D>> seeds = new ArrayList();

    List<ImageDisplay> displays = imageDisplayService.getImageDisplays();
    imgDatasets = new ArrayList<>(displays.size());
    List<List<Overlay>> overlaySet = new ArrayList<>();

    displays
        .stream()
        .forEach(
            id -> {
              imgDatasets.add(imageDisplayService.getActiveDataset(id));
              overlaySet.add(overlayService.getOverlays(id));
            });

    for (int ds = 0; ds < imgDatasets.size(); ds++) {
      List<Point2D> currSeeds = new ArrayList();

      for (Overlay o : overlaySet.get(ds)) {
        if (o instanceof PointOverlay) {
          double[] point = ((PointOverlay) o).getPoints().get(0);
          Point2D point2D = new Point2D(point[0], point[1]);
          currSeeds.add(point2D);
        }
      }
      seeds.add(currSeeds);
    }
    return seeds;
  }
  /** Generate the different intensity profiles from drawn objects for each ImageDisplay */
  public void generateTrainingSet() {

    double maxDiameter = 0.0;

    List<ImageDisplay> displays = imageDisplayService.getImageDisplays();
    imgDatasets = new ArrayList<>(displays.size());
    List<Dataset> labeledDs = new ArrayList<>(displays.size());
    List<List<Overlay>> overlaySet = new ArrayList<>();

    displays
        .stream()
        .forEach(
            id -> {
              imgDatasets.add(imageDisplayService.getActiveDataset(id));
              overlaySet.add(overlayService.getOverlays(id));
            });

    int numProfiles = 0;
    for (int ds = 0; ds < imgDatasets.size(); ds++) {

      labeledDs.add(imagePlaneService.createEmptyPlaneDataset(imgDatasets.get(ds)));
      ArrayList<Point2D> centers = new ArrayList<>();

      for (Overlay o : overlaySet.get(ds)) {

        OverlayShapeStatistics stats = overlayStatService.getShapeStatistics(o);
        centers.add(stats.getCenterOfGravity());

        if (stats.getFeretDiameter() > maxDiameter) maxDiameter = stats.getFeretDiameter();

        overlayDrawingService.drawOverlay(
            o, OverlayDrawingService.OUTLINER, labeledDs.get(ds), COLOR);
      }
      //            uis.show(labeledDs.get(ds));
      ProfilesSet profiles = new DefaultProfilesSet(centers, (int) maxDiameter, context);
      generateConfirmationSet(profiles, labeledDs.get(ds));
      numProfiles += profiles.size();
      trainingData.add(profiles);
    }
    eventService.publish(new ProfileEvent(ProfileType.TRAIN, numProfiles));
  }
 /**
  * @param imageDisplay
  * @param firstPosition
  * @param secondPosition
  * @param imageDisplayPane
  */
 public void selectPosition(
     ImageDisplay imageDisplay,
     long[] firstPosition,
     long[] secondPosition,
     ImageDisplayPane imageDisplayPane) {
   workflowModel.setPosition(firstPosition, imageDisplay);
   imageDisplayService.getActiveDatasetView(imageDisplay).setColorMode(ColorMode.COLOR);
   Dataset datasetFirstSlide = datasetUtillsService.extractPlane(imageDisplay);
   workflowModel.setPosition(secondPosition, imageDisplay);
   Dataset datasetSecondSlide = datasetUtillsService.extractPlane(imageDisplay);
   workflowModel.extractAndMerge(
       new Dataset[] {datasetFirstSlide, datasetSecondSlide}, imageDisplayPane);
 }