///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) Statoil ASA // Copyright (C) Ceetron Solutions AS // // 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 "RimRegularLegendConfig.h" #include "cafDisplayCoordTransform.h" #include "cafPdmChildField.h" #include "cafPdmField.h" #include "cafPdmObject.h" #include "cvfBoundingBox.h" #include "cvfGeometryBuilderFaceList.h" #include "cvfString.h" #include "cvfVector2.h" class RigMainGrid; class RigResultAccessor; class RimContourMapView; class RimEclipseResultCase; class RimEclipseResultDefinition; //================================================================================================== /// /// //================================================================================================== class RimContourMapProjection : public RimCheckableNamedObject { CAF_PDM_HEADER_INIT; public: struct ContourPolygon { std::vector vertices; double value; 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 ResultAggregation; typedef std::vector ContourPolygons; RimContourMapProjection(); ~RimContourMapProjection() override; void generateResultsIfNecessary(int timeStep); void generateGeometryIfNecessary(); void clearGeometry(); std::vector generatePickPointPolygon(); const std::vector& contourPolygons() const; const std::vector& trianglesWithVertexValues(); ResultAggregation resultAggregation() const; double sampleSpacing() const; double sampleSpacingFactor() const; bool showContourLines() const; bool showContourLabels() const; QString resultAggregationText() const; QString resultDescriptionText() const; QString weightingParameter() const; double maxValue() const; double minValue() const; 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; RimRegularLegendConfig* legendConfig() const; void updateLegend(); uint numberOfCells() const; uint numberOfValidCells() const; size_t numberOfVertices() const; void updatedWeightingResult(); bool checkForMapIntersection(const cvf::Vec3d& localPoint3d, cvf::Vec2d* contourMapPoint, double* valueAtPoint) const; void setPickPoint(cvf::Vec2d globalPickPoint); cvf::Vec3d origin3d() const; protected: void smoothContourPolygons(ContourPolygons* contourPolygons, const ContourPolygons* clipBy, bool favourExpansion); double interpolateValue(const cvf::Vec2d& gridPosition2d) const; 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; private: typedef std::pair CellIndexAndResult; private: void generateGridMapping(); void generateResults(int timeStep); void generateTrianglesWithVertexValues(); std::vector generateVertices() const; void generateContourPolygons(); bool gridMappingNeedsUpdating() const; bool resultsNeedUpdating(int timeStep) const; bool geometryNeedsUpdating() const; void clearGridMapping(); void clearResults(); double valueInCell(uint i, uint j) const; bool hasResultInCell(uint i, uint j) const; double calculateValueInCell(uint i, uint j) const; double calculateValueAtVertex(uint i, uint j) const; std::vector cellsAtIJ(uint i, uint j) const; std::vector visibleCellsAndOverlapVolumeFrom2dPoint(const cvf::Vec2d& globalPos2d, const std::vector* weightingResultValues = nullptr) const; std::vector visibleCellsAndLengthInCellFrom2dPoint(const cvf::Vec2d& globalPos2d, const std::vector* weightingResultValues = nullptr) const; double findColumnResult(ResultAggregation resultAggregation, size_t cellGlobalIdx) const; bool isMeanResult() const; bool isSummationResult() const; bool isStraightSummationResult() const; static bool isStraightSummationResult(ResultAggregationEnum aggregationType); 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; std::vector xVertexPositions() const; std::vector yVertexPositions() const; bool getLegendRangeFrom3dGrid() const; void updateGridInformation(); cvf::Vec2ui calculateMapSize() const; RimEclipseResultCase* eclipseCase() const; RimContourMapView* view() const; double gridEdgeOffset() const; protected: caf::PdmField m_relativeSampleSpacing; caf::PdmField m_resultAggregation; caf::PdmField m_showContourLines; caf::PdmField m_showContourLabels; caf::PdmField m_smoothContourLines; caf::PdmField m_weightByParameter; caf::PdmChildField m_weightingResult; cvf::ref m_cellGridIdxVisibility; std::vector m_aggregatedResults; std::vector m_aggregatedVertexResults; std::vector>> m_projected3dGridIndices; cvf::ref m_resultAccessor; cvf::Vec2d m_pickPoint; caf::PdmPointer m_eclipseCase; cvf::ref m_mainGrid; cvf::Vec2ui m_mapSize; cvf::BoundingBox m_expandedBoundingBox; cvf::BoundingBox m_gridBoundingBox; double m_sampleSpacing; std::vector m_contourPolygons; std::vector m_trianglesWithVertexValues; int m_currentResultTimestep; };