Prep for Geomech range: Introduced VizLogic

Refactored to use the new RivVizLogic class, together with the
partMgrCache
Works.
This commit is contained in:
Jacob Støren
2015-05-22 17:01:59 +02:00
parent 49fafbf47f
commit b280196b7c
9 changed files with 388 additions and 33 deletions
@@ -46,7 +46,7 @@ RivGeoMechPartMgr::~RivGeoMechPartMgr()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivGeoMechPartMgr::clearAndSetReservoir(const RigGeoMechCaseData* geoMechCase, RimGeoMechView* geomechView)
void RivGeoMechPartMgr::clearAndSetReservoir(const RigGeoMechCaseData* geoMechCase)
{
m_femPartPartMgrs.clear();
@@ -47,7 +47,8 @@ public:
RivGeoMechPartMgr();
~RivGeoMechPartMgr();
void clearAndSetReservoir(const RigGeoMechCaseData* geoMechCase, RimGeoMechView* geomechView);
int initializedFemPartCount() { return static_cast<int>(m_femPartPartMgrs.size());}
void clearAndSetReservoir(const RigGeoMechCaseData* geoMechCase);
void setTransform(cvf::Transform* scaleTransform);
void setCellVisibility(size_t partIndex, cvf::UByteArray* cellVisibilities );
@@ -30,6 +30,9 @@ ${CEE_CURRENT_LIST_DIR}RivTernaryTextureCoordsCreator.h
${CEE_CURRENT_LIST_DIR}RivTernaryScalarMapperEffectGenerator.h
${CEE_CURRENT_LIST_DIR}RivScalarMapperUtils.h
${CEE_CURRENT_LIST_DIR}RivCellEdgeGeometryUtils.h
${CEE_CURRENT_LIST_DIR}RivGeoMechPartMgrCache.h
${CEE_CURRENT_LIST_DIR}RivGeoMechVizLogic.h
)
set (SOURCE_GROUP_SOURCE_FILES
@@ -56,6 +59,9 @@ ${CEE_CURRENT_LIST_DIR}RivTernaryTextureCoordsCreator.cpp
${CEE_CURRENT_LIST_DIR}RivTernaryScalarMapperEffectGenerator.cpp
${CEE_CURRENT_LIST_DIR}RivScalarMapperUtils.cpp
${CEE_CURRENT_LIST_DIR}RivCellEdgeGeometryUtils.cpp
${CEE_CURRENT_LIST_DIR}RivGeoMechPartMgrCache.cpp
${CEE_CURRENT_LIST_DIR}RivGeoMechVizLogic.cpp
)
list(APPEND CODE_HEADER_FILES
@@ -0,0 +1,59 @@
#include "RivGeoMechPartMgrCache.h"
#include "RivGeoMechPartMgr.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivGeoMechPartMgrCache::RivGeoMechPartMgrCache()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivGeoMechPartMgrCache::~RivGeoMechPartMgrCache()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RivGeoMechPartMgrCache::needsRegeneration(const Key& key)
{
return m_partMgrs[key].needsRegen;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivGeoMechPartMgrCache::scheduleRegeneration(const Key& key)
{
m_partMgrs[key].needsRegen = true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivGeoMechPartMgrCache::generationFinished(const Key& key)
{
m_partMgrs[key].needsRegen = false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivGeoMechPartMgr* RivGeoMechPartMgrCache::partMgr(const Key& key)
{
CacheEntry& ce = m_partMgrs[key];
if (ce.partMgr.isNull())
{
ce.partMgr = new RivGeoMechPartMgr;
}
return ce.partMgr.p();
}
@@ -0,0 +1,61 @@
#pragma once
#include "cvfObject.h"
#include <map>
class RivGeoMechPartMgr;
class RivGeoMechPartMgrCache : public cvf::Object
{
public:
RivGeoMechPartMgrCache();
~RivGeoMechPartMgrCache();
class Key
{
public:
Key()
: geometryType(-1), frameIndex(-1)
{}
Key(unsigned short aGeometryType, int aFrameIndex)
: geometryType(aGeometryType), frameIndex(aFrameIndex)
{}
void set(unsigned short aGeometryType, int aFrameIndex)
{
frameIndex = aFrameIndex;
geometryType = aGeometryType;
}
int frameIndex;
unsigned short geometryType;
bool operator< (const Key& other) const
{
if (frameIndex != other.frameIndex)
{
return (frameIndex < other.frameIndex);
}
return (geometryType < other.geometryType);
}
};
bool needsRegeneration (const Key& key);
void scheduleRegeneration(const Key& key);
void generationFinished (const Key& key);
RivGeoMechPartMgr* partMgr (const Key& key);
private:
class CacheEntry
{
public:
CacheEntry() : needsRegen(true) {}
bool needsRegen;
cvf::ref<RivGeoMechPartMgr> partMgr;
};
std::map<Key, CacheEntry > m_partMgrs;
};
@@ -0,0 +1,159 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- 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
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RivGeoMechVizLogic.h"
#include "RimGeoMechView.h"
#include "cvfModelBasicList.h"
#include "RimGeoMechResultSlot.h"
#include "RivGeoMechPartMgrCache.h"
#include "RivGeoMechPartMgr.h"
#include "RivReservoirViewPartMgr.h"
#include "RimGeoMechCase.h"
#include "RigFemPartCollection.h"
#include "RigGeomechCaseData.h"
#include "RimCellRangeFilterCollection.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivGeoMechVizLogic::RivGeoMechVizLogic(RimGeoMechView * geomView)
{
CVF_ASSERT(geomView);
m_geomechView = geomView;
m_partMgrCache = new RivGeoMechPartMgrCache;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivGeoMechVizLogic::~RivGeoMechVizLogic()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivGeoMechVizLogic::appendNoAnimPartsToModel(cvf::ModelBasicList* model)
{
RivGeoMechPartMgrCache::Key pMgrKey = currentPartMgrKey();
RivGeoMechPartMgr* m_geoMechFullModel = m_partMgrCache->partMgr(pMgrKey);
RigGeoMechCaseData* caseData = m_geomechView->geoMechCase()->geoMechData();
int partCount = caseData->femParts()->partCount();
if (m_partMgrCache->needsRegeneration(pMgrKey))
{
if (m_geoMechFullModel->initializedFemPartCount() != partCount)
{
m_geoMechFullModel->clearAndSetReservoir(caseData);
}
for (int femPartIdx = 0; femPartIdx < partCount; ++femPartIdx)
{
cvf::ref<cvf::UByteArray> elmVisibility = m_geoMechFullModel->cellVisibility(femPartIdx);
m_geoMechFullModel->setTransform(m_geomechView->scaleTransform());
if (pMgrKey.geometryType == RANGE_FILTERED)
{
cvf::CellRangeFilter cellRangeFilter;
m_geomechView->rangeFilterCollection()->compoundCellRangeFilter(&cellRangeFilter, femPartIdx);
RivElmVisibilityCalculator::computeRangeVisibility(elmVisibility.p(), caseData->femParts()->part(femPartIdx), cellRangeFilter);
}
else
{
RivElmVisibilityCalculator::computeAllVisible(elmVisibility.p(), caseData->femParts()->part(femPartIdx));
}
m_geoMechFullModel->setCellVisibility(femPartIdx, elmVisibility.p());
}
m_partMgrCache->generationFinished(pMgrKey);
}
m_geoMechFullModel->appendGridPartsToModel(model);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivGeoMechVizLogic::appendPartsToModel( int timeStepIndex, cvf::ModelBasicList* model)
{
appendNoAnimPartsToModel(model);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivGeoMechVizLogic::updateCellResultColor(size_t timeStepIndex, RimGeoMechResultSlot* cellResultSlot)
{
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));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivGeoMechVizLogic::scheduleGeometryRegen(unsigned short geometryType)
{
switch (geometryType)
{
case RivReservoirViewPartMgr::RANGE_FILTERED:
m_partMgrCache->scheduleRegeneration(RivGeoMechPartMgrCache::Key(RANGE_FILTERED, 0));
break;
case RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE:
break;
case RivReservoirViewPartMgr::PROPERTY_FILTERED:
break;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivGeoMechPartMgrCache::Key RivGeoMechVizLogic::currentPartMgrKey()
{
RivGeoMechPartMgrCache::Key pMgrKey;
if (m_geomechView->rangeFilterCollection()->hasActiveFilters())
{
pMgrKey.set(RANGE_FILTERED, 0);
}
else
{
pMgrKey.set(ALL_CELLS, 0);
}
return pMgrKey;
}
@@ -0,0 +1,57 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- 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
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfObject.h"
#include "cvfColor4.h"
#include "RivGeoMechPartMgrCache.h"
class RimGeoMechView;
class RimGeoMechResultSlot;
namespace cvf
{
class ModelBasicList;
}
class RivGeoMechVizLogic : public cvf::Object
{
public:
enum GeometryType
{
ALL_CELLS,
RANGE_FILTERED
};
RivGeoMechVizLogic(RimGeoMechView * geomView);
virtual ~RivGeoMechVizLogic();
void appendNoAnimPartsToModel(cvf::ModelBasicList* model);
void appendPartsToModel(int timeStepIndex, cvf::ModelBasicList* model);
void updateCellResultColor(size_t timeStepIndex, RimGeoMechResultSlot* cellResultSlot);
void updateStaticCellColors();
void scheduleGeometryRegen(unsigned short geometryType);
private:
RivGeoMechPartMgrCache::Key currentPartMgrKey();
cvf::ref<RivGeoMechPartMgrCache> m_partMgrCache;
RimGeoMechView* m_geomechView;
};
@@ -45,6 +45,8 @@
#include <QMessageBox>
#include "cafProgressInfo.h"
#include "RimCellRangeFilterCollection.h"
#include "RivGeoMechPartMgrCache.h"
#include "RivGeoMechVizLogic.h"
@@ -74,9 +76,8 @@ RimGeoMechView::RimGeoMechView(void)
this->cellResult()->legendConfig()->setReservoirView(this);
m_scaleTransform = new cvf::Transform();
m_geoMechFullModel = new RivGeoMechPartMgr();
m_vizLogic = new RivGeoMechVizLogic(this);
m_isGeoMechFullGenerated = false;
}
//--------------------------------------------------------------------------------------------------
@@ -128,7 +129,7 @@ void RimGeoMechView::loadDataAndUpdate()
m_geomechCase = NULL;
return;
}
m_geoMechFullModel->clearAndSetReservoir(m_geomechCase->geoMechData(), this);
// m_geoMechFullModel->clearAndSetReservoir(m_geomechCase->geoMechData(), this);
}
progress.incrementProgress();
@@ -217,26 +218,8 @@ void RimGeoMechView::createDisplayModel()
bool isAnimationActive = m_viewer->isAnimationActive();
m_viewer->removeAllFrames();
if (!m_isGeoMechFullGenerated)
{
for (int femPartIdx = 0; femPartIdx < partCount; ++femPartIdx)
{
cvf::ref<cvf::UByteArray> elmVisibility = m_geoMechFullModel->cellVisibility(femPartIdx);
m_geoMechFullModel->setTransform(m_scaleTransform.p());
RivElmVisibilityCalculator::computeAllVisible(elmVisibility.p(), m_geomechCase->geoMechData()->femParts()->part(femPartIdx));
m_geoMechFullModel->setCellVisibility(femPartIdx, elmVisibility.p());
}
m_isGeoMechFullGenerated = true;
}
size_t frameIdx;
for (frameIdx = 0; frameIdx < frameModels.size(); ++frameIdx)
{
m_geoMechFullModel->appendGridPartsToModel(frameModels[frameIdx].p());
}
// Set static colors
this->updateStaticCellColors();
m_vizLogic->appendNoAnimPartsToModel(frameModels[0].p());
m_vizLogic->updateStaticCellColors();
// Create Scenes from the frameModels
// Animation frames for results display, starts from frame 1
@@ -258,7 +241,7 @@ void RimGeoMechView::createDisplayModel()
// If the animation was active before recreating everything, make viewer view current frame
if (isAnimationActive || cellResult->resultFieldName() != "")
if (isAnimationActive && cellResult->resultFieldName() != "")
{
m_viewer->slotSetCurrentFrame(m_currentTimeStep);
}
@@ -275,7 +258,21 @@ void RimGeoMechView::updateCurrentTimeStep()
updateLegends();
if ((this->animationMode() && cellResult()->resultFieldName() != ""))
{
m_geoMechFullModel->updateCellResultColor(m_currentTimeStep(), this->cellResult());
if (m_viewer)
{
cvf::Scene* frameScene = m_viewer->frame(m_currentTimeStep);
if (frameScene)
{
cvf::ref<cvf::ModelBasicList> frameParts = new cvf::ModelBasicList;
m_vizLogic->appendPartsToModel(m_currentTimeStep, frameParts.p());
frameParts->updateBoundingBoxesRecursive();
frameScene->removeAllModels();
frameScene->addModel(frameParts.p());
}
}
m_vizLogic->updateCellResultColor(m_currentTimeStep(), this->cellResult());
}
else
{
@@ -291,7 +288,7 @@ void RimGeoMechView::updateCurrentTimeStep()
//--------------------------------------------------------------------------------------------------
void RimGeoMechView::updateStaticCellColors()
{
m_geoMechFullModel->updateCellColor(cvf::Color4f(cvf::Color3f::ORANGE));
m_vizLogic->updateStaticCellColors();
}
//--------------------------------------------------------------------------------------------------
@@ -506,3 +503,11 @@ void RivElmVisibilityCalculator::computeAllVisible(cvf::UByteArray* elmVisibilit
elmVisibilities->setAll(true);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivElmVisibilityCalculator::computeRangeVisibility(cvf::UByteArray* elmVisibilities, const RigFemPart* femPart, const cvf::CellRangeFilter& rangeFilter)
{
}
@@ -35,11 +35,13 @@ class RiuViewer;
class RimGeoMechCase;
class RivGeoMechPartMgr;
class RimCellRangeFilterCollection;
class RivGeoMechVizLogic;
class RigFemPart;
namespace cvf {
class Transform;
class CellRangeFilter;
}
//==================================================================================================
@@ -66,13 +68,14 @@ public:
bool isTimeStepDependentDataVisible();
virtual cvf::Transform* scaleTransform();
private:
virtual void scheduleGeometryRegen(unsigned short geometryType){}
virtual void createDisplayModel();
virtual void updateDisplayModelVisibility();
virtual void updateScaleTransform();
virtual cvf::Transform* scaleTransform();
virtual void clampCurrentTimestep();
@@ -90,18 +93,22 @@ private:
virtual RimCase* ownerCase();
caf::PdmPointer<RimGeoMechCase> m_geomechCase;
cvf::ref<RivGeoMechPartMgr> m_geoMechFullModel;
bool m_isGeoMechFullGenerated;
cvf::ref<RivGeoMechVizLogic> m_vizLogic;
cvf::ref<cvf::Transform> m_scaleTransform;
};
#include "cvfArray.h"
namespace cvf {
class CellRangeFilter;
}
class RivElmVisibilityCalculator
{
public:
static void computeAllVisible(cvf::UByteArray* elmVisibilities, const RigFemPart* femPart );
static void computeRangeVisibility(cvf::UByteArray* elmVisibilities, const RigFemPart* femPart, const cvf::CellRangeFilter& rangeFilter);
};
};