Refactored RiuLineSegmnetQwtPlotCurve

Removed domain specific code
Created RigCurveDataTools
Use symbol to draw single values
This commit is contained in:
Magne Sjaastad 2015-11-06 10:08:35 +01:00
parent 3c00a8394d
commit ab3c5c029a
12 changed files with 210 additions and 146 deletions

View File

@ -84,8 +84,8 @@ set( USER_INTERFACE_FILES
UserInterface/RiuTreeViewEventFilter.h
UserInterface/RiuWellLogPlot.cpp
UserInterface/RiuWellLogPlot.h
UserInterface/RiuWellLogCurve.cpp
UserInterface/RiuWellLogCurve.h
UserInterface/RiuLineSegmentQwtPlotCurve.cpp
UserInterface/RiuLineSegmentQwtPlotCurve.h
UserInterface/RiuWellLogTrack.cpp
UserInterface/RiuWellLogTrack.h
UserInterface/RiuProjectPropertyView.h

View File

@ -1,6 +1,6 @@
#include "gtest/gtest.h"
#include "RigWellLogCurveData.h"
#include "RigCurveDataTools.h"
#include <cmath> // Needed for HUGE_VAL on Linux
@ -19,7 +19,7 @@ TEST(RimWellLogExtractionCurveImplTest, StripOffInvalidValAtEndsOfVector)
values.push_back(HUGE_VAL);
std::vector< std::pair<size_t, size_t> > valuesIntervals;
RigWellLogCurveDataTestInterface::calculateIntervalsOfValidValues(values, &valuesIntervals);
RigCurveDataTools::calculateIntervalsOfValidValues(values, &valuesIntervals);
EXPECT_EQ(1, static_cast<int>(valuesIntervals.size()));
EXPECT_EQ(2, static_cast<int>(valuesIntervals[0].first));
@ -43,7 +43,7 @@ TEST(RimWellLogExtractionCurveImplTest, StripOffHugeValAtEndsAndInteriorOfVector
values.push_back(HUGE_VAL);
std::vector< std::pair<size_t, size_t> > valuesIntervals;
RigWellLogCurveDataTestInterface::calculateIntervalsOfValidValues(values, &valuesIntervals);
RigCurveDataTools::calculateIntervalsOfValidValues(values, &valuesIntervals);
EXPECT_EQ(2, static_cast<int>(valuesIntervals.size()));
EXPECT_EQ(2, static_cast<int>(valuesIntervals[0].first));

View File

@ -255,7 +255,9 @@ void RimWellLogExtractionCurve::updatePlotData()
}
}
m_qwtPlotCurve->setCurveData(m_curveData.p());
m_qwtPlotCurve->setSamples(m_curveData->xPlotValues().data(), m_curveData->depthPlotValues().data(), static_cast<int>(m_curveData->xPlotValues().size()));
m_qwtPlotCurve->setLineSegmentStartStopIndices(m_curveData->polylineStartStopIndices());
zoomAllOwnerTrackAndPlot();
if (m_ownerQwtTrack) m_ownerQwtTrack->replot();

View File

@ -114,7 +114,8 @@ void RimWellLogFileCurve::updatePlotData()
}
}
m_qwtPlotCurve->setCurveData(m_curveData.p());
m_qwtPlotCurve->setSamples(m_curveData->xPlotValues().data(), m_curveData->depthPlotValues().data(), static_cast<int>(m_curveData->xPlotValues().size()));
m_qwtPlotCurve->setLineSegmentStartStopIndices(m_curveData->polylineStartStopIndices());
zoomAllOwnerTrackAndPlot();

View File

@ -38,6 +38,7 @@ ${CEE_CURRENT_LIST_DIR}RigEclipseNativeStatCalc.h
${CEE_CURRENT_LIST_DIR}RigEclipseMultiPropertyStatCalc.h
${CEE_CURRENT_LIST_DIR}RigWellLogCurveData.h
${CEE_CURRENT_LIST_DIR}RigTimeHistoryResultAccessor.h
${CEE_CURRENT_LIST_DIR}RigCurveDataTools.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -70,6 +71,7 @@ ${CEE_CURRENT_LIST_DIR}RigEclipseNativeStatCalc.cpp
${CEE_CURRENT_LIST_DIR}RigEclipseMultiPropertyStatCalc.cpp
${CEE_CURRENT_LIST_DIR}RigWellLogCurveData.cpp
${CEE_CURRENT_LIST_DIR}RigTimeHistoryResultAccessor.cpp
${CEE_CURRENT_LIST_DIR}RigCurveDataTools.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -0,0 +1,82 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RigCurveDataTools.h"
#include <cmath>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigCurveDataTools::calculateIntervalsOfValidValues(const std::vector<double>& values, std::vector< std::pair<size_t, size_t> >* intervals)
{
CVF_ASSERT(intervals);
int startIdx = -1;
size_t vIdx = 0;
size_t valueCount = values.size();
while (vIdx < valueCount)
{
double value = values[vIdx];
if (value == HUGE_VAL || value == -HUGE_VAL || value != value)
{
if (startIdx >= 0)
{
intervals->push_back(std::make_pair(startIdx, vIdx - 1));
startIdx = -1;
}
}
else if (startIdx < 0)
{
startIdx = (int)vIdx;
}
vIdx++;
}
if (startIdx >= 0 && startIdx < ((int)valueCount))
{
intervals->push_back(std::make_pair(startIdx, valueCount - 1));
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigCurveDataTools::computePolyLineStartStopIndices(const std::vector< std::pair<size_t, size_t> >& intervals,
std::vector< std::pair<size_t, size_t> >* fltrIntervals)
{
CVF_ASSERT(fltrIntervals);
const size_t intervalCount = intervals.size();
if (intervalCount < 1) return;
size_t index = 0;
for (size_t intIdx = 0; intIdx < intervalCount; intIdx++)
{
size_t intervalSize = intervals[intIdx].second - intervals[intIdx].first + 1;
fltrIntervals->push_back(std::make_pair(index, index + intervalSize - 1));
index += intervalSize;
}
}

View File

@ -0,0 +1,54 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfAssert.h"
#include <vector>
//==================================================================================================
///
//==================================================================================================
class RigCurveDataTools
{
public:
static void calculateIntervalsOfValidValues(const std::vector<double>& values,
std::vector< std::pair<size_t, size_t> >* intervals);
template <typename T>
static void getValuesByIntervals(const std::vector<T>& values,
const std::vector< std::pair<size_t, size_t> >& intervals,
std::vector<T>* filteredValues)
{
CVF_ASSERT(filteredValues);
for (size_t intIdx = 0; intIdx < intervals.size(); intIdx++)
{
for (size_t vIdx = intervals[intIdx].first; vIdx <= intervals[intIdx].second; vIdx++)
{
filteredValues->push_back(values[vIdx]);
}
}
}
static void computePolyLineStartStopIndices(const std::vector< std::pair<size_t, size_t> >& intervals,
std::vector< std::pair<size_t, size_t> >* filteredIntervals);
};

View File

@ -19,6 +19,8 @@
#include "RigWellLogCurveData.h"
#include "RigCurveDataTools.h"
#include "cvfMath.h"
#include "cvfAssert.h"
@ -101,7 +103,7 @@ const std::vector<double>& RigWellLogCurveData::measuredDepths() const
std::vector<double> RigWellLogCurveData::xPlotValues() const
{
std::vector<double> filteredValues;
getValuesByIntervals(m_xValues, m_intervalsOfContinousValidValues, &filteredValues);
RigCurveDataTools::getValuesByIntervals(m_xValues, m_intervalsOfContinousValidValues, &filteredValues);
return filteredValues;
}
@ -114,11 +116,11 @@ std::vector<double> RigWellLogCurveData::depthPlotValues() const
std::vector<double> filteredValues;
if (m_tvDepths.size())
{
getValuesByIntervals(m_tvDepths, m_intervalsOfContinousValidValues, &filteredValues);
RigCurveDataTools::getValuesByIntervals(m_tvDepths, m_intervalsOfContinousValidValues, &filteredValues);
}
else
{
getValuesByIntervals(m_measuredDepths, m_intervalsOfContinousValidValues, &filteredValues);
RigCurveDataTools::getValuesByIntervals(m_measuredDepths, m_intervalsOfContinousValidValues, &filteredValues);
}
return filteredValues;
@ -130,7 +132,7 @@ std::vector<double> RigWellLogCurveData::depthPlotValues() const
std::vector< std::pair<size_t, size_t> > RigWellLogCurveData::polylineStartStopIndices() const
{
std::vector< std::pair<size_t, size_t> > lineStartStopIndices;
computePolyLineStartStopIndices(m_intervalsOfContinousValidValues, &lineStartStopIndices);
RigCurveDataTools::computePolyLineStartStopIndices(m_intervalsOfContinousValidValues, &lineStartStopIndices);
return lineStartStopIndices;
}
@ -142,7 +144,7 @@ std::vector< std::pair<size_t, size_t> > RigWellLogCurveData::polylineStartStopI
void RigWellLogCurveData::calculateIntervalsOfContinousValidValues()
{
std::vector< std::pair<size_t, size_t> > intervalsOfValidValues;
calculateIntervalsOfValidValues(m_xValues, &intervalsOfValidValues);
RigCurveDataTools::calculateIntervalsOfValidValues(m_xValues, &intervalsOfValidValues);
m_intervalsOfContinousValidValues.clear();
@ -168,42 +170,6 @@ void RigWellLogCurveData::calculateIntervalsOfContinousValidValues()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigWellLogCurveData::calculateIntervalsOfValidValues(const std::vector<double>& values, std::vector< std::pair<size_t, size_t> >* intervals)
{
CVF_ASSERT(intervals);
int startIdx = -1;
size_t vIdx = 0;
size_t valueCount = values.size();
while (vIdx < valueCount)
{
double value = values[vIdx];
if (value == HUGE_VAL || value == -HUGE_VAL || value != value)
{
if (startIdx >= 0)
{
intervals->push_back(std::make_pair(startIdx, vIdx - 1));
startIdx = -1;
}
}
else if (startIdx < 0)
{
startIdx = (int)vIdx;
}
vIdx++;
}
if (startIdx >= 0 && startIdx < ((int)valueCount))
{
intervals->push_back(std::make_pair(startIdx, valueCount - 1));
}
}
//--------------------------------------------------------------------------------------------------
/// Splits the start stop interval between cells that are not close enough.
/// The depth values are expected to contain pair of depths: Depth at cell enter, and cell leave
@ -242,46 +208,6 @@ void RigWellLogCurveData::splitIntervalAtEmptySpace(const std::vector<double>& d
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigWellLogCurveData::getValuesByIntervals(const std::vector<double>& values,
const std::vector< std::pair<size_t, size_t> >& intervals,
std::vector<double>* filteredValues)
{
CVF_ASSERT(filteredValues);
for (size_t intIdx = 0; intIdx < intervals.size(); intIdx++)
{
for (size_t vIdx = intervals[intIdx].first; vIdx <= intervals[intIdx].second; vIdx++)
{
filteredValues->push_back(values[vIdx]);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigWellLogCurveData::computePolyLineStartStopIndices(const std::vector< std::pair<size_t, size_t> >& intervals,
std::vector< std::pair<size_t, size_t> >* fltrIntervals)
{
CVF_ASSERT(fltrIntervals);
const size_t intervalCount = intervals.size();
if (intervalCount < 1) return;
size_t index = 0;
for (size_t intIdx = 0; intIdx < intervalCount; intIdx++)
{
size_t intervalSize = intervals[intIdx].second - intervals[intIdx].first + 1;
fltrIntervals->push_back(std::make_pair(index, index + intervalSize - 1));
index += intervalSize;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -53,18 +53,9 @@ public:
private:
void calculateIntervalsOfContinousValidValues();
static void calculateIntervalsOfValidValues(const std::vector<double>& values,
std::vector< std::pair<size_t, size_t> >* intervals);
static void splitIntervalAtEmptySpace(const std::vector<double>& depthValues,
size_t startIdx, size_t stopIdx,
std::vector< std::pair<size_t, size_t> >* intervals);
static void getValuesByIntervals(const std::vector<double>& values,
const std::vector< std::pair<size_t, size_t> >& intervals,
std::vector<double>* filteredValues);
static void computePolyLineStartStopIndices(const std::vector< std::pair<size_t, size_t> >& intervals,
std::vector< std::pair<size_t, size_t> >* filteredIntervals);
private:
std::vector<double> m_xValues;
std::vector<double> m_measuredDepths;
@ -72,18 +63,5 @@ private:
bool m_isExtractionCurve;
std::vector< std::pair<size_t, size_t> > m_intervalsOfContinousValidValues;
friend class RigWellLogCurveDataTestInterface;
};
//==================================================================================================
///
//==================================================================================================
class RigWellLogCurveDataTestInterface
{
public:
static void calculateIntervalsOfValidValues(const std::vector<double>& values, std::vector< std::pair<size_t, size_t> >* intervals)
{
RigWellLogCurveData::calculateIntervalsOfValidValues(values, intervals);
}
};

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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();