Example #1
0
  @Override
  protected void updateShape() {
    ShapeUtil.buildPathFromAnchors(getPath(), getControlPoints());

    // call super method after shape has been updated
    super.updateShape();
  }
Example #2
0
  public ROI2DPath(Path2D path) {
    super(path);

    // add path points to the control point list
    controlPoints.addAll(ShapeUtil.getAnchorsFromShape(path));

    // add listeners
    for (Anchor2D pt : controlPoints) pt.addListener(this);

    setName("Path2D");
  }
    public void computeData() {
      computing = true;
      cancelCompute = false;
      try {
        maxData = new double[sequence.getSizeC()];
        minData = new double[sequence.getSizeC()];
        drawPolygon = new Polygon[sequence.getSizeC()];

        if (paintMode == PaintMode.line) {
          Line2D line = ((ROI2DLine) guideRoi).getLine();
          dataCount = (int) line.getP1().distance(line.getP2());
        } else {
          dataCount = sequence.getSizeZ();
        }
        dataArr = new ArrayList<double[]>();

        for (int component = 0; component < sequence.getSizeC(); component++) {
          double[] data = new double[dataCount];
          dataArr.add(data);
        }

        if (paintMode == PaintMode.line) {
          Line2D line = ((ROI2DLine) guideRoi).getLine();
          dataCount = (int) line.getP1().distance(line.getP2());

          ShapeUtil.consumeShapeFromPath(
              ((ROI2DShape) guideRoi).getPathIterator(null),
              new ShapeConsumer() {
                @Override
                public boolean consume(Shape shape) {
                  if (shape instanceof Line2D) {

                    Line2D line = (Line2D) shape;
                    Point2D Lp;
                    Point2D Rp;
                    if (line.getX2() > line.getX1()) {
                      Lp = line.getP1();
                      Rp = line.getP2();
                    } else {
                      Lp = line.getP2();
                      Rp = line.getP1();
                    }

                    for (int component = 0; component < sequence.getSizeC(); component++) {
                      // create histo data
                      int distance = dataCount;

                      double vx = (Rp.getX() - Lp.getX()) / distance;
                      double vy = (Rp.getY() - Lp.getY()) / distance;

                      double[] data = dataArr.get(component);

                      double x = Lp.getX();
                      double y = Lp.getY();
                      IcyBufferedImage image = canvas.getCurrentImage();

                      if (image.isInside((int) x, (int) y)) {
                        maxData[component] =
                            Array1DUtil.getValue(
                                image.getDataXY(component),
                                image.getOffset((int) x, (int) y),
                                image.isSignedDataType());
                      } else {
                        maxData[component] = 0;
                      }
                      minData[component] = maxData[component];

                      for (int i = 0; i < dataCount; i++) {
                        if (cancelCompute) break;
                        if (image.isInside((int) x, (int) y)) {
                          data[i] =
                              Array1DUtil.getValue(
                                  image.getDataXY(component),
                                  image.getOffset((int) x, (int) y),
                                  image.isSignedDataType());
                        } else {
                          data[i] = 0;
                        }
                        if (data[i] > maxData[component]) maxData[component] = data[i];
                        if (data[i] < minData[component]) minData[component] = data[i];
                        x += vx;
                        y += vy;
                      }
                      Polygon polygon = new Polygon();
                      polygon.addPoint(0, 0);
                      for (int i = 0; i < dataCount; i++) {
                        polygon.addPoint(i, (int) (data[i] - minData[component]));
                      }
                      polygon.addPoint(dataCount, 0);
                      drawPolygon[component] = polygon;
                    }
                  }
                  return true; // continue
                }
              });

        } else {

          for (int component = 0; component < sequence.getSizeC(); component++) {
            double[] data = dataArr.get(component);

            if (paintMode == PaintMode.point) {
              Point p = guideRoi.getPosition();
              if (p.x < sequence.getSizeX() && p.y < sequence.getSizeY()) {
                maxData[component] = sequence.getData(0, 0, component, p.y, p.x);
                minData[component] = maxData[component];
                for (int i = 0; i < dataCount; i++) {
                  if (cancelCompute) break;
                  data[i] = sequence.getData(0, i, component, p.y, p.x);
                  if (data[i] > maxData[component]) maxData[component] = data[i];
                  if (data[i] < minData[component]) minData[component] = data[i];
                }
              }
            } else {
              maxData[component] = ROIUtil.getMeanIntensity(sequence, guideRoi, 0, -1, component);
              ;
              minData[component] = maxData[component];
              for (int i = 0; i < dataCount; i++) {
                if (cancelCompute) break;
                data[i] = ROIUtil.getMeanIntensity(sequence, guideRoi, i, -1, component);
                if (data[i] > maxData[component]) maxData[component] = data[i];
                if (data[i] < minData[component]) minData[component] = data[i];
              }
            }
            Polygon polygon = new Polygon();

            polygon.addPoint(0, 0);
            for (int i = 0; i < dataCount; i++)
              // pity polygon does not support this with double...
              polygon.addPoint(i, (int) (data[i] - minData[component]));
            polygon.addPoint(dataCount, 0);
            drawPolygon[component] = polygon;
          }
        }
      } catch (Exception e) {
        System.out.print(e);
      }
      computing = false;
    }