Statistics dialog. Fix crash when no results exist

This commit is contained in:
Bjørn Erik Jensen 2017-11-16 13:22:05 +01:00
parent c59c167bbf
commit 985388e60f
2 changed files with 38 additions and 30 deletions

View File

@ -122,40 +122,43 @@ void RicGridStatisticsDialog::setHistogramData(RimEclipseView* eclipseView)
Rim3dOverlayInfoConfig::HistogramData histogramData = overlayInfo->histogramData();
QVector<QwtIntervalSample> histSamples;
QVector<QPointF> aggrSamples;
double xStep = (histogramData.max - histogramData.min) / (*histogramData.histogram).size();
double xCurr = histogramData.min;
double aggrValue = 0.0;
for(size_t value : *histogramData.histogram)
if (histogramData.isValid())
{
double xNext = xCurr + xStep;
histSamples.push_back(QwtIntervalSample(value, xCurr, xNext));
QVector<QwtIntervalSample> histSamples;
QVector<QPointF> aggrSamples;
double xStep = (histogramData.max - histogramData.min) / (*histogramData.histogram).size();
double xCurr = histogramData.min;
double aggrValue = 0.0;
for (size_t value : *histogramData.histogram)
{
double xNext = xCurr + xStep;
histSamples.push_back(QwtIntervalSample(value, xCurr, xNext));
aggrValue += value;
aggrSamples.push_back(QPointF(xCurr, aggrValue));
aggrValue += value;
aggrSamples.push_back(QPointF(xCurr, aggrValue));
xCurr = xNext;
xCurr = xNext;
}
// Axis
m_historgramPlot->setAxisScale(QwtPlot::xBottom, histogramData.min, histogramData.max);
m_aggregatedPlot->setAxisScale(QwtPlot::xBottom, histogramData.min, histogramData.max);
// Samples
hist->setSamples(histSamples);
aggr->setSamples(aggrSamples);
hist->attach(m_historgramPlot);
aggr->attach(m_aggregatedPlot);
// Markers
setMarkers(histogramData, m_historgramPlot);
setMarkers(histogramData, m_aggregatedPlot);
}
// Axis
m_historgramPlot->setAxisScale(QwtPlot::xBottom, histogramData.min, histogramData.max);
m_aggregatedPlot->setAxisScale(QwtPlot::xBottom, histogramData.min, histogramData.max);
// Samples
hist->setSamples(histSamples);
aggr->setSamples(aggrSamples);
hist->attach(m_historgramPlot);
aggr->attach(m_aggregatedPlot);
// Markers
setMarkers(histogramData, m_historgramPlot);
setMarkers(histogramData, m_aggregatedPlot);
// Refresh plot
m_historgramPlot->replot();
m_aggregatedPlot->replot();
}
// Refresh plot
m_historgramPlot->replot();
m_aggregatedPlot->replot();
}
//--------------------------------------------------------------------------------------------------

View File

@ -47,7 +47,7 @@ class Rim3dOverlayInfoConfig : public caf::PdmObject
class HistogramData
{
public:
HistogramData() : min(HUGE_VAL), max(HUGE_VAL), p10(HUGE_VAL), p90(HUGE_VAL), mean(HUGE_VAL), weightedMean(HUGE_VAL), sum(0.0) {}
HistogramData() : min(HUGE_VAL), max(HUGE_VAL), p10(HUGE_VAL), p90(HUGE_VAL), mean(HUGE_VAL), weightedMean(HUGE_VAL), sum(0.0), histogram(nullptr) {}
double min;
double max;
@ -57,6 +57,8 @@ class Rim3dOverlayInfoConfig : public caf::PdmObject
double sum;
double weightedMean;
const std::vector<size_t>* histogram;
bool isValid() { return histogram && histogram->size() > 0; }
};
public:
@ -97,6 +99,9 @@ private:
void updateEclipse3DInfo(RimEclipseView * reservoirView);
void updateGeoMech3DInfo(RimGeoMechView * geoMechView);
HistogramData histogramData(RimEclipseView* eclipseView);
HistogramData histogramData(RimGeoMechView* geoMechView);
caf::PdmField<bool> active;
caf::PdmField<bool> showAnimProgress;
caf::PdmField<bool> showCaseInfo;