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 int getTotalWork( CheckWizardPage options, IPlottingSystem system, final IFunctionService funcService) { try { int ret = 1; if (options.is(PersistWizardConstants.ORIGINAL_DATA)) { Collection<ITrace> traces = system.getTraces(); ret += traces != null ? traces.size() : 0; } if (options.is(PersistWizardConstants.IMAGE_HIST)) { final IToolPageSystem tsystem = (IToolPageSystem) system.getAdapter(IToolPageSystem.class); final IToolPage tool = tsystem.getActiveTool(); if (tool != null && tool.getToolId().equals("org.dawb.workbench.plotting.tools.imageCompareTool")) { final Map<String, IDataset> data = (Map<String, IDataset>) tool.getToolData(); if (data != null && !data.isEmpty()) { ret += data.size(); } } } final ITrace trace = system.getTraces().iterator().next(); if (options.is(PersistWizardConstants.MASK) && trace instanceof IImageTrace) { IImageTrace image = (IImageTrace) trace; final String name = options.getString(PersistWizardConstants.MASK); if (image.getMask() != null) { ret += 1; } } final Collection<IRegion> regions = system.getRegions(); if (options.is(PersistWizardConstants.REGIONS) && regions != null && !regions.isEmpty()) { ret += regions.size(); } if (options.is(PersistWizardConstants.DIFF_META)) { if (trace != null && trace instanceof IImageTrace && trace.getData() != null) { ret += 1; } } if (options.is(PersistWizardConstants.FUNCTIONS)) { if (funcService != null) { Map<String, IFunction> functions = funcService.getFunctions(); if (functions != null) ret += functions.size(); } } return ret; } catch (Exception ne) { logger.error("Cannot estimate work, assuming 100 things to do!", ne); return 100; } }
private IDataset getToggledData(IImageTrace image, IProgressMonitor monitor) { if (image.getData() == trans) { return orig; } else { this.orig = image.getData(); Object[] oa; try { oa = filter.filter(orig, null); this.trans = (IDataset) oa[0]; return trans; } catch (Exception e) { e.printStackTrace(); return orig; } } }
public static IROI runConicPeakFit( final IProgressMonitor monitor, Display display, final IPlottingSystem plotter, IImageTrace t, IParametricROI roi, IParametricROI[] innerOuter, int nPoints) { if (roi == null) return null; final ProgressMonitorWrapper mon = new ProgressMonitorWrapper(monitor); monitor.subTask("Find POIs near initial ellipse"); Dataset image = (Dataset) t.getData(); BooleanDataset mask = (BooleanDataset) t.getMask(); PolylineROI points; monitor.subTask("Fit POIs"); points = PeakFittingEllipseFinder.findPointsOnConic(image, mask, roi, innerOuter, nPoints, mon); if (monitor.isCanceled()) return null; if (points == null) return null; if (roi instanceof EllipticalROI) { if (points.getNumberOfPoints() < 3) { throw new IllegalArgumentException("Could not find enough points to trim"); } monitor.subTask("Trim POIs"); EllipticalFitROI efroi = PowderRingsUtils.fitAndTrimOutliers(mon, points, 5, false); logger.debug("Found {}...", efroi); monitor.subTask(""); return efroi; } return points; }