private void updateHistogramGraph(double min, double max) { xAxis.clear(); currentMaxMin.max = max; currentMaxMin.min = min; histogramFunc.setMinMax(min, max); histogramFunc.setIgnoreOutliers(true); // sanity check if there is actually a histogram live List<? extends Dataset> newHistogram = histogramFunc.value(data); Dataset histogram = newHistogram.get(0); if (histograms != null && histograms.size() > 1) { histograms.set(histograms.size() - 1, histogram); } else { histograms = new ArrayList<Dataset>(); histograms.add(histogram); } // Some logging to check on the histograms size logger.debug("number of histograms stored is {}", histograms.size()); if (histograms.size() > 10) { logger.warn( "Number of stored histograms is over expected levels, now at {}", histograms.size()); } xAxis.setValues( DatasetUtils.linSpace(min, max, Math.max(1, histogram.getSize() + 1), Dataset.FLOAT64)); histogramPlotter.setXAxisValues(xAxis, 1); generateHistogramUpdate(); updateChannelGraphs(); histogramPlotter.refresh(true); }
public void setGraphLines(boolean checked) { if (histogramPlotter != null) { Plot1DGraphTable table = histogramPlotter.getColourTable(); for (int i = 0; i < 4; i++) table.getLegendEntry(i).setVisible(checked); } histogramPlotter.updateAllAppearance(); histogramPlotter.refresh(false); }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { String viewID = event.getParameter("uk.ac.diamond.scisoft.analysis.command.sourceView"); if (viewID != null) { final AbstractPlotView apv = (AbstractPlotView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(viewID); DataSetPlotter plotter = apv.getPlotter(); if (plotter != null) { plotter.setYAxisScaling(ScaleType.LN); } return Boolean.TRUE; } return Boolean.FALSE; }
@Override public void dispose() { // store current settings back into preferences IPreferenceStore preferenceStore = AnalysisRCPActivator.getDefault().getPreferenceStore(); String pName = getPartName(); Integer setting = colourSettings.get(pName); if (setting != null) preferenceStore.setValue( pName + "." + PreferenceConstants.PLOT_VIEW_PLOT2D_COLOURMAP, setting); preferenceStore.setValue( pName + "." + PreferenceConstants.PLOT_VIEW_PLOT2D_SCALING, (useLog ? 1 : 0)); deleteIObservers(); if (histogramPlotter != null) histogramPlotter.cleanUp(); data = null; if (histogramUI != null) { histogramUI.deactivate(false); histogramUI.dispose(); } if (!cmbAlpha.isDisposed()) cmbAlpha.removeSelectionListener(this); if (!cmbRedColour.isDisposed()) cmbRedColour.removeSelectionListener(this); if (!cmbGreenColour.isDisposed()) cmbGreenColour.removeSelectionListener(this); if (!cmbBlueColour.isDisposed()) cmbBlueColour.removeSelectionListener(this); if (!btnGreenInverse.isDisposed()) btnGreenInverse.removeSelectionListener(this); if (!btnBlueInverse.isDisposed()) btnBlueInverse.removeSelectionListener(this); if (!btnAlphaInverse.isDisposed()) btnAlphaInverse.removeSelectionListener(this); if (!btnRedInverse.isDisposed()) btnRedInverse.removeSelectionListener(this); super.dispose(); }
private void autoRangeHistogram() { histogramPlotter.clearZoomHistory(); double[] m; if (autoContrast && data.getRank() == 2) { try { final int[] shape = data.getShape(); if (shape[0] > 512 && shape[1] > 512) { int yReduce = (int) Math.ceil(shape[0] / 512.0); int xReduce = (int) Math.ceil(shape[1] / 512.0); Downsample sample = new Downsample(DownsampleMode.MAXIMUM, xReduce, yReduce); m = Stats.quantile( (Dataset) sample.value(data).get(0), getPreferenceAutoContrastLo(), getPreferenceAutoContrastHi()); } else m = Stats.quantile(data, getPreferenceAutoContrastLo(), getPreferenceAutoContrastHi()); } catch (Exception e) { m = new double[] {data.min().doubleValue(), data.max().doubleValue()}; } } else { m = new double[] {data.min().doubleValue(), data.max().doubleValue()}; } if (Double.compare(m[1], m[0]) <= 0) m[1] = m[0] + PreferenceConstants.MINIMUM_CONTRAST_DELTA / 100.0; currentMaxMin.max = m[1]; currentMaxMin.min = m[0]; }
protected void buildGradientImage() { GlobalColourMaps.mappingFunctions.get(0); AbstractMapFunction redFunc = GlobalColourMaps.mappingFunctions.get(cmbRedColour.getSelectionIndex()); AbstractMapFunction greenFunc = GlobalColourMaps.mappingFunctions.get(cmbGreenColour.getSelectionIndex()); AbstractMapFunction blueFunc = GlobalColourMaps.mappingFunctions.get(cmbBlueColour.getSelectionIndex()); AbstractMapFunction alphaFunc = GlobalColourMaps.mappingFunctions.get(cmbAlpha.getSelectionIndex()); boolean negRed = btnRedInverse.getSelection(); boolean negGreen = btnGreenInverse.getSelection(); boolean negBlue = btnBlueInverse.getSelection(); boolean negAlpha = btnAlphaInverse.getSelection(); histogramPlotter.applyColourCast( redFunc, greenFunc, blueFunc, alphaFunc, negRed, negGreen, negBlue, negAlpha, 0, 256); histogramPlotter.refresh(false); }
public void setScaling(ScaleType newScaling) { useLog = (newScaling != ScaleType.LINEAR); histogramPlotter.setYAxisScaling(newScaling); }
protected void updateChannelGraphs() { if (histograms != null && histograms.size() > 1) { // remove red channel graph histograms.remove(0); // remove green channel graph histograms.remove(0); // remove blue channel graph histograms.remove(0); // remove alpha channel graph histograms.remove(0); } AbstractMapFunction redFunc = GlobalColourMaps.mappingFunctions.get(curRedSelect); AbstractMapFunction greenFunc = GlobalColourMaps.mappingFunctions.get(curGreenSelect); AbstractMapFunction blueFunc = GlobalColourMaps.mappingFunctions.get(curBlueSelect); AbstractMapFunction alphaFunc = GlobalColourMaps.mappingFunctions.get(curAlphaSelect); double maxValue = histograms.get(0).max().doubleValue(); int currentSize = histograms.get(0).getSize(); DoubleDataset redChannel = new DoubleDataset(currentSize); DoubleDataset greenChannel = new DoubleDataset(currentSize); DoubleDataset blueChannel = new DoubleDataset(currentSize); DoubleDataset alphaChannel = new DoubleDataset(currentSize); for (int i = 0; i < currentSize; i++) { double value = i / (double) currentSize; double redvalue = redFunc.getPoint(value); if (curRedInverse) redvalue = 1.0 - redvalue; redvalue *= maxValue; double greenvalue = greenFunc.getPoint(value); if (curGreenInverse) greenvalue = 1.0 - greenvalue; greenvalue *= maxValue; double bluevalue = blueFunc.getPoint(value); if (curBlueInverse) bluevalue = 1.0 - bluevalue; bluevalue *= maxValue; double alphavalue = alphaFunc.getPoint(value); if (curAlphaInverse) alphavalue = 1.0 - alphavalue; alphavalue *= maxValue; redChannel.set(Math.max(redvalue, 0.0), i); greenChannel.set(Math.max(greenvalue, 0.0), i); blueChannel.set(Math.max(bluevalue, 0.0), i); alphaChannel.set(Math.max(alphavalue, 0.0), i); } histograms.add(0, alphaChannel); histograms.add(0, blueChannel); histograms.add(0, greenChannel); histograms.add(0, redChannel); // Some logging to check on the histograms size logger.debug("number of histograms stored is {}", histograms.size()); if (histograms.size() > 10) { logger.warn( "Number of stored histograms is over expected levels, now at {}", histograms.size()); } try { histogramPlotter.replaceAllPlots(histograms); } catch (PlotException e) { e.printStackTrace(); } }
@Override public void widgetSelected(SelectionEvent e) { if (e.getSource().equals(cmbRedColour) || e.getSource().equals(cmbGreenColour) || e.getSource().equals(cmbBlueColour) || e.getSource().equals(cmbAlpha) || e.getSource().equals(btnRedInverse) || e.getSource().equals(btnGreenInverse) || e.getSource().equals(btnBlueInverse) || e.getSource().equals(btnAlphaInverse)) { curAlphaSelect = cmbAlpha.getSelectionIndex(); curRedSelect = cmbRedColour.getSelectionIndex(); curGreenSelect = cmbGreenColour.getSelectionIndex(); curBlueSelect = cmbBlueColour.getSelectionIndex(); curAlphaInverse = btnAlphaInverse.getSelection(); curRedInverse = btnRedInverse.getSelection(); curGreenInverse = btnGreenInverse.getSelection(); curBlueInverse = btnBlueInverse.getSelection(); if (hasData()) { if (e.getSource().equals(cmbRedColour)) handleChange(0); else if (e.getSource().equals(cmbGreenColour)) handleChange(1); else if (e.getSource().equals(cmbBlueColour)) handleChange(2); else if (e.getSource().equals(cmbAlpha)) handleChange(3); updateChannelGraphs(); generateHistogramUpdate(); } if (e.getSource().equals(cmbGreenColour) || e.getSource().equals(cmbRedColour) || e.getSource().equals(btnRedInverse) || e.getSource().equals(btnGreenInverse) || e.getSource().equals(btnBlueInverse) || e.getSource().equals(btnAlphaInverse)) histogramPlotter.refresh(true); buildGradientImage(); } else if (e.getSource().equals(cmbColourMap)) { colourSettings.put(getPartName(), cmbColourMap.getSelectionIndex()); buildSelection(); handleChange(0); handleChange(1); handleChange(2); if (hasData()) { updateChannelGraphs(); generateHistogramUpdate(); } histogramPlotter.refresh(true); buildGradientImage(); if (cmbColourMap.getItem(cmbColourMap.getSelectionIndex()).equals("Mark's special")) { spnMinValue.setSelection((int) (specialMinThreshold * 100)); spnMaxValue.setSelection((int) (specialMaxThreshold * 100)); threshPanel.setVisible(true); ((GridData) threshPanel.getLayoutData()).exclude = false; } else { threshPanel.setVisible(false); ((GridData) threshPanel.getLayoutData()).exclude = true; } container.layout(); } else if (e.getSource().equals(spnMinValue) || e.getSource().equals(spnMaxValue)) { SpecialExposureFunction redFunc = (SpecialExposureFunction) GlobalColourMaps.mappingFunctions.get(cmbRedColour.getSelectionIndex()); SpecialExposureFunction greenFunc = (SpecialExposureFunction) GlobalColourMaps.mappingFunctions.get(cmbGreenColour.getSelectionIndex()); SpecialExposureFunction blueFunc = (SpecialExposureFunction) GlobalColourMaps.mappingFunctions.get(cmbBlueColour.getSelectionIndex()); redFunc.setThresholds(spnMinValue.getSelection() / 100.0, spnMaxValue.getSelection() / 100.0); greenFunc.setThresholds( spnMinValue.getSelection() / 100.0, spnMaxValue.getSelection() / 100.0); blueFunc.setThresholds( spnMinValue.getSelection() / 100.0, spnMaxValue.getSelection() / 100.0); specialMaxThreshold = spnMaxValue.getSelection() / 100.0; specialMinThreshold = spnMinValue.getSelection() / 100.0; updateChannelGraphs(); generateHistogramUpdate(); histogramPlotter.refresh(true); } else if (e.getSource().equals(spnRangeStart.getControl()) || e.getSource().equals(spnRangeStop.getControl())) { final double min = spnRangeStart.getDouble(); final double max = spnRangeStop.getDouble(); updateHistogramGraph(min, max); } else if (e.getSource().equals(sldMinValue) || e.getSource().equals(sldMaxValue)) { final double min = spnRangeStart.getMinimum() + spnRangeStart.getRange() * (sldMinValue.getSelection() / (double) sldMinValue.getMaximum()); final double max = spnRangeStart.getMinimum() + spnRangeStart.getRange() * (sldMaxValue.getSelection() / (double) sldMaxValue.getMaximum()); spnRangeStart.setDouble(min); spnRangeStop.setDouble(max); if (hasData()) updateHistogramGraph(min, max); } else if (e.getSource().equals(btnExpertMode)) { expertGroup.setVisible(btnExpertMode.getSelection()); ((GridData) expertGroup.getLayoutData()).exclude = !btnExpertMode.getSelection(); container.layout(); } }
@Override public void createPartControl(Composite parent) { this.parent = parent; container = new Composite(parent, SWT.NONE); container.setLayout(new GridLayout(1, false)); final Composite top = new Composite(container, SWT.NONE); top.setLayout(new GridLayout(3, false)); top.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); final Label scheme = new Label(top, SWT.NONE); scheme.setText("Colour Scheme"); cmbColourMap = new CCombo(top, SWT.BORDER | SWT.READ_ONLY); cmbColourMap.setToolTipText("Change the color scheme."); cmbColourMap.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); btnExpertMode = new Button(top, SWT.CHECK); btnExpertMode.setText("Expert"); btnExpertMode.setToolTipText("Enable expert mode for customising colour channels"); btnExpertMode.addSelectionListener(this); advancedComp = new Composite(container, SWT.NONE); // controlGroup.setText("RGB Settings"); // Looks a bit busy with this label advancedComp.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); advancedComp.setLayout(new GridLayout(3, false)); expertGroup = new Group(advancedComp, SWT.NONE); expertGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1)); expertGroup.setLayout(new GridLayout(3, false)); { Label lblRed = new Label(expertGroup, SWT.NONE); lblRed.setText("Red"); cmbRedColour = new CCombo(expertGroup, SWT.BORDER | SWT.READ_ONLY); btnRedInverse = new Button(expertGroup, SWT.CHECK); btnRedInverse.setText("Inverse"); btnRedInverse.addSelectionListener(this); Label lblGreen = new Label(expertGroup, SWT.NONE); lblGreen.setText("Green"); cmbGreenColour = new CCombo(expertGroup, SWT.BORDER | SWT.READ_ONLY); btnGreenInverse = new Button(expertGroup, SWT.CHECK); btnGreenInverse.setText("Inverse"); btnGreenInverse.addSelectionListener(this); Label lblBlue = new Label(expertGroup, SWT.NONE); lblBlue.setText("Blue"); cmbBlueColour = new CCombo(expertGroup, SWT.BORDER | SWT.READ_ONLY); btnBlueInverse = new Button(expertGroup, SWT.CHECK); btnBlueInverse.setText("Inverse"); btnBlueInverse.addSelectionListener(this); Label lblAlpha = new Label(expertGroup, SWT.NONE); lblAlpha.setText("Alpha"); cmbAlpha = new CCombo(expertGroup, SWT.BORDER | SWT.READ_ONLY); btnAlphaInverse = new Button(expertGroup, SWT.CHECK); btnAlphaInverse.setText("Inverse"); btnAlphaInverse.addSelectionListener(this); } expertGroup.setVisible(getPreferenceColourMapExpertMode()); ((GridData) expertGroup.getLayoutData()).exclude = !getPreferenceColourMapExpertMode(); threshPanel = new Group(advancedComp, SWT.NONE); threshPanel.setText("Mark's special threshhold"); // Looks a bit busy with this label threshPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); threshPanel.setLayout(new GridLayout(2, false)); { Label lblMinValue = new Label(threshPanel, SWT.NONE); lblMinValue.setText("Min threshold"); spnMinValue = new Spinner(threshPanel, SWT.BORDER); spnMinValue.setMinimum(0); spnMinValue.setMaximum(100); spnMinValue.addSelectionListener(this); Label lblMaxValue = new Label(threshPanel, SWT.NONE); lblMaxValue.setText("Max threshold"); spnMaxValue = new Spinner(threshPanel, SWT.BORDER); spnMaxValue.setMinimum(0); spnMaxValue.setMaximum(100); spnMaxValue.addSelectionListener(this); } threshPanel.setVisible(false); ((GridData) threshPanel.getLayoutData()).exclude = true; rangePanel = new Group(container, SWT.NONE); rangePanel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); rangePanel.setLayout(new GridLayout(3, false)); rangePanel.setText("Histogram range"); { Label lblStartValue = new Label(rangePanel, SWT.NONE); lblStartValue.setText("Minimum"); spnRangeStart = new FloatSpinner(rangePanel, SWT.BORDER); GridData gridData = new GridData(SWT.NONE, SWT.NONE, true, false); spnRangeStart.setLayoutData(gridData); spnRangeStart.addSelectionListener(this); sldMinValue = new Slider(rangePanel, SWT.BORDER); gridData = new GridData(SWT.FILL, SWT.NONE, true, false); gridData.minimumWidth = 90; sldMinValue.setLayoutData(gridData); sldMinValue.addSelectionListener(this); sldMinValue.setMinimum(0); sldMinValue.setMaximum(SLIDERSECTIONS); sldMinValue.setIncrement(1); Label lblStopValue = new Label(rangePanel, SWT.NONE); lblStopValue.setText("Maximum"); gridData = new GridData(SWT.NONE, SWT.NONE, true, false); spnRangeStop = new FloatSpinner(rangePanel, SWT.BORDER); spnRangeStop.setLayoutData(gridData); spnRangeStop.addSelectionListener(this); spnRangeStart.setEnabled(false); spnRangeStop.setEnabled(false); sldMaxValue = new Slider(rangePanel, SWT.BORDER); gridData = new GridData(SWT.FILL, SWT.NONE, true, false); gridData.minimumWidth = 90; sldMaxValue.setLayoutData(gridData); sldMaxValue.addSelectionListener(this); sldMaxValue.setMinimum(0); sldMaxValue.setMaximum(SLIDERSECTIONS); sldMaxValue.setIncrement(1); spnRangeStart.setEnabled(false); spnRangeStop.setEnabled(false); sldMinValue.setEnabled(false); sldMaxValue.setEnabled(false); } { composite = new Composite(container, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); composite.setLayout(new FillLayout()); histogramPlotter = new DataSetPlotter(PlottingMode.BARCHART, composite, false); histogramPlotter.setXAxisLabel("Intensity Value"); histogramPlotter.setYAxisLabel("Count"); histogramPlotter.setAxisModes(AxisMode.CUSTOM, AxisMode.LINEAR, AxisMode.LINEAR); histogramPlotter.setXTickLabelFormat(TickFormatting.plainMode); histogramPlotter.setXAxisValues(xAxis, 1); Plot1DGraphTable colourTable = histogramPlotter.getColourTable(); Plot1DAppearance plotApp = new Plot1DAppearance(Color.RED, Plot1DStyles.SOLID, ""); colourTable.addEntryOnLegend(plotApp); plotApp = new Plot1DAppearance(Color.GREEN, Plot1DStyles.SOLID, ""); colourTable.addEntryOnLegend(plotApp); plotApp = new Plot1DAppearance(Color.BLUE, Plot1DStyles.SOLID, ""); colourTable.addEntryOnLegend(plotApp); plotApp = new Plot1DAppearance(Color.ORANGE, Plot1DStyles.SOLID, ""); colourTable.addEntryOnLegend(plotApp); } cmbColourMap.addSelectionListener(this); cmbRedColour.addSelectionListener(this); cmbGreenColour.addSelectionListener(this); cmbBlueColour.addSelectionListener(this); cmbAlpha.addSelectionListener(this); buildToolbar(); GlobalColourMaps.InitializeColourMaps(); fillupColourComboBoxes(); fillupColourMapBox(); buildGradientImage(); }
protected void buildToolbar() { IActionBars toolBar = getViewSite().getActionBars(); histogramUI = new HistogramUI(this, toolBar, histogramPlotter); histogramUI.addIObserver(this); histogramPlotter.registerUI(histogramUI); }