From 01f3fb8e94895910e2ec9a05b43c67430f8a876c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 1 Feb 2013 12:25:34 +0100 Subject: [PATCH] Moved result interface from struct grid to struct grid scalar data access Use this concept to configure result data values to use for vizualization. Created data access object for RegGrid. p4#: 20334 --- ApplicationCode/CMakeLists.txt | 2 + .../FileInterface_UnitTests/CMakeLists.txt | 1 + .../ModelVisualization/RivGridPartMgr.cpp | 11 +- .../ModelVisualization/RivGridPartMgr.h | 2 + .../ReservoirDataModel/RigGridBase.cpp | 17 +++ .../ReservoirDataModel/RigGridBase.h | 5 + .../RigGridScalarDataAccess.cpp | 107 ++++++++++++++++++ .../RigGridScalarDataAccess.h | 47 ++++++++ CommonCode/cvfStructGrid.h | 21 ---- CommonCode/cvfStructGridGeometryGenerator.cpp | 9 +- CommonCode/cvfStructGridGeometryGenerator.h | 4 +- CommonCode/cvfStructGridScalarDataAccess.h | 46 ++++++++ 12 files changed, 244 insertions(+), 28 deletions(-) create mode 100644 ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.cpp create mode 100644 ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.h create mode 100644 CommonCode/cvfStructGridScalarDataAccess.h diff --git a/ApplicationCode/CMakeLists.txt b/ApplicationCode/CMakeLists.txt index 1f8d428b8f..b68de1d233 100644 --- a/ApplicationCode/CMakeLists.txt +++ b/ApplicationCode/CMakeLists.txt @@ -100,6 +100,7 @@ list( APPEND CPP_SOURCES ReservoirDataModel/RigReservoir.cpp ReservoirDataModel/RigReservoirBuilderMock.cpp ReservoirDataModel/RigWellResults.cpp + ReservoirDataModel/RigGridScalarDataAccess.cpp ) list( APPEND CPP_SOURCES @@ -154,6 +155,7 @@ qt4_add_resources( QRC_FILES_CPP ${QRC_FILES} ) set( RAW_SOURCES ${CPP_SOURCES} ) list( REMOVE_ITEM RAW_SOURCES RIStdInclude.cpp) list( REMOVE_ITEM RAW_SOURCES ReservoirDataModel/RigReaderInterfaceECL.cpp) +list( REMOVE_ITEM RAW_SOURCES ReservoirDataModel/RigGridScalarDataAccess.cpp) list( REMOVE_ITEM RAW_SOURCES ModelVisualization/RivCellEdgeEffectGenerator.cpp) list( REMOVE_ITEM RAW_SOURCES ModelVisualization/RivPipeGeometryGenerator.cpp) list( REMOVE_ITEM RAW_SOURCES ModelVisualization/RivWellPipesPartMgr.cpp) diff --git a/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt b/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt index 56847313ee..7ae8924546 100644 --- a/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt +++ b/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt @@ -40,6 +40,7 @@ set( RESERVOIRDATAMODEL_CPP_SOURCES ${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp ${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.cpp ${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigWellResults.cpp + ${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.cpp ${ResInsight_SOURCE_DIR}/cafUserInterface/cafProgressInfo.cpp ) diff --git a/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp b/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp index b2f7c5c661..d5c875d19c 100644 --- a/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp @@ -27,6 +27,7 @@ #include "RimReservoirView.h" #include "RimResultSlot.h" #include "RimCellEdgeResultSlot.h" +#include "RigGridScalarDataAccess.h" //-------------------------------------------------------------------------------------------------- @@ -35,7 +36,8 @@ RivGridPartMgr::RivGridPartMgr(const RigGridBase* grid, size_t gridIdx) : m_surfaceGenerator(grid), m_faultGenerator(grid), - m_gridIdx(gridIdx), + m_gridIdx(gridIdx), + m_grid(grid), m_surfaceFaceFilter(grid), m_faultFaceFilter(grid), m_opacityLevel(1.0f), @@ -217,10 +219,13 @@ void RivGridPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* size_t resTimeStepIdx = timeStepIndex; if (cellResultSlot->hasStaticResult()) resTimeStepIdx = 0; + cvf::ref dataAccessObject = m_grid->dataAccessObject(timeStepIndex, scalarSetIndex); + if (dataAccessObject.isNull()) return; + // Outer surface if (m_surfaceFaces.notNull()) { - m_surfaceGenerator.textureCoordinates(m_surfaceFacesTextureCoords.p(), resTimeStepIdx, scalarSetIndex, mapper); + m_surfaceGenerator.textureCoordinates(m_surfaceFacesTextureCoords.p(), dataAccessObject.p(), mapper); for(size_t i = 0; i < m_surfaceFacesTextureCoords->size(); ++i) { @@ -246,7 +251,7 @@ void RivGridPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* // Faults if (m_faultFaces.notNull()) { - m_faultGenerator.textureCoordinates(m_faultFacesTextureCoords.p(), resTimeStepIdx, scalarSetIndex, mapper); + m_faultGenerator.textureCoordinates(m_faultFacesTextureCoords.p(), dataAccessObject.p(), mapper); for(size_t i = 0; i < m_faultFacesTextureCoords->size(); ++i) { diff --git a/ApplicationCode/ModelVisualization/RivGridPartMgr.h b/ApplicationCode/ModelVisualization/RivGridPartMgr.h index 36988fb17f..f8bee31ace 100644 --- a/ApplicationCode/ModelVisualization/RivGridPartMgr.h +++ b/ApplicationCode/ModelVisualization/RivGridPartMgr.h @@ -69,6 +69,8 @@ private: private: size_t m_gridIdx; + cvf::cref m_grid; + cvf::ref m_scaleTransform; float m_opacityLevel; cvf::Color3f m_defaultColor; diff --git a/ApplicationCode/ReservoirDataModel/RigGridBase.cpp b/ApplicationCode/ReservoirDataModel/RigGridBase.cpp index 368c6d934c..02bc71d4b3 100644 --- a/ApplicationCode/ReservoirDataModel/RigGridBase.cpp +++ b/ApplicationCode/ReservoirDataModel/RigGridBase.cpp @@ -21,6 +21,7 @@ #include "RigMainGrid.h" #include "RigCell.h" #include "RigReservoirCellResults.h" +#include "RigGridScalarDataAccess.h" #include "cvfAssert.h" @@ -579,6 +580,22 @@ void RigGridBase::computeMatrixAndFractureModelActiveCellCount() } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::ref RigGridBase::dataAccessObject(size_t timeStepIndex, size_t scalarSetIndex) const +{ + if (timeStepIndex != cvf::UNDEFINED_SIZE_T && + scalarSetIndex != cvf::UNDEFINED_SIZE_T) + { + cvf::ref dataAccess = new RigGridScalarDataAccess(this, timeStepIndex, scalarSetIndex); + return dataAccess; + } + + return NULL; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ReservoirDataModel/RigGridBase.h b/ApplicationCode/ReservoirDataModel/RigGridBase.h index 1637bf8c4d..5d89148342 100644 --- a/ApplicationCode/ReservoirDataModel/RigGridBase.h +++ b/ApplicationCode/ReservoirDataModel/RigGridBase.h @@ -27,10 +27,12 @@ #include #include +#include "cvfStructGridScalarDataAccess.h" class RigMainGrid; class RigCell; +class RigGridScalarDataAccess; class RigGridBase : public cvf::StructGridInterface { @@ -102,6 +104,8 @@ public: virtual bool isCellValid( size_t i, size_t j, size_t k ) const; virtual bool cellIJKNeighbor(size_t i, size_t j, size_t k, FaceType face, size_t* neighborCellIndex ) const; + cvf::ref dataAccessObject(size_t timeStepIndex, size_t scalarSetIndex) const; + private: std::string m_gridName; cvf::Vec3st m_gridPointDimensions; @@ -111,6 +115,7 @@ private: size_t m_matrixModelActiveCellCount; size_t m_fractureModelActiveCellCount; + }; diff --git a/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.cpp b/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.cpp new file mode 100644 index 0000000000..8e9bdb1ae1 --- /dev/null +++ b/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.cpp @@ -0,0 +1,107 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library 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. +// +// This library 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 "RigGridScalarDataAccess.h" + +#include "cvfLibCore.h" +#include "cvfBase.h" +#include "cvfAssert.h" + +#include "RigMainGrid.h" +#include "RigReservoirCellResults.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RigGridScalarDataAccess::RigGridScalarDataAccess(const RigGridBase* grid, size_t timeStepIndex, size_t scalarSetIndex) +{ + CVF_ASSERT(grid); + CVF_ASSERT(grid->mainGrid()); + CVF_ASSERT(grid->mainGrid()->results()); + + m_grid = grid; + + m_useGlobalActiveIndex = m_grid->mainGrid()->results()->isUsingGlobalActiveIndex(scalarSetIndex); + + std::vector< std::vector > & scalarSetResults = m_grid->mainGrid()->results()->cellScalarResults(scalarSetIndex); + CVF_ASSERT(timeStepIndex < scalarSetResults.size()); + + m_resultValues = &(scalarSetResults[timeStepIndex]); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RigGridScalarDataAccess::cellScalar(size_t i, size_t j, size_t k) const +{ + size_t cellIndex = m_grid->cellIndexFromIJK(i, j, k); + + return cellScalar(cellIndex); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RigGridScalarDataAccess::cellScalar(size_t cellIndex) const +{ + size_t resultValueIndex = cellIndex; + + if (m_useGlobalActiveIndex) + { + resultValueIndex = m_grid->cell(cellIndex).activeIndexInMatrixModel(); + if (resultValueIndex == cvf::UNDEFINED_SIZE_T) return HUGE_VAL; + } + + return m_resultValues->at(resultValueIndex); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RigGridScalarDataAccess::gridPointScalar(size_t i, size_t j, size_t k) const +{ + CVF_ASSERT(false); + return 0.0; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigGridScalarDataAccess::cellCornerScalars(size_t i, size_t j, size_t k, double scalars[8]) const +{ + CVF_ASSERT(false); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigGridScalarDataAccess::pointScalar(const cvf::Vec3d& p, double* scalarValue) const +{ + CVF_ASSERT(false); + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const cvf::Vec3d* RigGridScalarDataAccess::cellVector(size_t i, size_t j, size_t k) const +{ + CVF_ASSERT(false); + return new cvf::Vec3d(); +} diff --git a/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.h b/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.h new file mode 100644 index 0000000000..d80198b8e9 --- /dev/null +++ b/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.h @@ -0,0 +1,47 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library 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. +// +// This library 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 "cvfStructGridScalarDataAccess.h" +#include "RigGridBase.h" + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +class RigGridScalarDataAccess : public cvf::StructGridScalarDataAccess +{ +public: + RigGridScalarDataAccess(const RigGridBase* grid, size_t timeStepIndex, size_t scalarSetIndex); + + virtual double cellScalar(size_t i, size_t j, size_t k) const; + virtual double cellScalar(size_t cellIndex) const; + virtual void cellCornerScalars(size_t i, size_t j, size_t k, double scalars[8]) const; + virtual double gridPointScalar(size_t i, size_t j, size_t k) const; + virtual bool pointScalar(const cvf::Vec3d& p, double* scalarValue) const; + + virtual const cvf::Vec3d* cellVector(size_t i, size_t j, size_t k) const; + +private: + cvf::cref m_grid; + bool m_useGlobalActiveIndex; + std::vector* m_resultValues; +}; + diff --git a/CommonCode/cvfStructGrid.h b/CommonCode/cvfStructGrid.h index 4c179a8a35..a08e67e2f1 100644 --- a/CommonCode/cvfStructGrid.h +++ b/CommonCode/cvfStructGrid.h @@ -21,9 +21,7 @@ #include "cvfObject.h" #include "cvfVector3.h" -#include "cvfArray.h" -#include namespace cvf { @@ -72,7 +70,6 @@ public: virtual size_t cellIndexFromIJK(size_t i, size_t j, size_t k) const = 0; virtual bool ijkFromCellIndex(size_t cellIndex, size_t* i, size_t* j, size_t* k) const = 0; - // Ta med toleranse? virtual bool cellIJKFromCoordinate(const cvf::Vec3d& coord, size_t* i, size_t* j, size_t* k) const = 0; virtual void cellCornerVertices(size_t cellIndex, cvf::Vec3d vertices[8]) const = 0; @@ -83,24 +80,6 @@ public: virtual cvf::Vec3d gridPointCoordinate(size_t i, size_t j, size_t k) const = 0; - // Scalar results - virtual size_t scalarSetCount() const = 0; - virtual double cellScalar(size_t timeStepIndex, size_t scalarSetIndex, size_t i, size_t j, size_t k) const = 0; - virtual double cellScalar(size_t timeStepIndex, size_t scalarSetIndex, size_t cellIndex) const = 0; - virtual void cellCornerScalars(size_t timeStepIndex, size_t scalarSetIndex, size_t i, size_t j, size_t k, double scalars[8]) const = 0; - - // Trenger vi denne? Kan erstattes av cellCornerScalars for kuttplan - double gridPointScalar(size_t scalarSetIndex, size_t i, size_t j, size_t k) const; - bool pointScalar(size_t scalarSetIndex, const cvf::Vec3d& p, double* scalarValue) const; - - // Vector results - virtual size_t vectorSetCount() const = 0; - virtual const cvf::Vec3d* cellVector(size_t vectorSetIndex, size_t i, size_t j, size_t k) const = 0; - - //void filteredCellCenterResultVectors(Vec3dArray& positions, Vec3dArray& resultVectors, const double minPositionDistance, const double resultVectorLengthThreshold) const; - //void filteredCellCenterResultVectors(Vec3dArray& positions, Vec3dArray& resultVectors, uint vectorSetIndex, uint stride, const double resultVectorLengthThreshold) const; - - public: static void cellFaceVertexIndices(FaceType face, cvf::ubyte vertexIndices[4]); static FaceType oppositeFace(FaceType face); diff --git a/CommonCode/cvfStructGridGeometryGenerator.cpp b/CommonCode/cvfStructGridGeometryGenerator.cpp index 6cc88e6b6e..bd6f27a41b 100644 --- a/CommonCode/cvfStructGridGeometryGenerator.cpp +++ b/CommonCode/cvfStructGridGeometryGenerator.cpp @@ -18,8 +18,11 @@ //################################################################################################## #include "cvfBase.h" + #include "cvfStructGrid.h" #include "cvfStructGridGeometryGenerator.h" +#include "cvfStructGridScalarDataAccess.h" + #include "cvfDebugTimer.h" #include "cvfGeometryBuilderDrawableGeo.h" #include "cvfPrimitiveSetIndexedUInt.h" @@ -385,8 +388,10 @@ void StructGridGeometryGenerator::computeArrays() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void StructGridGeometryGenerator::textureCoordinates(Vec2fArray* textureCoords, size_t timeStepIndex, size_t scalarSetIndex, const ScalarMapper* mapper) const +void StructGridGeometryGenerator::textureCoordinates(Vec2fArray* textureCoords, const StructGridScalarDataAccess* dataAccessObject, const ScalarMapper* mapper) const { + if (!dataAccessObject) return; + size_t numVertices = m_quadsToGridCells.size()*4; textureCoords->resize(numVertices); @@ -398,7 +403,7 @@ void StructGridGeometryGenerator::textureCoordinates(Vec2fArray* textureCoords, #pragma omp parallel for private(texCoord, cellScalarValue) for (int i = 0; i < static_cast(m_quadsToGridCells.size()); i++) { - cellScalarValue = m_grid->cellScalar(timeStepIndex, scalarSetIndex, m_quadsToGridCells[i]); + cellScalarValue = dataAccessObject->cellScalar(m_quadsToGridCells[i]); texCoord = mapper->mapToTextureCoord(cellScalarValue); if (cellScalarValue == HUGE_VAL || cellScalarValue != cellScalarValue) // a != a is true for NAN's { diff --git a/CommonCode/cvfStructGridGeometryGenerator.h b/CommonCode/cvfStructGridGeometryGenerator.h index b718c1bbe1..f02880a11a 100644 --- a/CommonCode/cvfStructGridGeometryGenerator.h +++ b/CommonCode/cvfStructGridGeometryGenerator.h @@ -28,7 +28,7 @@ namespace cvf { class DrawableGeo; class ScalarMapper; - +class StructGridScalarDataAccess; //-------------------------------------------------------------------------------------------------- /// @@ -129,7 +129,7 @@ public: const StructGridInterface* activeGrid() { return m_grid.p(); } - void textureCoordinates(Vec2fArray* textureCoords, size_t timeStepIndex, size_t scalarSetIndex, const ScalarMapper* mapper) const; + void textureCoordinates(Vec2fArray* textureCoords, const StructGridScalarDataAccess* dataAccessObject, const ScalarMapper* mapper) const; // Mapping between cells and geometry ref > diff --git a/CommonCode/cvfStructGridScalarDataAccess.h b/CommonCode/cvfStructGridScalarDataAccess.h new file mode 100644 index 0000000000..226a821357 --- /dev/null +++ b/CommonCode/cvfStructGridScalarDataAccess.h @@ -0,0 +1,46 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2012 Ceetron AS +// +// This library 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. +// +// This library 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 "cvfVector3.h" + + +namespace cvf { + + +class StructGridScalarDataAccess : public Object +{ +public: + virtual double cellScalar(size_t i, size_t j, size_t k) const = 0; + virtual double cellScalar(size_t cellIndex) const = 0; + virtual void cellCornerScalars(size_t i, size_t j, size_t k, double scalars[8]) const = 0; + + // Trenger vi denne? Kan erstattes av cellCornerScalars for kuttplan + virtual double gridPointScalar(size_t i, size_t j, size_t k) const = 0; + virtual bool pointScalar(const cvf::Vec3d& p, double* scalarValue) const = 0; + + // Vector results + virtual const cvf::Vec3d* cellVector(size_t i, size_t j, size_t k) const = 0; +}; + + +} // namespace cvf