Пример #1
0
  // Note this is a bit of a integration test not a strict unit test
  @Test
  public void testFillingAMoreComplicatedBoundingRectangle() throws Exception {
    double xStart = 0.0;
    double xStop = 25.5;
    double yStart = 0.0;
    double yStop = 33.33;

    double xStep = 0.4;
    double yStep = 0.6;

    RectangularROI roi = new RectangularROI();
    roi.setPoint(Math.min(xStart, xStop), Math.min(yStart, yStop));
    roi.setLengths(Math.abs(xStop - xStart), Math.abs(yStop - yStart));

    RasterModel model = new RasterModel();
    model.setxStep(xStep);
    model.setyStep(yStep);

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

    int rows = (int) (Math.floor((xStop - xStart) / xStep) + 1);
    int cols = (int) (Math.floor((yStop - yStart) / yStep) + 1);
    // Check the list size
    assertEquals("Point list size should be correct", rows * cols, pointList.size());

    // Check some points
    assertEquals(new Point(0, xStart, 0, yStart), pointList.get(0));
    assertEquals(xStart + 3 * xStep, pointList.get(3).getX(), 1e-8);
    // TODO more

    GeneratorUtil.testGeneratorPoints(gen);
  }
Пример #2
0
 static Dataset getLabelsFromLabels(Dataset xl, RectangularROI bounds, int axisIndex) {
   try {
     int fromIndex = (int) bounds.getPoint()[axisIndex];
     int toIndex = (int) bounds.getEndPoint()[axisIndex];
     int step = toIndex > fromIndex ? 1 : -1;
     final Dataset slice =
         xl.getSlice(new int[] {fromIndex}, new int[] {toIndex}, new int[] {step});
     return slice;
   } catch (Exception ne) {
     return null;
   }
 }
 @Test
 public void testRectangularROIBeanConversionToRectangularROI() throws Exception {
   // RectangularROI
   ROIBean rbean = new RectangularROIBean();
   ((RectangularROIBean) rbean).setName("rectangle");
   ((RectangularROIBean) rbean).setStartPoint(startPoint);
   ((RectangularROIBean) rbean).setType("RectangularROI");
   ((RectangularROIBean) rbean).setLengths(lengths);
   ((RectangularROIBean) rbean).setAngle(0);
   RectangularROI rroi = (RectangularROI) ROIBeanFactory.decapsulate(rbean);
   assertArrayEquals(startPoint, rroi.getPoint(), 0);
   assertArrayEquals(lengths, rroi.getLengths(), 0);
 }
Пример #4
0
  @Override
  public DataReductionInfo export(DataReductionSlice drslice) throws Exception {

    final Collection<IRegion> regions = getPlottingSystem().getRegions();

    for (IRegion region : regions) {
      if (!isRegionTypeSupported(region.getRegionType())) continue;

      final RectangularROI bounds = (RectangularROI) region.getROI();
      if (bounds == null) continue;
      if (!region.isVisible()) continue;

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

      final Dataset slice =
          DatasetUtils.convertToDataset(
              drslice
                  .getData()
                  .getSlice(
                      new int[] {(int) bounds.getPoint()[1], (int) bounds.getPoint()[0]},
                      new int[] {(int) bounds.getEndPoint()[1], (int) bounds.getEndPoint()[0]},
                      new int[] {yInc, xInc}));
      slice.setName(region.getName().replace(' ', '_'));

      drslice.appendData(slice);
    }
    return new DataReductionInfo(Status.OK_STATUS);
  }
Пример #5
0
  @Override
  protected Collection<? extends ITrace> createProfile(
      final IImageTrace image,
      IRegion region,
      IROI rbs,
      boolean tryUpdate,
      boolean isDrag,
      IProgressMonitor monitor) {

    if (monitor.isCanceled()) return null;
    if (image == null) return null;

    if ((region.getRegionType() != RegionType.BOX)
        && (region.getRegionType() != RegionType.PERIMETERBOX)) return null;

    Dataset slice = createZoom(image, region, rbs, tryUpdate, isDrag, monitor);

    Dataset yData = slice.sum(0);
    yData.setName("Intensity");
    Dataset xData = slice.sum(1);
    xData.setName("Intensity");

    final RectangularROI bounds = (RectangularROI) (rbs == null ? region.getROI() : rbs);
    final Dataset y_indices =
        DatasetFactory.createRange(
            bounds.getPoint()[0], bounds.getPoint()[0] + bounds.getLength(0), 1, Dataset.FLOAT);
    y_indices.setName("X Location");

    topSystem.updatePlot1D(y_indices, Arrays.asList(new IDataset[] {yData}), monitor);
    topSystem.repaint();

    final Dataset x_indices =
        DatasetFactory.createRange(
            bounds.getPoint()[1] + bounds.getLength(1), bounds.getPoint()[1], -1, Dataset.FLOAT);
    x_indices.setName("Y Location");

    final Collection<ITrace> right =
        rightSystem.updatePlot1D(xData, Arrays.asList(new IDataset[] {x_indices}), monitor);
    rightSystem.repaint();

    Display.getDefault()
        .syncExec(
            new Runnable() {

              @Override
              public void run() {
                topSystem.setTitle("");
                rightSystem.setTitle("");

                ILineTrace line = (ILineTrace) right.iterator().next();
                line.setTraceColor(ColorConstants.red);
              }
            });

    return profilePlottingSystem.getTraces();
  }
Пример #6
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;
  }
  @Override
  protected OperationData process(IDataset input, IMonitor monitor) {

    RectangularROI box = model.getBox();

    Dataset in1 =
        BoxSlicerRodScanUtils.rOIBox(input, monitor, box.getIntLengths(), box.getIntPoint());

    if (g2 == null) g2 = new Polynomial2D(model.getFitPower());
    if ((int) Math.pow(model.getFitPower() + 1, 2) != g2.getNoOfParameters())
      g2 = new Polynomial2D(model.getFitPower());

    Dataset[] fittingBackground =
        BoxSlicerRodScanUtils.LeftRightTopBottomBoxes(
            input, monitor, box.getIntLengths(), box.getIntPoint(), model.getBoundaryBox());

    Dataset offset = DatasetFactory.ones(fittingBackground[2].getShape(), Dataset.FLOAT64);

    Dataset intermediateFitTest = Maths.add(offset, fittingBackground[2]);
    Dataset matrix =
        LinearLeastSquaresServicesForSXRD.polynomial2DLinearLeastSquaresMatrixGenerator(
            model.getFitPower(), fittingBackground[0], fittingBackground[1]);

    DoubleDataset test = (DoubleDataset) LinearAlgebra.solveSVD(matrix, intermediateFitTest);
    double[] params = test.getData();

    DoubleDataset in1Background =
        g2.getOutputValues0(
            params, box.getIntLengths(), model.getBoundaryBox(), model.getFitPower());

    IndexIterator it = in1Background.getIterator();

    while (it.hasNext()) {
      double v = in1Background.getElementDoubleAbs(it.index);
      if (v < 0) in1Background.setObjectAbs(it.index, 0);
    }

    Dataset pBackgroundSubtracted = Maths.subtract(in1, in1Background, null);

    pBackgroundSubtracted.setName("pBackgroundSubtracted");

    IndexIterator it1 = pBackgroundSubtracted.getIterator();

    while (it1.hasNext()) {
      double q = pBackgroundSubtracted.getElementDoubleAbs(it1.index);
      if (q < 0) pBackgroundSubtracted.setObjectAbs(it1.index, 0);
    }

    Dataset output = DatasetUtils.cast(pBackgroundSubtracted, Dataset.FLOAT64);

    output.setName("Region of Interest, polynomial background removed");

    return new OperationData(output);
  }