mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Refactored RiuLineSegmnetQwtPlotCurve
Removed domain specific code Created RigCurveDataTools Use symbol to draw single values
This commit is contained in:
@@ -19,13 +19,14 @@
|
||||
|
||||
#include "RiuLineSegmentQwtPlotCurve.h"
|
||||
|
||||
#include "RigWellLogCurveData.h"
|
||||
#include "qwt_symbol.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuLineSegmentQwtPlotCurve::RiuLineSegmentQwtPlotCurve()
|
||||
RiuLineSegmentQwtPlotCurve::RiuLineSegmentQwtPlotCurve(const QString &title)
|
||||
: QwtPlotCurve(title)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -48,28 +49,32 @@ void RiuLineSegmentQwtPlotCurve::drawCurve(QPainter* p, int style,
|
||||
{
|
||||
for (size_t intIdx = 0; intIdx < intervalCount; intIdx++)
|
||||
{
|
||||
QwtPlotCurve::drawCurve(p, style, xMap, yMap, canvasRect, (int) m_polyLineStartStopIndices[intIdx].first, (int) m_polyLineStartStopIndices[intIdx].second);
|
||||
if (m_polyLineStartStopIndices[intIdx].first == m_polyLineStartStopIndices[intIdx].second)
|
||||
{
|
||||
// Use a symbol to draw a single value, as a single value will not be visible
|
||||
// when using QwtPlotCurve::drawCurve without symbols activated
|
||||
|
||||
QwtSymbol symbol(QwtSymbol::XCross);
|
||||
symbol.setSize(10, 10);
|
||||
|
||||
QwtPlotCurve::drawSymbols(p, symbol, xMap, yMap, canvasRect, (int) m_polyLineStartStopIndices[intIdx].first, (int) m_polyLineStartStopIndices[intIdx].second);
|
||||
}
|
||||
else
|
||||
{
|
||||
QwtPlotCurve::drawCurve(p, style, xMap, yMap, canvasRect, (int) m_polyLineStartStopIndices[intIdx].first, (int) m_polyLineStartStopIndices[intIdx].second);
|
||||
}
|
||||
}
|
||||
}
|
||||
else QwtPlotCurve::drawCurve(p, style, xMap, yMap, canvasRect, from, to);
|
||||
else
|
||||
{
|
||||
QwtPlotCurve::drawCurve(p, style, xMap, yMap, canvasRect, from, to);
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuLineSegmentQwtPlotCurve::setCurveData(const RigWellLogCurveData* curveData)
|
||||
void RiuLineSegmentQwtPlotCurve::setLineSegmentStartStopIndices(const std::vector< std::pair<size_t, size_t> >& lineSegmentStartStopIndices)
|
||||
{
|
||||
CVF_ASSERT(curveData);
|
||||
|
||||
setCurveData(curveData->xPlotValues(), curveData->depthPlotValues(), curveData->polylineStartStopIndices());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuLineSegmentQwtPlotCurve::setCurveData(const std::vector<double>& xValues, const std::vector<double>& yValues, const std::vector< std::pair<size_t, size_t> >& lineSegmentStartStopIndices)
|
||||
{
|
||||
setSamples(xValues.data(), yValues.data(), static_cast<int>(xValues.size()));
|
||||
|
||||
m_polyLineStartStopIndices = lineSegmentStartStopIndices;
|
||||
}
|
||||
|
||||
@@ -21,15 +21,12 @@
|
||||
|
||||
#include "qwt_plot_curve.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class RigWellLogCurveData;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// The PlotCurve class is able to draw a curve using line segments. If inf data is present
|
||||
// in the curve data, Qwt is not able to draw a nice curve. This class assumes that inf data is removed,
|
||||
// and segments to be draw are indicated by start/stop indices into curve data.
|
||||
// If infinite data is present in the curve data, Qwt is not able to draw a nice curve.
|
||||
// This class assumes that inf data is removed, and segments to be draw are indicated by start/stop indices into curve data.
|
||||
//
|
||||
// Single values in the curve are drawn using a CrossX symbol
|
||||
//
|
||||
// Here you can see the curve segments visualized. Curve segments are drawn between vector indices.
|
||||
//
|
||||
@@ -37,21 +34,20 @@ class RigWellLogCurveData;
|
||||
// 5 - 7
|
||||
// 9 -10
|
||||
//
|
||||
// * *
|
||||
// / ^
|
||||
// / / \
|
||||
// Curve * * * *---*
|
||||
// Curve / / \ ----- X
|
||||
//
|
||||
// Values 1.0|2.0|inf|inf|inf|1.0|2.0|1.0|inf|1.0|1.0
|
||||
// Vec index 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
|
||||
// Values 1.0|2.0|inf|inf|inf|1.0|2.0|1.0|inf|1.0|1.0|inf|1.0|inf
|
||||
// Vec index 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13
|
||||
//==================================================================================================
|
||||
class RiuLineSegmentQwtPlotCurve : public QwtPlotCurve
|
||||
{
|
||||
public:
|
||||
RiuLineSegmentQwtPlotCurve();
|
||||
explicit RiuLineSegmentQwtPlotCurve(const QString &title = QString::null);
|
||||
virtual ~RiuLineSegmentQwtPlotCurve();
|
||||
|
||||
void setCurveData(const RigWellLogCurveData* curveData);
|
||||
void setCurveData(const std::vector<double>& xValues, const std::vector<double>& yValues, const std::vector< std::pair<size_t, size_t> >& lineSegmentStartStopIndices);
|
||||
void setLineSegmentStartStopIndices(const std::vector< std::pair<size_t, size_t> >& lineSegmentStartStopIndices);
|
||||
|
||||
protected:
|
||||
virtual void drawCurve(QPainter* p, int style,
|
||||
@@ -59,5 +55,5 @@ protected:
|
||||
const QRectF& canvasRect, int from, int to) const;
|
||||
|
||||
private:
|
||||
std::vector< std::pair<size_t, size_t> > m_polyLineStartStopIndices;
|
||||
std::vector< std::pair<size_t, size_t> > m_polyLineStartStopIndices;
|
||||
};
|
||||
|
||||
@@ -19,8 +19,12 @@
|
||||
|
||||
#include "RiuTimeHistoryQwtPlot.h"
|
||||
|
||||
#include "RigCurveDataTools.h"
|
||||
|
||||
#include "WellLogCommands/RicWellLogPlotCurveFeatureImpl.h"
|
||||
|
||||
#include "RiuLineSegmentQwtPlotCurve.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
#include "cvfColor3.h"
|
||||
|
||||
@@ -31,6 +35,7 @@
|
||||
#include "qwt_date_scale_draw.h"
|
||||
#include "qwt_date_scale_engine.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -55,16 +60,29 @@ void RiuTimeHistoryQwtPlot::addCurve(const QString& curveName, const std::vector
|
||||
{
|
||||
CVF_ASSERT(dateTimes.size() == timeHistoryValues.size());
|
||||
|
||||
QwtPlotCurve* plotCurve = new QwtPlotCurve("Curve 1");
|
||||
std::vector< std::pair<size_t, size_t> > intervalsOfValidValues;
|
||||
RigCurveDataTools::calculateIntervalsOfValidValues(timeHistoryValues, &intervalsOfValidValues);
|
||||
|
||||
std::vector<double> filteredTimeHistoryValues;
|
||||
RigCurveDataTools::getValuesByIntervals(timeHistoryValues, intervalsOfValidValues, &filteredTimeHistoryValues);
|
||||
|
||||
std::vector<QDateTime> filteredDateTimes;
|
||||
RigCurveDataTools::getValuesByIntervals(dateTimes, intervalsOfValidValues, &filteredDateTimes);
|
||||
|
||||
std::vector< std::pair<size_t, size_t> > filteredIntervals;
|
||||
RigCurveDataTools::computePolyLineStartStopIndices(intervalsOfValidValues, &filteredIntervals);
|
||||
|
||||
RiuLineSegmentQwtPlotCurve* plotCurve = new RiuLineSegmentQwtPlotCurve("Curve 1");
|
||||
|
||||
QPolygonF points;
|
||||
for (int i = 0; i < dateTimes.size(); i++)
|
||||
for (int i = 0; i < filteredDateTimes.size(); i++)
|
||||
{
|
||||
double milliSecSinceEpoch = QwtDate::toDouble(dateTimes[i]);
|
||||
points << QPointF(milliSecSinceEpoch, timeHistoryValues[i]);
|
||||
double milliSecSinceEpoch = QwtDate::toDouble(filteredDateTimes[i]);
|
||||
points << QPointF(milliSecSinceEpoch, filteredTimeHistoryValues[i]);
|
||||
}
|
||||
|
||||
plotCurve->setSamples(points);
|
||||
plotCurve->setLineSegmentStartStopIndices(filteredIntervals);
|
||||
plotCurve->setTitle(curveName);
|
||||
|
||||
cvf::Color3f curveColor = RicWellLogPlotCurveFeatureImpl::curveColorFromTable();
|
||||
|
||||
Reference in New Issue
Block a user