Ejemplo n.º 1
0
  protected Dataset createZoom(
      final IImageTrace image,
      IRegion region,
      IROI rbs,
      boolean tryUpdate,
      boolean isDrag,
      IProgressMonitor monitor) {

    if (!(region.getROI() instanceof RectangularROI)) return null;
    final RectangularROI bounds = (RectangularROI) (rbs == null ? region.getROI() : rbs);
    if (bounds == null) return null;
    if (!region.isVisible()) return null;

    if (monitor.isCanceled()) return null;

    final int yInc = bounds.getPoint()[1] < bounds.getEndPoint()[1] ? 1 : -1;
    final int xInc = bounds.getPoint()[0] < bounds.getEndPoint()[0] ? 1 : -1;

    Dataset im = DatasetUtils.convertToDataset(image.getData());
    Dataset slice = DatasetUtils.convertToDataset(ToolUtils.getClippedSlice(im, bounds));
    slice.setName(region.getName());
    // Calculate axes to have real values not size
    Dataset yLabels = null;
    Dataset xLabels = null;
    if (image.getAxes() != null && image.getAxes().size() > 0) {
      Dataset xl = DatasetUtils.convertToDataset(image.getAxes().get(0));
      if (xl != null) xLabels = ZoomTool.getLabelsFromLabels(xl, bounds, 0);
      Dataset yl = DatasetUtils.convertToDataset(image.getAxes().get(1));
      if (yl != null) yLabels = ZoomTool.getLabelsFromLabels(yl, bounds, 1);
    }

    if (yLabels == null)
      yLabels =
          DatasetFactory.createRange(
              IntegerDataset.class, bounds.getPoint()[1], bounds.getEndPoint()[1], yInc);
    if (xLabels == null)
      xLabels =
          DatasetFactory.createRange(
              IntegerDataset.class, bounds.getPoint()[0], bounds.getEndPoint()[0], xInc);

    final IImageTrace zoom_trace =
        (IImageTrace)
            profilePlottingSystem.updatePlot2D(
                slice, Arrays.asList(new IDataset[] {xLabels, yLabels}), monitor);
    registerTraces(region, Arrays.asList(new ITrace[] {zoom_trace}));
    Display.getDefault()
        .syncExec(
            new Runnable() {
              public void run() {
                zoom_trace.setPaletteData(image.getPaletteData());
              }
            });

    return slice;
  }