mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Refactor PLT stacked curve code to be more general
This commit is contained in:
@@ -165,7 +165,9 @@ void RimWellFlowRateCurve::onLoadDataAndUpdate( bool updateParentPlot )
|
||||
{
|
||||
m_qwtPlotCurve->setTitle( createCurveAutoName() );
|
||||
|
||||
updateStackedPlotData();
|
||||
RimWellLogTrack* track = nullptr;
|
||||
this->firstAncestorOrThisOfTypeAsserted( track );
|
||||
track->updateStackedCurveData();
|
||||
|
||||
updateZoomInParentPlot();
|
||||
|
||||
@@ -184,9 +186,9 @@ void RimWellFlowRateCurve::updateCurveAppearance()
|
||||
{
|
||||
RimWellLogTrack* wellLogTrack;
|
||||
firstAncestorOrThisOfTypeAsserted( wellLogTrack );
|
||||
std::map<int, std::vector<RimWellFlowRateCurve*>> stackedCurveGroups = wellLogTrack->visibleStackedCurves();
|
||||
const std::vector<RimWellFlowRateCurve*>& curveGroup = stackedCurveGroups[this->m_groupId];
|
||||
isLastCurveInGroup = ( curveGroup.back() == this );
|
||||
std::map<int, std::vector<RimWellLogCurve*>> stackedCurveGroups = wellLogTrack->visibleStackedCurves();
|
||||
const std::vector<RimWellLogCurve*>& curveGroup = stackedCurveGroups[this->m_groupId];
|
||||
isLastCurveInGroup = ( curveGroup.back() == this );
|
||||
}
|
||||
|
||||
if ( isUsingConnectionNumberDepthType() )
|
||||
@@ -241,81 +243,6 @@ void RimWellFlowRateCurve::defineUiOrdering( QString uiConfigName, caf::PdmUiOrd
|
||||
uiOrdering.skipRemainingFields();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellFlowRateCurve::updateStackedPlotData()
|
||||
{
|
||||
RimWellLogPlot* wellLogPlot;
|
||||
firstAncestorOrThisOfTypeAsserted( wellLogPlot );
|
||||
|
||||
RimWellLogTrack* wellLogTrack;
|
||||
firstAncestorOrThisOfTypeAsserted( wellLogTrack );
|
||||
|
||||
RimWellLogPlot::DepthTypeEnum depthType = wellLogPlot->depthType();
|
||||
RiaDefines::DepthUnitType displayUnit = wellLogPlot->depthUnit();
|
||||
if ( depthType == RiaDefines::DepthTypeEnum::CONNECTION_NUMBER )
|
||||
{
|
||||
displayUnit = RiaDefines::DepthUnitType::UNIT_NONE;
|
||||
}
|
||||
|
||||
std::vector<double> depthValues;
|
||||
std::vector<double> stackedValues;
|
||||
std::vector<std::pair<size_t, size_t>> polyLineStartStopIndices;
|
||||
|
||||
// Z-position of curve, to draw them in correct order
|
||||
double zPos = -10000.0 + 100.0 * static_cast<double>( groupId() );
|
||||
|
||||
// Starting way behind the grid (z == 0) at -10000 giving room for 100 groups with 100 curves each before getting
|
||||
// above the grid
|
||||
{
|
||||
std::map<int, std::vector<RimWellFlowRateCurve*>> stackedCurveGroups = wellLogTrack->visibleStackedCurves();
|
||||
|
||||
std::vector<RimWellFlowRateCurve*> stackedCurves;
|
||||
|
||||
if ( stackedCurveGroups.count( groupId() ) > 0 )
|
||||
{
|
||||
stackedCurves = stackedCurveGroups[groupId()];
|
||||
}
|
||||
|
||||
std::vector<double> allDepthValues = curveData()->depths( depthType );
|
||||
if ( allDepthValues.empty() ) return;
|
||||
|
||||
std::vector<double> allStackedValues( allDepthValues.size() );
|
||||
|
||||
for ( RimWellFlowRateCurve* stCurve : stackedCurves )
|
||||
{
|
||||
std::vector<double> allValues = stCurve->curveData()->xValues();
|
||||
|
||||
for ( size_t i = 0; i < allValues.size(); ++i )
|
||||
{
|
||||
if ( allValues[i] != HUGE_VAL )
|
||||
{
|
||||
allStackedValues[i] += allValues[i];
|
||||
}
|
||||
}
|
||||
|
||||
if ( stCurve == this ) break;
|
||||
zPos -= 1.0;
|
||||
}
|
||||
|
||||
RigWellLogCurveData tempCurveData;
|
||||
tempCurveData.setValuesAndDepths( allStackedValues, allDepthValues, depthType, 0.0, displayUnit, false );
|
||||
|
||||
depthValues = tempCurveData.depthPlotValues( depthType, displayUnit );
|
||||
stackedValues = tempCurveData.xPlotValues();
|
||||
polyLineStartStopIndices = tempCurveData.polylineStartStopIndices();
|
||||
}
|
||||
|
||||
auto minmax_it = std::minmax_element( stackedValues.begin(), stackedValues.end() );
|
||||
|
||||
this->setOverrideCurveDataXRange( *( minmax_it.first ), *( minmax_it.second ) );
|
||||
m_qwtPlotCurve->setSamples( stackedValues.data(), depthValues.data(), static_cast<int>( depthValues.size() ) );
|
||||
m_qwtPlotCurve->setLineSegmentStartStopIndices( polyLineStartStopIndices );
|
||||
|
||||
m_qwtPlotCurve->setZ( zPos );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -42,7 +42,6 @@ public:
|
||||
RiaDefines::DepthTypeEnum depthType,
|
||||
const std::vector<double>& depthValues,
|
||||
const std::vector<double>& flowRates );
|
||||
void updateStackedPlotData();
|
||||
|
||||
RimEclipseResultCase* rimCase();
|
||||
int timeStep();
|
||||
|
||||
@@ -195,6 +195,22 @@ QString RimWellLogCurve::wellLogCurveIconName()
|
||||
return ":/WellLogCurve16x16.png";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellLogCurve::setOverrideCurveData( const std::vector<double>& xValues,
|
||||
const std::vector<double>& depthValues,
|
||||
const RiaCurveDataTools::CurveIntervals& curveIntervals )
|
||||
{
|
||||
auto minmax_it = std::minmax_element( xValues.begin(), xValues.end() );
|
||||
this->setOverrideCurveDataXRange( *( minmax_it.first ), *( minmax_it.second ) );
|
||||
if ( m_qwtPlotCurve )
|
||||
{
|
||||
m_qwtPlotCurve->setSamples( xValues.data(), depthValues.data(), static_cast<int>( depthValues.size() ) );
|
||||
m_qwtPlotCurve->setLineSegmentStartStopIndices( curveIntervals );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -75,6 +75,10 @@ public:
|
||||
|
||||
static QString wellLogCurveIconName();
|
||||
|
||||
void setOverrideCurveData( const std::vector<double>& xValues,
|
||||
const std::vector<double>& depthValues,
|
||||
const RiaCurveDataTools::CurveIntervals& curveIntervals );
|
||||
|
||||
protected:
|
||||
void updateZoomInParentPlot() override;
|
||||
void updateLegendsInPlot() override;
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
#include <QWheelEvent>
|
||||
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
|
||||
#define RI_LOGPLOTTRACK_MINX_DEFAULT -10.0
|
||||
#define RI_LOGPLOTTRACK_MAXX_DEFAULT 100.0
|
||||
@@ -185,6 +186,7 @@ RimWellLogTrack::RimWellLogTrack()
|
||||
m_visibleDepthRangeMax.uiCapability()->setUiHidden( true );
|
||||
m_visibleDepthRangeMax.xmlCapability()->disableIO();
|
||||
|
||||
CAF_PDM_InitField( &m_stackCurves, "StackCurves", false, "Stack Curves", "", "", "" );
|
||||
CAF_PDM_InitField( &m_isAutoScaleXEnabled, "AutoScaleX", true, "Auto Scale", "", "", "" );
|
||||
m_isAutoScaleXEnabled.uiCapability()->setUiHidden( true );
|
||||
|
||||
@@ -357,12 +359,7 @@ void RimWellLogTrack::detachAllPlotItems()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellLogTrack::calculateXZoomRange()
|
||||
{
|
||||
std::map<int, std::vector<RimWellFlowRateCurve*>> stackCurveGroups = visibleStackedCurves();
|
||||
for ( const std::pair<int, std::vector<RimWellFlowRateCurve*>>& curveGroup : stackCurveGroups )
|
||||
{
|
||||
for ( RimWellFlowRateCurve* stCurve : curveGroup.second )
|
||||
stCurve->updateStackedPlotData();
|
||||
}
|
||||
updateStackedCurveData();
|
||||
|
||||
double minValue = HUGE_VAL;
|
||||
double maxValue = -HUGE_VAL;
|
||||
@@ -2002,18 +1999,22 @@ void RimWellLogTrack::setLogarithmicScale( bool enable )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<int, std::vector<RimWellFlowRateCurve*>> RimWellLogTrack::visibleStackedCurves()
|
||||
std::map<int, std::vector<RimWellLogCurve*>> RimWellLogTrack::visibleStackedCurves()
|
||||
{
|
||||
std::map<int, std::vector<RimWellFlowRateCurve*>> stackedCurves;
|
||||
std::map<int, std::vector<RimWellLogCurve*>> stackedCurves;
|
||||
for ( RimWellLogCurve* curve : m_curves )
|
||||
{
|
||||
if ( curve && curve->isCurveVisible() )
|
||||
{
|
||||
RimWellFlowRateCurve* wfrCurve = dynamic_cast<RimWellFlowRateCurve*>( curve );
|
||||
if ( wfrCurve != nullptr )
|
||||
if ( wfrCurve != nullptr ) // Flow rate curves are always stacked
|
||||
{
|
||||
stackedCurves[wfrCurve->groupId()].push_back( wfrCurve );
|
||||
}
|
||||
else if ( m_stackCurves() )
|
||||
{
|
||||
stackedCurves[-1].push_back( curve );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2252,6 +2253,91 @@ std::vector<QString> RimWellLogTrack::formationNamesVector( RimCase* rimCase )
|
||||
return std::vector<QString>();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellLogTrack::updateStackedCurveData()
|
||||
{
|
||||
RimWellLogPlot* wellLogPlot;
|
||||
firstAncestorOrThisOfTypeAsserted( wellLogPlot );
|
||||
|
||||
RimWellLogPlot::DepthTypeEnum depthType = wellLogPlot->depthType();
|
||||
RiaDefines::DepthUnitType displayUnit = wellLogPlot->depthUnit();
|
||||
bool reverseOrder = false;
|
||||
if ( depthType == RiaDefines::DepthTypeEnum::CONNECTION_NUMBER )
|
||||
{
|
||||
displayUnit = RiaDefines::DepthUnitType::UNIT_NONE;
|
||||
reverseOrder = true;
|
||||
}
|
||||
|
||||
std::map<int, std::vector<RimWellLogCurve*>> stackedCurves = visibleStackedCurves();
|
||||
|
||||
for ( auto groupCurvePair : stackedCurves )
|
||||
{
|
||||
int groupId = groupCurvePair.first;
|
||||
const std::vector<RimWellLogCurve*>& stackedCurvesInGroup = groupCurvePair.second;
|
||||
if ( stackedCurvesInGroup.empty() ) continue;
|
||||
|
||||
// Z-position of curve, to draw them in correct order
|
||||
double zPos = -10000.0 + 100.0 * static_cast<double>( groupId );
|
||||
|
||||
// Find common depths. We retain all depths from the first curve and insert ones that aren't already added.
|
||||
std::vector<double> allDepthValues;
|
||||
|
||||
for ( auto curve : stackedCurvesInGroup )
|
||||
{
|
||||
auto depths = curve->curveData()->depths( depthType );
|
||||
if ( allDepthValues.empty() )
|
||||
{
|
||||
allDepthValues.insert( allDepthValues.end(), depths.begin(), depths.end() );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( double depth : depths )
|
||||
{
|
||||
// Finds the first larger or equal depth.
|
||||
auto it = std::lower_bound( allDepthValues.begin(),
|
||||
allDepthValues.end(),
|
||||
depth,
|
||||
[reverseOrder]( double lhs, double rhs ) {
|
||||
return reverseOrder ? rhs < lhs : lhs < rhs;
|
||||
} );
|
||||
|
||||
// Insert if there is no larger or equal depths or if the first equal or if it actually larger.
|
||||
if ( it == allDepthValues.end() || std::fabs( depth - *it ) > 1.0e-8 )
|
||||
{
|
||||
allDepthValues.insert( it, depth );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( allDepthValues.empty() ) continue;
|
||||
|
||||
std::vector<double> allStackedValues( allDepthValues.size(), 0.0 );
|
||||
for ( auto curve : stackedCurvesInGroup )
|
||||
{
|
||||
auto interpolatedCurveValues = curve->curveData()->calculateResampledCurveData( depthType, allDepthValues );
|
||||
auto xValues = interpolatedCurveValues->xValues();
|
||||
for ( size_t i = 0; i < xValues.size(); ++i )
|
||||
{
|
||||
if ( xValues[i] != HUGE_VAL )
|
||||
{
|
||||
allStackedValues[i] += xValues[i];
|
||||
}
|
||||
}
|
||||
|
||||
RigWellLogCurveData tempCurveData;
|
||||
tempCurveData.setValuesAndDepths( allStackedValues, allDepthValues, depthType, 0.0, displayUnit, false );
|
||||
auto plotDepthValues = tempCurveData.depthPlotValues( depthType, displayUnit );
|
||||
auto polyLineStartStopIndices = tempCurveData.polylineStartStopIndices();
|
||||
|
||||
curve->setOverrideCurveData( allStackedValues, plotDepthValues, polyLineStartStopIndices );
|
||||
curve->setZOrder( zPos );
|
||||
zPos -= 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -191,7 +191,7 @@ public:
|
||||
|
||||
void setLogarithmicScale( bool enable );
|
||||
|
||||
std::map<int, std::vector<RimWellFlowRateCurve*>> visibleStackedCurves();
|
||||
std::map<int, std::vector<RimWellLogCurve*>> visibleStackedCurves();
|
||||
|
||||
std::vector<RimWellLogCurve*> curves() const;
|
||||
std::vector<RimWellLogCurve*> visibleCurves() const;
|
||||
@@ -224,6 +224,7 @@ public:
|
||||
std::vector<std::pair<double, double>>* yValues );
|
||||
|
||||
static std::vector<QString> formationNamesVector( RimCase* rimCase );
|
||||
void updateStackedCurveData();
|
||||
|
||||
static void addOverburden( std::vector<QString>& namesVector, CurveSamplingPointData& curveData, double height );
|
||||
static void addUnderburden( std::vector<QString>& namesVector, CurveSamplingPointData& curveData, double height );
|
||||
@@ -304,6 +305,7 @@ private:
|
||||
caf::PdmField<double> m_visibleDepthRangeMin;
|
||||
caf::PdmField<double> m_visibleDepthRangeMax;
|
||||
|
||||
caf::PdmField<bool> m_stackCurves;
|
||||
caf::PdmField<bool> m_isAutoScaleXEnabled;
|
||||
caf::PdmField<bool> m_isLogarithmicScaleEnabled;
|
||||
caf::PdmField<RimWellLogPlot::AxisGridEnum> m_xAxisGridVisibility;
|
||||
|
||||
Reference in New Issue
Block a user