From 6cac031ffffc407b7eaf33b9a01f74a91575b712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Mon, 22 Apr 2013 09:13:37 +0200 Subject: [PATCH] Added well pipe visibility filter based on cell visibility. Only show pipes with wells with open connections in visible cells p4#: 21349 --- .../RivReservoirPipesPartMgr.cpp | 2 +- .../RivReservoirViewPartMgr.cpp | 51 ++-- .../RivReservoirViewPartMgr.h | 61 +++-- .../ModelVisualization/RivWellHeadPartMgr.cpp | 11 +- .../RivWellPipesPartMgr.cpp | 10 +- .../ProjectDataModel/RimReservoirView.cpp | 246 +++++++++--------- .../ProjectDataModel/RimReservoirView.h | 6 +- ApplicationCode/ProjectDataModel/RimWell.cpp | 73 ++++++ ApplicationCode/ProjectDataModel/RimWell.h | 2 + .../ProjectDataModel/RimWellCollection.cpp | 36 ++- .../ProjectDataModel/RimWellCollection.h | 18 +- 11 files changed, 304 insertions(+), 212 deletions(-) diff --git a/ApplicationCode/ModelVisualization/RivReservoirPipesPartMgr.cpp b/ApplicationCode/ModelVisualization/RivReservoirPipesPartMgr.cpp index d71b0a71cd..ddb5120560 100644 --- a/ApplicationCode/ModelVisualization/RivReservoirPipesPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivReservoirPipesPartMgr.cpp @@ -91,7 +91,7 @@ void RivReservoirPipesPartMgr::setScaleTransform(cvf::Transform * scaleTransform //-------------------------------------------------------------------------------------------------- void RivReservoirPipesPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicList* model, size_t frameIndex) { - if (m_reservoirView->wellCollection()->wellPipeVisibility() == RimWellCollection::FORCE_ALL_OFF) return; + if (m_reservoirView->wellCollection()->wellPipeVisibility() == RimWellCollection::PIPES_FORCE_ALL_OFF) return; if (m_reservoirView->wellCollection()->wells.size() != m_wellPipesPartMgrs.size()) { diff --git a/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.cpp b/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.cpp index 7f81bee176..3566c1bbc3 100644 --- a/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.cpp @@ -646,18 +646,8 @@ void RivReservoirViewPartMgr::computePropertyVisibility(cvf::UByteArray* cellVis //-------------------------------------------------------------------------------------------------- void RivReservoirViewPartMgr::updateCellColor(ReservoirGeometryCacheType geometryType, size_t timeStepIndex, cvf::Color4f color) { - if (geometryType == PROPERTY_FILTERED) - { - m_propFilteredGeometryFrames[timeStepIndex]->updateCellColor(color ); - } - else if (geometryType == PROPERTY_FILTERED_WELL_CELLS) - { - m_propFilteredWellGeometryFrames[timeStepIndex]->updateCellColor(color ); - } - else - { - m_geometries[geometryType].updateCellColor(color); - } + RivReservoirPartMgr * pmgr = reservoirPartManager( geometryType, timeStepIndex ); + pmgr->updateCellColor(color); } //-------------------------------------------------------------------------------------------------- @@ -676,35 +666,40 @@ void RivReservoirViewPartMgr::updateCellColor(ReservoirGeometryCacheType geometr //-------------------------------------------------------------------------------------------------- void RivReservoirViewPartMgr::updateCellResultColor(ReservoirGeometryCacheType geometryType, size_t timeStepIndex, RimResultSlot* cellResultSlot) { - if (geometryType == PROPERTY_FILTERED) - { - m_propFilteredGeometryFrames[timeStepIndex]->updateCellResultColor(timeStepIndex, cellResultSlot); - } - else if (geometryType == PROPERTY_FILTERED_WELL_CELLS) - { - m_propFilteredWellGeometryFrames[timeStepIndex]->updateCellResultColor(timeStepIndex, cellResultSlot); - } - else - { - m_geometries[geometryType].updateCellResultColor(timeStepIndex, cellResultSlot); - } + RivReservoirPartMgr * pmgr = reservoirPartManager( geometryType, timeStepIndex ); + pmgr->updateCellResultColor(timeStepIndex, cellResultSlot); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RivReservoirViewPartMgr::updateCellEdgeResultColor(ReservoirGeometryCacheType geometryType, size_t timeStepIndex, RimResultSlot* cellResultSlot, RimCellEdgeResultSlot* cellEdgeResultSlot) +{ + RivReservoirPartMgr * pmgr = reservoirPartManager( geometryType, timeStepIndex ); + pmgr->updateCellEdgeResultColor(timeStepIndex, cellResultSlot, cellEdgeResultSlot ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::cref RivReservoirViewPartMgr::cellVisibility(ReservoirGeometryCacheType geometryType, size_t gridIndex, size_t timeStepIndex) const +{ + RivReservoirPartMgr * pmgr = (const_cast(this))->reservoirPartManager( geometryType, timeStepIndex ); + return pmgr->cellVisibility(gridIndex).p(); +} + +RivReservoirPartMgr * RivReservoirViewPartMgr::reservoirPartManager(ReservoirGeometryCacheType geometryType, size_t timeStepIndex ) { if (geometryType == PROPERTY_FILTERED) { - m_propFilteredGeometryFrames[timeStepIndex]->updateCellEdgeResultColor( timeStepIndex, cellResultSlot, cellEdgeResultSlot ); + return m_propFilteredGeometryFrames[timeStepIndex].p(); } else if (geometryType == PROPERTY_FILTERED_WELL_CELLS) { - m_propFilteredWellGeometryFrames[timeStepIndex]->updateCellEdgeResultColor( timeStepIndex, cellResultSlot, cellEdgeResultSlot ); + return m_propFilteredWellGeometryFrames[timeStepIndex].p(); } else { - m_geometries[geometryType].updateCellEdgeResultColor(timeStepIndex, cellResultSlot, cellEdgeResultSlot ); + return &m_geometries[geometryType]; } -} +} \ No newline at end of file diff --git a/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.h b/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.h index fb4bb6420b..30f13ae0eb 100644 --- a/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.h +++ b/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.h @@ -19,7 +19,6 @@ #pragma once #include "RivReservoirPartMgr.h" #include "cvfTransform.h" -#include "RimReservoirView.h" #include "cafFixedArray.h" #include "cvfArray.h" #include "cafPdmObject.h" @@ -35,8 +34,8 @@ class RivReservoirViewPartMgr: public cvf::Object public: RivReservoirViewPartMgr(RimReservoirView * resv); - cvf::Transform* scaleTransform() { return m_scaleTransform.p();} - void setScaleTransform(cvf::Mat4d scale) { m_scaleTransform->setLocalTransform(scale);} + cvf::Transform* scaleTransform() { return m_scaleTransform.p();} + void setScaleTransform(cvf::Mat4d scale) { m_scaleTransform->setLocalTransform(scale);} enum ReservoirGeometryCacheType { @@ -54,49 +53,49 @@ public: PROPERTY_FILTERED_WELL_CELLS // Includes RANGE_FILTERED_WELL_CELLS and VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER and VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER }; - void clearGeometryCache(); - void scheduleGeometryRegen(ReservoirGeometryCacheType geometryType); + void clearGeometryCache(); + void scheduleGeometryRegen(ReservoirGeometryCacheType geometryType); + cvf::cref cellVisibility(ReservoirGeometryCacheType geometryType, size_t gridIndex, size_t frameIndex) const; - void appendStaticGeometryPartsToModel (cvf::ModelBasicList* model, ReservoirGeometryCacheType geometryType, const std::vector& gridIndices); - void appendDynamicGeometryPartsToModel(cvf::ModelBasicList* model, ReservoirGeometryCacheType geometryType, size_t frameIndex, const std::vector& gridIndices); + void appendStaticGeometryPartsToModel (cvf::ModelBasicList* model, ReservoirGeometryCacheType geometryType, const std::vector& gridIndices); + void appendDynamicGeometryPartsToModel(cvf::ModelBasicList* model, ReservoirGeometryCacheType geometryType, size_t frameIndex, const std::vector& gridIndices); - void updateCellColor (ReservoirGeometryCacheType geometryType, cvf::Color4f color); - void updateCellColor (ReservoirGeometryCacheType geometryType, size_t timeStepIndex, - cvf::Color4f color); - void updateCellResultColor (ReservoirGeometryCacheType geometryType, size_t timeStepIndex, - RimResultSlot* cellResultSlot); - void updateCellEdgeResultColor(ReservoirGeometryCacheType geometryType, size_t timeStepIndex, - RimResultSlot* cellResultSlot, RimCellEdgeResultSlot* cellEdgeResultSlot); + void updateCellColor (ReservoirGeometryCacheType geometryType, cvf::Color4f color); + void updateCellColor (ReservoirGeometryCacheType geometryType, size_t timeStepIndex, + cvf::Color4f color); + void updateCellResultColor (ReservoirGeometryCacheType geometryType, size_t timeStepIndex, + RimResultSlot* cellResultSlot); + void updateCellEdgeResultColor(ReservoirGeometryCacheType geometryType, size_t timeStepIndex, + RimResultSlot* cellResultSlot, RimCellEdgeResultSlot* cellEdgeResultSlot); private: - void createGeometry(ReservoirGeometryCacheType geometryType); - void computeVisibility(cvf::UByteArray* cellVisibility, ReservoirGeometryCacheType geometryType, RigGridBase* grid, size_t gridIdx); + void createGeometry(ReservoirGeometryCacheType geometryType); + void computeVisibility(cvf::UByteArray* cellVisibility, ReservoirGeometryCacheType geometryType, RigGridBase* grid, size_t gridIdx); - void createPropertyFilteredGeometry(size_t frameIndex); - void createPropertyFilteredWellGeometry(size_t frameIndex); + void createPropertyFilteredGeometry(size_t frameIndex); + void createPropertyFilteredWellGeometry(size_t frameIndex); - void clearGeometryCache(ReservoirGeometryCacheType geomType); + void clearGeometryCache(ReservoirGeometryCacheType geomType); - static void computeNativeVisibility (cvf::UByteArray* cellVisibilities, const RigGridBase* grid, const RigActiveCellInfo* activeCellInfo, const cvf::UByteArray* cellIsInWellStatuses, bool invalidCellsIsVisible, bool inactiveCellsIsVisible, bool activeCellsIsVisible, bool mainGridIsVisible); - static void computeRangeVisibility (cvf::UByteArray* cellVisibilities, const RigGridBase* grid, const cvf::UByteArray* nativeVisibility, const RimCellRangeFilterCollection* rangeFilterColl); - static void computePropertyVisibility(cvf::UByteArray* cellVisibilities, const RigGridBase* grid, size_t timeStepIndex, const cvf::UByteArray* rangeFilterVisibility, RimCellPropertyFilterCollection* propFilterColl); - static void copyByteArray(cvf::UByteArray* cellVisibilities, const cvf::UByteArray* cellIsWellStatuses ); + static void computeNativeVisibility (cvf::UByteArray* cellVisibilities, const RigGridBase* grid, const RigActiveCellInfo* activeCellInfo, const cvf::UByteArray* cellIsInWellStatuses, bool invalidCellsIsVisible, bool inactiveCellsIsVisible, bool activeCellsIsVisible, bool mainGridIsVisible); + static void computeRangeVisibility (cvf::UByteArray* cellVisibilities, const RigGridBase* grid, const cvf::UByteArray* nativeVisibility, const RimCellRangeFilterCollection* rangeFilterColl); + static void computePropertyVisibility(cvf::UByteArray* cellVisibilities, const RigGridBase* grid, size_t timeStepIndex, const cvf::UByteArray* rangeFilterVisibility, RimCellPropertyFilterCollection* propFilterColl); + static void copyByteArray(cvf::UByteArray* cellVisibilities, const cvf::UByteArray* cellIsWellStatuses ); + + RivReservoirPartMgr * reservoirPartManager(ReservoirGeometryCacheType geometryType, size_t timeStepIndex ); private: - caf::FixedArray m_geometries; - caf::FixedArray m_geometriesNeedsRegen; + caf::FixedArray m_geometriesNeedsRegen; cvf::Collection m_propFilteredGeometryFrames; - std::vector m_propFilteredGeometryFramesNeedsRegen; + std::vector m_propFilteredGeometryFramesNeedsRegen; cvf::Collection m_propFilteredWellGeometryFrames; - std::vector m_propFilteredWellGeometryFramesNeedsRegen; + std::vector m_propFilteredWellGeometryFramesNeedsRegen; - - - cvf::ref m_scaleTransform; - caf::PdmPointer m_reservoirView; + cvf::ref m_scaleTransform; + caf::PdmPointer m_reservoirView; }; diff --git a/ApplicationCode/ModelVisualization/RivWellHeadPartMgr.cpp b/ApplicationCode/ModelVisualization/RivWellHeadPartMgr.cpp index 39a76dfab5..bc8275d664 100644 --- a/ApplicationCode/ModelVisualization/RivWellHeadPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivWellHeadPartMgr.cpp @@ -267,17 +267,10 @@ void RivWellHeadPartMgr::buildWellHeadParts(size_t frameIndex) //-------------------------------------------------------------------------------------------------- void RivWellHeadPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicList* model, size_t frameIndex) { + if (m_rimWell.isNull()) return; if (m_rimReservoirView.isNull()) return; - if (m_rimWell.isNull() || m_rimWell->wellResults() == NULL) return; - - if ( m_rimReservoirView->wellCollection()->wellPipeVisibility() != RimWellCollection::FORCE_ALL_ON - && m_rimWell->showWellPipes() == false) return; - if (m_rimReservoirView->wellCollection()->showWellHead() == false) return; - - if ( m_rimWell->wellResults()->firstResultTimeStep() == cvf::UNDEFINED_SIZE_T - || frameIndex < m_rimWell->wellResults()->firstResultTimeStep() ) - return; + if (!m_rimWell->isWellVisible(frameIndex)) return; buildWellHeadParts(frameIndex); diff --git a/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp b/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp index 7d82f2f717..8f4ebdd9e9 100644 --- a/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp @@ -325,14 +325,8 @@ void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector void RivWellPipesPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicList* model, size_t frameIndex) { if (m_rimReservoirView.isNull()) return; - if (m_rimWell.isNull() || m_rimWell->wellResults() == NULL) return; - - if ( m_rimReservoirView->wellCollection()->wellPipeVisibility() != RimWellCollection::FORCE_ALL_ON - && m_rimWell->showWellPipes() == false) return; - - if ( m_rimWell->wellResults()->firstResultTimeStep() == cvf::UNDEFINED_SIZE_T - || frameIndex < m_rimWell->wellResults()->firstResultTimeStep() ) - return; + if (m_rimWell.isNull()) return; + if (!m_rimWell->isWellVisible(frameIndex)) return; if (m_needsTransformUpdate) buildWellPipeParts(); diff --git a/ApplicationCode/ProjectDataModel/RimReservoirView.cpp b/ApplicationCode/ProjectDataModel/RimReservoirView.cpp index 1999524bb6..156bf9684b 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirView.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirView.cpp @@ -457,146 +457,155 @@ void RimReservoirView::createDisplayModel() // static int callCount = 0; // qDebug() << "RimReservoirView::createDisplayModel()" << callCount++; - if (m_reservoir && m_reservoir->reservoirData()) + if (!(m_reservoir && m_reservoir->reservoirData())) return; + + // Define a vector containing time step indices to produce geometry for. + // First entry in this vector is used to define the geometry only result mode with no results. + std::vector timeStepIndices; + + // The one and only geometry entry + timeStepIndices.push_back(0); + + // Find the number of time frames the animation needs to show the requested data. + + if (this->cellResult()->hasDynamicResult() + || this->propertyFilterCollection()->hasActiveDynamicFilters() + || this->wellCollection->hasVisibleWellPipes()) { - // Define a vector containing time step indices to produce geometry for. - // First entry in this vector is used to define the geometry only result mode with no results. - std::vector timeStepIndices; + CVF_ASSERT(currentGridCellResults()); - // The one and only geometry entry + size_t i; + for (i = 0; i < currentGridCellResults()->cellResults()->maxTimeStepCount(); i++) + { + timeStepIndices.push_back(i); + } + } + else if (this->cellResult()->hasStaticResult() + || this->cellEdgeResult()->hasResult() + || this->propertyFilterCollection()->hasActiveFilters()) + { + // The one and only result entry timeStepIndices.push_back(0); + } - // Find the number of time frames the animation needs to show the requested data. + updateLegends(); - if (this->cellResult()->hasDynamicResult() - || this->propertyFilterCollection()->hasActiveDynamicFilters() - || this->wellCollection->hasVisibleWellPipes()) + cvf::Collection frameModels; + size_t timeIdx; + for (timeIdx = 0; timeIdx < timeStepIndices.size(); timeIdx++) + { + frameModels.push_back(new cvf::ModelBasicList); + } + + // Remove all existing animation frames from the viewer. + // The parts are still cached in the RivReservoir geometry and friends + + bool isAnimationActive = m_viewer->isAnimationActive(); + m_viewer->removeAllFrames(); + + + // Create vector of grid indices to render + std::vector gridIndices; + this->indicesToVisibleGrids(&gridIndices); + + /// + // Get or create the parts for "static" type geometry. The same geometry is used + // for the different frames. updateCurrentTimeStep updates the colors etc. + // For property filtered geometry : just set all the models as empty scenes + // updateCurrentTimeStep requests the actual parts + + if (! this->propertyFilterCollection()->hasActiveFilters()) + { + std::vector geometryTypesToAdd; + + if (this->rangeFilterCollection()->hasActiveFilters() || this->wellCollection()->hasVisibleWellCells()) { - CVF_ASSERT(currentGridCellResults()); - - size_t i; - for (i = 0; i < currentGridCellResults()->cellResults()->maxTimeStepCount(); i++) + geometryTypesToAdd.push_back(RivReservoirViewPartMgr::RANGE_FILTERED); + geometryTypesToAdd.push_back(RivReservoirViewPartMgr::RANGE_FILTERED_WELL_CELLS); + geometryTypesToAdd.push_back(RivReservoirViewPartMgr::VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER); + geometryTypesToAdd.push_back(RivReservoirViewPartMgr::VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER); + if (this->showInactiveCells()) { - timeStepIndices.push_back(i); + geometryTypesToAdd.push_back(RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE); } - } - else if (this->cellResult()->hasStaticResult() - || this->cellEdgeResult()->hasResult() - || this->propertyFilterCollection()->hasActiveFilters()) - { - // The one and only result entry - timeStepIndices.push_back(0); } - - updateLegends(); - - cvf::Collection frameModels; - size_t timeIdx; - for (timeIdx = 0; timeIdx < timeStepIndices.size(); timeIdx++) + else { - frameModels.push_back(new cvf::ModelBasicList); - } + geometryTypesToAdd.push_back(RivReservoirViewPartMgr::ALL_WELL_CELLS); // Should be all well cells + geometryTypesToAdd.push_back(RivReservoirViewPartMgr::ACTIVE); - // Remove all existing animation frames from the viewer. - // The parts are still cached in the RivReservoir geometry and friends - - bool isAnimationActive = m_viewer->isAnimationActive(); - m_viewer->removeAllFrames(); - - - // Create vector of grid indices to render - std::vector gridIndices; - this->indicesToVisibleGrids(&gridIndices); - - /// - // Get or create the parts for "static" type geometry. The same geometry is used - // for the different frames. updateCurrentTimeStep updates the colors etc. - // For property filtered geometry : just set all the models as empty scenes - // updateCurrentTimeStep requests the actual parts - - if (! this->propertyFilterCollection()->hasActiveFilters()) - { - size_t frameIdx; - for (frameIdx = 0; frameIdx < frameModels.size(); ++frameIdx) + if (this->showInactiveCells()) { - - if (this->rangeFilterCollection()->hasActiveFilters() || this->wellCollection()->hasVisibleWellCells()) - { - m_reservoirGridPartManager->appendStaticGeometryPartsToModel(frameModels[frameIdx].p(), RivReservoirViewPartMgr::VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER, gridIndices); // Should be visible well cells outside range filter - m_reservoirGridPartManager->appendStaticGeometryPartsToModel(frameModels[frameIdx].p(), RivReservoirViewPartMgr::VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER, gridIndices); // Should be visible well cells outside range filter - m_reservoirGridPartManager->appendStaticGeometryPartsToModel(frameModels[frameIdx].p(), RivReservoirViewPartMgr::RANGE_FILTERED_WELL_CELLS, gridIndices); - m_reservoirGridPartManager->appendStaticGeometryPartsToModel(frameModels[frameIdx].p(), RivReservoirViewPartMgr::RANGE_FILTERED, gridIndices); - if (this->showInactiveCells()) - { - m_reservoirGridPartManager->appendStaticGeometryPartsToModel(frameModels[frameIdx].p(), RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE, gridIndices); - } - } - else - { - m_reservoirGridPartManager->appendStaticGeometryPartsToModel(frameModels[frameIdx].p(), RivReservoirViewPartMgr::ALL_WELL_CELLS, gridIndices); // Should be all well cells - m_reservoirGridPartManager->appendStaticGeometryPartsToModel(frameModels[frameIdx].p(), RivReservoirViewPartMgr::ACTIVE, gridIndices); - - if (this->showInactiveCells()) - { - m_reservoirGridPartManager->appendStaticGeometryPartsToModel(frameModels[frameIdx].p(), RivReservoirViewPartMgr::INACTIVE, gridIndices); - } - } - - // Set static colors - this->updateStaticCellColors(); + geometryTypesToAdd.push_back(RivReservoirViewPartMgr::INACTIVE); } } - - // Compute triangle count, Debug only - - if (false) + + size_t frameIdx; + for (frameIdx = 0; frameIdx < frameModels.size(); ++frameIdx) { - size_t totalTriangleCount = 0; + for (size_t gtIdx = 0; gtIdx < geometryTypesToAdd.size(); ++gtIdx) { - size_t mIdx; - for (mIdx = 0; mIdx < frameModels.size(); mIdx++) - { - cvf::Collection partCollection; - frameModels.at(mIdx)->allParts(&partCollection); - - size_t modelTriangleCount = 0; - size_t pIdx; - for (pIdx = 0; pIdx < partCollection.size(); pIdx++) - { - modelTriangleCount += partCollection.at(pIdx)->drawable()->triangleCount(); - } - - totalTriangleCount += modelTriangleCount; - } + m_reservoirGridPartManager->appendStaticGeometryPartsToModel(frameModels[frameIdx].p(), geometryTypesToAdd[gtIdx], gridIndices); } } - // Create Scenes from the frameModels - // Animation frames for results display, starts from frame 1 + // Set static colors + this->updateStaticCellColors(); - size_t frameIndex; - for (frameIndex = 0; frameIndex < frameModels.size(); frameIndex++) + m_visibleGridParts = geometryTypesToAdd; + } + + + // Compute triangle count, Debug only + + if (false) + { + size_t totalTriangleCount = 0; { - cvf::ModelBasicList* model = frameModels.at(frameIndex); - model->updateBoundingBoxesRecursive(); + size_t mIdx; + for (mIdx = 0; mIdx < frameModels.size(); mIdx++) + { + cvf::Collection partCollection; + frameModels.at(mIdx)->allParts(&partCollection); - cvf::ref scene = new cvf::Scene; - scene->addModel(model); + size_t modelTriangleCount = 0; + size_t pIdx; + for (pIdx = 0; pIdx < partCollection.size(); pIdx++) + { + modelTriangleCount += partCollection.at(pIdx)->drawable()->triangleCount(); + } - if (frameIndex == 0) - m_viewer->setMainScene(scene.p()); - else - m_viewer->addFrame(scene.p()); - } - - // If the animation was active before recreating everything, make viewer view current frame - - if (isAnimationActive) - { - m_viewer->slotSetCurrentFrame(m_currentTimeStep); + totalTriangleCount += modelTriangleCount; + } } } + + // Create Scenes from the frameModels + // Animation frames for results display, starts from frame 1 + + size_t frameIndex; + for (frameIndex = 0; frameIndex < frameModels.size(); frameIndex++) + { + cvf::ModelBasicList* model = frameModels.at(frameIndex); + model->updateBoundingBoxesRecursive(); + + cvf::ref scene = new cvf::Scene; + scene->addModel(model); + + if (frameIndex == 0) + m_viewer->setMainScene(scene.p()); + else + m_viewer->addFrame(scene.p()); + } + + // If the animation was active before recreating everything, make viewer view current frame + + if (isAnimationActive) + { + m_viewer->slotSetCurrentFrame(m_currentTimeStep); + } + } @@ -636,6 +645,8 @@ void RimReservoirView::updateCurrentTimeStep() frameScene->addModel(frameParts.p()); } } + + m_visibleGridParts = geometriesToRecolor; } else if (rangeFilterCollection->hasActiveFilters() || this->wellCollection()->hasVisibleWellCells()) { @@ -650,9 +661,10 @@ void RimReservoirView::updateCurrentTimeStep() geometriesToRecolor.push_back(RivReservoirViewPartMgr::ALL_WELL_CELLS); } + + for (size_t i = 0; i < geometriesToRecolor.size(); ++i) { - if (this->animationMode() && this->cellEdgeResult()->hasResult()) { m_reservoirGridPartManager->updateCellEdgeResultColor(geometriesToRecolor[i], m_currentTimeStep, this->cellResult(), this->cellEdgeResult()); @@ -1210,7 +1222,7 @@ void RimReservoirView::calculateVisibleWellCellsIncFence(cvf::UByteArray* visibl visibleCells->setAll(false); // If all wells are forced off, return - if (this->wellCollection()->wellCellVisibility() == RimWellCollection::FORCE_ALL_OFF) return; + if (this->wellCollection()->wellCellsToRangeFilterMode() == RimWellCollection::RANGE_ADD_NONE) return; RigActiveCellInfo* activeCellInfo = this->currentActiveCellInfo(); @@ -1220,7 +1232,7 @@ void RimReservoirView::calculateVisibleWellCellsIncFence(cvf::UByteArray* visibl for (size_t wIdx = 0; wIdx < this->wellCollection()->wells().size(); ++wIdx) { RimWell* well = this->wellCollection()->wells()[wIdx]; - if (this->wellCollection()->wellCellVisibility() == RimWellCollection::FORCE_ALL_ON || well->showWellCells()) + if (this->wellCollection()->wellCellsToRangeFilterMode() == RimWellCollection::RANGE_ADD_ALL || well->showWellCells()) { RigSingleWellResultsData* wres = well->wellResults(); if (!wres) continue; diff --git a/ApplicationCode/ProjectDataModel/RimReservoirView.h b/ApplicationCode/ProjectDataModel/RimReservoirView.h index 2889fdaf2e..a747025f1a 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirView.h +++ b/ApplicationCode/ProjectDataModel/RimReservoirView.h @@ -42,7 +42,6 @@ class RiuViewer; class RigGridBase; class RigGridCellFaceVisibilityFilter; -class RivReservoirViewPartMgr; namespace cvf { @@ -157,6 +156,9 @@ public: void schedulePipeGeometryRegen(); void updateDisplayModelForWellResults(); + const std::vector& + visibleGridParts() const { return m_visibleGridParts;} + cvf::cref reservoirGridPartManager() const { return m_reservoirGridPartManager.p(); } // Display model generation private: @@ -190,5 +192,7 @@ private: caf::PdmField m_currentTimeStep; QPointer m_viewer; caf::PdmPointer m_reservoir; + + std::vector m_visibleGridParts; }; diff --git a/ApplicationCode/ProjectDataModel/RimWell.cpp b/ApplicationCode/ProjectDataModel/RimWell.cpp index b6b40828e0..db22cfc6ae 100644 --- a/ApplicationCode/ProjectDataModel/RimWell.cpp +++ b/ApplicationCode/ProjectDataModel/RimWell.cpp @@ -131,3 +131,76 @@ caf::PdmFieldHandle* RimWell::objectToggleField() return &showWellPipes; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimWell::isWellVisible(size_t frameIndex) +{ + if (m_reservoirView == NULL) return false; + if (this->wellResults() == NULL) return false; + + if ( this->wellResults()->firstResultTimeStep() == cvf::UNDEFINED_SIZE_T + || frameIndex < this->wellResults()->firstResultTimeStep() + || frameIndex >= this->wellResults()->m_wellCellsTimeSteps.size()) + return false; + + if (m_reservoirView->wellCollection()->wellPipeVisibility() == RimWellCollection::PIPES_FORCE_ALL_ON) + return true; + + if (m_reservoirView->wellCollection()->wellPipeVisibility() == RimWellCollection::PIPES_FORCE_ALL_OFF) + return false; + + if ( this->showWellPipes() == false ) + return false; + + if (m_reservoirView->wellCollection()->wellPipeVisibility() == RimWellCollection::PIPES_INDIVIDUALLY) + return true; + + if (m_reservoirView->wellCollection()->wellPipeVisibility() == RimWellCollection::PIPES_OPEN_IN_VISIBLE_CELLS) + { + const std::vector& visGridParts = m_reservoirView->visibleGridParts(); + cvf::cref rvMan = m_reservoirView->reservoirGridPartManager(); + + for (size_t gpIdx = 0; gpIdx < visGridParts.size(); ++gpIdx) + { + const RigWellResultFrame& wrsf = this->wellResults()->wellResultFrame(frameIndex); + + // First check the wellhead: + + size_t gridIndex = wrsf.m_wellHead.m_gridIndex; + size_t gridCellIndex = wrsf.m_wellHead.m_gridCellIndex; + + cvf::cref cellVisibility = rvMan->cellVisibility(visGridParts[gpIdx], gridIndex, frameIndex); + if ((*cellVisibility)[gridCellIndex]) + { + return true; + } + + // Then check the rest of the well, with all the branches + + const std::vector& wellResSegments = wrsf.m_wellResultBranches; + for (size_t wsIdx = 0; wsIdx < wellResSegments.size(); ++wsIdx) + { + const std::vector& wsResCells = wellResSegments[wsIdx].m_wellCells; + for (size_t cIdx = 0; cIdx < wsResCells.size(); ++ cIdx) + { + gridIndex = wsResCells[cIdx].m_gridIndex; + gridCellIndex = wsResCells[cIdx].m_gridCellIndex; + + cvf::cref cellVisibility = rvMan->cellVisibility(visGridParts[gpIdx], gridIndex, frameIndex); + if ((*cellVisibility)[gridCellIndex]) + { + return true; + } + } + } + } + + return false; + } + + CVF_ASSERT(false); // Never end here. have you added new pipe visibility modes ? + + return false; +} + diff --git a/ApplicationCode/ProjectDataModel/RimWell.h b/ApplicationCode/ProjectDataModel/RimWell.h index 0c48a76df2..91436af66b 100644 --- a/ApplicationCode/ProjectDataModel/RimWell.h +++ b/ApplicationCode/ProjectDataModel/RimWell.h @@ -44,6 +44,8 @@ public: void setWellResults(RigSingleWellResultsData* wellResults) { m_wellResults = wellResults;} RigSingleWellResultsData* wellResults() { return m_wellResults.p(); } + bool isWellVisible(size_t frameIndex); + virtual caf::PdmFieldHandle* userDescriptionField(); virtual caf::PdmFieldHandle* objectToggleField(); diff --git a/ApplicationCode/ProjectDataModel/RimWellCollection.cpp b/ApplicationCode/ProjectDataModel/RimWellCollection.cpp index d1fd3f5ba0..80fd285645 100644 --- a/ApplicationCode/ProjectDataModel/RimWellCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellCollection.cpp @@ -32,10 +32,22 @@ namespace caf template<> void RimWellCollection::WellVisibilityEnum::setUp() { - addItem(RimWellCollection::FORCE_ALL_OFF, "FORCE_ALL_OFF", "Off"); - addItem(RimWellCollection::ALL_ON, "ALL_ON", "Individual"); - //addItem(RimWellCollection::RANGE_INTERSECTING, "RANGE_INTERSECTING", "Intersecting range filter only"); - addItem(RimWellCollection::FORCE_ALL_ON, "FORCE_ALL_ON", "On"); + addItem(RimWellCollection::PIPES_FORCE_ALL_OFF, "FORCE_ALL_OFF", "All Off"); + addItem(RimWellCollection::PIPES_INDIVIDUALLY, "ALL_ON", "Individual"); + addItem(RimWellCollection::PIPES_OPEN_IN_VISIBLE_CELLS,"OPEN_IN_VISIBLE_CELLS", "Visible cells filtered"); + addItem(RimWellCollection::PIPES_FORCE_ALL_ON, "FORCE_ALL_ON", "All On"); + } +} + + +namespace caf +{ + template<> + void RimWellCollection::WellCellsRangeFilterEnum::setUp() + { + addItem(RimWellCollection::RANGE_ADD_NONE, "FORCE_ALL_OFF", "Off"); + addItem(RimWellCollection::RANGE_ADD_INDIVIDUAL, "ALL_ON", "Individually"); + addItem(RimWellCollection::RANGE_ADD_ALL, "FORCE_ALL_ON", "On"); } } @@ -65,13 +77,13 @@ RimWellCollection::RimWellCollection() CAF_PDM_InitField(&showWellLabel, "ShowWellLabel", true, " Show well labels", "", "", ""); CAF_PDM_InitField(&wellHeadScaleFactor, "WellHeadScale", 1.0, " Well head scale", "", "", ""); - CAF_PDM_InitField(&wellPipeVisibility, "GlobalWellPipeVisibility", WellVisibilityEnum(ALL_ON), "Global well pipe visibility", "", "", ""); + CAF_PDM_InitField(&wellPipeVisibility, "GlobalWellPipeVisibility", WellVisibilityEnum(PIPES_INDIVIDUALLY), "Global well pipe visibility", "", "", ""); CAF_PDM_InitField(&pipeRadiusScaleFactor, "WellPipeRadiusScale", 0.1, " Pipe radius scale", "", "", ""); CAF_PDM_InitField(&pipeCrossSectionVertexCount, "WellPipeVertexCount", 12, "Pipe vertex count", "", "", ""); pipeCrossSectionVertexCount.setUiHidden(true); - CAF_PDM_InitField(&wellCellVisibility, "GlobalWellCellVisibility", WellVisibilityEnum(FORCE_ALL_OFF), "Add cells to range filter", "", "", ""); + CAF_PDM_InitField(&wellCellsToRangeFilterMode, "GlobalWellCellVisibility", WellCellsRangeFilterEnum(RANGE_ADD_NONE), "Add cells to range filter", "", "", ""); CAF_PDM_InitField(&showWellCellFences, "ShowWellFences", false, " Use well fence", "", "", ""); CAF_PDM_InitField(&wellCellFenceType, "DefaultWellFenceDirection", WellFenceEnum(K_DIRECTION), " Well Fence direction", "", "", ""); @@ -112,14 +124,14 @@ RimWell* RimWellCollection::findWell(QString name) //-------------------------------------------------------------------------------------------------- bool RimWellCollection::hasVisibleWellCells() { - if (this->wellCellVisibility() == FORCE_ALL_OFF) return false; + if (this->wellCellsToRangeFilterMode() == RANGE_ADD_NONE) return false; if (this->wells().size() == 0 ) return false; bool hasCells = false; for (size_t i = 0 ; !hasCells && i < this->wells().size(); ++i) { RimWell* well = this->wells()[i]; - if ( well && well->wellResults() && (well->showWellCells() || this->wellCellVisibility() == FORCE_ALL_ON) ) + if ( well && well->wellResults() && (well->showWellCells() || this->wellCellsToRangeFilterMode() == RANGE_ADD_ALL) ) { for (size_t tIdx = 0; !hasCells && tIdx < well->wellResults()->m_wellCellsTimeSteps.size(); ++tIdx ) { @@ -134,7 +146,7 @@ bool RimWellCollection::hasVisibleWellCells() if (!hasCells) return false; - if (this->wellCellVisibility() == ALL_ON || this->wellCellVisibility() == FORCE_ALL_ON) return true; + if (this->wellCellsToRangeFilterMode() == RANGE_ADD_INDIVIDUAL || this->wellCellsToRangeFilterMode() == RANGE_ADD_ALL) return true; // Todo: Handle range filter intersection @@ -146,9 +158,9 @@ bool RimWellCollection::hasVisibleWellCells() //-------------------------------------------------------------------------------------------------- bool RimWellCollection::hasVisibleWellPipes() { - if (this->wellPipeVisibility() == FORCE_ALL_OFF) return false; + if (this->wellPipeVisibility() == PIPES_FORCE_ALL_OFF) return false; if (this->wells().size() == 0 ) return false; - if (this->wellPipeVisibility() == FORCE_ALL_ON) return true; + if (this->wellPipeVisibility() == PIPES_FORCE_ALL_ON) return true; return true; } @@ -166,7 +178,7 @@ void RimWellCollection::fieldChangedByUi(const caf::PdmFieldHandle* changedField m_reservoirView->createDisplayModelAndRedraw(); } } - if (&wellCellVisibility == changedField) + if (&wellCellsToRangeFilterMode == changedField) { if (m_reservoirView) { diff --git a/ApplicationCode/ProjectDataModel/RimWellCollection.h b/ApplicationCode/ProjectDataModel/RimWellCollection.h index 5f9c04f192..f7254a4825 100644 --- a/ApplicationCode/ProjectDataModel/RimWellCollection.h +++ b/ApplicationCode/ProjectDataModel/RimWellCollection.h @@ -44,13 +44,21 @@ public: enum WellVisibilityType { - FORCE_ALL_OFF, - ALL_ON, - RANGE_INTERSECTING, - FORCE_ALL_ON + PIPES_FORCE_ALL_OFF, + PIPES_INDIVIDUALLY, + PIPES_OPEN_IN_VISIBLE_CELLS, + PIPES_FORCE_ALL_ON }; typedef caf::AppEnum WellVisibilityEnum; + enum WellCellsRangeFilterType + { + RANGE_ADD_ALL, + RANGE_ADD_INDIVIDUAL, + RANGE_ADD_NONE + }; + typedef caf::AppEnum WellCellsRangeFilterEnum; + enum WellFenceType { K_DIRECTION, @@ -61,7 +69,7 @@ public: caf::PdmField showWellLabel; - caf::PdmField wellCellVisibility; + caf::PdmField wellCellsToRangeFilterMode; caf::PdmField showWellCellFences; caf::PdmField wellCellFenceType; caf::PdmField wellCellTransparencyLevel;