diff --git a/ApplicationCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.cpp b/ApplicationCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.cpp index f8e9994d23..68628f510b 100644 --- a/ApplicationCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.cpp +++ b/ApplicationCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.cpp @@ -71,3 +71,95 @@ void RivFemElmVisibilityCalculator::computeRangeVisibility(cvf::UByteArray* elmV +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivFemElmVisibilityCalculator::computePropertyVisibility(cvf::UByteArray* cellVisibility, + const RigFemPart* grid, + int timeStepIndex, + const cvf::UByteArray* rangeFilterVisibility, + RimGeoMechPropertyFilterCollection* propFilterColl) +{ +#if 0 + CVF_ASSERT(cellVisibility != NULL); + CVF_ASSERT(rangeFilterVisibility != NULL); + CVF_ASSERT(propFilterColl != NULL); + + CVF_ASSERT(grid->elementCount() > 0); + CVF_ASSERT(rangeFilterVisibility->size() == grid->elementCount()); + + // Copy if not equal + if (cellVisibility != rangeFilterVisibility ) (*cellVisibility) = *rangeFilterVisibility; + const int elementCount = grid->elementCount(); + + if (propFilterColl->hasActiveFilters()) + { + for (size_t i = 0; i < propFilterColl->propertyFilters().size(); i++) + { + RimCellPropertyFilter* propertyFilter = propFilterColl->propertyFilters()[i]; + + if (propertyFilter->isActive() && propertyFilter->resultDefinition->hasResult()) + { + const double lowerBound = propertyFilter->lowerBound(); + const double upperBound = propertyFilter->upperBound(); + + RigFemResultAddress resVarAddress = propertyFilter->resultDefinition->resulAddress(); + + size_t adjustedTimeStepIndex = timeStepIndex; + + // Set time step to zero for static results + if (propertyFilter->resultDefinition()->hasStaticResult()) + { + adjustedTimeStepIndex = 0; + } + + const RimCellFilter::FilterModeType filterType = propertyFilter->filterMode(); + + RigGeoMechCaseData* caseData = propFilterColl->reservoirView()->geoMechCase()->geoMechCaseData(); + + const std::vector& resVals = caseData->femPartResults()->resultValues(resVarAddress, grid->elementPartId(), timeStepIndex); + //#pragma omp parallel for schedule(dynamic) + for (int cellIndex = 0; cellIndex < elementCount; cellIndex++) + { + if ( (*cellVisibility)[cellIndex] ) + { + RigElementType eType = grid->elementType(cellIndex); + int elmNodeCount = RigFemTypes::elmentNodeCount(eType); + + const int* elmNodeIndices = grid->connectivities(cellIndex); + for(int enIdx = 0; enIdx < elmNodeCount; ++enIdx) + { + size_t resultValueIndex = cvf::UNDEFINED_SIZE_T; + if (resVarAddress.resultPosType == RIG_NODAL) + { + resultValueIndex = elmNodeIndices[enIdx]; + } + else + { + resultValueIndex = grid->elementNodeResultIdx(cellIndex, enIdx); + } + + double scalarValue = resVals[resultValueIndex]; + if (lowerBound <= scalarValue && scalarValue <= upperBound) + { + if (filterType == RimCellFilter::EXCLUDE) + { + (*cellVisibility)[cellIndex] = false; + } + } + else + { + if (filterType == RimCellFilter::INCLUDE) + { + (*cellVisibility)[cellIndex] = false; + } + } + } + } + } + } + } + } +#endif +} + diff --git a/ApplicationCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.h b/ApplicationCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.h index 133fa75483..defd9f4f4f 100644 --- a/ApplicationCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.h +++ b/ApplicationCode/GeoMech/GeoMechVisualization/RivFemElmVisibilityCalculator.h @@ -27,14 +27,20 @@ namespace cvf } class RigFemPart; - +class RimGeoMechPropertyFilterCollection; class RivFemElmVisibilityCalculator { public: static void computeAllVisible(cvf::UByteArray* elmVisibilities, const RigFemPart* femPart ); - static void computeRangeVisibility(cvf::UByteArray* elmVisibilities, RigFemPart* femPart, const cvf::CellRangeFilter& rangeFilter); + static void computeRangeVisibility(cvf::UByteArray* elmVisibilities, RigFemPart* femPart, + const cvf::CellRangeFilter& rangeFilter); + static void computePropertyVisibility(cvf::UByteArray* cellVisibility, + const RigFemPart* grid, + int timeStepIndex, + const cvf::UByteArray* rangeFilterVisibility, + RimGeoMechPropertyFilterCollection* propFilterColl); }; diff --git a/ApplicationCode/ModelVisualization/RivGeoMechPartMgrCache.cpp b/ApplicationCode/ModelVisualization/RivGeoMechPartMgrCache.cpp index 80b10cef3a..8306b2cc19 100644 --- a/ApplicationCode/ModelVisualization/RivGeoMechPartMgrCache.cpp +++ b/ApplicationCode/ModelVisualization/RivGeoMechPartMgrCache.cpp @@ -21,9 +21,17 @@ RivGeoMechPartMgrCache::~RivGeoMechPartMgrCache() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RivGeoMechPartMgrCache::needsRegeneration(const Key& key) +bool RivGeoMechPartMgrCache::isNeedingRegeneration(const Key& key) const { - return m_partMgrs[key].needsRegen; + std::map::const_iterator ceIt = m_partMgrs.find(key); + if (ceIt != m_partMgrs.end()) + { + return ceIt->second.needsRegen; + } + else + { + return true; + } } //-------------------------------------------------------------------------------------------------- @@ -31,13 +39,17 @@ bool RivGeoMechPartMgrCache::needsRegeneration(const Key& key) //-------------------------------------------------------------------------------------------------- void RivGeoMechPartMgrCache::scheduleRegeneration(const Key& key) { - m_partMgrs[key].needsRegen = true; + std::map::iterator ceIt = m_partMgrs.find(key); + if (ceIt != m_partMgrs.end()) + { + ceIt->second.needsRegen = true; + } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RivGeoMechPartMgrCache::generationFinished(const Key& key) +void RivGeoMechPartMgrCache::setGenerationFinished(const Key& key) { m_partMgrs[key].needsRegen = false; } @@ -57,7 +69,6 @@ RivGeoMechPartMgr* RivGeoMechPartMgrCache::partMgr(const Key& key) } - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ModelVisualization/RivGeoMechPartMgrCache.h b/ApplicationCode/ModelVisualization/RivGeoMechPartMgrCache.h index e55e5af8bc..2089a38640 100644 --- a/ApplicationCode/ModelVisualization/RivGeoMechPartMgrCache.h +++ b/ApplicationCode/ModelVisualization/RivGeoMechPartMgrCache.h @@ -5,6 +5,7 @@ #include "RivCellSetEnum.h" class RivGeoMechPartMgr; +class RivGeoMechPartMgrGeneratorInterface; class RivGeoMechPartMgrCache : public cvf::Object { @@ -31,9 +32,9 @@ public: unsigned short m_geometryType; }; - bool needsRegeneration (const Key& key); + bool isNeedingRegeneration(const Key& key) const; void scheduleRegeneration (const Key& key); - void generationFinished (const Key& key); + void setGenerationFinished(const Key& key); RivGeoMechPartMgr* partMgr (const Key& key); private: diff --git a/ApplicationCode/ModelVisualization/RivGeoMechVizLogic.cpp b/ApplicationCode/ModelVisualization/RivGeoMechVizLogic.cpp index 4b9558fc1a..b9756f4393 100644 --- a/ApplicationCode/ModelVisualization/RivGeoMechVizLogic.cpp +++ b/ApplicationCode/ModelVisualization/RivGeoMechVizLogic.cpp @@ -32,6 +32,7 @@ #include "RivCellSetEnum.h" #include "RivFemElmVisibilityCalculator.h" +#include "RigFemPartResultsCollection.h" //-------------------------------------------------------------------------------------------------- /// @@ -57,70 +58,49 @@ RivGeoMechVizLogic::~RivGeoMechVizLogic() //-------------------------------------------------------------------------------------------------- void RivGeoMechVizLogic::appendNoAnimPartsToModel(cvf::ModelBasicList* model) { - RivGeoMechPartMgrCache::Key pMgrKey = currentPartMgrKey(); + this->appendPartsToModel(-1, model); +} - RivGeoMechPartMgr* currentGeoMechPartMgr = m_partMgrCache->partMgr(pMgrKey); - RigGeoMechCaseData* caseData = m_geomechView->geoMechCase()->geoMechData(); - int partCount = caseData->femParts()->partCount(); - - if (m_partMgrCache->needsRegeneration(pMgrKey)) +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivGeoMechVizLogic::appendPartsToModel(int timeStepIndex, cvf::ModelBasicList* model) +{ + std::vector visiblePartMgrs = keysToVisiblePartMgrs(timeStepIndex); + for (size_t pmIdx = 0; pmIdx < visiblePartMgrs.size(); ++pmIdx) { - if (currentGeoMechPartMgr->initializedFemPartCount() != partCount) - { - currentGeoMechPartMgr->clearAndSetReservoir(caseData); - } + RivGeoMechPartMgr* partMgr = getUpdatedPartMgr(visiblePartMgrs[pmIdx]); - for (int femPartIdx = 0; femPartIdx < partCount; ++femPartIdx) - { - cvf::ref elmVisibility = currentGeoMechPartMgr->cellVisibility(femPartIdx); - currentGeoMechPartMgr->setTransform(m_geomechView->scaleTransform()); - - if (pMgrKey.geometryType() == RANGE_FILTERED) - { - cvf::CellRangeFilter cellRangeFilter; - m_geomechView->rangeFilterCollection()->compoundCellRangeFilter(&cellRangeFilter, femPartIdx); - RivFemElmVisibilityCalculator::computeRangeVisibility(elmVisibility.p(), caseData->femParts()->part(femPartIdx), cellRangeFilter); - } - else - { - RivFemElmVisibilityCalculator::computeAllVisible(elmVisibility.p(), caseData->femParts()->part(femPartIdx)); - } - - currentGeoMechPartMgr->setCellVisibility(femPartIdx, elmVisibility.p()); - } - - m_partMgrCache->generationFinished(pMgrKey); + partMgr->appendGridPartsToModel(model); } - - currentGeoMechPartMgr->appendGridPartsToModel(model); + } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RivGeoMechVizLogic::appendPartsToModel( int timeStepIndex, cvf::ModelBasicList* model) +void RivGeoMechVizLogic::updateCellResultColor(int timeStepIndex, RimGeoMechResultSlot* cellResultSlot) { - appendNoAnimPartsToModel(model); + std::vector visiblePartMgrs = keysToVisiblePartMgrs(timeStepIndex); + for (size_t pmIdx = 0; pmIdx < visiblePartMgrs.size(); ++pmIdx) + { + RivGeoMechPartMgr* partMgr = m_partMgrCache->partMgr(visiblePartMgrs[pmIdx]); + partMgr->updateCellResultColor(timeStepIndex, cellResultSlot); + } + } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RivGeoMechVizLogic::updateCellResultColor(size_t timeStepIndex, RimGeoMechResultSlot* cellResultSlot) +void RivGeoMechVizLogic::updateStaticCellColors(int timeStepIndex) { - RivGeoMechPartMgrCache::Key pMgrKey = currentPartMgrKey(); - RivGeoMechPartMgr* partMgr = m_partMgrCache->partMgr(pMgrKey); - partMgr->updateCellResultColor(timeStepIndex, cellResultSlot); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RivGeoMechVizLogic::updateStaticCellColors() -{ - RivGeoMechPartMgrCache::Key pMgrKey = currentPartMgrKey(); - RivGeoMechPartMgr* partMgr = m_partMgrCache->partMgr(pMgrKey); - partMgr->updateCellColor(cvf::Color4f(cvf::Color3f::ORANGE)); + std::vector visiblePartMgrs = keysToVisiblePartMgrs(timeStepIndex); + for (size_t pmIdx = 0; pmIdx < visiblePartMgrs.size(); ++pmIdx) + { + RivGeoMechPartMgr* partMgr = m_partMgrCache->partMgr(visiblePartMgrs[pmIdx]); + partMgr->updateCellColor(cvf::Color4f(cvf::Color3f::ORANGE)); + } } //-------------------------------------------------------------------------------------------------- @@ -128,35 +108,94 @@ void RivGeoMechVizLogic::updateStaticCellColors() //-------------------------------------------------------------------------------------------------- void RivGeoMechVizLogic::scheduleGeometryRegen(RivCellSetEnum geometryType) { - switch (geometryType) + int frameCount = m_geomechView->geoMechCase()->geoMechData()->femPartResults()->frameCount(); + + for (int fIdx = -1; fIdx < frameCount; ++fIdx) { - case RANGE_FILTERED: - m_partMgrCache->scheduleRegeneration(RivGeoMechPartMgrCache::Key(RANGE_FILTERED, 0)); - break; - case RANGE_FILTERED_INACTIVE: - break; - case PROPERTY_FILTERED: - break; + RivGeoMechPartMgrCache::Key geomToRegen(geometryType, fIdx); + m_partMgrCache->scheduleRegeneration(geomToRegen); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RivGeoMechPartMgrCache::Key RivGeoMechVizLogic::currentPartMgrKey() +std::vector RivGeoMechVizLogic::keysToVisiblePartMgrs(int timeStepIndex) { - RivGeoMechPartMgrCache::Key pMgrKey; - - if (m_geomechView->rangeFilterCollection()->hasActiveFilters()) + std::vector visiblePartMgrs; + + if (false)//m_geomechView->propertyFilterCollection()->hasActiveFilters()) { - pMgrKey.set(RANGE_FILTERED, 0); + visiblePartMgrs.push_back(RivGeoMechPartMgrCache::Key(PROPERTY_FILTERED, timeStepIndex)); + } + else if (m_geomechView->rangeFilterCollection()->hasActiveFilters()) + { + visiblePartMgrs.push_back(RivGeoMechPartMgrCache::Key(RANGE_FILTERED, -1)); } else { - pMgrKey.set(ALL_CELLS, 0); + visiblePartMgrs.push_back(RivGeoMechPartMgrCache::Key(ALL_CELLS, -1)); } - return pMgrKey; + return visiblePartMgrs; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RivGeoMechPartMgr* RivGeoMechVizLogic::getUpdatedPartMgr(RivGeoMechPartMgrCache::Key pMgrKey) +{ + if (!m_partMgrCache->isNeedingRegeneration(pMgrKey)) + { + return m_partMgrCache->partMgr(pMgrKey); + } + + RivGeoMechPartMgr* partMgrToUpdate = m_partMgrCache->partMgr(pMgrKey); + RigGeoMechCaseData* caseData = m_geomechView->geoMechCase()->geoMechData(); + int partCount = caseData->femParts()->partCount(); + + if (partMgrToUpdate->initializedFemPartCount() != partCount) + { + partMgrToUpdate->clearAndSetReservoir(caseData); + } + + for (int femPartIdx = 0; femPartIdx < partCount; ++femPartIdx) + { + cvf::ref elmVisibility = partMgrToUpdate->cellVisibility(femPartIdx); + partMgrToUpdate->setTransform(m_geomechView->scaleTransform()); + + if (pMgrKey.geometryType() == RANGE_FILTERED) + { + cvf::CellRangeFilter cellRangeFilter; + m_geomechView->rangeFilterCollection()->compoundCellRangeFilter(&cellRangeFilter, femPartIdx); + RivFemElmVisibilityCalculator::computeRangeVisibility( elmVisibility.p(), + caseData->femParts()->part(femPartIdx), + cellRangeFilter); + } + else if (pMgrKey.geometryType() == PROPERTY_FILTERED) + { + RivGeoMechPartMgr* rangefiltered = getUpdatedPartMgr(RivGeoMechPartMgrCache::Key(RANGE_FILTERED, -1)); + cvf::ref rangeFiltVisibility = rangefiltered->cellVisibility(femPartIdx); + + RivFemElmVisibilityCalculator::computePropertyVisibility(elmVisibility.p(), + caseData->femParts()->part(femPartIdx), + pMgrKey.frameIndex(), + rangeFiltVisibility.p(), + NULL + //m_geomechView->propertyFilterCollection() + ); + } + else + { + RivFemElmVisibilityCalculator::computeAllVisible(elmVisibility.p(), caseData->femParts()->part(femPartIdx)); + } + + partMgrToUpdate->setCellVisibility(femPartIdx, elmVisibility.p()); + } + + m_partMgrCache->setGenerationFinished(pMgrKey); + + return partMgrToUpdate; } diff --git a/ApplicationCode/ModelVisualization/RivGeoMechVizLogic.h b/ApplicationCode/ModelVisualization/RivGeoMechVizLogic.h index ddba1b62e4..47620b141a 100644 --- a/ApplicationCode/ModelVisualization/RivGeoMechVizLogic.h +++ b/ApplicationCode/ModelVisualization/RivGeoMechVizLogic.h @@ -25,6 +25,8 @@ #include "RivGeoMechPartMgrCache.h" #include "RivCellSetEnum.h" +#include + class RimGeoMechView; class RimGeoMechResultSlot; @@ -42,12 +44,14 @@ public: void appendNoAnimPartsToModel(cvf::ModelBasicList* model); void appendPartsToModel(int timeStepIndex, cvf::ModelBasicList* model); - void updateCellResultColor(size_t timeStepIndex, RimGeoMechResultSlot* cellResultSlot); - void updateStaticCellColors(); + void updateCellResultColor(int timeStepIndex, RimGeoMechResultSlot* cellResultSlot); + void updateStaticCellColors(int timeStepIndex); void scheduleGeometryRegen(RivCellSetEnum geometryType); private: - - RivGeoMechPartMgrCache::Key currentPartMgrKey(); + + std::vector keysToVisiblePartMgrs(int timeStepIndex); + RivGeoMechPartMgr* getUpdatedPartMgr(RivGeoMechPartMgrCache::Key partMgrKey); + cvf::ref m_partMgrCache; RimGeoMechView* m_geomechView; }; diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp index 272e0688ce..67a6b0db3a 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp @@ -225,7 +225,7 @@ void RimGeoMechView::createDisplayModel() m_viewer->removeAllFrames(); m_vizLogic->appendNoAnimPartsToModel(frameModels[0].p()); - m_vizLogic->updateStaticCellColors(); + m_vizLogic->updateStaticCellColors(-1); // Create Scenes from the frameModels // Animation frames for results display, starts from frame 1 @@ -296,7 +296,7 @@ void RimGeoMechView::updateCurrentTimeStep() } else { - this->updateStaticCellColors(); + m_vizLogic->updateStaticCellColors(m_currentTimeStep); m_viewer->animationControl()->slotPause(); // To avoid animation timer spinning in the background } @@ -308,7 +308,7 @@ void RimGeoMechView::updateCurrentTimeStep() //-------------------------------------------------------------------------------------------------- void RimGeoMechView::updateStaticCellColors() { - m_vizLogic->updateStaticCellColors(); + m_vizLogic->updateStaticCellColors(-1); } //--------------------------------------------------------------------------------------------------