///////////////////////////////////////////////////////////////////////////////// // // 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 // for more details. // ///////////////////////////////////////////////////////////////////////////////// #pragma once #include "RimCheckableNamedObject.h" #include "RigContourMapCalculator.h" #include "RigContourPolygonsTools.h" #include "cafPdmField.h" #include "cafPdmObject.h" #include "cvfArray.h" #include "cvfBoundingBox.h" #include "cvfVector2.h" class RigContourMapGrid; class RimGridView; class RimRegularLegendConfig; //================================================================================================== /// /// //================================================================================================== class RimContourMapProjection : public RimCheckableNamedObject { CAF_PDM_HEADER_INIT; public: using CellIndexAndResult = std::pair; using ResultAggregation = caf::AppEnum; using ContourPolygons = std::vector; RimContourMapProjection(); ~RimContourMapProjection() override; void generateResultsIfNecessary( int timeStep ); void generateGeometryIfNecessary(); void clearGeometry(); std::vector generatePickPointPolygon(); const std::vector& contourPolygons() const; const std::vector& trianglesWithVertexValues(); virtual double sampleSpacing() const = 0; double sampleSpacingFactor() const; void setSampleSpacingFactor( double spacingFactor ); bool showContourLines() const; bool showContourLabels() const; QString resultAggregationText() const; QString caseName() const; QString currentTimeStepName() const; double maxValue() const; double minValue() const; double meanValue() const; double sumAllValues() const; cvf::Vec2ui numberOfElementsIJ() const; cvf::Vec2ui numberOfVerticesIJ() const; bool isColumnResult() const; bool isMeanResult() const; bool isStraightSummationResult() const; double valueAtVertex( uint i, uint j ) const; uint numberOfCells() const; uint numberOfValidCells() const; size_t numberOfVertices() const; bool checkForMapIntersection( const cvf::Vec3d& domainPoint3d, cvf::Vec2d* contourMapPoint, double* valueAtPoint ) const; void setPickPoint( cvf::Vec2d globalPickPoint ); cvf::Vec3d origin3d() const; std::vector xVertexPositions() const; std::vector yVertexPositions() const; // 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; // Use this function to get the result index into grid cell results. The index will differ if we have active cells virtual size_t gridResultIndex( size_t globalCellIdx ) const; virtual std::vector retrieveParameterWeights() = 0; virtual size_t kLayer( size_t globalCellIdx ) const = 0; virtual size_t kLayers() const = 0; virtual std::vector findIntersectingCells( const cvf::BoundingBox& bbox ) const = 0; 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; virtual double getParameterWeightForCell( size_t globalCellIdx, const std::vector& parameterWeights ) const = 0; virtual cvf::ref getCellVisibility() const; protected: // Protected virtual methods to be overridden by Eclipse and Geo-mechanical contour map implementations virtual void updateGridInformation() = 0; virtual std::vector generateResults( int timeStep ) = 0; virtual bool resultVariableChanged() const = 0; virtual void clearResultVariable() = 0; virtual RimGridView* baseView() const = 0; double calculateValueInMapCell( uint i, uint j, const std::vector& gridCellValues ) const; protected: // Keep track of whether cached data needs updating bool gridMappingNeedsUpdating() const; bool resultsNeedsUpdating( int timeStep ) const; bool geometryNeedsUpdating() const; bool resultRangeIsValid() const; void clearGridMapping(); void clearResults(); void clearTimeStepRange(); double maxValue( const std::vector& aggregatedResults ) const; double minValue( const std::vector& aggregatedResults ) const; virtual std::pair minmaxValuesAllTimeSteps(); virtual std::vector getMapCellVisibility(); bool mapCellVisibilityNeedsUpdating(); static std::vector>> generateGridMapping( RimContourMapProjection& contourMapProjection, const RigContourMapGrid& contourMapGrid ); void generateVertexResults(); void generateTrianglesWithVertexValues(); void generateContourPolygons(); static double sumTriangleAreas( const std::vector& triangles ); 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; // Cell index and position conversion std::vector cellsAtIJ( uint i, uint j ) const; double gridEdgeOffset() const; virtual void updateAfterResultGeneration( int timeStep ) = 0; 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; protected: caf::PdmField m_relativeSampleSpacing; caf::PdmField m_resultAggregation; caf::PdmField m_showContourLines; caf::PdmField m_showContourLabels; caf::PdmField m_smoothContourLines; cvf::ref m_cellGridIdxVisibility; std::vector m_aggregatedResults; std::vector m_aggregatedVertexResults; std::vector>> m_projected3dGridIndices; cvf::Vec2d m_pickPoint; std::vector m_contourPolygons; std::vector m_contourLevelCumulativeAreas; std::vector m_trianglesWithVertexValues; int m_currentResultTimestep; std::vector m_mapCellVisibility; double m_minResultAllTimeSteps; double m_maxResultAllTimeSteps; std::unique_ptr m_contourMapGrid; };