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(); Rim3dOverlayInfoConfig::HistogramData histogramData = overlayInfo->histogramData();
QVector<QwtIntervalSample> histSamples; if (histogramData.isValid())
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; QVector<QwtIntervalSample> histSamples;
histSamples.push_back(QwtIntervalSample(value, xCurr, xNext)); 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; aggrValue += value;
aggrSamples.push_back(QPointF(xCurr, aggrValue)); 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 class HistogramData
{ {
public: 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 min;
double max; double max;
@ -57,6 +57,8 @@ class Rim3dOverlayInfoConfig : public caf::PdmObject
double sum; double sum;
double weightedMean; double weightedMean;
const std::vector<size_t>* histogram; const std::vector<size_t>* histogram;
bool isValid() { return histogram && histogram->size() > 0; }
}; };
public: public:
@ -97,6 +99,9 @@ private:
void updateEclipse3DInfo(RimEclipseView * reservoirView); void updateEclipse3DInfo(RimEclipseView * reservoirView);
void updateGeoMech3DInfo(RimGeoMechView * geoMechView); void updateGeoMech3DInfo(RimGeoMechView * geoMechView);
HistogramData histogramData(RimEclipseView* eclipseView);
HistogramData histogramData(RimGeoMechView* geoMechView);
caf::PdmField<bool> active; caf::PdmField<bool> active;
caf::PdmField<bool> showAnimProgress; caf::PdmField<bool> showAnimProgress;
caf::PdmField<bool> showCaseInfo; caf::PdmField<bool> showCaseInfo;