From 1161ff7c73973a5030139dc633a96513ef7344f2 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 11 Aug 2014 08:10:07 +0200 Subject: [PATCH] Added ternary texture and scalar mappers --- .../ModelVisualization/CMakeLists_files.cmake | 3 + .../RivTernaryResultToTextureMapper.h | 51 +++++++++ .../RivTernaryTextureCoordsCreator.cpp | 106 ++++++++++++++++++ .../RivTernaryTextureCoordsCreator.h | 59 ++++++++++ .../RimTernaryLegendConfig.cpp | 15 ++- .../ProjectDataModel/RimTernaryLegendConfig.h | 5 +- 6 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 ApplicationCode/ModelVisualization/RivTernaryResultToTextureMapper.h create mode 100644 ApplicationCode/ModelVisualization/RivTernaryTextureCoordsCreator.cpp create mode 100644 ApplicationCode/ModelVisualization/RivTernaryTextureCoordsCreator.h diff --git a/ApplicationCode/ModelVisualization/CMakeLists_files.cmake b/ApplicationCode/ModelVisualization/CMakeLists_files.cmake index ee8779f9c2..4197e8e99f 100644 --- a/ApplicationCode/ModelVisualization/CMakeLists_files.cmake +++ b/ApplicationCode/ModelVisualization/CMakeLists_files.cmake @@ -23,8 +23,10 @@ ${CEE_CURRENT_LIST_DIR}RivWellPathCollectionPartMgr.h ${CEE_CURRENT_LIST_DIR}RivWellPipesPartMgr.h ${CEE_CURRENT_LIST_DIR}RivWellHeadPartMgr.h ${CEE_CURRENT_LIST_DIR}RivResultToTextureMapper.h +${CEE_CURRENT_LIST_DIR}RivTernaryResultToTextureMapper.h ${CEE_CURRENT_LIST_DIR}RivTextureCoordsCreator.h ${CEE_CURRENT_LIST_DIR}RivTernaryScalarMapper.h +${CEE_CURRENT_LIST_DIR}RivTernaryTextureCoordsCreator.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -47,6 +49,7 @@ ${CEE_CURRENT_LIST_DIR}RivWellPipesPartMgr.cpp ${CEE_CURRENT_LIST_DIR}RivWellHeadPartMgr.cpp ${CEE_CURRENT_LIST_DIR}RivTextureCoordsCreator.cpp ${CEE_CURRENT_LIST_DIR}RivTernaryScalarMapper.cpp +${CEE_CURRENT_LIST_DIR}RivTernaryTextureCoordsCreator.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ModelVisualization/RivTernaryResultToTextureMapper.h b/ApplicationCode/ModelVisualization/RivTernaryResultToTextureMapper.h new file mode 100644 index 0000000000..a93e8e95c2 --- /dev/null +++ b/ApplicationCode/ModelVisualization/RivTernaryResultToTextureMapper.h @@ -0,0 +1,51 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Statoil ASA, 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 "RigPipeInCellEvaluator.h" + +#include "RivTernaryScalarMapper.h" + +#include "cvfBase.h" +#include "cvfObject.h" +#include "cvfStructGrid.h" +#include "cvfVector2.h" + +#include + +class RivTernaryResultToTextureMapper : public cvf::Object +{ +public: + RivTernaryResultToTextureMapper(const RivTernaryScalarMapper* scalarMapper, const RigPipeInCellEvaluator* pipeInCellEvaluator) + : m_scalarMapper(scalarMapper), m_pipeInCellEvaluator(pipeInCellEvaluator) + {} + + cvf::Vec2f getTexCoord(double soil, double sgas, size_t cellIndex) const + { + bool isTransparent = m_pipeInCellEvaluator->isWellPipeInCell(cellIndex); + + return m_scalarMapper->mapToTextureCoord(soil, sgas, isTransparent); + } + +private: + cvf::cref m_scalarMapper; + cvf::cref m_pipeInCellEvaluator; +}; + + diff --git a/ApplicationCode/ModelVisualization/RivTernaryTextureCoordsCreator.cpp b/ApplicationCode/ModelVisualization/RivTernaryTextureCoordsCreator.cpp new file mode 100644 index 0000000000..9a8826ec03 --- /dev/null +++ b/ApplicationCode/ModelVisualization/RivTernaryTextureCoordsCreator.cpp @@ -0,0 +1,106 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Statoil ASA, 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. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RivTernaryTextureCoordsCreator.h" + +#include "RigCaseCellResultsData.h" +#include "RigCaseData.h" +#include "RigPipeInCellEvaluator.h" +#include "RigResultAccessorFactory.h" +#include "RigTernaryResultAccessor2d.h" + +#include "RimCase.h" +#include "RimReservoirView.h" +#include "RimResultSlot.h" +#include "RimTernaryLegendConfig.h" +#include "RimWellCollection.h" + +#include "RivTernaryResultToTextureMapper.h" +#include "RivTernaryScalarMapper.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RivTernaryTextureCoordsCreator::RivTernaryTextureCoordsCreator( + RimResultSlot* cellResultSlot, + RimTernaryLegendConfig* ternaryLegendConfig, + size_t timeStepIndex, + size_t gridIndex, + const cvf::StructGridQuadToCellFaceMapper* quadMapper) +{ + RigCaseData* eclipseCase = cellResultSlot->reservoirView()->eclipseCase()->reservoirData(); + + m_quadMapper = quadMapper; + CVF_ASSERT(quadMapper && eclipseCase ); + + size_t resTimeStepIdx = timeStepIndex; + + if (cellResultSlot->hasStaticResult()) resTimeStepIdx = 0; + + RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel()); + + cvf::ref soil = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, resTimeStepIdx, "SOIL"); + cvf::ref sgas = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, resTimeStepIdx, "SGAS"); + cvf::ref swat = RigResultAccessorFactory::createResultAccessor(eclipseCase, gridIndex, porosityModel, resTimeStepIdx, "SWAT"); + + m_resultAccessor = new RigTernaryResultAccessor(); + m_resultAccessor->setTernaryResultAccessors(soil.p(), sgas.p(), swat.p()); + + cvf::ref pipeInCellEval = new RigPipeInCellEvaluator( cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex), + eclipseCase->gridCellToWellIndex(gridIndex)); + + const RivTernaryScalarMapper* mapper = ternaryLegendConfig->scalarMapper(); + + m_texMapper = new RivTernaryResultToTextureMapper(mapper, pipeInCellEval.p()); + CVF_ASSERT(m_texMapper.notNull()); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivTernaryTextureCoordsCreator::createTextureCoords( + cvf::Vec2fArray* quadTextureCoords, + const cvf::StructGridQuadToCellFaceMapper* quadMapper, + const RigTernaryResultAccessor* resultAccessor, + const RivTernaryResultToTextureMapper* texMapper) +{ + CVF_ASSERT(quadTextureCoords && quadMapper && resultAccessor && texMapper); + + size_t numVertices = quadMapper->quadCount()*4; + quadTextureCoords->resize(numVertices); + cvf::Vec2f* rawPtr = quadTextureCoords->ptr(); + + cvf::Vec2d resultValue; + cvf::Vec2f texCoord; + +#pragma omp parallel for private(texCoord, resultValue) + for (int i = 0; i < static_cast(quadMapper->quadCount()); i++) + { + cvf::StructGridInterface::FaceType faceId = quadMapper->cellFace(i); + size_t cellIdx = quadMapper->cellIndex(i); + + resultValue = resultAccessor->cellFaceScalar(cellIdx, faceId); + texCoord = texMapper->getTexCoord(resultValue.x(), resultValue.y(), cellIdx); + + size_t j; + for (j = 0; j < 4; j++) + { + rawPtr[i*4 + j] = texCoord; + } + } +} diff --git a/ApplicationCode/ModelVisualization/RivTernaryTextureCoordsCreator.h b/ApplicationCode/ModelVisualization/RivTernaryTextureCoordsCreator.h new file mode 100644 index 0000000000..fcf41f8eb7 --- /dev/null +++ b/ApplicationCode/ModelVisualization/RivTernaryTextureCoordsCreator.h @@ -0,0 +1,59 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Statoil ASA, 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 "cvfBase.h" +#include "cvfObject.h" +#include "cvfArray.h" + +class RimResultSlot; +class RigTernaryResultAccessor; +class RivTernaryResultToTextureMapper; +class RimTernaryLegendConfig; + +namespace cvf +{ + class StructGridQuadToCellFaceMapper; +} + + +class RivTernaryTextureCoordsCreator +{ +public: + RivTernaryTextureCoordsCreator( RimResultSlot* cellResultSlot, + RimTernaryLegendConfig* ternaryLegendConfig, + size_t timeStepIndex, + size_t gridIndex, + const cvf::StructGridQuadToCellFaceMapper* quadMapper); + + void createTextureCoords(cvf::Vec2fArray* quadTextureCoords) + { + createTextureCoords(quadTextureCoords, m_quadMapper.p(), m_resultAccessor.p(), m_texMapper.p()); + } + +private: + static void createTextureCoords(cvf::Vec2fArray* quadTextureCoords, + const cvf::StructGridQuadToCellFaceMapper* quadMapper, + const RigTernaryResultAccessor* resultAccessor, + const RivTernaryResultToTextureMapper* texMapper); + + cvf::cref m_quadMapper; + cvf::ref m_resultAccessor; + cvf::ref m_texMapper; +}; diff --git a/ApplicationCode/ProjectDataModel/RimTernaryLegendConfig.cpp b/ApplicationCode/ProjectDataModel/RimTernaryLegendConfig.cpp index dab84420e6..5ee3e364a3 100644 --- a/ApplicationCode/ProjectDataModel/RimTernaryLegendConfig.cpp +++ b/ApplicationCode/ProjectDataModel/RimTernaryLegendConfig.cpp @@ -25,9 +25,11 @@ #include "RimReservoirView.h" #include "RivTernarySaturationOverlayItem.h" +#include "RivTernaryScalarMapper.h" + +#include "cvfqtUtils.h" #include -#include "cvfqtUtils.h" CAF_PDM_SOURCE_INIT(RimTernaryLegendConfig, "RimTernaryLegendConfig"); @@ -93,6 +95,8 @@ RimTernaryLegendConfig::RimTernaryLegendConfig() m_localAutoMin.resize(3, 0.0); m_localAutoMax.resize(3, 1.0); + m_scalarMapper = new RivTernaryScalarMapper(cvf::Color3f::GRAY); + recreateLegend(); updateLegend(); } @@ -163,6 +167,7 @@ void RimTernaryLegendConfig::updateLegend() double swatUpper = 1.0; ternaryRanges(soilLower, soilUpper, sgasLower, sgasUpper, swatLower, swatUpper); + m_scalarMapper->setTernaryRanges(soilLower, soilUpper, sgasLower, sgasUpper); cvf::String soilRange; cvf::String sgasRange; @@ -438,3 +443,11 @@ void RimTernaryLegendConfig::updateLabelText() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RivTernaryScalarMapper* RimTernaryLegendConfig::scalarMapper() +{ + return m_scalarMapper.p(); +} + diff --git a/ApplicationCode/ProjectDataModel/RimTernaryLegendConfig.h b/ApplicationCode/ProjectDataModel/RimTernaryLegendConfig.h index 79c94d5d11..7567867752 100644 --- a/ApplicationCode/ProjectDataModel/RimTernaryLegendConfig.h +++ b/ApplicationCode/ProjectDataModel/RimTernaryLegendConfig.h @@ -27,6 +27,7 @@ class RimReservoirView; class RivTernarySaturationOverlayItem; +class RivTernaryScalarMapper; namespace cvf { @@ -70,7 +71,8 @@ public: void recreateLegend(); - RivTernarySaturationOverlayItem* legend(); + RivTernarySaturationOverlayItem* legend(); + RivTernaryScalarMapper* scalarMapper(); protected: virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); @@ -106,4 +108,5 @@ private: caf::PdmPointer m_reservoirView; cvf::ref m_legend; + cvf::ref m_scalarMapper; };