Histogram: add data source for ensemble fracture statistics histograms.

This commit is contained in:
Kristian Bendiksen committed 2025-07-04 16:57:41 +02:00
1 parent 11d85583dd
commit 0da6e3ccb5
13 files changed
+272 -174

No files matched your search

@@ -8,6 +8,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RimHistogramMultiPlot.h
${CMAKE_CURRENT_LIST_DIR}/RimHistogramMultiPlotCollection.h
${CMAKE_CURRENT_LIST_DIR}/RimHistogramPlot.h
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleFractureHistogramDataSource.h
)
set(SOURCE_GROUP_SOURCE_FILES
@@ -20,6 +21,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimHistogramMultiPlot.cpp
${CMAKE_CURRENT_LIST_DIR}/RimHistogramMultiPlotCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimHistogramPlot.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleFractureHistogramDataSource.cpp
)
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
@@ -0,0 +1,185 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025 Equinor ASA
//
// 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 "RimEnsembleFractureHistogramDataSource.h"
#include "Histogram/RimHistogramPlot.h"
#include "RimEnsembleFractureStatistics.h"
#include "RimProject.h"
CAF_PDM_XML_SOURCE_INIT( RimEnsembleFractureHistogramDataSource, "EnsembleFractureHistogramDataSource" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEnsembleFractureHistogramDataSource::RimEnsembleFractureHistogramDataSource()
{
CAF_PDM_InitObject( "Ensemble Fracture Histogram Data Source" );
CAF_PDM_InitFieldNoDefault( &m_ensembleFractureStatistics, "EnsembleFractureStatistics", "Ensemble Fracture Statistics" );
m_ensembleFractureStatistics.uiCapability()->setUiTreeChildrenHidden( true );
CAF_PDM_InitFieldNoDefault( &m_property, "Property", "Property" );
CAF_PDM_InitField( &m_numBins, "NumBins", 15, "Number of Bins" );
setDefaults();
setDeletable( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEnsembleFractureHistogramDataSource::~RimEnsembleFractureHistogramDataSource()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RimEnsembleFractureHistogramDataSource::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions )
{
QList<caf::PdmOptionItemInfo> options;
if ( fieldNeedingOptions == &m_ensembleFractureStatistics )
{
std::vector<RimEnsembleFractureStatistics*> esfItems =
RimProject::current()->descendantsIncludingThisOfType<RimEnsembleFractureStatistics>();
for ( auto item : esfItems )
{
options.push_back( caf::PdmOptionItemInfo( item->name(), item ) );
}
}
return options;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFractureHistogramDataSource ::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
uiOrdering.add( &m_ensembleFractureStatistics );
uiOrdering.add( &m_property );
uiOrdering.add( &m_numBins );
uiOrdering.skipRemainingFields( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFractureHistogramDataSource::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
dataSourceChanged.send();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string RimEnsembleFractureHistogramDataSource::unitNameY() const
{
return "";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string RimEnsembleFractureHistogramDataSource::unitNameX() const
{
return "";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimHistogramDataSource::HistogramResult RimEnsembleFractureHistogramDataSource::compute( RimHistogramPlot::GraphType graphType,
RimHistogramPlot::FrequencyType frequencyType ) const
{
RimHistogramDataSource::HistogramResult result;
RigHistogramData histogramData =
RigEnsembleFractureStatisticsCalculator::createStatisticsData( m_ensembleFractureStatistics(), m_property(), m_numBins() );
if ( !histogramData.isHistogramVectorValid() ) return result;
double min = histogramData.min;
double max = histogramData.max;
result.valuesX = computeHistogramBins( min, max, m_numBins, graphType );
result.valuesY = computeHistogramFrequencies( histogramData.histogram, graphType, frequencyType );
result.p10 = histogramData.p10;
result.mean = histogramData.mean;
result.p90 = histogramData.p90;
return result;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string RimEnsembleFractureHistogramDataSource::name() const
{
if ( m_ensembleFractureStatistics() == nullptr )
{
return "Undefined";
}
QStringList nameTags;
nameTags += m_ensembleFractureStatistics()->name();
nameTags += caf::AppEnum<RigEnsembleFractureStatisticsCalculator::PropertyType>::uiText( m_property() );
return nameTags.join( ", " ).toStdString();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFractureHistogramDataSource::setEnsembleFractureStatistics( RimEnsembleFractureStatistics* statistics )
{
m_ensembleFractureStatistics = statistics;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFractureHistogramDataSource::setProperty( RigEnsembleFractureStatisticsCalculator::PropertyType property )
{
m_property = property;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFractureHistogramDataSource::setDefaults()
{
auto esfItems = RimProject::current()->descendantsIncludingThisOfType<RimEnsembleFractureStatistics>();
if ( !esfItems.empty() ) m_ensembleFractureStatistics = esfItems.front();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFractureHistogramDataSource::loadDataAndUpdate()
{
dataSourceChanged.send();
}
@@ -0,0 +1,64 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025 Equinor ASA
//
// 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 "RimHistogramDataSource.h"
#include "cafPdmField.h"
#include "cafPdmPtrField.h"
#include "RigEnsembleFractureStatisticsCalculator.h"
class RimEnsembleFractureStatistics;
//==================================================================================================
///
///
//==================================================================================================
class RimEnsembleFractureHistogramDataSource : public RimHistogramDataSource
{
CAF_PDM_HEADER_INIT;
public:
RimEnsembleFractureHistogramDataSource();
~RimEnsembleFractureHistogramDataSource() override;
void setEnsembleFractureStatistics( RimEnsembleFractureStatistics* statistics );
void setProperty( RigEnsembleFractureStatisticsCalculator::PropertyType property );
std::string unitNameX() const override;
std::string unitNameY() const override;
HistogramResult compute( RimHistogramPlot::GraphType graphType, RimHistogramPlot::FrequencyType frequencyType ) const override;
void setDefaults() override;
std::string name() const override;
void loadDataAndUpdate();
protected:
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
caf::PdmPtrField<RimEnsembleFractureStatistics*> m_ensembleFractureStatistics;
caf::PdmField<caf::AppEnum<RigEnsembleFractureStatisticsCalculator::PropertyType>> m_property;
caf::PdmField<int> m_numBins;
};