private void setStx(Stx stx) { if (stx != null) { HistogramPanelModel.HistogramConfig config = createHistogramConfig(); if (config == null) { return; } if (!model.hasStx(config)) { model.setStx(config, stx); } dataset = new XIntervalSeriesCollection(); final int[] binCounts = stx.getHistogramBins(); final RasterDataNode raster = getRaster(); final XIntervalSeries series = new XIntervalSeries(raster.getName()); final Histogram histogram = stx.getHistogram(); for (int i = 0; i < binCounts.length; i++) { final double xMin = histogram.getBinLowValue(0, i); final double xMax = i < binCounts.length - 1 ? histogram.getBinLowValue(0, i + 1) : histogram.getHighValue(0); series.add(xMin, xMin, xMax, binCounts[i]); } dataset.addSeries(series); } handleStxChange(); }
@Override public String getDataAsText() { HistogramPanelModel.HistogramConfig config = createHistogramConfig(); if (!model.hasStx(config)) { return null; } Stx stx = model.getStx(config); final int[] binVals = stx.getHistogramBins(); final int numBins = binVals.length; final double min = stx.getMinimum(); final double max = stx.getMaximum(); final StringBuilder sb = new StringBuilder(16000); sb.append("Product name:\t").append(getRaster().getProduct().getName()).append("\n"); sb.append("Dataset name:\t").append(getRaster().getName()).append("\n"); sb.append('\n'); sb.append("Histogram minimum:\t") .append(min) .append("\t") .append(getRaster().getUnit()) .append("\n"); sb.append("Histogram maximum:\t") .append(max) .append("\t") .append(getRaster().getUnit()) .append("\n"); sb.append("Histogram bin size:\t") .append( getRaster().isLog10Scaled() ? ("NA\t") : ((max - min) / numBins + "\t") + getRaster().getUnit() + "\n"); sb.append("Histogram #bins:\t").append(numBins).append("\n"); sb.append('\n'); sb.append("Bin center value"); sb.append('\t'); sb.append("Bin counts"); sb.append('\n'); for (int i = 0; i < numBins; i++) { sb.append(min + ((i + 0.5) * (max - min)) / numBins); sb.append('\t'); sb.append(binVals[i]); sb.append('\n'); } return sb.toString(); }
@Override public void done() { try { Stx stx = get(); if (stx == null) { return; } if (stx.getSampleCount() > 0) { if (autoMinMaxEnabled) { histogramComputing = true; xAxisRangeControl.adjustComponents( stx.getHistogramScaling().scale(stx.getMinimum()), stx.getHistogramScaling().scale(stx.getMaximum()), 4); histogramComputing = false; } setStx(stx); } else { SnapDialogs.showError( "Either the selected ROI is empty or no pixels have been found within the minimum and maximum values specified.\n" + "No valid histogram could be computed.\n"); handleStxChange(); } } catch (ExecutionException e) { if (histogramPlotConfig.useRoiMask) { SnapDialogs.showError( "An internal error occurred.\n" + "No valid histogram could be computed.\n" + "Possible reason: The selected ROI is empty."); } else { SnapDialogs.showError( "An internal error occurred.\n" + "No valid histogram could be computed. Reason:\n" + e.getMessage()); } handleStxChange(); } catch (InterruptedException e) { SnapDialogs.showError("The histogram computation has been interrupted."); handleStxChange(); } }