@Test
 public void testCircularROIBeanConversionToCircularROI() throws Exception {
   // CircularROI
   double radius = 100;
   ROIBean rbean = new CircularROIBean();
   ((CircularROIBean) rbean).setName("circle");
   ((CircularROIBean) rbean).setStartPoint(startPoint);
   ((CircularROIBean) rbean).setType("CircularROI");
   ((CircularROIBean) rbean).setRadius(radius);
   CircularROI croi = (CircularROI) ROIBeanFactory.decapsulate(rbean);
   assertArrayEquals(startPoint, croi.getPoint(), 0);
   assertEquals(radius, croi.getRadius(), 0);
 }
Beispiel #2
0
  // Note this is a bit of a integration test not a strict unit test
  @Test
  public void testFillingACircle() throws Exception {
    double xCentre = 0;
    double yCentre = 0;
    double radius = 1;

    CircularROI roi = new CircularROI();
    roi.setPoint(xCentre, yCentre);
    roi.setRadius(radius);

    RasterModel model = new RasterModel();
    model.setxStep(1);
    model.setyStep(1);

    // Get the point list
    IPointGenerator<RasterModel, Point> gen = service.createGenerator(model, roi);
    List<Point> pointList = gen.createPoints();

    // Check the length of the lists are equal
    assertEquals(5, pointList.size());

    // Check the points are correct and the order is maintained
    // 0
    assertEquals(0, pointList.get(0).getX(), 1e-8);
    assertEquals(-1, pointList.get(0).getY(), 1e-8);
    // 1
    assertEquals(-1, pointList.get(1).getX(), 1e-8);
    assertEquals(0, pointList.get(1).getY(), 1e-8);
    // 2
    assertEquals(0, pointList.get(2).getX(), 1e-8);
    assertEquals(0, pointList.get(2).getY(), 1e-8);
    // 3
    assertEquals(1, pointList.get(3).getX(), 1e-8);
    assertEquals(0, pointList.get(3).getY(), 1e-8);
    // 4
    assertEquals(0, pointList.get(4).getX(), 1e-8);
    assertEquals(1, pointList.get(4).getY(), 1e-8);

    GeneratorUtil.testGeneratorPoints(gen);
  }
  /**
   * @param spt starting point
   * @param pt
   * @return resized ROI
   */
  @SuppressWarnings("unchecked")
  public T resize(double[] spt, double[] pt) {
    T rroi = null;

    if (!closed && handle == 4) return rroi;

    rroi = (T) roi.copy();
    pt[0] -= spt[0];
    pt[1] -= spt[1];

    switch (handle) {
      case -1: // new definition
        rroi.setPoint(spt);
        break;
      case 0: // focus/centre
        rroi.addPoint(pt);
        break;
      case 1: // periapsis
        if (rroi instanceof CircularROI) {
          if (pt[0] == 0) break;
          CircularROI lroi = (CircularROI) rroi;
          // work out perpendicular displacement
          double r = lroi.getRadius();
          r -= pt[0];
          if (r < 0) r = 0;
          lroi.setRadius(r);
        } else if (rroi instanceof OrientableROIBase) {
          // work out perpendicular displacement
          double a = rroi.getAngle();
          double d = pt[0] * Math.cos(a) + pt[1] * Math.sin(a);
          if (d == 0) break;

          if (rroi instanceof EllipticalROI) {
            EllipticalROI lroi = (EllipticalROI) rroi;
            double r = lroi.getSemiAxis(0) - d;
            if (r < 0) r = 0;
            lroi.setSemiAxis(0, r);
          } else if (rroi instanceof ParabolicROI) {
            ParabolicROI lroi = (ParabolicROI) rroi;
            double p = lroi.getFocalParameter() - d;
            if (p < 0) p = 0;
            lroi.setFocalParameter(p);
          } else if (rroi instanceof HyperbolicROI) {
            HyperbolicROI lroi = (HyperbolicROI) rroi;
            double l = lroi.getSemilatusRectum();
            double e = lroi.getEccentricity();
            double x = l / (1 + e) - d;
            e = l / x - 1;
            if (e < 1) e = 1;
            lroi.setEccentricity(e);
          }
        }
        break;
      case 2:
        if (rroi instanceof CircularROI) {
          if (pt[1] == 0) break;
          CircularROI lroi = (CircularROI) rroi;
          double r = lroi.getRadius();
          r += pt[1];
          if (r < 0) r = 0;
          lroi.setRadius(r);
        } else if (rroi instanceof OrientableROIBase) {
          // work out perpendicular displacement
          double a = rroi.getAngle();
          double d = -pt[0] * Math.sin(a) + pt[1] * Math.cos(a);
          if (d == 0) break;

          if (rroi instanceof EllipticalROI) {
            EllipticalROI lroi = (EllipticalROI) rroi;
            // work out perpendicular displacement
            double r = lroi.getSemiAxis(1) + d;
            if (r < 0) r = 0;
            lroi.setSemiAxis(1, r);
          } else if (rroi instanceof ParabolicROI) {
            ParabolicROI lroi = (ParabolicROI) rroi;
            double p = lroi.getFocalParameter() + 0.5 * d;
            if (p < 0) p = 0;
            lroi.setFocalParameter(p);
          } else if (rroi instanceof HyperbolicROI) {
            HyperbolicROI lroi = (HyperbolicROI) rroi;
            double l = lroi.getSemilatusRectum() + d;
            if (l < 0) l = 0;
            lroi.setSemilatusRectum(l);
          }
        }
        break;
      case 3:
        if (rroi instanceof CircularROI) {
          if (pt[1] == 0) break;
          CircularROI lroi = (CircularROI) rroi;
          double r = lroi.getRadius();
          r -= pt[1];
          if (r < 0) r = 0;
          lroi.setRadius(r);
        } else if (rroi instanceof OrientableROIBase) {
          // work out perpendicular displacement
          double a = rroi.getAngle();
          double d = -pt[0] * Math.sin(a) + pt[1] * Math.cos(a);
          if (d == 0) break;

          if (rroi instanceof EllipticalROI) {
            EllipticalROI lroi = (EllipticalROI) rroi;
            // work out perpendicular displacement
            double r = lroi.getSemiAxis(1) - d;
            if (r < 0) r = 0;
            lroi.setSemiAxis(1, r);
          } else if (rroi instanceof ParabolicROI) {
            ParabolicROI lroi = (ParabolicROI) rroi;
            double p = lroi.getFocalParameter() - 0.5 * d;
            if (p < 0) p = 0;
            lroi.setFocalParameter(p);
          } else if (rroi instanceof HyperbolicROI) {
            HyperbolicROI lroi = (HyperbolicROI) rroi;
            double l = lroi.getSemilatusRectum() - d;
            if (l < 0) l = 0;
            lroi.setSemilatusRectum(l);
          }
        }
        break;
      case 4:
        if (closed) {
          if (rroi instanceof CircularROI) {
            if (pt[0] == 0) break;
            CircularROI lroi = (CircularROI) rroi;
            double r = lroi.getRadius();
            r += pt[0];
            if (r < 0) r = 0;
            lroi.setRadius(r);
          } else if (rroi instanceof EllipticalROI) {
            EllipticalROI lroi = (EllipticalROI) rroi;
            // work out perpendicular displacement
            double a = lroi.getAngle();
            double d = pt[0] * Math.cos(a) + pt[1] * Math.sin(a);
            if (d == 0) break;
            double r = lroi.getSemiAxis(0) + d;
            if (r < 0) r = 0;
            lroi.setSemiAxis(0, r);
          }
        }
        break;
      default:
        break;
    }

    return rroi;
  }