Preparing for property filter. #314

Prototype code for property filter visibility
Refactoring the VizLogic class to make the responsibilities clearer
This commit is contained in:
Jacob Støren 2015-06-22 08:16:46 +02:00
parent e9fe03f63a
commit 088bc12459
7 changed files with 232 additions and 79 deletions

View File

@ -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<float>& 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
}

View File

@ -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);
};

View File

@ -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<Key, CacheEntry >::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<Key, CacheEntry >::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)
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -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:

View File

@ -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<RivGeoMechPartMgrCache::Key> 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<cvf::UByteArray> 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<RivGeoMechPartMgrCache::Key> 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<RivGeoMechPartMgrCache::Key> 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<RivGeoMechPartMgrCache::Key> RivGeoMechVizLogic::keysToVisiblePartMgrs(int timeStepIndex)
{
RivGeoMechPartMgrCache::Key pMgrKey;
if (m_geomechView->rangeFilterCollection()->hasActiveFilters())
std::vector<RivGeoMechPartMgrCache::Key> 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<cvf::UByteArray> 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<cvf::UByteArray> 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;
}

View File

@ -25,6 +25,8 @@
#include "RivGeoMechPartMgrCache.h"
#include "RivCellSetEnum.h"
#include <vector>
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<RivGeoMechPartMgrCache::Key> keysToVisiblePartMgrs(int timeStepIndex);
RivGeoMechPartMgr* getUpdatedPartMgr(RivGeoMechPartMgrCache::Key partMgrKey);
cvf::ref<RivGeoMechPartMgrCache> m_partMgrCache;
RimGeoMechView* m_geomechView;
};

View File

@ -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);
}
//--------------------------------------------------------------------------------------------------