@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); }
@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(); }
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; }
private void clearListeners(IPlottingSystem plotSystem, IRegionListener listener) { if (plotSystem == null) return; Collection<IRegion> regions = plotSystem.getRegions(); if (regions != null && regions.size() > 0) { Iterator<IRegion> it = regions.iterator(); while (it.hasNext()) { IRegion region = it.next(); region.removeROIListener(this); } } plotSystem.removeRegionListener(listener); }
/** * Add a region listener * * @param plotSystem */ public void addRegionListener(IPlottingSystem plotSystem) { if (plotSystem == null) return; Collection<IRegion> regions = plotSystem.getRegions(); if (regions != null && regions.size() > 0) { Iterator<IRegion> it = regions.iterator(); while (it.hasNext()) { IRegion region = it.next(); region.addROIListener(this); } } plotSystem.addRegionListener(regionListener); }
/** Creates the widget and its controls */ public void createWidget() { regionComposite = new Composite(parent, SWT.NONE); GridData gridData = new GridData(SWT.FILL, SWT.LEFT, true, true); regionComposite.setLayout(new GridLayout(1, false)); regionComposite.setLayoutData(gridData); Collection<IRegion> regions = plottingSystem.getRegions(); if (regions.size() > 0) { IRegion region = (IRegion) regions.toArray()[0]; createRegionComposite(regionComposite, region.getRegionType()); region.addROIListener(ROIWidget.this); } else { createRegionComposite(regionComposite, RegionType.PERIMETERBOX); } }
@Override public void roiDragged(ROIEvent evt) { if (roiViewer == null) return; roiViewer.cancelEditing(); IRegion region = (IRegion) evt.getSource(); if (region == null) return; IROI roi = evt.getROI(); if (roi != null) { roiViewer.setTableValues(roi); if (nameText != null && !nameText.isDisposed()) nameText.setText(region.getName()); regionName = region.getName(); } roiChanged = true; this.region = region; }
/** Update the widget with the correct roi information */ public void update() { this.plottingSystem = PlottingFactory.getPlottingSystem(viewName); if (plottingSystem != null) { Collection<IRegion> regions = plottingSystem.getRegions(); if (regions.size() > 0) { IRegion region = (IRegion) regions.toArray()[0]; if (roiViewer == null) createRegionComposite(regionComposite, region.getRegionType()); roiViewer.setTableValues(region.getROI()); if (nameText != null) nameText.setText(region.getName()); regionName = region.getName(); this.region = region; region.addROIListener(ROIWidget.this); } } }
/** * Method to set the input of this widget given an IRegion * * @param region */ public void setEditingRegion(IRegion region) { if (region == null || roiViewer == null) return; if (region.getROI() != null) roiViewer.setTableValues(region.getROI()); if (nameText != null && !nameText.isDisposed()) nameText.setText(region.getName()); regionName = region.getName(); }