diff --git a/ApplicationCode/ModelVisualization/CMakeLists_files.cmake b/ApplicationCode/ModelVisualization/CMakeLists_files.cmake index 02509f21c9..9ca5bb10e4 100644 --- a/ApplicationCode/ModelVisualization/CMakeLists_files.cmake +++ b/ApplicationCode/ModelVisualization/CMakeLists_files.cmake @@ -22,6 +22,8 @@ ${CEE_CURRENT_LIST_DIR}RivWellPathPartMgr.h ${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}RivTextureCoordsCreator.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -42,6 +44,7 @@ ${CEE_CURRENT_LIST_DIR}RivWellPathPartMgr.cpp ${CEE_CURRENT_LIST_DIR}RivWellPathCollectionPartMgr.cpp ${CEE_CURRENT_LIST_DIR}RivWellPipesPartMgr.cpp ${CEE_CURRENT_LIST_DIR}RivWellHeadPartMgr.cpp +${CEE_CURRENT_LIST_DIR}RivTextureCoordsCreator.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp b/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp index 47fe6765b8..9a018b8ed4 100644 --- a/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp @@ -50,6 +50,11 @@ #include "RimWellCollection.h" #include "RivCellEdgeEffectGenerator.h" #include "RivSourceInfo.h" +#include "cvfStructGridGeometryGenerator.h" +#include "RigResultAccessor.h" +#include "RigResultAccessorFactory.h" +#include "RivResultToTextureMapper.h" +#include "RivTextureCoordsCreator.h" //-------------------------------------------------------------------------------------------------- @@ -207,7 +212,7 @@ void RivGridPartMgr::updateCellColor(cvf::Color4f color) m_surfaceGridLines->setEffect(eff.p()); } } - +#if 0 //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -275,6 +280,96 @@ void RivGridPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* } } } +#endif +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivGridPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* cellResultSlot) +{ + CVF_ASSERT(cellResultSlot); + + const cvf::ScalarMapper* mapper = cellResultSlot->legendConfig()->scalarMapper(); + RigCaseData* eclipseCase = cellResultSlot->reservoirView()->eclipseCase()->reservoirData(); + + cvf::ref surfaceFacesColorArray; + + // Outer surface + if (m_surfaceFaces.notNull()) + { + if (cellResultSlot->isTernarySaturationSelected()) + { + surfaceFacesColorArray = new cvf::Color3ubArray; + + RivTransmissibilityColorMapper::updateTernarySaturationColorArray(timeStepIndex, cellResultSlot, m_grid.p(), surfaceFacesColorArray.p(), m_surfaceGenerator.quadToCellFaceMapper()); + } + else + { + RivTextureCoordsCreator texturer(cellResultSlot, timeStepIndex, m_grid->gridIndex(), m_surfaceGenerator.quadToCellFaceMapper()); + texturer.createTextureCoords(m_surfaceFacesTextureCoords.p()); + /* + // If the result is static, only read that. + size_t resTimeStepIdx = timeStepIndex; + const cvf::StructGridQuadToCellFaceMapper* quadMapper = m_surfaceGenerator.quadToCellFaceMapper(); + + if (cellResultSlot->hasStaticResult()) resTimeStepIdx = 0; + + RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel()); + cvf::ref resultAccessor = RigResultAccessorFactory::createResultAccessor(eclipseCase, m_grid->gridIndex(), porosityModel, resTimeStepIdx, cellResultSlot->resultVariable()); + + if (resultAccessor.isNull()) return; + + cvf::ref pipeInCellEval = new RigPipeInCellEvaluator( cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex), + eclipseCase->gridCellToWellIndex(m_grid->gridIndex())); + + cvf::ref texMapper = new RivResultToTextureMapper(mapper, pipeInCellEval.p()); + + + + size_t numVertices = quadMapper->quadCount()*4; + m_surfaceFacesTextureCoords->resize(numVertices); + cvf::Vec2f* rawPtr = m_surfaceFacesTextureCoords->ptr(); + + double cellScalarValue; + cvf::Vec2f texCoord; + +#pragma omp parallel for private(texCoord, cellScalarValue) + for (int i = 0; i < static_cast(quadMapper->quadCount()); i++) + { + cvf::StructGridInterface::FaceType faceId = quadMapper->cellFace(i); + size_t cellIdx = quadMapper->cellIndex(i); + + cellScalarValue = resultAccessor->cellFaceScalar(cellIdx, faceId); + texCoord = texMapper->getTexCoord(cellScalarValue, cellIdx); + + size_t j; + for (j = 0; j < 4; j++) + { + rawPtr[i*4 + j] = texCoord; + } + } + */ + } + + + if (surfaceFacesColorArray.notNull()) // Ternary result + { + cvf::DrawableGeo* dg = dynamic_cast(m_surfaceFaces->drawable()); + if (dg) + { + dg->setColorArray(surfaceFacesColorArray.p()); + } + + cvf::ref perVertexColorEffect = RivGridPartMgr::createPerVertexColoringEffect(m_opacityLevel); + m_surfaceFaces->setEffect(perVertexColorEffect.p()); + + m_surfaceFaces->setPriority(100); + } + else + { + applyTextureResultsToPart(m_surfaceFaces.p(), m_surfaceFacesTextureCoords.p(), mapper ); + } + } +} //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake b/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake index 950bbb3f0d..4a23c7302f 100644 --- a/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake +++ b/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake @@ -29,6 +29,7 @@ ${CEE_CURRENT_LIST_DIR}RigFault.h ${CEE_CURRENT_LIST_DIR}RigNNCData.h ${CEE_CURRENT_LIST_DIR}cvfGeometryTools.h ${CEE_CURRENT_LIST_DIR}cvfGeometryTools.inl +${CEE_CURRENT_LIST_DIR}RigPipeInCellEvaluator.h ) set (SOURCE_GROUP_SOURCE_FILES diff --git a/ApplicationCode/ReservoirDataModel/RigResultAccessor.h b/ApplicationCode/ReservoirDataModel/RigResultAccessor.h index 1113695e22..dc248b7c73 100644 --- a/ApplicationCode/ReservoirDataModel/RigResultAccessor.h +++ b/ApplicationCode/ReservoirDataModel/RigResultAccessor.h @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// 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 @@ -87,156 +87,5 @@ private: float m_opacityLevel; }; -class RigPipeInCellEvaluator: public cvf::Object -{ -public: - RigPipeInCellEvaluator(const std::vector& isWellPipeVisibleForWellIndex, - const cvf::UIntArray* gridCellToWellIndexMap) - : m_isWellPipeVisibleForWellIndex(isWellPipeVisibleForWellIndex), - m_gridCellToWellIndexMap(gridCellToWellIndexMap) - { - } - - bool isWellPipeInCell( size_t cellIndex) - { - cvf::uint wellIndex = m_gridCellToWellIndexMap->get(cellIndex); - - if (wellIndex == cvf::UNDEFINED_UINT) - { - return false; - } - - return m_isWellPipeVisibleForWellIndex[wellIndex]; - } - -private: - - const std::vector& m_isWellPipeVisibleForWellIndex; - const cvf::UIntArray* m_gridCellToWellIndexMap; -}; - -class RivResultToTextureMapper : public cvf::Object -{ - - RivResultToTextureMapper(const cvf::ScalarMapper* scalarMapper, - const RigPipeInCellEvaluator* pipeInCellEvaluator) - : m_scalarMapper(scalarMapper), m_pipeInCellEvaluator(pipeInCellEvaluator) - {} - - Vec2f getTexCoord(double resultValue, size_t cellIndex) - { - Vec2f texCoord(0,0); - - if (resultValue == HUGE_VAL || resultValue != resultValue) // a != a is true for NAN's - { - texCoord[1] = 1.0f; - return texCoord; - } - - texCoord = m_scalarMapper->mapToTexCoord(resultValue); - - if (!m_pipeInCellEvaluator->isWellPipeInCell(cellIndex)) - { - texCoord[1] = 0; // Set the Y texture coordinate to the opaque line in the texture - } - - return texCoord; - } - -private: - cvf::cref m_scalarMapper; - cvf::cref m_pipeInCellEvaluator; -}; - - - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RivGridPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* cellResultSlot) -{ - CVF_ASSERT(cellResultSlot); - - const cvf::ScalarMapper* mapper = cellResultSlot->legendConfig()->scalarMapper(); - RigCaseData* eclipseCase = cellResultSlot->reservoirView()->eclipseCase()->reservoirData(); - - cvf::ref surfaceFacesColorArray; - - // Outer surface - if (m_surfaceFaces.notNull()) - { - if (cellResultSlot->isTernarySaturationSelected()) - { - surfaceFacesColorArray = new cvf::Color3ubArray; - - RivTransmissibilityColorMapper::updateTernarySaturationColorArray(timeStepIndex, cellResultSlot, m_grid.p(), surfaceFacesColorArray.p(), m_surfaceGenerator.quadToCellFaceMapper()); - } - else if (cellResultSlot->resultVariable().compare(RimDefines::combinedTransmissibilityResultName(), Qt::CaseInsensitive) == 0) - { - cvf::Vec2fArray* textureCoords = m_surfaceFacesTextureCoords.p(); - RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordinates(cellResultSlot, m_grid.p(), textureCoords, m_surfaceGenerator.quadToCellFaceMapper()); - } - else - { - // If the result is static, only read that. - size_t resTimeStepIdx = timeStepIndex; - if (cellResultSlot->hasStaticResult()) resTimeStepIdx = 0; - - RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel()); - cvf::ref resultAccessor = RigResultAccessObjectFactory::createResultAccessObject(eclipseCase, m_grid->gridIdx(), porosityModel, resTimeStepIdx, cellResultSlot->resultVariable()); - - if (resultAccessor.isNull()) return; - - RivResultToTextureMapper texMapper(mapper, - RigPipeInCellEvaluator(cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex), - eclipseCase->gridCellToWellIndex(m_grid->gridIndex()))); - - const StructGridQuadToCellFaceMapper* quadMapper = m_surfaceGenerator.quadToCellFaceMapper(); - - size_t numVertices = quadMapper->quadCount()*4; - m_surfaceFacesTextureCoords->resize(numVertices); - cvf::Vec2f* rawPtr = m_surfaceFacesTextureCoords->ptr(); - - double cellScalarValue; - cvf::Vec2f texCoord; - -#pragma omp parallel for private(texCoord, cellScalarValue) - for (int i = 0; i < static_cast(m_quadMapper->quadCount()); i++) - { - StructGridInterface::FaceType faceId = m_quadMapper->cellFace(i); - - cellScalarValue = resultAccessor->cellFaceScalar(m_quadMapper->cellIndex(i), faceId); - - texCoord = texMapper->mapToTextureCoord(cellScalarValue); - - size_t j; - for (j = 0; j < 4; j++) - { - rawPtr[i*4 + j] = texCoord; - } - } - } - - - if (surfaceFacesColorArray.notNull()) // Ternary result - { - cvf::DrawableGeo* dg = dynamic_cast(m_surfaceFaces->drawable()); - if (dg) - { - dg->setColorArray(surfaceFacesColorArray.p()); - } - - cvf::ref perVertexColorEffect = RivGridPartMgr::createPerVertexColoringEffect(m_opacityLevel); - m_surfaceFaces->setEffect(perVertexColorEffect.p()); - - m_surfaceFaces->setPriority(100); - } - else - { - applyTextureResultsToPart(m_surfaceFaces.p(), m_surfaceFacesTextureCoords.p(), mapper ); - } - } -} #endif diff --git a/ApplicationCode/ReservoirDataModel/RigResultAccessorFactory.cpp b/ApplicationCode/ReservoirDataModel/RigResultAccessorFactory.cpp index d44ffc0dfb..de23da6f87 100644 --- a/ApplicationCode/ReservoirDataModel/RigResultAccessorFactory.cpp +++ b/ApplicationCode/ReservoirDataModel/RigResultAccessorFactory.cpp @@ -107,12 +107,7 @@ cvf::ref RigResultAccessorFactory::createResultAccessor(RigCa RigGridBase* grid = eclipseCase->grid(gridIndex); - // Ternary - if (uiResultName == RimDefines::ternarySaturationResultName()) - { - return NULL; - } - else if (uiResultName == RimDefines::combinedTransmissibilityResultName()) + if (uiResultName == RimDefines::combinedTransmissibilityResultName()) { cvf::ref cellFaceAccessObject = new RigCombTransResultAccessor(grid); @@ -125,8 +120,7 @@ cvf::ref RigResultAccessorFactory::createResultAccessor(RigCa return cellFaceAccessObject; } - - return NULL; + return RigResultAccessorFactory::createNativeResultAccessor(eclipseCase, gridIndex, porosityModel, timeStepIndex, uiResultName); }