RimView etc: Refactored and alligned

To implement geomechView features alligned with ReservoirView
Now geomech results are shown with correct legend, and updated fairly
well.
This commit is contained in:
Jacob Støren 2015-05-08 10:38:10 +02:00
parent 93d92e5cb5
commit 86b058cdbe
6 changed files with 366 additions and 194 deletions

View File

@ -41,6 +41,7 @@
#include "RigGeoMechCaseData.h"
#include "cvfqtUtils.h"
#include "RigFemPartCollection.h"
#include "cafFrameAnimationControl.h"
namespace caf {
@ -91,6 +92,10 @@ RimGeoMechView::RimGeoMechView(void)
this->cellResult()->setReservoirView(this);
this->cellResult()->legendConfig()->setPosition(cvf::Vec2ui(10, 120));
this->cellResult()->legendConfig()->setReservoirView(this);
m_scaleTransform = new cvf::Transform();
m_geoMechVizModel = new RivGeoMechPartMgr();
}
//--------------------------------------------------------------------------------------------------
@ -131,65 +136,195 @@ void RimGeoMechView::loadDataAndUpdate()
if (m_geomechCase)
{
m_geomechCase->openGeoMechCase();
m_geoMechVizModel->clearAndSetReservoir(m_geomechCase->geoMechData(), this);
}
updateViewerWidget();
createDisplayModelAndRedraw();
if (cameraPosition().isIdentity())
{
setDefaultView();
}
}
//--------------------------------------------------------------------------------------------------
///
/// Todo: Work in progress
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechView::updateScaleTransform()
{
CVF_ASSERT(m_scaleTransform.notNull());
cvf::Mat4d scale = cvf::Mat4d::IDENTITY;
scale(2, 2) = scaleZ();
m_scaleTransform->setLocalTransform(scale);
if (m_viewer) m_viewer->updateCachedValuesInScene();
}
//--------------------------------------------------------------------------------------------------
/// Create display model,
/// or at least empty scenes as frames that is delivered to the viewer
/// The real geometry generation is done inside RivReservoirViewGeometry and friends
//--------------------------------------------------------------------------------------------------
void RimGeoMechView::createDisplayModel()
{
if (m_viewer.isNull()) return;
if (!(m_geomechCase
&& m_geomechCase->geoMechData()
&& m_geomechCase->geoMechData()->femParts()))
return;
int partCount = m_geomechCase->geoMechData()->femParts()->partCount();
if (partCount <= 0) 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<size_t> 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 (isTimeStepDependentDataVisible())
{
size_t i;
for (i = 0; i < geoMechCase()->geoMechData()->frameCount(0, cellResult()->resultAddress()); i++)
{
timeStepIndices.push_back(i);
}
}
cvf::Collection<cvf::ModelBasicList> 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();
for (int femPartIdx = 0; femPartIdx < partCount; ++femPartIdx)
{
cvf::ref<cvf::UByteArray> elmVisibility = m_geoMechVizModel->cellVisibility(femPartIdx);
m_geoMechVizModel->setTransform(m_scaleTransform.p());
RivElmVisibilityCalculator::computeAllVisible(elmVisibility.p(), m_geomechCase->geoMechData()->femParts()->part(femPartIdx));
m_geoMechVizModel->setCellVisibility(femPartIdx, elmVisibility.p());
}
size_t frameIdx;
for (frameIdx = 0; frameIdx < frameModels.size(); ++frameIdx)
{
m_geoMechVizModel->appendGridPartsToModel(frameModels[frameIdx].p());
}
// Set static colors
this->updateStaticCellColors();
// 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<cvf::Scene> 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 || cellResult->resultFieldName() != "")
{
m_viewer->slotSetCurrentFrame(m_currentTimeStep);
}
updateLegends();
overlayInfoConfig()->update3DInfo();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechView::createDisplayModelAndRedraw()
void RimGeoMechView::updateCurrentTimeStep()
{
if (m_viewer && m_geomechCase)
if ((this->animationMode() && cellResult()->resultFieldName() != ""))
{
int partCount = 0;
if (m_geomechCase->geoMechData() && m_geomechCase->geoMechData()->femParts())
{
partCount = m_geomechCase->geoMechData()->femParts()->partCount();
}
if (partCount >= 0)
{
cvf::ref<cvf::Transform> scaleTransform = new cvf::Transform();
scaleTransform->setLocalTransform(cvf::Mat4d::IDENTITY);
cvf::ref<cvf::ModelBasicList> cvfModel = new cvf::ModelBasicList;
m_geoMechVizModel = new RivGeoMechPartMgr();
m_geoMechVizModel->clearAndSetReservoir(m_geomechCase->geoMechData(), this);
for (int femPartIdx = 0; femPartIdx < partCount; ++femPartIdx)
{
cvf::ref<cvf::UByteArray> elmVisibility = m_geoMechVizModel->cellVisibility(femPartIdx);
m_geoMechVizModel->setTransform(scaleTransform.p());
RivElmVisibilityCalculator::computeAllVisible(elmVisibility.p(), m_geomechCase->geoMechData()->femParts()->part(femPartIdx));
m_geoMechVizModel->setCellVisibility(femPartIdx, elmVisibility.p());
}
m_geoMechVizModel->updateCellColor(cvf::Color4f(cvf::Color3f::ORANGE));
if (cellResult()->resultFieldName() != "")
{
m_geoMechVizModel->updateCellResultColor(m_currentTimeStep(), this->cellResult());
}
m_geoMechVizModel->appendGridPartsToModel(cvfModel.p());
cvf::ref<cvf::Scene> scene = new cvf::Scene;
scene->addModel(cvfModel.p());
scene->updateBoundingBoxesRecursive();
m_viewer->setMainScene(scene.p());
m_viewer->zoomAll();
m_viewer->update();
updateLegends();
overlayInfoConfig()->update3DInfo();
}
m_geoMechVizModel->updateCellResultColor(m_currentTimeStep(), this->cellResult());
}
RiuMainWindow::instance()->refreshAnimationActions();
else
{
this->updateStaticCellColors();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechView::updateStaticCellColors()
{
m_geoMechVizModel->updateCellColor(cvf::Color4f(cvf::Color3f::ORANGE));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechView::updateDisplayModelVisibility()
{
if (m_viewer.isNull()) return;
const cvf::uint uintSurfaceBit = surfaceBit;
const cvf::uint uintMeshSurfaceBit = meshSurfaceBit;
const cvf::uint uintFaultBit = faultBit;
const cvf::uint uintMeshFaultBit = meshFaultBit;
// Initialize the mask to show everything except the the bits controlled here
unsigned int mask = 0xffffffff & ~uintSurfaceBit & ~uintFaultBit & ~uintMeshSurfaceBit & ~uintMeshFaultBit ;
// Then turn the appropriate bits on according to the user settings
if (surfaceMode == SURFACE)
{
mask |= uintSurfaceBit;
mask |= uintFaultBit;
}
else if (surfaceMode == FAULTS)
{
mask |= uintFaultBit;
}
if (meshMode == FULL_MESH)
{
mask |= uintMeshSurfaceBit;
mask |= uintMeshFaultBit;
}
else if (meshMode == FAULTS_MESH)
{
mask |= uintMeshFaultBit;
}
m_viewer->setEnableMask(mask);
m_viewer->update();
}
//--------------------------------------------------------------------------------------------------
@ -232,37 +367,34 @@ void RimGeoMechView::updateLegends()
double localMin, localMax;
double localPosClosestToZero, localNegClosestToZero;
#if 0
double globalMin, globalMax;
double globalPosClosestToZero, globalNegClosestToZero;
RigCaseCellResultsData* results = gmCase->results(porosityModel);
CVF_ASSERT(results);
if (cellResult->hasDynamicResult())
RigFemResultAddress resVarAddress = cellResult->resultAddress();
if (resVarAddress.fieldName != "")
{
cellResultsData->minMaxCellScalarValues(cellResult->scalarResultIndex(), m_currentTimeStep, localMin, localMax);
cellResultsData->posNegClosestToZero(cellResult->scalarResultIndex(), m_currentTimeStep, localPosClosestToZero, localNegClosestToZero);
gmCase->minMaxScalarValues(resVarAddress, 0, m_currentTimeStep, &localMin, &localMax);
gmCase->posNegClosestToZero(resVarAddress, 0, m_currentTimeStep, &localPosClosestToZero, &localNegClosestToZero);
gmCase->minMaxScalarValues(resVarAddress, 0, &globalMin, &globalMax);
gmCase->posNegClosestToZero(resVarAddress, 0, &globalPosClosestToZero, &globalNegClosestToZero);
cellResult->legendConfig->setClosestToZeroValues(globalPosClosestToZero, globalNegClosestToZero, localPosClosestToZero, localNegClosestToZero);
cellResult->legendConfig->setAutomaticRanges(globalMin, globalMax, localMin, localMax);
m_viewer->addColorLegendToBottomLeftCorner(cellResult->legendConfig->legend());
cellResult->legendConfig->legend()->setTitle(cvfqt::Utils::toString(
caf::AppEnum<RigFemResultPosEnum>(cellResult->resultPositionType()).uiText() + "\n"
+ cellResult->resultFieldName() + " " + cellResult->resultComponentName() ));
}
else
{
localMin = globalMin;
localMax = globalMax;
localPosClosestToZero = globalPosClosestToZero;
localNegClosestToZero = globalNegClosestToZero;
cellResult->legendConfig->setClosestToZeroValues(0, 0, 0, 0);
cellResult->legendConfig->setAutomaticRanges(cvf::UNDEFINED_DOUBLE, cvf::UNDEFINED_DOUBLE, cvf::UNDEFINED_DOUBLE, cvf::UNDEFINED_DOUBLE);
}
cellResult->legendConfig->setClosestToZeroValues(globalPosClosestToZero, globalNegClosestToZero, localPosClosestToZero, localNegClosestToZero);
cellResult->legendConfig->setAutomaticRanges(globalMin, globalMax, localMin, localMax);
#endif
caf::AppEnum<RigFemResultPosEnum> resPosType = cellResult->resultPositionType();
QString fieldName = cellResult->resultFieldName();
QString compName = cellResult->resultComponentName();
m_viewer->addColorLegendToBottomLeftCorner(cellResult->legendConfig->legend());
cellResult->legendConfig->legend()->setTitle(cvfqt::Utils::toString( resPosType.text() + "\n" + fieldName + " " + compName));
}
@ -274,6 +406,26 @@ RimGeoMechCase* RimGeoMechView::geoMechCase()
return m_geomechCase;
}
//--------------------------------------------------------------------------------------------------
/// Clamp the current timestep to actual possibilities
//--------------------------------------------------------------------------------------------------
void RimGeoMechView::clampCurrentTimestep()
{
size_t maxFrameCount = m_geomechCase->geoMechData()->frameCount(0, cellResult()->resultAddress());
if (m_currentTimeStep >= maxFrameCount ) m_currentTimeStep = (int)(maxFrameCount -1);
if (m_currentTimeStep < 0 ) m_currentTimeStep = 0;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimGeoMechView::isTimeStepDependentDataVisible()
{
return (cellResult->resultFieldName() != "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -36,6 +36,9 @@ class RimGeoMechCase;
class RivGeoMechPartMgr;
class RigFemPart;
namespace cvf {
class Transform;
}
//==================================================================================================
///
@ -43,7 +46,7 @@ class RigFemPart;
//==================================================================================================
class RimGeoMechView : public RimView
{
CAF_PDM_HEADER_INIT;
CAF_PDM_HEADER_INIT;
public:
RimGeoMechView(void);
@ -64,13 +67,10 @@ public:
};
void setGeoMechCase(RimGeoMechCase* gmCase);
RimGeoMechCase* geoMechCase();
RimGeoMechCase* geoMechCase();
void loadDataAndUpdate();
virtual void createDisplayModelAndRedraw();
virtual void setCurrentTimeStep(int frameIdx){}
virtual void updateCurrentTimeStepAndRedraw(){}
virtual void endAnimation() {}
caf::PdmField<RimGeoMechResultSlot*> cellResult;
@ -79,13 +79,24 @@ public:
caf::PdmField< caf::AppEnum< SurfaceModeType > > surfaceMode;
private:
virtual void updateViewerWidgetWindowTitle();
virtual void resetLegendsInViewer();
virtual void createDisplayModel();
virtual void updateDisplayModelVisibility();
void updateScaleTransform();
virtual void clampCurrentTimestep();
virtual void updateCurrentTimeStep();
virtual void updateStaticCellColors();
virtual void updateViewerWidgetWindowTitle();
virtual void resetLegendsInViewer();
void updateLegends();
bool isTimeStepDependentDataVisible();
caf::PdmPointer<RimGeoMechCase> m_geomechCase;
cvf::ref<RivGeoMechPartMgr> m_geoMechVizModel;
cvf::ref<cvf::Transform> m_scaleTransform;
void updateLegends();
caf::PdmPointer<RimGeoMechCase> m_geomechCase;
cvf::ref<RivGeoMechPartMgr> m_geoMechVizModel;
};
#include "cvfArray.h"

View File

@ -194,11 +194,10 @@ void RimReservoirView::updateViewerWidgetWindowTitle()
}
//--------------------------------------------------------------------------------------------------
///
/// Clamp the current timestep to actual possibilities
//--------------------------------------------------------------------------------------------------
void RimReservoirView::clampCurrentTimestep()
{
// Clamp the current timestep to actual possibilities
if (this->currentGridCellResults() && this->currentGridCellResults()->cellResults())
{
if (m_currentTimeStep() >= static_cast<int>(this->currentGridCellResults()->cellResults()->maxTimeStepCount()))
@ -211,40 +210,6 @@ void RimReservoirView::clampCurrentTimestep()
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirView::createDisplayModelAndRedraw()
{
if (m_viewer)
{
m_viewer->animationControl()->slotStop();
this->clampCurrentTimestep();
createDisplayModel();
updateDisplayModelVisibility();
if (m_viewer->frameCount() > 0)
{
m_viewer->animationControl()->setCurrentFrame(m_currentTimeStep);
}
}
RiuMainWindow::instance()->refreshAnimationActions();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirView::setDefaultView()
{
if (m_viewer)
{
m_viewer->setDefaultView();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -853,24 +818,6 @@ void RimReservoirView::initAfterRead()
this->updateUiIconFromToggleField();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirView::setCurrentTimeStep(int frameIndex)
{
m_currentTimeStep = frameIndex;
this->animationMode = true;
this->updateCurrentTimeStep();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirView::endAnimation()
{
this->animationMode = false;
this->updateStaticCellColors();
}
//--------------------------------------------------------------------------------------------------
///
@ -959,18 +906,6 @@ void RimReservoirView::updateDisplayModelVisibility()
faultCollection->updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirView::setupBeforeSave()
{
if (m_viewer)
{
animationMode = m_viewer->isAnimationActive();
cameraPosition = m_viewer->mainCamera()->viewMatrix();
}
}
//--------------------------------------------------------------------------------------------------
/// Convenience for quick access to results
//--------------------------------------------------------------------------------------------------
@ -1028,15 +963,6 @@ void RimReservoirView::schedulePipeGeometryRegen()
m_pipesPartManager->scheduleGeometryRegen();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirView::updateCurrentTimeStepAndRedraw()
{
this->updateCurrentTimeStep();
if (m_viewer) m_viewer->update();
}
//--------------------------------------------------------------------------------------------------
///

View File

@ -124,21 +124,7 @@ public:
void setEclipseCase(RimCase* reservoir);
RimCase* eclipseCase();
// Animation overrides from RimView
virtual void setCurrentTimeStep(int frameIdx);
virtual void updateCurrentTimeStepAndRedraw();
virtual void endAnimation();
private:
virtual void resetLegendsInViewer();
virtual void updateViewerWidgetWindowTitle();
void setDefaultView();
public:
void setMeshOnlyDrawstyle();
@ -155,7 +141,6 @@ public:
// Display model generation
public:
virtual void createDisplayModelAndRedraw();
void loadDataAndUpdate();
bool isTimeStepDependentDataVisible() const;
@ -168,15 +153,21 @@ public:
visibleGridParts() const { return m_visibleGridParts;}
cvf::cref<RivReservoirViewPartMgr> reservoirGridPartManager() const { return m_reservoirGridPartManager.p(); }
private:
virtual void resetLegendsInViewer();
virtual void updateViewerWidgetWindowTitle();
// Display model generation
private:
void createDisplayModel();
void updateDisplayModelVisibility();
void updateCurrentTimeStep();
virtual void updateCurrentTimeStep();
void indicesToVisibleGrids(std::vector<size_t>* gridIndices);
void updateScaleTransform();
void updateStaticCellColors();
virtual void updateStaticCellColors();
void updateStaticCellColors(unsigned short geometryType);
void updateLegends();
void updateMinMaxValuesAndAddLegendToView(QString legendLabel, RimResultSlot* resultSlot, RigCaseCellResultsData* cellResultsData);
@ -193,7 +184,6 @@ public:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
protected:
virtual void initAfterRead();
virtual void setupBeforeSave();
virtual void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering );
// Really private

View File

@ -10,6 +10,7 @@
#include "cafCadNavigation.h"
#include "cvfCamera.h"
#include "cvfViewport.h"
#include "cafFrameAnimationControl.h"
CAF_PDM_ABSTRACT_SOURCE_INIT(RimView, "GenericView"); // Do not use. Abstract class
@ -143,6 +144,82 @@ void RimView::scheduleCreateDisplayModelAndRedraw()
RiaApplication::instance()->scheduleDisplayModelUpdateAndRedraw(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView::setCurrentTimeStep(int frameIndex)
{
m_currentTimeStep = frameIndex;
this->animationMode = true;
this->updateCurrentTimeStep();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView::updateCurrentTimeStepAndRedraw()
{
this->updateCurrentTimeStep();
if (m_viewer) m_viewer->update();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView::createDisplayModelAndRedraw()
{
if (m_viewer)
{
m_viewer->animationControl()->slotStop();
this->clampCurrentTimestep();
createDisplayModel();
updateDisplayModelVisibility();
if (m_viewer->frameCount() > 0)
{
m_viewer->animationControl()->setCurrentFrame(m_currentTimeStep);
}
}
RiuMainWindow::instance()->refreshAnimationActions();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView::setDefaultView()
{
if (m_viewer)
{
m_viewer->setDefaultView();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView::endAnimation()
{
this->animationMode = false;
this->updateStaticCellColors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView::setupBeforeSave()
{
if (m_viewer)
{
animationMode = m_viewer->isAnimationActive();
cameraPosition = m_viewer->mainCamera()->viewMatrix();
}
}

View File

@ -43,38 +43,54 @@ public:
virtual ~RimView(void);
// 3D Viewer
RiuViewer* viewer();
RiuViewer* viewer();
caf::PdmField<QString> name;
caf::PdmField<double> scaleZ;
caf::PdmField<QString> name;
caf::PdmField<double> scaleZ;
caf::PdmField<bool> showWindow;
caf::PdmField<cvf::Mat4d> cameraPosition;
caf::PdmField< cvf::Color3f > backgroundColor;
caf::PdmField<bool> showWindow;
caf::PdmField<cvf::Mat4d> cameraPosition;
caf::PdmField< cvf::Color3f > backgroundColor;
caf::PdmField<int> maximumFrameRate;
caf::PdmField<bool> animationMode;
caf::PdmField<int> maximumFrameRate;
caf::PdmField<bool> animationMode;
// Animation
int currentTimeStep() { return m_currentTimeStep;}
virtual void setCurrentTimeStep(int frameIdx) = 0;
virtual void updateCurrentTimeStepAndRedraw() = 0;
virtual void endAnimation() = 0;
int currentTimeStep() { return m_currentTimeStep;}
void setCurrentTimeStep(int frameIdx);
void updateCurrentTimeStepAndRedraw();
void endAnimation();
void scheduleCreateDisplayModelAndRedraw();
virtual void createDisplayModelAndRedraw() = 0;
void scheduleCreateDisplayModelAndRedraw();
void createDisplayModelAndRedraw();
public:
virtual caf::PdmFieldHandle* objectToggleField() { return &showWindow; }
virtual caf::PdmFieldHandle* userDescriptionField() { return &name; }
virtual caf::PdmFieldHandle* objectToggleField() { return &showWindow; }
virtual caf::PdmFieldHandle* userDescriptionField() { return &name; }
protected:
//void updateViewerWidget();
virtual void resetLegendsInViewer() = 0;
void updateViewerWidget();
virtual void updateViewerWidgetWindowTitle() = 0;
void setDefaultView();
virtual void createDisplayModel() = 0;
virtual void updateDisplayModelVisibility() = 0;
virtual void clampCurrentTimestep() = 0;
virtual void updateCurrentTimeStep() = 0;
virtual void updateStaticCellColors() = 0;
void updateViewerWidget();
virtual void updateViewerWidgetWindowTitle() = 0;
virtual void resetLegendsInViewer() = 0;
QPointer<RiuViewer> m_viewer;
caf::PdmField<int> m_currentTimeStep;
caf::PdmField<Rim3dOverlayInfoConfig*> overlayInfoConfig;
caf::PdmField<Rim3dOverlayInfoConfig*> overlayInfoConfig;
// Overridden PDM methods:
virtual void setupBeforeSave();
};