コード例 #1
0
  @Override
  public void updateFigure(final OverlayView view, final F figure) {
    final Overlay overlay = view.getData();
    final ColorRGB lineColor = overlay.getLineColor();
    if (overlay.getLineStyle() != Overlay.LineStyle.NONE) {
      figure.set(AttributeKeys.STROKE_COLOR, AWTColors.getColor(lineColor));

      // FIXME - is this next line dangerous for drawing attributes? width could
      // conceivably need to always stay 0.
      figure.set(AttributeKeys.STROKE_WIDTH, overlay.getLineWidth());
      double[] dash_pattern;
      switch (overlay.getLineStyle()) {
        case SOLID:
          dash_pattern = SOLID_LINE_STYLE;
          break;
        case DASH:
          dash_pattern = DASH_LINE_STYLE;
          break;
        case DOT:
          dash_pattern = DOT_LINE_STYLE;
          break;
        case DOT_DASH:
          dash_pattern = DOT_DASH_LINE_STYLE;
          break;
        default:
          throw new UnsupportedOperationException(
              "Unsupported line style: " + overlay.getLineStyle());
      }
      figure.set(AttributeKeys.STROKE_DASHES, dash_pattern);
    } else {
      // Render a "NONE" line style as alpha = transparent.
      figure.set(AttributeKeys.STROKE_COLOR, new Color(0, 0, 0, 0));
    }
    final ColorRGB fillColor = overlay.getFillColor();
    final int alpha = overlay.getAlpha();
    figure.set(AttributeKeys.FILL_COLOR, AWTColors.getColor(fillColor, alpha));
    switch (overlay.getLineStartArrowStyle()) {
      case ARROW:
        figure.set(AttributeKeys.START_DECORATION, new ArrowTip());
        break;
      case NONE:
        figure.set(AttributeKeys.START_DECORATION, null);
    }
    switch (overlay.getLineEndArrowStyle()) {
      case ARROW:
        figure.set(AttributeKeys.END_DECORATION, new ArrowTip());
        break;
      case NONE:
        figure.set(AttributeKeys.END_DECORATION, null);
        break;
    }
  }
コード例 #2
0
  @Override
  public void updateOverlay(final F figure, final OverlayView view) {
    final Color strokeColor = figure.get(AttributeKeys.STROKE_COLOR);
    final Overlay overlay = view.getData();
    overlay.setLineColor(AWTColors.getColorRGB(strokeColor));
    // The line style is intentionally omitted here because it is ambiguous and
    // because there is no UI for setting it by the JHotDraw UI.

    // FIXME - is this next line dangerous for drawing attributes? width could
    // conceivably be 0.
    overlay.setLineWidth(figure.get(AttributeKeys.STROKE_WIDTH));
    final Color fillColor = figure.get(AttributeKeys.FILL_COLOR);
    overlay.setFillColor(AWTColors.getColorRGB(fillColor));
    overlay.setAlpha(fillColor.getAlpha());
  }
コード例 #3
0
 @Override
 public void run() {
   if (!threshSrv.hasThreshold(input)) {
     cancel("This command requires a thresholded image.");
     return;
   }
   ThresholdOverlay thresh = threshSrv.getThreshold(input);
   PointSetIterator iter = thresh.getPointsWithin().iterator();
   if (!iter.hasNext()) {
     cancel("No pixels are within the threshold");
     return;
   }
   Dataset ds = dispSrv.getActiveDataset(input);
   final int numDims = ds.numDimensions();
   final long[] dimensions = new long[numDims];
   final long[] min = new long[numDims];
   /*
    * First pass - find minima and maxima so we can use a shrunken image in some cases.
    */
   for (int i = 0; i < numDims; i++) {
     min[i] = (long) Math.floor(thresh.realMin(i));
     dimensions[i] = (long) Math.floor(thresh.realMax(i) - thresh.realMin(i) + 1);
   }
   final ArrayImg<BitType, BitArray> arrayMask =
       new ArrayImgFactory<BitType>().createBitInstance(dimensions, 1);
   final BitType t = new BitType(arrayMask);
   arrayMask.setLinkedType(t);
   final Img<BitType> mask =
       new ImgTranslationAdapter<BitType, ArrayImg<BitType, BitArray>>(arrayMask, min);
   final RandomAccess<BitType> raMask = mask.randomAccess();
   iter.reset();
   while (iter.hasNext()) {
     long[] pos = iter.next();
     raMask.setPosition(pos);
     raMask.get().set(true);
   }
   output =
       new BinaryMaskOverlay(context, new BinaryMaskRegionOfInterest<BitType, Img<BitType>>(mask));
   output.setAlpha(alpha);
   output.setFillColor(color);
   for (int i = 0; i < numDims; i++) {
     output.setAxis(ds.getImgPlus().axis(i), i);
   }
 }