2018-11-09 02:04:40 -06:00
|
|
|
#include "RimContourMapProjection.h"
|
2018-10-16 02:53:30 -05:00
|
|
|
|
2018-11-01 09:21:35 -05:00
|
|
|
#include "RiaWeightedGeometricMeanCalculator.h"
|
|
|
|
#include "RiaWeightedHarmonicMeanCalculator.h"
|
2018-10-17 06:26:15 -05:00
|
|
|
#include "RiaWeightedMeanCalculator.h"
|
|
|
|
|
2018-10-16 02:53:30 -05:00
|
|
|
#include "RigActiveCellInfo.h"
|
2018-11-05 07:31:07 -06:00
|
|
|
#include "RigCaseCellResultsData.h"
|
2018-11-01 07:21:13 -05:00
|
|
|
#include "RigCell.h"
|
2018-11-06 06:14:13 -06:00
|
|
|
#include "RigCellGeometryTools.h"
|
2018-10-16 02:53:30 -05:00
|
|
|
#include "RigEclipseCaseData.h"
|
2018-10-17 06:26:15 -05:00
|
|
|
#include "RigHexIntersectionTools.h"
|
2018-10-16 02:53:30 -05:00
|
|
|
#include "RigMainGrid.h"
|
|
|
|
#include "RigResultAccessor.h"
|
|
|
|
#include "RigResultAccessorFactory.h"
|
|
|
|
|
2018-10-17 06:26:15 -05:00
|
|
|
#include "RivReservoirViewPartMgr.h"
|
|
|
|
|
2018-10-30 05:43:50 -05:00
|
|
|
#include "RimCellRangeFilterCollection.h"
|
2018-11-14 05:38:20 -06:00
|
|
|
#include "RimContourMapView.h"
|
2018-10-16 02:53:30 -05:00
|
|
|
#include "RimEclipseCellColors.h"
|
|
|
|
#include "RimEclipseView.h"
|
|
|
|
#include "RimEclipseResultCase.h"
|
2018-11-09 08:25:35 -06:00
|
|
|
#include "RimEclipseResultDefinition.h"
|
2018-10-16 02:53:30 -05:00
|
|
|
#include "RimProject.h"
|
2018-10-30 05:43:50 -05:00
|
|
|
#include "RimRegularLegendConfig.h"
|
2018-12-20 03:38:20 -06:00
|
|
|
#include "RimTextAnnotation.h"
|
2018-10-16 02:53:30 -05:00
|
|
|
|
2018-10-30 05:43:50 -05:00
|
|
|
#include "cafContourLines.h"
|
2018-10-16 02:53:30 -05:00
|
|
|
#include "cafPdmUiDoubleSliderEditor.h"
|
|
|
|
#include "cafPdmUiTreeOrdering.h"
|
2018-10-30 05:43:50 -05:00
|
|
|
|
2018-10-17 06:26:15 -05:00
|
|
|
#include "cvfArray.h"
|
|
|
|
#include "cvfCellRange.h"
|
2018-11-15 14:40:10 -06:00
|
|
|
#include "cvfGeometryTools.h"
|
2019-01-02 08:53:13 -06:00
|
|
|
#include "cvfGeometryUtils.h"
|
2018-10-30 05:43:50 -05:00
|
|
|
#include "cvfScalarMapper.h"
|
2018-10-17 06:26:15 -05:00
|
|
|
#include "cvfStructGridGeometryGenerator.h"
|
|
|
|
|
2018-10-16 02:53:30 -05:00
|
|
|
#include <algorithm>
|
2019-01-02 08:53:13 -06:00
|
|
|
#include <omp.h>
|
2018-10-16 02:53:30 -05:00
|
|
|
|
|
|
|
namespace caf
|
|
|
|
{
|
|
|
|
template<>
|
2018-11-09 02:04:40 -06:00
|
|
|
void RimContourMapProjection::ResultAggregation::setUp()
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2018-11-20 04:32:02 -06:00
|
|
|
addItem(RimContourMapProjection::RESULTS_OIL_COLUMN, "OIL_COLUMN", "Oil Column");
|
|
|
|
addItem(RimContourMapProjection::RESULTS_GAS_COLUMN, "GAS_COLUMN", "Gas Column");
|
|
|
|
addItem(RimContourMapProjection::RESULTS_HC_COLUMN, "HC_COLUMN", "Hydrocarbon Column");
|
|
|
|
|
2018-11-09 02:04:40 -06:00
|
|
|
addItem(RimContourMapProjection::RESULTS_MEAN_VALUE, "MEAN_VALUE", "Arithmetic Mean");
|
|
|
|
addItem(RimContourMapProjection::RESULTS_HARM_VALUE, "HARM_VALUE", "Harmonic Mean");
|
|
|
|
addItem(RimContourMapProjection::RESULTS_GEOM_VALUE, "GEOM_VALUE", "Geometric Mean");
|
2018-11-13 07:22:34 -06:00
|
|
|
addItem(RimContourMapProjection::RESULTS_VOLUME_SUM, "VOLUME_SUM", "Volume Weighted Sum");
|
2018-11-09 02:04:40 -06:00
|
|
|
addItem(RimContourMapProjection::RESULTS_SUM, "SUM", "Sum");
|
2018-11-20 04:32:02 -06:00
|
|
|
|
|
|
|
addItem(RimContourMapProjection::RESULTS_TOP_VALUE, "TOP_VALUE", "Top Value");
|
|
|
|
addItem(RimContourMapProjection::RESULTS_MIN_VALUE, "MIN_VALUE", "Min Value");
|
|
|
|
addItem(RimContourMapProjection::RESULTS_MAX_VALUE, "MAX_VALUE", "Max Value");
|
|
|
|
|
2018-11-09 04:40:46 -06:00
|
|
|
setDefault(RimContourMapProjection::RESULTS_MEAN_VALUE);
|
2018-10-16 02:53:30 -05:00
|
|
|
}
|
|
|
|
}
|
2018-11-09 02:04:40 -06:00
|
|
|
CAF_PDM_SOURCE_INIT(RimContourMapProjection, "RimContourMapProjection");
|
2018-10-16 02:53:30 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-09 02:04:40 -06:00
|
|
|
RimContourMapProjection::RimContourMapProjection()
|
2019-01-11 03:48:28 -06:00
|
|
|
: m_pickPoint(cvf::Vec2d::UNDEFINED)
|
|
|
|
, m_mapSize(cvf::Vec2ui(0u, 0u))
|
|
|
|
, m_sampleSpacing(-1.0)
|
|
|
|
, m_currentResultTimestep(-1)
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2018-12-04 07:55:28 -06:00
|
|
|
CAF_PDM_InitObject("RimContourMapProjection", ":/2DMapProjection16x16.png", "", "");
|
2018-10-16 02:53:30 -05:00
|
|
|
|
2018-11-06 06:39:23 -06:00
|
|
|
CAF_PDM_InitField(&m_relativeSampleSpacing, "SampleSpacing", 0.75, "Sample Spacing Factor", "", "", "");
|
|
|
|
m_relativeSampleSpacing.uiCapability()->setUiEditorTypeName(caf::PdmUiDoubleSliderEditor::uiEditorTypeName());
|
2018-10-16 02:53:30 -05:00
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault(&m_resultAggregation, "ResultAggregation", "Result Aggregation", "", "", "");
|
|
|
|
|
2018-11-05 09:19:04 -06:00
|
|
|
CAF_PDM_InitField(&m_showContourLines, "ContourLines", true, "Show Contour Lines", "", "", "");
|
2019-01-08 04:07:19 -06:00
|
|
|
CAF_PDM_InitField(&m_showContourLabels, "ContourLabels", true, "Show Contour Labels", "", "", "");
|
2019-01-08 04:45:16 -06:00
|
|
|
CAF_PDM_InitField(&m_smoothContourLines, "SmoothContourLines", true, "Smooth Contour Lines", "", "", "");
|
2018-11-05 09:19:04 -06:00
|
|
|
|
2018-11-09 08:25:35 -06:00
|
|
|
CAF_PDM_InitField(&m_weightByParameter, "WeightByParameter", false, "Weight by Result Parameter", "", "", "");
|
|
|
|
CAF_PDM_InitFieldNoDefault(&m_weightingResult, "WeightingResult", "", "", "", "");
|
|
|
|
m_weightingResult.uiCapability()->setUiHidden(true);
|
|
|
|
m_weightingResult.uiCapability()->setUiTreeChildrenHidden(true);
|
|
|
|
m_weightingResult = new RimEclipseResultDefinition;
|
|
|
|
m_weightingResult->findField("MResultType")->uiCapability()->setUiName("Result Type");
|
2018-12-20 03:38:20 -06:00
|
|
|
|
2018-11-09 02:04:40 -06:00
|
|
|
setName("Map Projection");
|
2018-10-16 02:53:30 -05:00
|
|
|
nameField()->uiCapability()->setUiReadOnly(true);
|
2018-11-02 07:15:03 -05:00
|
|
|
|
|
|
|
m_resultAccessor = new RigHugeValResultAccessor;
|
2018-10-16 02:53:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-09 02:04:40 -06:00
|
|
|
RimContourMapProjection::~RimContourMapProjection()
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-12-20 03:38:20 -06:00
|
|
|
std::vector<cvf::Vec3d>
|
|
|
|
RimContourMapProjection::generatePickPointPolygon()
|
2018-11-15 14:40:10 -06:00
|
|
|
{
|
2018-12-20 03:38:20 -06:00
|
|
|
std::vector<cvf::Vec3d> points;
|
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
if (!m_pickPoint.isUndefined())
|
|
|
|
{
|
2018-11-20 04:00:02 -06:00
|
|
|
{
|
|
|
|
cvf::Vec2d cellDiagonal(m_sampleSpacing*0.5, m_sampleSpacing*0.5);
|
2019-01-02 08:53:13 -06:00
|
|
|
cvf::Vec2ui pickedCell = ijFromLocalPos(m_pickPoint);
|
|
|
|
cvf::Vec2d cellCenter = cellCenterPosition(pickedCell.x(), pickedCell.y());
|
2018-11-20 04:00:02 -06:00
|
|
|
cvf::Vec2d cellCorner = cellCenter - cellDiagonal;
|
|
|
|
#ifndef NDEBUG
|
2019-01-02 08:53:13 -06:00
|
|
|
points.push_back(cvf::Vec3d(cellCorner, 0.0));
|
|
|
|
points.push_back(cvf::Vec3d(cellCorner + cvf::Vec2d(m_sampleSpacing, 0.0), 0.0));
|
|
|
|
points.push_back(cvf::Vec3d(cellCorner + cvf::Vec2d(m_sampleSpacing, 0.0), 0.0));
|
|
|
|
points.push_back(cvf::Vec3d(cellCorner + cvf::Vec2d(m_sampleSpacing, m_sampleSpacing), 0.0));
|
|
|
|
points.push_back(cvf::Vec3d(cellCorner + cvf::Vec2d(m_sampleSpacing, m_sampleSpacing), 0.0));
|
|
|
|
points.push_back(cvf::Vec3d(cellCorner + cvf::Vec2d(0.0, m_sampleSpacing), 0.0));
|
|
|
|
points.push_back(cvf::Vec3d(cellCorner + cvf::Vec2d(0.0, m_sampleSpacing), 0.0));
|
|
|
|
points.push_back(cvf::Vec3d(cellCorner, 0.0));
|
2018-11-20 04:00:02 -06:00
|
|
|
#endif
|
2019-01-02 08:53:13 -06:00
|
|
|
points.push_back(cvf::Vec3d(m_pickPoint - cvf::Vec2d(0.5 * m_sampleSpacing, 0.0), 0.0));
|
|
|
|
points.push_back(cvf::Vec3d(m_pickPoint + cvf::Vec2d(0.5 * m_sampleSpacing, 0.0), 0.0));
|
|
|
|
points.push_back(cvf::Vec3d(m_pickPoint - cvf::Vec2d(0.0, 0.5 * m_sampleSpacing), 0.0));
|
|
|
|
points.push_back(cvf::Vec3d(m_pickPoint + cvf::Vec2d(0.0, 0.5 * m_sampleSpacing), 0.0));
|
2018-11-20 04:00:02 -06:00
|
|
|
}
|
2018-11-15 14:40:10 -06:00
|
|
|
}
|
2018-12-20 03:38:20 -06:00
|
|
|
return points;
|
2018-11-15 14:40:10 -06:00
|
|
|
}
|
|
|
|
|
2018-10-17 08:46:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-11 03:48:28 -06:00
|
|
|
void RimContourMapProjection::generateResultsIfNecessary(int timeStep)
|
2018-10-17 08:46:47 -05:00
|
|
|
{
|
2018-11-15 14:40:10 -06:00
|
|
|
updateGridInformation();
|
|
|
|
|
2019-01-10 13:55:58 -06:00
|
|
|
if (gridMappingNeedsUpdating())
|
|
|
|
{
|
|
|
|
generateGridMapping();
|
|
|
|
}
|
2018-11-15 14:40:10 -06:00
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
if (resultsNeedUpdating(timeStep))
|
|
|
|
{
|
|
|
|
generateResults(timeStep);
|
|
|
|
}
|
|
|
|
}
|
2018-10-23 09:32:40 -05:00
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimContourMapProjection::generateGeometryIfNecessary()
|
|
|
|
{
|
|
|
|
if (geometryNeedsUpdating())
|
2018-10-17 08:46:47 -05:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
generateContourPolygons();
|
|
|
|
generateTrianglesWithVertexValues();
|
|
|
|
}
|
|
|
|
}
|
2018-10-16 02:53:30 -05:00
|
|
|
|
2018-12-20 03:38:20 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
const std::vector<RimContourMapProjection::ContourPolygons>& RimContourMapProjection::contourPolygons() const
|
|
|
|
{
|
|
|
|
return m_contourPolygons;
|
|
|
|
}
|
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
const std::vector<cvf::Vec4d>& RimContourMapProjection::trianglesWithVertexValues()
|
|
|
|
{
|
|
|
|
return m_trianglesWithVertexValues;
|
|
|
|
}
|
|
|
|
|
2018-11-21 02:32:04 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimContourMapProjection::ResultAggregation RimContourMapProjection::resultAggregation() const
|
|
|
|
{
|
|
|
|
return m_resultAggregation();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
double RimContourMapProjection::sampleSpacing() const
|
|
|
|
{
|
|
|
|
return m_sampleSpacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
double RimContourMapProjection::sampleSpacingFactor() const
|
|
|
|
{
|
|
|
|
return m_relativeSampleSpacing();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RimContourMapProjection::showContourLines() const
|
|
|
|
{
|
|
|
|
return m_showContourLines();
|
|
|
|
}
|
|
|
|
|
2018-12-21 01:44:30 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RimContourMapProjection::showContourLabels() const
|
|
|
|
{
|
|
|
|
return m_showContourLines() && m_showContourLabels();
|
|
|
|
}
|
|
|
|
|
2018-11-21 02:32:04 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RimContourMapProjection::resultAggregationText() const
|
|
|
|
{
|
|
|
|
return m_resultAggregation().uiText();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RimContourMapProjection::resultDescriptionText() const
|
|
|
|
{
|
|
|
|
QString resultText = resultAggregationText();
|
|
|
|
if (!isColumnResult())
|
|
|
|
{
|
|
|
|
resultText += QString(", %1").arg(view()->cellResult()->resultVariable());
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultText;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RimContourMapProjection::weightingParameter() const
|
|
|
|
{
|
|
|
|
QString parameter = "None";
|
|
|
|
if (m_weightByParameter() && !m_weightingResult->isTernarySaturationSelected())
|
|
|
|
{
|
|
|
|
parameter = m_weightingResult->resultVariableUiShortName();
|
|
|
|
}
|
|
|
|
return parameter;
|
|
|
|
}
|
|
|
|
|
2018-10-16 02:53:30 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-09 02:04:40 -06:00
|
|
|
double RimContourMapProjection::maxValue() const
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2018-11-02 05:48:33 -05:00
|
|
|
double maxV = -std::numeric_limits<double>::infinity();
|
2018-10-17 08:46:47 -05:00
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
int nVertices = numberOfCells();
|
2018-10-17 08:46:47 -05:00
|
|
|
|
|
|
|
for (int index = 0; index < nVertices; ++index)
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2018-10-17 08:46:47 -05:00
|
|
|
if (m_aggregatedResults[index] != std::numeric_limits<double>::infinity())
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2018-10-17 08:46:47 -05:00
|
|
|
maxV = std::max(maxV, m_aggregatedResults[index]);
|
2018-10-16 02:53:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return maxV;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-09 02:04:40 -06:00
|
|
|
double RimContourMapProjection::minValue() const
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2018-10-17 06:26:15 -05:00
|
|
|
double minV = std::numeric_limits<double>::infinity();
|
2018-10-17 08:46:47 -05:00
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
int nVertices = numberOfCells();
|
2018-10-17 08:46:47 -05:00
|
|
|
|
|
|
|
for (int index = 0; index < nVertices; ++index)
|
2018-10-17 06:26:15 -05:00
|
|
|
{
|
2018-10-17 08:46:47 -05:00
|
|
|
if (m_aggregatedResults[index] != std::numeric_limits<double>::infinity())
|
2018-10-17 06:26:15 -05:00
|
|
|
{
|
2018-10-17 08:46:47 -05:00
|
|
|
minV = std::min(minV, m_aggregatedResults[index]);
|
2018-10-17 06:26:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return minV;
|
2018-10-16 02:53:30 -05:00
|
|
|
}
|
|
|
|
|
2018-11-06 05:47:54 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-09 02:04:40 -06:00
|
|
|
double RimContourMapProjection::meanValue() const
|
2018-11-06 05:47:54 -06:00
|
|
|
{
|
2018-11-15 14:40:10 -06:00
|
|
|
return sumAllValues() / numberOfValidCells();
|
2018-11-06 05:47:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-09 02:04:40 -06:00
|
|
|
double RimContourMapProjection::sumAllValues() const
|
2018-11-06 05:47:54 -06:00
|
|
|
{
|
|
|
|
double sum = 0.0;
|
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
int nVertices = numberOfCells();
|
2018-11-06 05:47:54 -06:00
|
|
|
|
|
|
|
for (int index = 0; index < nVertices; ++index)
|
|
|
|
{
|
|
|
|
if (m_aggregatedResults[index] != std::numeric_limits<double>::infinity())
|
|
|
|
{
|
|
|
|
sum += m_aggregatedResults[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2018-10-16 02:53:30 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
cvf::Vec2ui RimContourMapProjection::numberOfElementsIJ() const
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
return m_mapSize;
|
2018-10-16 02:53:30 -05:00
|
|
|
}
|
|
|
|
|
2018-11-09 03:12:33 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
cvf::Vec2ui RimContourMapProjection::numberOfVerticesIJ() const
|
2018-11-09 03:12:33 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
cvf::Vec2ui mapSize = this->numberOfElementsIJ();
|
|
|
|
mapSize.x() += 1u;
|
|
|
|
mapSize.y() += 1u;
|
|
|
|
return mapSize;
|
2018-11-09 03:12:33 -06:00
|
|
|
}
|
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
bool RimContourMapProjection::isColumnResult() const
|
2018-11-15 14:40:10 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
return m_resultAggregation() == RESULTS_OIL_COLUMN ||
|
|
|
|
m_resultAggregation() == RESULTS_GAS_COLUMN ||
|
|
|
|
m_resultAggregation() == RESULTS_HC_COLUMN;
|
2018-11-15 14:40:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
double RimContourMapProjection::valueAtVertex(uint i, uint j) const
|
2018-11-15 14:40:10 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
size_t index = vertexIndexFromIJ(i, j);
|
|
|
|
if (index < numberOfVertices())
|
|
|
|
{
|
|
|
|
return m_aggregatedVertexResults.at(index);
|
|
|
|
}
|
|
|
|
return std::numeric_limits<double>::infinity();
|
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
}
|
|
|
|
|
2018-11-05 09:19:04 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
bool RimContourMapProjection::hasResultAtVertex(uint i, uint j) const
|
2018-11-05 09:19:04 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
size_t index = vertexIndexFromIJ(i, j);
|
|
|
|
return m_aggregatedVertexResults[index] != std::numeric_limits<double>::infinity();
|
2018-11-05 09:19:04 -06:00
|
|
|
}
|
|
|
|
|
2018-10-30 05:43:50 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
RimRegularLegendConfig* RimContourMapProjection::legendConfig() const
|
2018-10-30 05:43:50 -05:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
return view()->cellResult()->legendConfig();
|
2018-10-30 05:43:50 -05:00
|
|
|
}
|
|
|
|
|
2018-11-09 08:25:35 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
void RimContourMapProjection::updateLegend()
|
|
|
|
{
|
|
|
|
RimEclipseCellColors* cellColors = view()->cellResult();
|
|
|
|
|
|
|
|
if (getLegendRangeFrom3dGrid())
|
2018-11-09 08:25:35 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
cellColors->updateLegendData(view()->currentTimeStep(), legendConfig());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double minVal = minValue();
|
|
|
|
double maxVal = maxValue();
|
|
|
|
|
|
|
|
legendConfig()->setAutomaticRanges(minVal, maxVal, minVal, maxVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_resultAggregation() == RESULTS_OIL_COLUMN ||
|
|
|
|
m_resultAggregation() == RESULTS_GAS_COLUMN ||
|
|
|
|
m_resultAggregation() == RESULTS_HC_COLUMN)
|
|
|
|
{
|
|
|
|
legendConfig()->setTitle(QString("Map Projection\n%1").arg(m_resultAggregation().uiText()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString projectionLegendText = QString("Map Projection\n%1").arg(m_resultAggregation().uiText());
|
|
|
|
if (weightingParameter() != "None")
|
|
|
|
{
|
|
|
|
projectionLegendText += QString("(W: %1)").arg(weightingParameter());
|
|
|
|
}
|
|
|
|
projectionLegendText += QString("\nResult: %1").arg(cellColors->resultVariableUiShortName());
|
|
|
|
|
|
|
|
legendConfig()->setTitle(projectionLegendText);
|
2018-11-09 08:25:35 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
uint RimContourMapProjection::numberOfCells() const
|
2018-11-09 08:25:35 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
return m_mapSize.x() * m_mapSize.y();
|
2018-11-09 08:25:35 -06:00
|
|
|
}
|
|
|
|
|
2018-11-05 07:31:07 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
uint RimContourMapProjection::numberOfValidCells() const
|
2018-11-13 07:22:34 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
uint validCount = 0u;
|
|
|
|
for (uint i = 0; i < numberOfCells(); ++i)
|
|
|
|
{
|
|
|
|
cvf::Vec2ui ij = ijFromCellIndex(i);
|
|
|
|
if (hasResultInCell(ij.x(), ij.y()))
|
|
|
|
{
|
|
|
|
validCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return validCount;
|
2018-11-13 07:22:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
size_t RimContourMapProjection::numberOfVertices() const
|
2018-11-06 06:23:24 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
cvf::Vec2ui gridSize = numberOfVerticesIJ();
|
|
|
|
return static_cast<size_t>(gridSize.x()) * static_cast<size_t>(gridSize.y());
|
2018-11-15 14:40:10 -06:00
|
|
|
}
|
|
|
|
|
2018-11-21 02:32:04 -06:00
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
void RimContourMapProjection::updatedWeightingResult()
|
2018-11-15 14:40:10 -06:00
|
|
|
{
|
2019-01-11 05:32:46 -06:00
|
|
|
this->clearGridMapping();
|
2018-11-21 02:32:04 -06:00
|
|
|
this->updateConnectedEditors();
|
2019-01-11 03:48:28 -06:00
|
|
|
this->generateResultsIfNecessary(view()->currentTimeStep());
|
2018-11-21 02:32:04 -06:00
|
|
|
this->updateLegend();
|
|
|
|
|
|
|
|
RimProject* proj;
|
|
|
|
this->firstAncestorOrThisOfTypeAsserted(proj);
|
|
|
|
proj->scheduleCreateDisplayModelAndRedrawAllViews();
|
2018-11-06 06:23:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-02 01:59:57 -06:00
|
|
|
bool RimContourMapProjection::checkForMapIntersection(const cvf::Vec3d& localPoint3d, cvf::Vec2d* contourMapPoint, double* valueAtPoint) const
|
2018-11-05 07:31:07 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
CVF_TIGHT_ASSERT(contourMapPoint);
|
|
|
|
CVF_TIGHT_ASSERT(valueAtPoint);
|
2019-01-02 01:59:57 -06:00
|
|
|
|
2019-01-02 08:53:13 -06:00
|
|
|
cvf::Vec3d localPos3d(localPoint3d.x() + gridEdgeOffset(), localPoint3d.y() + gridEdgeOffset(), 0.0);
|
2019-01-02 01:59:57 -06:00
|
|
|
cvf::Vec2d gridPos2d(localPos3d.x(), localPos3d.y());
|
2019-01-10 14:16:22 -06:00
|
|
|
cvf::Vec2d gridorigin(m_expandedBoundingBox.min().x(), m_expandedBoundingBox.min().y());
|
2019-01-01 09:20:04 -06:00
|
|
|
|
2019-01-02 01:59:57 -06:00
|
|
|
double value = interpolateValue(gridPos2d);
|
|
|
|
if (value != std::numeric_limits<double>::infinity())
|
2018-11-21 02:32:04 -06:00
|
|
|
{
|
|
|
|
*valueAtPoint = value;
|
2019-01-02 01:59:57 -06:00
|
|
|
*contourMapPoint = gridPos2d + gridorigin;
|
2018-11-21 02:32:04 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2018-11-05 07:31:07 -06:00
|
|
|
}
|
|
|
|
|
2019-01-02 01:59:57 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-10 09:07:58 -06:00
|
|
|
void RimContourMapProjection::smoothContourPolygons(ContourPolygons* contourPolygons, const ContourPolygons* clipBy, bool favourExpansion)
|
2019-01-02 01:59:57 -06:00
|
|
|
{
|
2019-01-02 08:53:13 -06:00
|
|
|
CVF_ASSERT(contourPolygons);
|
|
|
|
for (size_t i = 0; i < contourPolygons->size(); ++i)
|
|
|
|
{
|
|
|
|
ContourPolygon& polygon = contourPolygons->at(i);
|
2019-01-10 09:07:58 -06:00
|
|
|
|
|
|
|
for (size_t n = 0; n < 20; ++n)
|
2019-01-02 08:53:13 -06:00
|
|
|
{
|
|
|
|
std::vector<cvf::Vec3d> newVertices;
|
|
|
|
newVertices.resize(polygon.vertices.size());
|
|
|
|
double maxChange = 0.0;
|
|
|
|
for (size_t j = 0; j < polygon.vertices.size(); ++j)
|
|
|
|
{
|
|
|
|
cvf::Vec3d vm1 = polygon.vertices.back();
|
|
|
|
cvf::Vec3d v = polygon.vertices[j];
|
|
|
|
cvf::Vec3d vp1 = polygon.vertices.front();
|
|
|
|
if (j > 0u)
|
|
|
|
{
|
|
|
|
vm1 = polygon.vertices[j - 1];
|
|
|
|
}
|
|
|
|
if (j < polygon.vertices.size() - 1)
|
|
|
|
{
|
|
|
|
vp1 = polygon.vertices[j + 1];
|
|
|
|
}
|
|
|
|
// Only expand.
|
|
|
|
cvf::Vec3d modifiedVertex = 0.5 * (v + 0.5 * (vm1 + vp1));
|
|
|
|
cvf::Vec3d delta = (modifiedVertex - v).getNormalized();
|
|
|
|
cvf::Vec3d tangent3d = vp1 - vm1;
|
|
|
|
cvf::Vec2d tangent2d(tangent3d.x(), tangent3d.y());
|
2019-01-10 09:07:58 -06:00
|
|
|
cvf::Vec3d norm3d(tangent2d.getNormalized().perpendicularVector());
|
2019-01-08 04:45:16 -06:00
|
|
|
if (delta * norm3d > 0 && favourExpansion)
|
2019-01-02 08:53:13 -06:00
|
|
|
{
|
|
|
|
// Normal is always inwards facing so a positive dot product means inward movement
|
|
|
|
// Favour expansion rather than contraction by only contracting by half the amount
|
|
|
|
modifiedVertex = v + 0.5 *delta;
|
|
|
|
}
|
|
|
|
newVertices[j] = modifiedVertex;
|
2019-01-10 09:07:58 -06:00
|
|
|
maxChange = std::max(maxChange, (modifiedVertex - v).length());
|
2019-01-02 08:53:13 -06:00
|
|
|
}
|
|
|
|
polygon.vertices.swap(newVertices);
|
|
|
|
if (maxChange < m_sampleSpacing * 1.0e-2)
|
|
|
|
break;
|
|
|
|
}
|
2019-01-10 09:07:58 -06:00
|
|
|
if (clipBy)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < clipBy->size(); ++j)
|
|
|
|
{
|
|
|
|
std::vector<std::vector<cvf::Vec3d>> intersections = RigCellGeometryTools::intersectPolygons(polygon.vertices, clipBy->at(j).vertices);
|
|
|
|
if (!intersections.empty())
|
|
|
|
{
|
|
|
|
polygon.vertices = intersections.front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-02 08:53:13 -06:00
|
|
|
}
|
|
|
|
}
|
2019-01-02 01:59:57 -06:00
|
|
|
|
2019-01-02 08:53:13 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
double RimContourMapProjection::interpolateValue(const cvf::Vec2d& gridPos2d) const
|
|
|
|
{
|
2019-01-02 01:59:57 -06:00
|
|
|
cvf::Vec2ui cellContainingPoint = ijFromLocalPos(gridPos2d);
|
2019-01-02 08:53:13 -06:00
|
|
|
cvf::Vec2d cellCenter = cellCenterPosition(cellContainingPoint.x(), cellContainingPoint.y());
|
2019-01-02 01:59:57 -06:00
|
|
|
|
|
|
|
std::array<cvf::Vec3d, 4> x;
|
|
|
|
x[0] = cvf::Vec3d(cellCenter + cvf::Vec2d(-m_sampleSpacing * 0.5, -m_sampleSpacing * 0.5), 0.0);
|
|
|
|
x[1] = cvf::Vec3d(cellCenter + cvf::Vec2d(m_sampleSpacing * 0.5, -m_sampleSpacing * 0.5), 0.0);
|
|
|
|
x[2] = cvf::Vec3d(cellCenter + cvf::Vec2d(m_sampleSpacing * 0.5, m_sampleSpacing * 0.5), 0.0);
|
|
|
|
x[3] = cvf::Vec3d(cellCenter + cvf::Vec2d(-m_sampleSpacing * 0.5, m_sampleSpacing * 0.5), 0.0);
|
|
|
|
|
|
|
|
cvf::Vec4d baryCentricCoords = cvf::GeometryTools::barycentricCoords(x[0], x[1], x[2], x[3], cvf::Vec3d(gridPos2d, 0.0));
|
|
|
|
|
|
|
|
std::array<cvf::Vec2ui, 4> v;
|
|
|
|
v[0] = cellContainingPoint;
|
|
|
|
v[1] = cvf::Vec2ui(cellContainingPoint.x() + 1u, cellContainingPoint.y());
|
|
|
|
v[2] = cvf::Vec2ui(cellContainingPoint.x() + 1u, cellContainingPoint.y() + 1u);
|
|
|
|
v[3] = cvf::Vec2ui(cellContainingPoint.x(), cellContainingPoint.y() + 1u);
|
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
std::array<double, 4> vertexValues;
|
|
|
|
double validBarycentricCoordsSum = 0.0;
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
double vertexValue = valueAtVertex(v[i].x(), v[i].y());
|
|
|
|
if (vertexValue == std::numeric_limits<double>::infinity())
|
|
|
|
{
|
|
|
|
baryCentricCoords[i] = 0.0;
|
|
|
|
vertexValues[i] = 0.0;
|
|
|
|
return std::numeric_limits<double>::infinity();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vertexValues[i] = vertexValue;
|
|
|
|
validBarycentricCoordsSum += baryCentricCoords[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (validBarycentricCoordsSum < 1.0e-8)
|
|
|
|
{
|
|
|
|
return std::numeric_limits<double>::infinity();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate final value
|
|
|
|
double value = 0.0;
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
value += baryCentricCoords[i] / validBarycentricCoordsSum * vertexValues[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimContourMapProjection::setPickPoint(cvf::Vec2d globalPickPoint)
|
|
|
|
{
|
|
|
|
m_pickPoint = globalPickPoint - origin2d();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
cvf::Vec3d RimContourMapProjection::origin3d() const
|
|
|
|
{
|
|
|
|
return m_expandedBoundingBox.min();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimContourMapProjection::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
|
|
|
|
const QVariant& oldValue,
|
|
|
|
const QVariant& newValue)
|
|
|
|
{
|
|
|
|
legendConfig()->disableAllTimeStepsRange(!getLegendRangeFrom3dGrid());
|
|
|
|
|
|
|
|
if (changedField == &m_weightByParameter || changedField == &m_weightingResult)
|
|
|
|
{
|
|
|
|
clearGridMapping();
|
|
|
|
}
|
|
|
|
else if (changedField == &m_resultAggregation)
|
|
|
|
{
|
|
|
|
ResultAggregation previousAggregation = static_cast<ResultAggregationEnum>(oldValue.toInt());
|
|
|
|
if (isStraightSummationResult(previousAggregation) != isStraightSummationResult())
|
|
|
|
{
|
|
|
|
clearGridMapping();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clearResults();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (changedField == &m_smoothContourLines)
|
|
|
|
{
|
|
|
|
clearGeometry();
|
|
|
|
}
|
|
|
|
else if (changedField == &m_relativeSampleSpacing || changedField == &m_weightingResult)
|
|
|
|
{
|
|
|
|
clearResults();
|
|
|
|
}
|
|
|
|
|
|
|
|
view()->updateConnectedEditors();
|
|
|
|
|
|
|
|
RimProject* proj;
|
|
|
|
firstAncestorOrThisOfTypeAsserted(proj);
|
|
|
|
proj->scheduleCreateDisplayModelAndRedrawAllViews();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimContourMapProjection::defineEditorAttribute(const caf::PdmFieldHandle* field,
|
|
|
|
QString uiConfigName,
|
|
|
|
caf::PdmUiEditorAttribute* attribute)
|
|
|
|
{
|
|
|
|
if (&m_relativeSampleSpacing == field)
|
|
|
|
{
|
|
|
|
caf::PdmUiDoubleSliderEditorAttribute* myAttr = dynamic_cast<caf::PdmUiDoubleSliderEditorAttribute*>(attribute);
|
|
|
|
if (myAttr)
|
|
|
|
{
|
|
|
|
myAttr->m_minimum = 0.25;
|
|
|
|
myAttr->m_maximum = 2.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimContourMapProjection::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
|
|
|
|
{
|
|
|
|
caf::PdmUiGroup* mainGroup = uiOrdering.addNewGroup("Projection Settings");
|
|
|
|
mainGroup->add(&m_relativeSampleSpacing);
|
|
|
|
mainGroup->add(&m_showContourLines);
|
|
|
|
mainGroup->add(&m_showContourLabels);
|
|
|
|
m_showContourLabels.uiCapability()->setUiReadOnly(!m_showContourLines());
|
|
|
|
mainGroup->add(&m_smoothContourLines);
|
|
|
|
m_smoothContourLines.uiCapability()->setUiReadOnly(!m_showContourLines());
|
|
|
|
mainGroup->add(&m_resultAggregation);
|
|
|
|
|
|
|
|
caf::PdmUiGroup* weightingGroup = uiOrdering.addNewGroup("Mean Weighting Options");
|
|
|
|
weightingGroup->add(&m_weightByParameter);
|
|
|
|
weightingGroup->setCollapsedByDefault(true);
|
|
|
|
|
|
|
|
m_weightByParameter.uiCapability()->setUiReadOnly(!isMeanResult());
|
|
|
|
if (!isMeanResult())
|
|
|
|
{
|
|
|
|
m_weightByParameter = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_weightByParameter())
|
|
|
|
{
|
|
|
|
m_weightingResult->uiOrdering(uiConfigName, *weightingGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
uiOrdering.skipRemainingFields(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimContourMapProjection::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/)
|
|
|
|
{
|
|
|
|
uiTreeOrdering.skipRemainingChildren(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimContourMapProjection::initAfterRead()
|
|
|
|
{
|
|
|
|
legendConfig()->disableAllTimeStepsRange(!getLegendRangeFrom3dGrid());
|
|
|
|
if (eclipseCase())
|
|
|
|
{
|
|
|
|
m_weightingResult->setEclipseCase(eclipseCase());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimContourMapProjection::generateGridMapping()
|
|
|
|
{
|
|
|
|
clearResults();
|
|
|
|
|
|
|
|
m_cellGridIdxVisibility = view()->currentTotalCellVisibility();
|
|
|
|
|
|
|
|
int nCells = numberOfCells();
|
|
|
|
m_projected3dGridIndices.resize(nCells);
|
|
|
|
|
|
|
|
const std::vector<double>* weightingResultValues = nullptr;
|
|
|
|
if (m_weightByParameter())
|
|
|
|
{
|
|
|
|
size_t gridScalarResultIdx = m_weightingResult->scalarResultIndex();
|
|
|
|
if (gridScalarResultIdx != cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
m_weightingResult->loadResult();
|
|
|
|
int timeStep = 0;
|
|
|
|
if (m_weightingResult->hasDynamicResult())
|
|
|
|
{
|
|
|
|
timeStep = view()->currentTimeStep();
|
|
|
|
}
|
|
|
|
weightingResultValues =
|
|
|
|
&(m_weightingResult->currentGridCellResults()->cellScalarResults(gridScalarResultIdx)[timeStep]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isStraightSummationResult())
|
|
|
|
{
|
|
|
|
#pragma omp parallel for
|
|
|
|
for (int index = 0; index < nCells; ++index)
|
|
|
|
{
|
|
|
|
cvf::Vec2ui ij = ijFromCellIndex(index);
|
|
|
|
|
|
|
|
cvf::Vec2d globalPos = cellCenterPosition(ij.x(), ij.y()) + origin2d();
|
|
|
|
m_projected3dGridIndices[index] = visibleCellsAndLengthInCellFrom2dPoint(globalPos, weightingResultValues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#pragma omp parallel for
|
|
|
|
for (int index = 0; index < nCells; ++index)
|
|
|
|
{
|
|
|
|
cvf::Vec2ui ij = ijFromCellIndex(index);
|
|
|
|
|
|
|
|
cvf::Vec2d globalPos = cellCenterPosition(ij.x(), ij.y()) + origin2d();
|
|
|
|
m_projected3dGridIndices[index] = visibleCellsAndOverlapVolumeFrom2dPoint(globalPos, weightingResultValues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimContourMapProjection::generateResults(int timeStep)
|
|
|
|
{
|
|
|
|
clearGeometry();
|
|
|
|
|
|
|
|
m_weightingResult->loadResult();
|
|
|
|
|
|
|
|
size_t nCells = numberOfCells();
|
|
|
|
size_t nVertices = numberOfVertices();
|
|
|
|
|
|
|
|
m_aggregatedResults = std::vector<double>(nCells, std::numeric_limits<double>::infinity());
|
|
|
|
m_aggregatedVertexResults = std::vector<double>(nVertices, std::numeric_limits<double>::infinity());
|
|
|
|
RimEclipseCellColors* cellColors = view()->cellResult();
|
|
|
|
|
|
|
|
RimEclipseResultCase* eclipseCase = this->eclipseCase();
|
|
|
|
{
|
|
|
|
if (!cellColors->isTernarySaturationSelected())
|
|
|
|
{
|
|
|
|
RigCaseCellResultsData* resultData = eclipseCase->results(RiaDefines::MATRIX_MODEL);
|
|
|
|
|
|
|
|
if (isColumnResult())
|
|
|
|
{
|
2019-01-11 05:32:46 -06:00
|
|
|
m_currentResultName = "";
|
2019-01-11 03:48:28 -06:00
|
|
|
resultData->findOrLoadScalarResult(RiaDefines::STATIC_NATIVE, "PORO");
|
|
|
|
resultData->findOrLoadScalarResult(RiaDefines::STATIC_NATIVE, "NTG");
|
|
|
|
resultData->findOrLoadScalarResult(RiaDefines::STATIC_NATIVE, "DZ");
|
|
|
|
if (m_resultAggregation == RESULTS_OIL_COLUMN || m_resultAggregation == RESULTS_HC_COLUMN)
|
|
|
|
{
|
|
|
|
resultData->findOrLoadScalarResultForTimeStep(RiaDefines::DYNAMIC_NATIVE, "SOIL", timeStep);
|
|
|
|
}
|
|
|
|
if (m_resultAggregation == RESULTS_GAS_COLUMN || m_resultAggregation == RESULTS_HC_COLUMN)
|
|
|
|
{
|
|
|
|
resultData->findOrLoadScalarResultForTimeStep(RiaDefines::DYNAMIC_NATIVE, "SGAS", timeStep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-11 05:32:46 -06:00
|
|
|
m_currentResultName = cellColors->resultVariable();
|
2019-01-11 03:48:28 -06:00
|
|
|
m_resultAccessor =
|
|
|
|
RigResultAccessorFactory::createFromResultDefinition(eclipseCase->eclipseCaseData(), 0, timeStep, cellColors);
|
|
|
|
|
|
|
|
if (m_resultAccessor.isNull())
|
|
|
|
{
|
|
|
|
m_resultAccessor = new RigHugeValResultAccessor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma omp parallel for
|
|
|
|
for (int index = 0; index < static_cast<int>(nCells); ++index)
|
|
|
|
{
|
|
|
|
cvf::Vec2ui ij = ijFromCellIndex(index);
|
|
|
|
m_aggregatedResults[index] = calculateValueInCell(ij.x(), ij.y());
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma omp parallel for
|
|
|
|
for (int index = 0; index < static_cast<int>(nVertices); ++index)
|
|
|
|
{
|
|
|
|
cvf::Vec2ui ij = ijFromVertexIndex(index);
|
|
|
|
m_aggregatedVertexResults[index] = calculateValueAtVertex(ij.x(), ij.y());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_currentResultTimestep = timeStep;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimContourMapProjection::generateTrianglesWithVertexValues()
|
|
|
|
{
|
|
|
|
std::vector<cvf::Vec3d> vertices = generateVertices();
|
|
|
|
|
|
|
|
cvf::Vec2ui patchSize = numberOfVerticesIJ();
|
|
|
|
cvf::ref<cvf::UIntArray> faceList = new cvf::UIntArray;
|
|
|
|
cvf::GeometryUtils::tesselatePatchAsTriangles(patchSize.x(), patchSize.y(), 0u, true, faceList.p());
|
|
|
|
|
|
|
|
bool discrete = false;
|
|
|
|
std::vector<double> contourLevels;
|
|
|
|
if (legendConfig()->mappingMode() != RimRegularLegendConfig::CATEGORY_INTEGER)
|
|
|
|
{
|
|
|
|
legendConfig()->scalarMapper()->majorTickValues(&contourLevels);
|
|
|
|
if (legendConfig()->mappingMode() == RimRegularLegendConfig::LINEAR_DISCRETE ||
|
|
|
|
legendConfig()->mappingMode() == RimRegularLegendConfig::LOG10_DISCRETE)
|
|
|
|
{
|
|
|
|
discrete = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::vector<std::vector<cvf::Vec3d>>> subtractPolygons;
|
|
|
|
if (!m_contourPolygons.empty())
|
|
|
|
{
|
|
|
|
subtractPolygons.resize(m_contourPolygons.size());
|
|
|
|
for (size_t i = 0; i < m_contourPolygons.size() - 1; ++i)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < m_contourPolygons[i + 1].size(); ++j)
|
|
|
|
{
|
|
|
|
subtractPolygons[i].push_back(m_contourPolygons[i + 1][j].vertices);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::vector<std::vector<cvf::Vec4d>> threadTriangles(omp_get_max_threads());
|
|
|
|
|
|
|
|
#pragma omp parallel
|
|
|
|
{
|
|
|
|
int myThread = omp_get_thread_num();
|
|
|
|
threadTriangles[myThread].reserve(faceList->size() / omp_get_num_threads());
|
|
|
|
|
|
|
|
std::set<int64_t> excludedFaceIndices;
|
|
|
|
|
|
|
|
#pragma omp for schedule(dynamic)
|
|
|
|
for (int64_t i = 0; i < (int64_t)faceList->size(); i += 3)
|
|
|
|
{
|
|
|
|
std::vector<cvf::Vec3d> triangle(3);
|
|
|
|
std::vector<cvf::Vec4d> triangleWithValues(3);
|
|
|
|
for (size_t n = 0; n < 3; ++n)
|
|
|
|
{
|
|
|
|
uint vn = (*faceList)[i + n];
|
|
|
|
double value = m_aggregatedVertexResults[vn];
|
|
|
|
triangle[n] = vertices[vn];
|
|
|
|
triangleWithValues[n] = cvf::Vec4d(vertices[vn], value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_contourPolygons.empty())
|
|
|
|
{
|
|
|
|
threadTriangles[myThread].insert(
|
|
|
|
threadTriangles[myThread].end(), triangleWithValues.begin(), triangleWithValues.end());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t c = 0; c < m_contourPolygons.size() && excludedFaceIndices.count(i) == 0u; ++c)
|
|
|
|
{
|
|
|
|
std::vector<std::vector<cvf::Vec3d>> intersectPolygons;
|
|
|
|
for (size_t j = 0; j < m_contourPolygons[c].size(); ++j)
|
|
|
|
{
|
|
|
|
bool containsAtLeastOne = false;
|
|
|
|
for (size_t t = 0; t < 3; ++t)
|
|
|
|
{
|
|
|
|
if (m_contourPolygons[c][j].bbox.contains(triangle[t]))
|
|
|
|
{
|
|
|
|
containsAtLeastOne = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (containsAtLeastOne)
|
|
|
|
{
|
|
|
|
std::vector<std::vector<cvf::Vec3d>> clippedPolygons =
|
|
|
|
RigCellGeometryTools::intersectPolygons(triangle, m_contourPolygons[c][j].vertices);
|
|
|
|
intersectPolygons.insert(intersectPolygons.end(), clippedPolygons.begin(), clippedPolygons.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intersectPolygons.empty())
|
|
|
|
{
|
|
|
|
excludedFaceIndices.insert(i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::vector<cvf::Vec3d>> clippedPolygons;
|
|
|
|
|
|
|
|
if (!subtractPolygons[c].empty())
|
|
|
|
{
|
|
|
|
for (const std::vector<cvf::Vec3d>& polygon : intersectPolygons)
|
|
|
|
{
|
|
|
|
std::vector<std::vector<cvf::Vec3d>> fullyClippedPolygons =
|
|
|
|
RigCellGeometryTools::subtractPolygons(polygon, subtractPolygons[c]);
|
|
|
|
clippedPolygons.insert(clippedPolygons.end(), fullyClippedPolygons.begin(), fullyClippedPolygons.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clippedPolygons.swap(intersectPolygons);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::vector<cvf::Vec4d> clippedTriangles;
|
|
|
|
for (std::vector<cvf::Vec3d>& clippedPolygon : clippedPolygons)
|
|
|
|
{
|
|
|
|
std::vector<std::vector<cvf::Vec3d>> polygonTriangles;
|
|
|
|
if (clippedPolygon.size() == 3u)
|
|
|
|
{
|
|
|
|
polygonTriangles.push_back(clippedPolygon);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cvf::Vec3d baryCenter = cvf::Vec3d::ZERO;
|
|
|
|
for (size_t v = 0; v < clippedPolygon.size(); ++v)
|
|
|
|
{
|
|
|
|
cvf::Vec3d& clippedVertex = clippedPolygon[v];
|
|
|
|
baryCenter += clippedVertex;
|
|
|
|
}
|
|
|
|
baryCenter /= clippedPolygon.size();
|
|
|
|
for (size_t v = 0; v < clippedPolygon.size(); ++v)
|
|
|
|
{
|
|
|
|
std::vector<cvf::Vec3d> clippedTriangle;
|
|
|
|
if (v == clippedPolygon.size() - 1)
|
|
|
|
{
|
|
|
|
clippedTriangle = {clippedPolygon[v], clippedPolygon[0], baryCenter};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clippedTriangle = {clippedPolygon[v], clippedPolygon[v + 1], baryCenter};
|
|
|
|
}
|
|
|
|
polygonTriangles.push_back(clippedTriangle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const std::vector<cvf::Vec3d>& polygonTriangle : polygonTriangles)
|
|
|
|
{
|
|
|
|
for (const cvf::Vec3d& localVertex : polygonTriangle)
|
|
|
|
{
|
|
|
|
double value = std::numeric_limits<double>::infinity();
|
|
|
|
if (discrete)
|
|
|
|
{
|
|
|
|
value = contourLevels[c] +
|
|
|
|
0.01 * (contourLevels.back() - contourLevels.front()) / contourLevels.size();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (size_t n = 0; n < 3; ++n)
|
|
|
|
{
|
|
|
|
if ((triangle[n] - localVertex).length() < m_sampleSpacing * 0.01 &&
|
|
|
|
triangleWithValues[n].w() != std::numeric_limits<double>::infinity())
|
|
|
|
{
|
|
|
|
value = triangleWithValues[n].w();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (value == std::numeric_limits<double>::infinity())
|
|
|
|
{
|
|
|
|
value = interpolateValue(cvf::Vec2d(localVertex.x(), localVertex.y()));
|
|
|
|
if (value == std::numeric_limits<double>::infinity())
|
|
|
|
{
|
|
|
|
value = contourLevels[c];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cvf::Vec4d globalVertex(localVertex, value);
|
|
|
|
clippedTriangles.push_back(globalVertex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
threadTriangles[myThread].insert(
|
|
|
|
threadTriangles[myThread].end(), clippedTriangles.begin(), clippedTriangles.end());
|
|
|
|
}
|
|
|
|
}
|
2019-01-09 02:09:26 -06:00
|
|
|
}
|
|
|
|
}
|
2019-01-11 03:48:28 -06:00
|
|
|
std::vector<cvf::Vec4d> finalTriangles;
|
|
|
|
for (size_t i = 0; i < threadTriangles.size(); ++i)
|
2019-01-09 02:09:26 -06:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
finalTriangles.insert(finalTriangles.end(), threadTriangles[i].begin(), threadTriangles[i].end());
|
2019-01-09 02:09:26 -06:00
|
|
|
}
|
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
m_trianglesWithVertexValues = finalTriangles;
|
2019-01-02 01:59:57 -06:00
|
|
|
}
|
|
|
|
|
2018-10-16 02:53:30 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-11 03:48:28 -06:00
|
|
|
std::vector<cvf::Vec3d> RimContourMapProjection::generateVertices() const
|
2019-01-02 08:53:13 -06:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
size_t nVertices = numberOfVertices();
|
|
|
|
std::vector<cvf::Vec3d> vertices(nVertices, cvf::Vec3d::ZERO);
|
2019-01-02 08:53:13 -06:00
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
#pragma omp parallel for
|
|
|
|
for (int index = 0; index < static_cast<int>(nVertices); ++index)
|
|
|
|
{
|
|
|
|
cvf::Vec2ui ij = ijFromVertexIndex(index);
|
|
|
|
cvf::Vec2d mapPos = cellCenterPosition(ij.x(), ij.y());
|
|
|
|
// Shift away from sample point to vertex
|
|
|
|
mapPos.x() -= m_sampleSpacing * 0.5;
|
|
|
|
mapPos.y() -= m_sampleSpacing * 0.5;
|
|
|
|
|
|
|
|
cvf::Vec3d vertexPos(mapPos, 0.0);
|
|
|
|
vertices[index] = vertexPos;
|
|
|
|
}
|
|
|
|
return vertices;
|
2018-11-21 02:32:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-11 03:48:28 -06:00
|
|
|
void RimContourMapProjection::generateContourPolygons()
|
2018-11-21 02:32:04 -06:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
std::vector<ContourPolygons> contourPolygons;
|
2018-11-21 02:32:04 -06:00
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
const double areaTreshold = (m_sampleSpacing * m_sampleSpacing) / (sampleSpacingFactor() * sampleSpacingFactor());
|
|
|
|
|
|
|
|
if (minValue() != std::numeric_limits<double>::infinity() && maxValue() != -std::numeric_limits<double>::infinity() &&
|
|
|
|
std::fabs(maxValue() - minValue()) > 1.0e-8)
|
2019-01-10 13:55:58 -06:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
std::vector<double> contourLevels;
|
|
|
|
if (legendConfig()->mappingMode() != RimRegularLegendConfig::CATEGORY_INTEGER)
|
2019-01-10 13:55:58 -06:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
legendConfig()->scalarMapper()->majorTickValues(&contourLevels);
|
|
|
|
int nContourLevels = static_cast<int>(contourLevels.size());
|
|
|
|
if (nContourLevels > 2)
|
|
|
|
{
|
2019-01-11 05:32:46 -06:00
|
|
|
if (legendConfig()->mappingMode() == RimRegularLegendConfig::LINEAR_DISCRETE ||
|
|
|
|
legendConfig()->mappingMode() == RimRegularLegendConfig::LINEAR_CONTINUOUS)
|
|
|
|
{
|
|
|
|
contourLevels.front() -= 0.01 * (contourLevels.back() - contourLevels.front());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
contourLevels.front() *= 0.5;
|
|
|
|
}
|
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
std::vector<caf::ContourLines::ClosedPolygons> closedContourLines = caf::ContourLines::create(
|
|
|
|
m_aggregatedVertexResults, xVertexPositions(), yVertexPositions(), contourLevels, areaTreshold);
|
2018-11-15 14:40:10 -06:00
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
contourPolygons.resize(closedContourLines.size());
|
2018-11-21 02:32:04 -06:00
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
for (size_t i = 0; i < closedContourLines.size(); ++i)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < closedContourLines[i].size(); ++j)
|
|
|
|
{
|
|
|
|
ContourPolygon contourPolygon;
|
|
|
|
contourPolygon.value = contourLevels[i];
|
|
|
|
contourPolygon.vertices.reserve(closedContourLines[i][j].size() / 2);
|
2018-11-15 14:40:10 -06:00
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
for (size_t k = 0; k < closedContourLines[i][j].size(); k += 2)
|
|
|
|
{
|
|
|
|
cvf::Vec3d contourPoint3d = cvf::Vec3d(closedContourLines[i][j][k], 0.0);
|
|
|
|
contourPolygon.vertices.push_back(contourPoint3d);
|
|
|
|
contourPolygon.bbox.add(contourPoint3d);
|
|
|
|
}
|
|
|
|
contourPolygons[i].push_back(contourPolygon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < contourPolygons.size(); ++i)
|
|
|
|
{
|
|
|
|
if (i == 0 || m_smoothContourLines())
|
|
|
|
{
|
|
|
|
const ContourPolygons* clipBy = i > 0 ? &contourPolygons[i - 1] : nullptr;
|
|
|
|
smoothContourPolygons(&contourPolygons[i], clipBy, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-21 02:32:04 -06:00
|
|
|
}
|
|
|
|
}
|
2019-01-11 03:48:28 -06:00
|
|
|
m_contourPolygons = contourPolygons;
|
2018-11-15 14:40:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-11 03:48:28 -06:00
|
|
|
bool RimContourMapProjection::gridMappingNeedsUpdating() const
|
2018-11-05 07:31:07 -06:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
// Check grid visibility and projected grid indices;
|
2018-11-15 14:40:10 -06:00
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
if (m_projected3dGridIndices.size() != numberOfCells())
|
2018-11-15 14:40:10 -06:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
return true;
|
2018-11-15 14:40:10 -06:00
|
|
|
}
|
2018-11-21 02:32:04 -06:00
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
cvf::ref<cvf::UByteArray> currentVisibility = view()->currentTotalCellVisibility();
|
|
|
|
CVF_ASSERT(currentVisibility->size() == m_cellGridIdxVisibility->size());
|
|
|
|
for (size_t i = 0; i < currentVisibility->size(); ++i)
|
2018-11-14 05:38:20 -06:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
if ((*currentVisibility)[i] != (*m_cellGridIdxVisibility)[i]) return true;
|
2018-11-14 05:38:20 -06:00
|
|
|
}
|
2018-11-21 02:32:04 -06:00
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
return false;
|
2018-11-05 07:31:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-11 03:48:28 -06:00
|
|
|
bool RimContourMapProjection::resultsNeedUpdating(int timeStep) const
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
if (m_aggregatedResults.size() != numberOfCells())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_aggregatedVertexResults.size() != numberOfVertices())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeStep != m_currentResultTimestep)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-11 05:32:46 -06:00
|
|
|
if (!m_currentResultName.isEmpty())
|
|
|
|
{
|
|
|
|
RimEclipseCellColors* cellColors = view()->cellResult();
|
|
|
|
if (cellColors->resultVariable() != m_currentResultName)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-11 03:48:28 -06:00
|
|
|
return false;
|
2018-11-21 02:32:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-11 03:48:28 -06:00
|
|
|
bool RimContourMapProjection::geometryNeedsUpdating() const
|
2018-11-21 02:32:04 -06:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
return m_contourPolygons.empty() || m_trianglesWithVertexValues.empty();
|
2018-11-21 02:32:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-11 03:48:28 -06:00
|
|
|
void RimContourMapProjection::clearGridMapping()
|
2018-11-21 02:32:04 -06:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
m_projected3dGridIndices.clear();
|
|
|
|
clearResults();
|
2018-10-16 02:53:30 -05:00
|
|
|
}
|
|
|
|
|
2019-01-10 13:55:58 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-11 03:48:28 -06:00
|
|
|
void RimContourMapProjection::clearResults()
|
2019-01-10 13:55:58 -06:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
m_aggregatedResults.clear();
|
|
|
|
m_aggregatedVertexResults.clear();
|
|
|
|
m_currentResultTimestep = -1;
|
|
|
|
clearGeometry();
|
2019-01-10 13:55:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-11 03:48:28 -06:00
|
|
|
void RimContourMapProjection::clearGeometry()
|
2019-01-10 13:55:58 -06:00
|
|
|
{
|
2019-01-11 03:48:28 -06:00
|
|
|
m_contourPolygons.clear();
|
|
|
|
m_trianglesWithVertexValues.clear();
|
2019-01-10 13:55:58 -06:00
|
|
|
}
|
|
|
|
|
2018-10-16 02:53:30 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-15 14:40:10 -06:00
|
|
|
double RimContourMapProjection::valueInCell(uint i, uint j) const
|
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
size_t index = cellIndexFromIJ(i, j);
|
2018-11-15 14:40:10 -06:00
|
|
|
if (index < numberOfCells())
|
2018-10-16 03:11:37 -05:00
|
|
|
{
|
2018-11-15 14:40:10 -06:00
|
|
|
return m_aggregatedResults.at(index);
|
2018-10-16 03:11:37 -05:00
|
|
|
}
|
2018-11-15 14:40:10 -06:00
|
|
|
return std::numeric_limits<double>::infinity();
|
2018-10-16 02:53:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-15 14:40:10 -06:00
|
|
|
bool RimContourMapProjection::hasResultInCell(uint i, uint j) const
|
2018-11-21 02:32:04 -06:00
|
|
|
{
|
2018-11-15 14:40:10 -06:00
|
|
|
RimEclipseCellColors* cellColors = view()->cellResult();
|
2018-10-16 02:53:30 -05:00
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
if (cellColors->isTernarySaturationSelected())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-20 04:00:02 -06:00
|
|
|
return !cellsAtIJ(i, j).empty();
|
2018-10-16 02:53:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
double RimContourMapProjection::calculateValueInCell(uint i, uint j) const
|
2018-11-06 05:47:54 -06:00
|
|
|
{
|
2018-11-30 06:47:46 -06:00
|
|
|
if (!isColumnResult())
|
2018-11-06 05:47:54 -06:00
|
|
|
{
|
2018-11-30 06:47:46 -06:00
|
|
|
if (!view()->cellResult()->isFlowDiagOrInjectionFlooding() &&
|
|
|
|
view()->cellResult()->scalarResultIndex() == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
return 0.0; // Special case of NONE-result. Show 0 all over to ensure we see something.
|
|
|
|
}
|
2018-11-21 02:32:04 -06:00
|
|
|
}
|
|
|
|
const std::vector<std::pair<size_t, double>>& matchingCells = cellsAtIJ(i, j);
|
|
|
|
if (!matchingCells.empty())
|
|
|
|
{
|
|
|
|
switch (m_resultAggregation())
|
2018-11-06 05:47:54 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
case RESULTS_TOP_VALUE:
|
|
|
|
{
|
|
|
|
size_t cellIdx = matchingCells.front().first;
|
|
|
|
double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx);
|
|
|
|
return cellValue;
|
|
|
|
}
|
|
|
|
case RESULTS_MEAN_VALUE:
|
|
|
|
{
|
|
|
|
RiaWeightedMeanCalculator<double> calculator;
|
|
|
|
for (auto cellIdxAndWeight : matchingCells)
|
|
|
|
{
|
|
|
|
size_t cellIdx = cellIdxAndWeight.first;
|
|
|
|
double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx);
|
|
|
|
calculator.addValueAndWeight(cellValue, cellIdxAndWeight.second);
|
|
|
|
}
|
|
|
|
if (calculator.validAggregatedWeight())
|
|
|
|
{
|
|
|
|
return calculator.weightedMean();
|
|
|
|
}
|
|
|
|
return std::numeric_limits<double>::infinity();
|
|
|
|
}
|
|
|
|
case RESULTS_GEOM_VALUE:
|
|
|
|
{
|
|
|
|
RiaWeightedGeometricMeanCalculator calculator;
|
|
|
|
for (auto cellIdxAndWeight : matchingCells)
|
|
|
|
{
|
|
|
|
size_t cellIdx = cellIdxAndWeight.first;
|
|
|
|
double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx);
|
|
|
|
if (cellValue < 1.0e-8)
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
calculator.addValueAndWeight(cellValue, cellIdxAndWeight.second);
|
|
|
|
}
|
|
|
|
if (calculator.validAggregatedWeight())
|
|
|
|
{
|
|
|
|
return calculator.weightedMean();
|
|
|
|
}
|
|
|
|
return std::numeric_limits<double>::infinity();
|
|
|
|
}
|
|
|
|
case RESULTS_HARM_VALUE:
|
|
|
|
{
|
|
|
|
RiaWeightedHarmonicMeanCalculator calculator;
|
|
|
|
for (auto cellIdxAndWeight : matchingCells)
|
|
|
|
{
|
|
|
|
size_t cellIdx = cellIdxAndWeight.first;
|
|
|
|
double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx);
|
|
|
|
if (std::fabs(cellValue) < 1.0e-8)
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
calculator.addValueAndWeight(cellValue, cellIdxAndWeight.second);
|
|
|
|
}
|
|
|
|
if (calculator.validAggregatedWeight())
|
|
|
|
{
|
|
|
|
return calculator.weightedMean();
|
|
|
|
}
|
|
|
|
return std::numeric_limits<double>::infinity();
|
|
|
|
}
|
|
|
|
case RESULTS_MAX_VALUE:
|
|
|
|
{
|
|
|
|
double maxValue = -std::numeric_limits<double>::infinity();
|
|
|
|
for (auto cellIdxAndWeight : matchingCells)
|
|
|
|
{
|
|
|
|
size_t cellIdx = cellIdxAndWeight.first;
|
|
|
|
double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx);
|
|
|
|
maxValue = std::max(maxValue, cellValue);
|
|
|
|
}
|
|
|
|
return maxValue;
|
|
|
|
}
|
|
|
|
case RESULTS_MIN_VALUE:
|
|
|
|
{
|
|
|
|
double minValue = std::numeric_limits<double>::infinity();
|
|
|
|
for (auto cellIdxAndWeight : matchingCells)
|
|
|
|
{
|
|
|
|
size_t cellIdx = cellIdxAndWeight.first;
|
|
|
|
double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx);
|
|
|
|
minValue = std::min(minValue, cellValue);
|
|
|
|
}
|
|
|
|
return minValue;
|
|
|
|
}
|
|
|
|
case RESULTS_VOLUME_SUM:
|
|
|
|
case RESULTS_SUM:
|
|
|
|
{
|
|
|
|
double sum = 0.0;
|
|
|
|
for (auto cellIdxAndWeight : matchingCells)
|
|
|
|
{
|
|
|
|
size_t cellIdx = cellIdxAndWeight.first;
|
|
|
|
double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx);
|
|
|
|
sum += cellValue * cellIdxAndWeight.second;
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
case RESULTS_OIL_COLUMN:
|
|
|
|
case RESULTS_GAS_COLUMN:
|
|
|
|
case RESULTS_HC_COLUMN:
|
|
|
|
{
|
|
|
|
double sum = 0.0;
|
|
|
|
for (auto cellIdxAndWeight : matchingCells)
|
|
|
|
{
|
|
|
|
size_t cellIdx = cellIdxAndWeight.first;
|
|
|
|
double cellValue = findColumnResult(m_resultAggregation(), cellIdx);
|
|
|
|
sum += cellValue * cellIdxAndWeight.second;
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
CVF_TIGHT_ASSERT(false);
|
2018-11-06 05:47:54 -06:00
|
|
|
}
|
|
|
|
}
|
2018-11-21 02:32:04 -06:00
|
|
|
return std::numeric_limits<double>::infinity();
|
2018-10-29 06:52:57 -05:00
|
|
|
}
|
|
|
|
|
2018-10-16 02:53:30 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
double RimContourMapProjection::calculateValueAtVertex(uint vi, uint vj) const
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
std::vector<uint> averageIs;
|
|
|
|
std::vector<uint> averageJs;
|
2018-11-20 04:00:02 -06:00
|
|
|
|
2018-11-21 02:32:04 -06:00
|
|
|
if (vi > 0u) averageIs.push_back(vi - 1);
|
|
|
|
if (vj > 0u) averageJs.push_back(vj - 1);
|
|
|
|
if (vi < m_mapSize.x()) averageIs.push_back(vi);
|
|
|
|
if (vj < m_mapSize.y()) averageJs.push_back(vj);
|
2018-10-16 02:53:30 -05:00
|
|
|
|
2018-11-21 02:32:04 -06:00
|
|
|
RiaWeightedMeanCalculator<double> calc;
|
|
|
|
for (uint j : averageJs)
|
|
|
|
{
|
|
|
|
for (uint i : averageIs)
|
|
|
|
{
|
|
|
|
if (hasResultInCell(i, j))
|
|
|
|
{
|
|
|
|
calc.addValueAndWeight(valueInCell(i, j), 1.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (calc.validAggregatedWeight())
|
|
|
|
{
|
|
|
|
return calc.weightedMean();
|
|
|
|
}
|
|
|
|
return std::numeric_limits<double>::infinity();
|
2018-10-16 02:53:30 -05:00
|
|
|
}
|
|
|
|
|
2018-11-14 05:38:20 -06:00
|
|
|
|
2018-10-16 02:53:30 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-20 04:00:02 -06:00
|
|
|
std::vector<std::pair<size_t, double>> RimContourMapProjection::cellsAtIJ(uint i, uint j) const
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
size_t cellIndex = this->cellIndexFromIJ(i, j);
|
2018-11-15 14:40:10 -06:00
|
|
|
if (cellIndex < m_projected3dGridIndices.size())
|
|
|
|
{
|
|
|
|
return m_projected3dGridIndices[cellIndex];
|
|
|
|
}
|
|
|
|
return std::vector<std::pair<size_t, double>>();
|
2018-10-16 02:53:30 -05:00
|
|
|
}
|
|
|
|
|
2018-10-17 06:26:15 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
std::vector<std::pair<size_t, double>>
|
|
|
|
RimContourMapProjection::visibleCellsAndOverlapVolumeFrom2dPoint(const cvf::Vec2d& globalPos2d,
|
|
|
|
const std::vector<double>* weightingResultValues) const
|
|
|
|
{
|
2019-01-10 14:16:22 -06:00
|
|
|
cvf::Vec3d top2dElementCentroid(globalPos2d, m_expandedBoundingBox.max().z());
|
|
|
|
cvf::Vec3d bottom2dElementCentroid(globalPos2d, m_expandedBoundingBox.min().z());
|
2018-11-15 14:40:10 -06:00
|
|
|
cvf::Vec3d planarDiagonalVector(0.5 * m_sampleSpacing, 0.5 * m_sampleSpacing, 0.0);
|
2018-11-21 02:32:04 -06:00
|
|
|
cvf::Vec3d topNECorner = top2dElementCentroid + planarDiagonalVector;
|
2018-11-05 01:46:50 -06:00
|
|
|
cvf::Vec3d bottomSWCorner = bottom2dElementCentroid - planarDiagonalVector;
|
2018-10-17 06:26:15 -05:00
|
|
|
|
2018-11-06 06:23:24 -06:00
|
|
|
cvf::BoundingBox bbox2dElement(bottomSWCorner, topNECorner);
|
2018-10-17 06:26:15 -05:00
|
|
|
|
2019-01-10 14:16:22 -06:00
|
|
|
std::vector<std::pair<size_t, double>> matchingVisibleCellsAndWeight;
|
|
|
|
|
|
|
|
// Bounding box has been expanded, so 2d element may be outside actual 3d grid
|
|
|
|
if (!bbox2dElement.intersects(m_gridBoundingBox))
|
|
|
|
{
|
|
|
|
return matchingVisibleCellsAndWeight;
|
|
|
|
}
|
|
|
|
|
2018-10-17 06:26:15 -05:00
|
|
|
std::vector<size_t> allCellIndices;
|
2018-11-21 02:32:04 -06:00
|
|
|
m_mainGrid->findIntersectingCells(bbox2dElement, &allCellIndices);
|
2018-10-17 06:26:15 -05:00
|
|
|
|
2018-11-13 07:22:34 -06:00
|
|
|
typedef std::map<size_t, std::vector<std::pair<size_t, double>>> KLayerCellWeightMap;
|
2018-11-21 02:32:04 -06:00
|
|
|
KLayerCellWeightMap matchingVisibleCellsWeightPerKLayer;
|
2018-10-17 08:46:47 -05:00
|
|
|
|
2018-11-06 06:23:24 -06:00
|
|
|
std::array<cvf::Vec3d, 8> hexCorners;
|
2018-10-23 09:32:40 -05:00
|
|
|
for (size_t globalCellIdx : allCellIndices)
|
2018-10-17 06:26:15 -05:00
|
|
|
{
|
2018-11-08 03:18:49 -06:00
|
|
|
if ((*m_cellGridIdxVisibility)[globalCellIdx])
|
2018-10-17 06:26:15 -05:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
RigCell cell = m_mainGrid->globalCellArray()[globalCellIdx];
|
2018-11-13 07:22:34 -06:00
|
|
|
|
|
|
|
size_t mainGridCellIdx = cell.mainGridCellIndex();
|
|
|
|
size_t i, j, k;
|
2018-11-21 02:32:04 -06:00
|
|
|
m_mainGrid->ijkFromCellIndex(mainGridCellIdx, &i, &j, &k);
|
2018-11-13 07:22:34 -06:00
|
|
|
|
|
|
|
size_t localCellIdx = cell.gridLocalCellIndex();
|
2018-11-21 02:32:04 -06:00
|
|
|
RigGridBase* localGrid = cell.hostGrid();
|
2018-11-08 03:18:49 -06:00
|
|
|
|
2018-11-06 06:23:24 -06:00
|
|
|
localGrid->cellCornerVertices(localCellIdx, hexCorners.data());
|
|
|
|
|
2018-11-21 02:32:04 -06:00
|
|
|
cvf::BoundingBox overlapBBox;
|
|
|
|
std::array<cvf::Vec3d, 8> overlapCorners =
|
|
|
|
RigCellGeometryTools::estimateHexOverlapWithBoundingBox(hexCorners, bbox2dElement, &overlapBBox);
|
|
|
|
|
2018-11-08 03:18:49 -06:00
|
|
|
double overlapVolume = RigCellGeometryTools::calculateCellVolume(overlapCorners);
|
2018-11-05 01:46:50 -06:00
|
|
|
|
2018-11-06 06:23:24 -06:00
|
|
|
if (overlapVolume > 0.0)
|
2018-11-09 08:25:35 -06:00
|
|
|
{
|
|
|
|
double weight = overlapVolume;
|
|
|
|
if (weightingResultValues)
|
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
const RigActiveCellInfo* activeCellInfo =
|
|
|
|
eclipseCase()->eclipseCaseData()->activeCellInfo(RiaDefines::MATRIX_MODEL);
|
2018-11-09 08:25:35 -06:00
|
|
|
size_t cellResultIdx = activeCellInfo->cellResultIndex(globalCellIdx);
|
2018-11-21 02:32:04 -06:00
|
|
|
double result = std::max((*weightingResultValues)[cellResultIdx], 0.0);
|
2018-11-09 08:25:35 -06:00
|
|
|
if (result < 1.0e-6)
|
|
|
|
{
|
|
|
|
result = 0.0;
|
|
|
|
}
|
|
|
|
weight *= result;
|
|
|
|
}
|
|
|
|
if (weight > 0.0)
|
|
|
|
{
|
2018-11-13 07:22:34 -06:00
|
|
|
matchingVisibleCellsWeightPerKLayer[k].push_back(std::make_pair(globalCellIdx, weight));
|
2018-11-09 08:25:35 -06:00
|
|
|
}
|
2018-10-17 06:26:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-13 07:22:34 -06:00
|
|
|
for (auto kLayerCellWeight : matchingVisibleCellsWeightPerKLayer)
|
|
|
|
{
|
|
|
|
for (auto cellWeight : kLayerCellWeight.second)
|
|
|
|
{
|
2018-11-13 07:31:08 -06:00
|
|
|
matchingVisibleCellsAndWeight.push_back(std::make_pair(cellWeight.first, cellWeight.second));
|
2018-11-13 07:22:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matchingVisibleCellsAndWeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
std::vector<std::pair<size_t, double>> RimContourMapProjection::visibleCellsAndLengthInCellFrom2dPoint(
|
|
|
|
const cvf::Vec2d& globalPos2d,
|
|
|
|
const std::vector<double>* weightingResultValues /*= nullptr*/) const
|
2018-11-13 07:22:34 -06:00
|
|
|
{
|
2019-01-10 14:16:22 -06:00
|
|
|
std::vector<std::pair<size_t, double>> matchingVisibleCellsAndWeight;
|
|
|
|
|
|
|
|
cvf::Vec3d highestPoint(globalPos2d, m_expandedBoundingBox.max().z());
|
|
|
|
cvf::Vec3d lowestPoint(globalPos2d, m_expandedBoundingBox.min().z());
|
|
|
|
|
|
|
|
// Bounding box has been expanded, so ray may be outside actual grid
|
|
|
|
if (!m_gridBoundingBox.contains(highestPoint))
|
|
|
|
{
|
|
|
|
return matchingVisibleCellsAndWeight;
|
|
|
|
}
|
2018-11-13 07:22:34 -06:00
|
|
|
|
|
|
|
cvf::BoundingBox rayBBox;
|
|
|
|
rayBBox.add(highestPoint);
|
|
|
|
rayBBox.add(lowestPoint);
|
|
|
|
|
|
|
|
std::vector<size_t> allCellIndices;
|
2018-11-21 02:32:04 -06:00
|
|
|
m_mainGrid->findIntersectingCells(rayBBox, &allCellIndices);
|
2018-11-13 07:22:34 -06:00
|
|
|
|
|
|
|
std::map<size_t, std::vector<std::pair<size_t, double>>> matchingVisibleCellsAndWeightPerKLayer;
|
|
|
|
|
|
|
|
cvf::Vec3d hexCorners[8];
|
|
|
|
for (size_t globalCellIdx : allCellIndices)
|
|
|
|
{
|
|
|
|
if ((*m_cellGridIdxVisibility)[globalCellIdx])
|
2018-11-21 02:32:04 -06:00
|
|
|
{
|
|
|
|
RigCell cell = m_mainGrid->globalCellArray()[globalCellIdx];
|
|
|
|
|
2018-11-13 07:22:34 -06:00
|
|
|
size_t mainGridCellIdx = cell.mainGridCellIndex();
|
|
|
|
size_t i, j, k;
|
2018-11-21 02:32:04 -06:00
|
|
|
m_mainGrid->ijkFromCellIndex(mainGridCellIdx, &i, &j, &k);
|
2018-11-13 07:22:34 -06:00
|
|
|
|
|
|
|
size_t localCellIdx = cell.gridLocalCellIndex();
|
2018-11-21 02:32:04 -06:00
|
|
|
RigGridBase* localGrid = cell.hostGrid();
|
2018-11-13 07:22:34 -06:00
|
|
|
|
|
|
|
localGrid->cellCornerVertices(localCellIdx, hexCorners);
|
|
|
|
std::vector<HexIntersectionInfo> intersections;
|
|
|
|
|
|
|
|
if (RigHexIntersectionTools::lineHexCellIntersection(highestPoint, lowestPoint, hexCorners, 0, &intersections))
|
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
double lengthInCell =
|
|
|
|
(intersections.back().m_intersectionPoint - intersections.front().m_intersectionPoint).length();
|
2018-11-13 07:22:34 -06:00
|
|
|
matchingVisibleCellsAndWeightPerKLayer[k].push_back(std::make_pair(globalCellIdx, lengthInCell));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto kLayerCellWeight : matchingVisibleCellsAndWeightPerKLayer)
|
2018-11-01 09:21:35 -05:00
|
|
|
{
|
2018-11-13 07:22:34 -06:00
|
|
|
// Make sure the sum of all weights in the same K-layer is 1.
|
|
|
|
double weightSumThisKLayer = 0.0;
|
|
|
|
for (auto cellWeight : kLayerCellWeight.second)
|
|
|
|
{
|
|
|
|
weightSumThisKLayer += cellWeight.second;
|
|
|
|
}
|
2018-11-02 05:48:33 -05:00
|
|
|
|
2018-11-13 07:22:34 -06:00
|
|
|
for (auto cellWeight : kLayerCellWeight.second)
|
2018-11-02 05:48:33 -05:00
|
|
|
{
|
2018-11-13 07:22:34 -06:00
|
|
|
matchingVisibleCellsAndWeight.push_back(std::make_pair(cellWeight.first, cellWeight.second / weightSumThisKLayer));
|
2018-11-02 05:48:33 -05:00
|
|
|
}
|
2018-11-01 09:21:35 -05:00
|
|
|
}
|
|
|
|
|
2018-10-17 08:46:47 -05:00
|
|
|
return matchingVisibleCellsAndWeight;
|
2018-10-17 06:26:15 -05:00
|
|
|
}
|
|
|
|
|
2018-11-05 07:31:07 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-09 02:04:40 -06:00
|
|
|
double RimContourMapProjection::findColumnResult(ResultAggregation resultAggregation, size_t cellGlobalIdx) const
|
2018-11-05 07:31:07 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
const RigCaseCellResultsData* resultData = eclipseCase()->results(RiaDefines::MATRIX_MODEL);
|
|
|
|
size_t poroResultIndex = resultData->findScalarResultIndex(RiaDefines::STATIC_NATIVE, "PORO");
|
|
|
|
size_t ntgResultIndex = resultData->findScalarResultIndex(RiaDefines::STATIC_NATIVE, "NTG");
|
|
|
|
size_t dzResultIndex = resultData->findScalarResultIndex(RiaDefines::STATIC_NATIVE, "DZ");
|
2018-11-05 07:31:07 -06:00
|
|
|
|
|
|
|
if (poroResultIndex == cvf::UNDEFINED_SIZE_T || ntgResultIndex == cvf::UNDEFINED_SIZE_T)
|
|
|
|
{
|
|
|
|
return std::numeric_limits<double>::infinity();
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<double>& poroResults = resultData->cellScalarResults(poroResultIndex)[0];
|
|
|
|
const std::vector<double>& ntgResults = resultData->cellScalarResults(ntgResultIndex)[0];
|
2018-11-21 02:32:04 -06:00
|
|
|
const std::vector<double>& dzResults = resultData->cellScalarResults(dzResultIndex)[0];
|
2018-11-05 07:31:07 -06:00
|
|
|
|
|
|
|
const RigActiveCellInfo* activeCellInfo = eclipseCase()->eclipseCaseData()->activeCellInfo(RiaDefines::MATRIX_MODEL);
|
2018-11-21 02:32:04 -06:00
|
|
|
size_t cellResultIdx = activeCellInfo->cellResultIndex(cellGlobalIdx);
|
2018-11-05 07:31:07 -06:00
|
|
|
|
|
|
|
if (cellResultIdx >= poroResults.size() || cellResultIdx >= ntgResults.size())
|
|
|
|
{
|
|
|
|
return std::numeric_limits<double>::infinity();
|
|
|
|
}
|
|
|
|
|
|
|
|
double poro = poroResults.at(cellResultIdx);
|
|
|
|
double ntg = ntgResults.at(cellResultIdx);
|
2018-11-13 07:22:34 -06:00
|
|
|
double dz = dzResults.at(cellResultIdx);
|
2018-11-05 07:31:07 -06:00
|
|
|
|
2018-11-14 05:38:20 -06:00
|
|
|
int timeStep = view()->currentTimeStep();
|
2018-11-05 07:31:07 -06:00
|
|
|
|
|
|
|
double resultValue = 0.0;
|
|
|
|
if (resultAggregation == RESULTS_OIL_COLUMN || resultAggregation == RESULTS_HC_COLUMN)
|
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
size_t soilResultIndex = resultData->findScalarResultIndex(RiaDefines::DYNAMIC_NATIVE, "SOIL");
|
|
|
|
const std::vector<double>& soilResults = resultData->cellScalarResults(soilResultIndex)[timeStep];
|
2018-11-05 07:31:07 -06:00
|
|
|
if (cellResultIdx < soilResults.size())
|
2018-11-21 02:32:04 -06:00
|
|
|
{
|
2018-11-05 07:31:07 -06:00
|
|
|
resultValue = soilResults.at(cellResultIdx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resultAggregation == RESULTS_GAS_COLUMN || resultAggregation == RESULTS_HC_COLUMN)
|
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
size_t sgasResultIndex = resultData->findScalarResultIndex(RiaDefines::DYNAMIC_NATIVE, "SGAS");
|
|
|
|
const std::vector<double>& sgasResults = resultData->cellScalarResults(sgasResultIndex)[timeStep];
|
2018-11-05 07:31:07 -06:00
|
|
|
if (cellResultIdx < sgasResults.size())
|
|
|
|
{
|
|
|
|
resultValue += sgasResults.at(cellResultIdx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-13 07:22:34 -06:00
|
|
|
return resultValue * poro * ntg * dz;
|
2018-11-06 06:23:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
bool RimContourMapProjection::isMeanResult() const
|
|
|
|
{
|
|
|
|
return m_resultAggregation() == RESULTS_MEAN_VALUE || m_resultAggregation() == RESULTS_HARM_VALUE ||
|
|
|
|
m_resultAggregation() == RESULTS_GEOM_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RimContourMapProjection::isSummationResult() const
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
return isStraightSummationResult() || m_resultAggregation() == RESULTS_VOLUME_SUM;
|
2018-11-09 08:25:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
bool RimContourMapProjection::isStraightSummationResult() const
|
2018-11-09 08:25:35 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
return isStraightSummationResult(m_resultAggregation());
|
2018-10-16 02:53:30 -05:00
|
|
|
}
|
|
|
|
|
2018-11-14 05:38:20 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
bool RimContourMapProjection::isStraightSummationResult(ResultAggregationEnum aggregationType)
|
2018-11-14 05:38:20 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
return aggregationType == RESULTS_OIL_COLUMN || aggregationType == RESULTS_GAS_COLUMN ||
|
|
|
|
aggregationType == RESULTS_HC_COLUMN || aggregationType == RESULTS_SUM;
|
2018-11-14 05:38:20 -06:00
|
|
|
}
|
|
|
|
|
2018-10-16 02:53:30 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
size_t RimContourMapProjection::cellIndexFromIJ(uint i, uint j) const
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2018-11-15 14:40:10 -06:00
|
|
|
CVF_ASSERT(i < m_mapSize.x());
|
|
|
|
CVF_ASSERT(j < m_mapSize.y());
|
2018-10-16 02:53:30 -05:00
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
return i + j * m_mapSize.x();
|
|
|
|
}
|
2018-10-16 02:53:30 -05:00
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
size_t RimContourMapProjection::vertexIndexFromIJ(uint i, uint j) const
|
2018-11-15 14:40:10 -06:00
|
|
|
{
|
|
|
|
return i + j * (m_mapSize.x() + 1);
|
2018-10-16 02:53:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-15 14:40:10 -06:00
|
|
|
cvf::Vec2ui RimContourMapProjection::ijFromVertexIndex(size_t gridIndex) const
|
2018-10-16 02:53:30 -05:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
cvf::Vec2ui gridSize = numberOfVerticesIJ();
|
2018-10-16 02:53:30 -05:00
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
uint quotientX = static_cast<uint>(gridIndex) / gridSize.x();
|
|
|
|
uint remainderX = static_cast<uint>(gridIndex) % gridSize.x();
|
2018-10-16 02:53:30 -05:00
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
return cvf::Vec2ui(remainderX, quotientX);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
cvf::Vec2ui RimContourMapProjection::ijFromCellIndex(size_t cellIndex) const
|
|
|
|
{
|
|
|
|
CVF_TIGHT_ASSERT(cellIndex < numberOfCells());
|
|
|
|
|
|
|
|
uint quotientX = static_cast<uint>(cellIndex) / m_mapSize.x();
|
|
|
|
uint remainderX = static_cast<uint>(cellIndex) % m_mapSize.x();
|
2018-10-16 02:53:30 -05:00
|
|
|
|
|
|
|
return cvf::Vec2ui(remainderX, quotientX);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 02:32:04 -06:00
|
|
|
cvf::Vec2ui RimContourMapProjection::ijFromLocalPos(const cvf::Vec2d& localPos2d) const
|
2018-11-09 08:25:35 -06:00
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
uint i = localPos2d.x() / m_sampleSpacing;
|
|
|
|
uint j = localPos2d.y() / m_sampleSpacing;
|
|
|
|
return cvf::Vec2ui(i, j);
|
2018-11-09 08:25:35 -06:00
|
|
|
}
|
|
|
|
|
2018-11-14 05:38:20 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-02 08:53:13 -06:00
|
|
|
cvf::Vec2d RimContourMapProjection::cellCenterPosition(uint i, uint j) const
|
2018-11-14 05:38:20 -06:00
|
|
|
{
|
2019-01-10 14:16:22 -06:00
|
|
|
cvf::Vec3d gridExtent = m_expandedBoundingBox.extent();
|
2019-01-02 08:53:13 -06:00
|
|
|
cvf::Vec2d cellCorner = cvf::Vec2d((i * gridExtent.x()) / (m_mapSize.x()), (j * gridExtent.y()) / (m_mapSize.y()));
|
2018-11-14 05:38:20 -06:00
|
|
|
|
2018-11-21 02:32:04 -06:00
|
|
|
return cellCorner + cvf::Vec2d(m_sampleSpacing * 0.5, m_sampleSpacing * 0.5);
|
2018-11-15 14:40:10 -06:00
|
|
|
}
|
2018-10-30 05:43:50 -05:00
|
|
|
|
2019-01-02 08:53:13 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
cvf::Vec2d RimContourMapProjection::origin2d() const
|
|
|
|
{
|
2019-01-10 14:16:22 -06:00
|
|
|
return cvf::Vec2d(m_expandedBoundingBox.min().x(), m_expandedBoundingBox.min().y());
|
2019-01-02 08:53:13 -06:00
|
|
|
}
|
|
|
|
|
2018-11-15 14:40:10 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<double> RimContourMapProjection::xVertexPositions() const
|
|
|
|
{
|
2019-01-10 14:16:22 -06:00
|
|
|
double gridExtent = m_expandedBoundingBox.extent().x();
|
2018-10-30 05:43:50 -05:00
|
|
|
|
2018-11-21 02:32:04 -06:00
|
|
|
cvf::Vec2ui gridSize = numberOfVerticesIJ();
|
2018-10-30 05:43:50 -05:00
|
|
|
std::vector<double> positions;
|
2018-11-15 14:40:10 -06:00
|
|
|
positions.reserve(gridSize.x());
|
|
|
|
for (uint i = 0; i < gridSize.x(); ++i)
|
2018-10-30 05:43:50 -05:00
|
|
|
{
|
2019-01-02 08:53:13 -06:00
|
|
|
positions.push_back((i * gridExtent) / (gridSize.x() - 1));
|
2018-10-30 05:43:50 -05:00
|
|
|
}
|
2018-11-21 02:32:04 -06:00
|
|
|
|
2018-10-30 05:43:50 -05:00
|
|
|
return positions;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-15 14:40:10 -06:00
|
|
|
std::vector<double> RimContourMapProjection::yVertexPositions() const
|
2018-10-30 05:43:50 -05:00
|
|
|
{
|
2019-01-10 14:16:22 -06:00
|
|
|
double gridExtent = m_expandedBoundingBox.extent().y();
|
2018-10-30 05:43:50 -05:00
|
|
|
|
2018-11-21 02:32:04 -06:00
|
|
|
cvf::Vec2ui gridSize = numberOfVerticesIJ();
|
2018-10-30 05:43:50 -05:00
|
|
|
std::vector<double> positions;
|
2018-11-15 14:40:10 -06:00
|
|
|
positions.reserve(gridSize.y());
|
|
|
|
for (uint j = 0; j < gridSize.y(); ++j)
|
2018-10-30 05:43:50 -05:00
|
|
|
{
|
2019-01-02 08:53:13 -06:00
|
|
|
positions.push_back((j * gridExtent) / (gridSize.y() - 1));
|
2018-10-30 05:43:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return positions;
|
|
|
|
}
|
|
|
|
|
2018-11-13 07:22:34 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RimContourMapProjection::getLegendRangeFrom3dGrid() const
|
|
|
|
{
|
|
|
|
if (isMeanResult())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (m_resultAggregation == RESULTS_TOP_VALUE)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-15 14:40:10 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimContourMapProjection::updateGridInformation()
|
|
|
|
{
|
2018-11-21 02:32:04 -06:00
|
|
|
m_mainGrid = eclipseCase()->eclipseCaseData()->mainGrid();
|
|
|
|
m_sampleSpacing = m_relativeSampleSpacing * m_mainGrid->characteristicIJCellSize();
|
2019-01-10 14:16:22 -06:00
|
|
|
m_gridBoundingBox = eclipseCase()->activeCellsBoundingBox();
|
|
|
|
cvf::Vec3d minExpandedPoint = m_gridBoundingBox.min() - cvf::Vec3d(gridEdgeOffset(), gridEdgeOffset(), 0.0);
|
|
|
|
cvf::Vec3d maxExpandedPoint = m_gridBoundingBox.max() + cvf::Vec3d(gridEdgeOffset(), gridEdgeOffset(), 0.0);
|
|
|
|
m_expandedBoundingBox = cvf::BoundingBox(minExpandedPoint, maxExpandedPoint);
|
|
|
|
|
2018-11-21 02:32:04 -06:00
|
|
|
m_mapSize = calculateMapSize();
|
2018-11-20 04:00:02 -06:00
|
|
|
|
|
|
|
// Re-jig max point to be an exact multiple of cell size
|
2019-01-10 14:16:22 -06:00
|
|
|
cvf::Vec3d minPoint = m_expandedBoundingBox.min();
|
|
|
|
cvf::Vec3d maxPoint = m_expandedBoundingBox.max();
|
2018-11-20 04:00:02 -06:00
|
|
|
maxPoint.x() = minPoint.x() + m_mapSize.x() * m_sampleSpacing;
|
|
|
|
maxPoint.y() = minPoint.y() + m_mapSize.y() * m_sampleSpacing;
|
2019-01-10 14:16:22 -06:00
|
|
|
m_expandedBoundingBox = cvf::BoundingBox(minPoint, maxPoint);
|
2018-11-15 14:40:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
cvf::Vec2ui RimContourMapProjection::calculateMapSize() const
|
|
|
|
{
|
2019-01-10 14:16:22 -06:00
|
|
|
cvf::Vec3d gridExtent = m_expandedBoundingBox.extent();
|
2018-11-15 14:40:10 -06:00
|
|
|
|
|
|
|
uint projectionSizeX = static_cast<uint>(std::ceil(gridExtent.x() / m_sampleSpacing));
|
|
|
|
uint projectionSizeY = static_cast<uint>(std::ceil(gridExtent.y() / m_sampleSpacing));
|
|
|
|
|
|
|
|
return cvf::Vec2ui(projectionSizeX, projectionSizeY);
|
|
|
|
}
|
|
|
|
|
2018-11-21 02:32:04 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimEclipseResultCase* RimContourMapProjection::eclipseCase() const
|
|
|
|
{
|
|
|
|
RimEclipseResultCase* eclipseCase = nullptr;
|
|
|
|
firstAncestorOrThisOfType(eclipseCase);
|
|
|
|
return eclipseCase;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimContourMapView* RimContourMapProjection::view() const
|
|
|
|
{
|
|
|
|
RimContourMapView* view = nullptr;
|
|
|
|
firstAncestorOrThisOfTypeAsserted(view);
|
|
|
|
return view;
|
|
|
|
}
|
2019-01-02 08:53:13 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
double RimContourMapProjection::gridEdgeOffset() const
|
|
|
|
{
|
|
|
|
return m_sampleSpacing * 2.0;
|
|
|
|
}
|