2019-01-11 08:11:38 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2018- 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 "RimCheckableNamedObject.h"
|
|
|
|
#include "RimRegularLegendConfig.h"
|
|
|
|
|
|
|
|
#include "cafDisplayCoordTransform.h"
|
|
|
|
#include "cafPdmChildField.h"
|
|
|
|
#include "cafPdmField.h"
|
|
|
|
#include "cafPdmObject.h"
|
|
|
|
|
2019-01-16 03:51:43 -06:00
|
|
|
#include "cvfArray.h"
|
2019-01-11 08:11:38 -06:00
|
|
|
#include "cvfBoundingBox.h"
|
|
|
|
#include "cvfGeometryBuilderFaceList.h"
|
|
|
|
#include "cvfString.h"
|
|
|
|
#include "cvfVector2.h"
|
|
|
|
|
|
|
|
class RimGridView;
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
///
|
|
|
|
///
|
|
|
|
//==================================================================================================
|
|
|
|
class RimContourMapProjection : public RimCheckableNamedObject
|
|
|
|
{
|
|
|
|
CAF_PDM_HEADER_INIT;
|
|
|
|
|
|
|
|
public:
|
2019-01-11 09:06:08 -06:00
|
|
|
typedef std::pair<size_t, double> CellIndexAndResult;
|
|
|
|
|
2019-01-11 08:11:38 -06:00
|
|
|
struct ContourPolygon
|
|
|
|
{
|
|
|
|
std::vector<cvf::Vec3d> vertices;
|
|
|
|
double value;
|
2019-01-17 12:27:49 -06:00
|
|
|
double area;
|
2019-01-11 08:11:38 -06:00
|
|
|
cvf::BoundingBox bbox;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ResultAggregationEnum
|
|
|
|
{
|
|
|
|
RESULTS_TOP_VALUE,
|
|
|
|
RESULTS_MEAN_VALUE,
|
|
|
|
RESULTS_GEOM_VALUE,
|
|
|
|
RESULTS_HARM_VALUE,
|
|
|
|
RESULTS_MIN_VALUE,
|
|
|
|
RESULTS_MAX_VALUE,
|
|
|
|
RESULTS_VOLUME_SUM,
|
|
|
|
RESULTS_SUM,
|
|
|
|
RESULTS_OIL_COLUMN,
|
|
|
|
RESULTS_GAS_COLUMN,
|
|
|
|
RESULTS_HC_COLUMN
|
|
|
|
};
|
|
|
|
typedef caf::AppEnum<ResultAggregationEnum> ResultAggregation;
|
|
|
|
typedef std::vector<ContourPolygon> ContourPolygons;
|
|
|
|
|
|
|
|
RimContourMapProjection();
|
|
|
|
~RimContourMapProjection() override;
|
|
|
|
|
|
|
|
void generateResultsIfNecessary(int timeStep);
|
|
|
|
void generateGeometryIfNecessary();
|
|
|
|
void clearGeometry();
|
|
|
|
|
|
|
|
std::vector<cvf::Vec3d> generatePickPointPolygon();
|
|
|
|
|
|
|
|
const std::vector<ContourPolygons>& contourPolygons() const;
|
|
|
|
const std::vector<cvf::Vec4d>& trianglesWithVertexValues();
|
|
|
|
|
|
|
|
ResultAggregation resultAggregation() const;
|
|
|
|
double sampleSpacing() const;
|
|
|
|
double sampleSpacingFactor() const;
|
|
|
|
bool showContourLines() const;
|
|
|
|
bool showContourLabels() const;
|
|
|
|
|
|
|
|
QString resultAggregationText() const;
|
|
|
|
|
|
|
|
double maxValue() const;
|
|
|
|
double minValue() const;
|
2019-01-18 06:32:05 -06:00
|
|
|
|
2019-01-11 08:11:38 -06:00
|
|
|
double meanValue() const;
|
|
|
|
double sumAllValues() const;
|
|
|
|
|
|
|
|
cvf::Vec2ui numberOfElementsIJ() const;
|
|
|
|
cvf::Vec2ui numberOfVerticesIJ() const;
|
|
|
|
|
|
|
|
bool isColumnResult() const;
|
|
|
|
|
|
|
|
double valueAtVertex(uint i, uint j) const;
|
|
|
|
bool hasResultAtVertex(uint i, uint j) const;
|
|
|
|
|
|
|
|
uint numberOfCells() const;
|
|
|
|
uint numberOfValidCells() const;
|
|
|
|
size_t numberOfVertices() const;
|
|
|
|
|
|
|
|
bool checkForMapIntersection(const cvf::Vec3d& localPoint3d, cvf::Vec2d* contourMapPoint, double* valueAtPoint) const;
|
|
|
|
void setPickPoint(cvf::Vec2d globalPickPoint);
|
|
|
|
cvf::Vec3d origin3d() const;
|
|
|
|
|
2019-01-11 09:06:08 -06:00
|
|
|
// Pure-virtual public methods which should be overridden by Eclipse and Geo-mechanical contour map implementations
|
|
|
|
virtual QString resultDescriptionText() const = 0;
|
|
|
|
virtual RimRegularLegendConfig* legendConfig() const = 0;
|
|
|
|
virtual void updateLegend() = 0;
|
2019-01-11 08:11:38 -06:00
|
|
|
|
|
|
|
protected:
|
2019-01-11 09:06:08 -06:00
|
|
|
// Protected virtual methods to be overridden by Eclipse and Geo-mechanical contour map implementations
|
2019-01-16 03:51:43 -06:00
|
|
|
virtual void updateGridInformation() = 0;
|
|
|
|
virtual std::vector<double> retrieveParameterWeights() = 0;
|
2019-01-18 09:12:02 -06:00
|
|
|
virtual std::vector<double> generateResults(int timeStep) = 0;
|
2019-01-16 03:51:43 -06:00
|
|
|
virtual bool resultVariableChanged() const = 0;
|
|
|
|
virtual void clearResultVariable() = 0;
|
|
|
|
virtual RimGridView* baseView() const = 0;
|
2019-01-21 08:45:35 -06:00
|
|
|
virtual size_t kLayer(size_t globalCellIdx) const = 0;
|
2019-01-16 03:51:43 -06:00
|
|
|
virtual std::vector<size_t> findIntersectingCells(const cvf::BoundingBox& bbox) const = 0;
|
2019-01-21 08:45:35 -06:00
|
|
|
virtual double calculateOverlapVolume(size_t globalCellIdx, const cvf::BoundingBox& bbox) const = 0;
|
|
|
|
virtual double calculateRayLengthInCell(size_t globalCellIdx, const cvf::Vec3d& highestPoint, const cvf::Vec3d& lowestPoint) const = 0;
|
2019-01-16 03:51:43 -06:00
|
|
|
virtual double getParameterWeightForCell(size_t globalCellIdx, const std::vector<double>& parameterWeights) const = 0;
|
|
|
|
|
2019-01-21 08:45:35 -06:00
|
|
|
virtual size_t gridResultIndex(size_t globalCellIdx) const;
|
|
|
|
|
|
|
|
double calculateValueInMapCell(uint i, uint j, const std::vector<double>& gridCellValues) const;
|
2019-01-11 08:11:38 -06:00
|
|
|
|
2019-01-11 09:06:08 -06:00
|
|
|
protected:
|
|
|
|
// Keep track of whether cached data needs updating
|
|
|
|
bool gridMappingNeedsUpdating() const;
|
|
|
|
bool resultsNeedsUpdating(int timeStep) const;
|
|
|
|
bool geometryNeedsUpdating() const;
|
2019-01-18 06:32:05 -06:00
|
|
|
bool timestepRangeNeedsUpdating() const;
|
2019-01-11 09:06:08 -06:00
|
|
|
void clearGridMapping();
|
|
|
|
void clearResults();
|
2019-01-18 06:32:05 -06:00
|
|
|
void clearTimeStepRange();
|
|
|
|
|
|
|
|
double maxValue(const std::vector<double>& aggregatedResults) const;
|
|
|
|
double minValue(const std::vector<double>& aggregatedResults) const;
|
2019-01-21 08:45:35 -06:00
|
|
|
std::pair<double, double> minmaxValuesAllTimeSteps();
|
|
|
|
|
|
|
|
virtual cvf::ref<cvf::UByteArray> getCellVisibility() const;
|
|
|
|
virtual std::vector<bool> getMapCellVisibility();
|
|
|
|
bool mapCellVisibilityNeedsUpdating();
|
|
|
|
std::vector<std::vector<std::pair<size_t, double>>> generateGridMapping();
|
2019-01-11 08:11:38 -06:00
|
|
|
|
2019-01-16 03:51:43 -06:00
|
|
|
void generateVertexResults();
|
2019-01-11 08:11:38 -06:00
|
|
|
void generateTrianglesWithVertexValues();
|
|
|
|
std::vector<cvf::Vec3d> generateVertices() const;
|
|
|
|
void generateContourPolygons();
|
2019-01-11 09:06:08 -06:00
|
|
|
void smoothContourPolygons(ContourPolygons* contourPolygons, const ContourPolygons* clipBy, bool favourExpansion);
|
2019-01-17 12:27:49 -06:00
|
|
|
static double sumPolygonArea(const ContourPolygons& contourPolygons);
|
|
|
|
static double sumTriangleAreas(const std::vector<cvf::Vec4d>& triangles);
|
2019-01-16 03:51:43 -06:00
|
|
|
|
2019-01-21 08:45:35 -06:00
|
|
|
std::vector<CellIndexAndResult> cellOverlapVolumesAndResults(const cvf::Vec2d& globalPos2d,
|
2019-01-16 03:51:43 -06:00
|
|
|
const std::vector<double>& weightingResultValues) const;
|
2019-01-21 08:45:35 -06:00
|
|
|
std::vector<CellIndexAndResult> cellRayIntersectionAndResults(const cvf::Vec2d& globalPos2d,
|
2019-01-16 03:51:43 -06:00
|
|
|
const std::vector<double>& weightingResultValues) const;
|
|
|
|
|
2019-01-11 08:11:38 -06:00
|
|
|
bool isMeanResult() const;
|
|
|
|
bool isSummationResult() const;
|
|
|
|
bool isStraightSummationResult() const;
|
|
|
|
static bool isStraightSummationResult(ResultAggregationEnum aggregationType);
|
|
|
|
|
2019-01-11 09:06:08 -06:00
|
|
|
double interpolateValue(const cvf::Vec2d& gridPosition2d) const;
|
|
|
|
double valueInCell(uint i, uint j) const;
|
|
|
|
bool hasResultInCell(uint i, uint j) const;
|
|
|
|
double calculateValueAtVertex(uint i, uint j) const;
|
2019-01-11 08:11:38 -06:00
|
|
|
|
2019-01-11 09:06:08 -06:00
|
|
|
// Cell index and position conversion
|
|
|
|
std::vector<CellIndexAndResult> cellsAtIJ(uint i, uint j) const;
|
|
|
|
size_t cellIndexFromIJ(uint i, uint j) const;
|
|
|
|
size_t vertexIndexFromIJ(uint i, uint j) const;
|
|
|
|
cvf::Vec2ui ijFromVertexIndex(size_t gridIndex) const;
|
|
|
|
cvf::Vec2ui ijFromCellIndex(size_t mapIndex) const;
|
|
|
|
cvf::Vec2ui ijFromLocalPos(const cvf::Vec2d& localPos2d) const;
|
|
|
|
cvf::Vec2d cellCenterPosition(uint i, uint j) const;
|
|
|
|
cvf::Vec2d origin2d() const;
|
2019-01-11 08:11:38 -06:00
|
|
|
|
|
|
|
std::vector<double> xVertexPositions() const;
|
|
|
|
std::vector<double> yVertexPositions() const;
|
|
|
|
|
2019-01-11 09:06:08 -06:00
|
|
|
cvf::Vec2ui calculateMapSize() const;
|
|
|
|
double gridEdgeOffset() const;
|
2019-01-11 08:11:38 -06:00
|
|
|
|
2019-01-11 09:06:08 -06:00
|
|
|
protected:
|
|
|
|
// Framework overrides
|
|
|
|
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
|
|
|
void defineEditorAttribute(const caf::PdmFieldHandle* field,
|
|
|
|
QString uiConfigName,
|
|
|
|
caf::PdmUiEditorAttribute* attribute) override;
|
|
|
|
void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
|
|
|
|
void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "") override;
|
|
|
|
void initAfterRead() override;
|
|
|
|
|
2019-01-11 08:11:38 -06:00
|
|
|
protected:
|
|
|
|
caf::PdmField<double> m_relativeSampleSpacing;
|
|
|
|
caf::PdmField<ResultAggregation> m_resultAggregation;
|
|
|
|
caf::PdmField<bool> m_showContourLines;
|
|
|
|
caf::PdmField<bool> m_showContourLabels;
|
|
|
|
caf::PdmField<bool> m_smoothContourLines;
|
|
|
|
|
2019-01-16 03:51:43 -06:00
|
|
|
cvf::ref<cvf::UByteArray> m_cellGridIdxVisibility;
|
2019-01-11 09:06:08 -06:00
|
|
|
std::vector<double> m_aggregatedResults;
|
|
|
|
std::vector<double> m_aggregatedVertexResults;
|
2019-01-11 08:11:38 -06:00
|
|
|
std::vector<std::vector<std::pair<size_t, double>>> m_projected3dGridIndices;
|
|
|
|
|
2019-01-11 09:06:08 -06:00
|
|
|
cvf::Vec2d m_pickPoint;
|
2019-01-11 08:11:38 -06:00
|
|
|
cvf::Vec2ui m_mapSize;
|
|
|
|
cvf::BoundingBox m_expandedBoundingBox;
|
|
|
|
cvf::BoundingBox m_gridBoundingBox;
|
|
|
|
double m_sampleSpacing;
|
|
|
|
std::vector<ContourPolygons> m_contourPolygons;
|
2019-01-17 12:27:49 -06:00
|
|
|
std::vector<double> m_contourLevelCumulativeAreas;
|
2019-01-11 08:11:38 -06:00
|
|
|
std::vector<cvf::Vec4d> m_trianglesWithVertexValues;
|
|
|
|
int m_currentResultTimestep;
|
2019-01-21 08:45:35 -06:00
|
|
|
std::vector<bool> m_mapCellVisibility;
|
2019-01-11 08:11:38 -06:00
|
|
|
|
2019-01-18 06:32:05 -06:00
|
|
|
double m_minResultAllTimeSteps;
|
|
|
|
double m_maxResultAllTimeSteps;
|
2019-01-11 08:11:38 -06:00
|
|
|
};
|