(#657) Wired up UI to viz model generation for cross sections

This commit is contained in:
Magne Sjaastad 2015-11-19 11:41:16 +01:00
parent 5ac3dea46d
commit 9c2b1b44a6
11 changed files with 205 additions and 63 deletions

View File

@ -19,21 +19,17 @@
#include "RivCrossSectionPartMgr.h"
//#include "RiaApplication.h"
//#include "RiaPreferences.h"
#include "RigCaseCellResultsData.h"
#include "RigCaseData.h"
#include "RigResultAccessor.h"
#include "RigResultAccessorFactory.h"
#include "RimCrossSection.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimEclipseCellColors.h"
#include "RimEclipseView.h"
#include "RimTernaryLegendConfig.h"
//#include "RimCrossSectionCollection.h"
#include "RivResultToTextureMapper.h"
#include "RivScalarMapperUtils.h"
#include "RivTernaryScalarMapper.h"
@ -47,19 +43,16 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivCrossSectionPartMgr::RivCrossSectionPartMgr( const RigMainGrid* grid,
const RimCrossSectionCollection* rimCrossSectionCollection,
const RimCrossSection* rimCrossSection,
const std::vector<cvf::Vec3d>& polyLine)
: m_grid(grid),
m_rimCrossSectionCollection(rimCrossSectionCollection),
m_rimCrossSection(rimCrossSection),
m_defaultColor(cvf::Color3::WHITE)
RivCrossSectionPartMgr::RivCrossSectionPartMgr(const RimCrossSection* rimCrossSection)
: m_rimCrossSection(rimCrossSection),
m_grid(NULL),
m_defaultColor(cvf::Color3::WHITE)
{
m_nativeCrossSectionGenerator = new RivCrossSectionGeometryGenerator(polyLine, cvf::Vec3d(0.0,0,1.0), grid );
CVF_ASSERT(m_rimCrossSection);
m_nativeCrossSectionFacesTextureCoords = new cvf::Vec2fArray;
computeData();
}
//--------------------------------------------------------------------------------------------------
@ -67,6 +60,8 @@ RivCrossSectionPartMgr::RivCrossSectionPartMgr( const RigMainGrid* grid,
//--------------------------------------------------------------------------------------------------
void RivCrossSectionPartMgr::applySingleColorEffect()
{
if (m_nativeCrossSectionGenerator.isNull()) return;
m_defaultColor = cvf::Color3f::OLIVE;//m_rimCrossSection->CrossSectionColor();
this->updatePartEffect();
}
@ -76,6 +71,8 @@ void RivCrossSectionPartMgr::applySingleColorEffect()
//--------------------------------------------------------------------------------------------------
void RivCrossSectionPartMgr::updateCellResultColor(size_t timeStepIndex, RimEclipseCellColors* cellResultColors)
{
if (m_nativeCrossSectionGenerator.isNull()) return;
CVF_ASSERT(cellResultColors);
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultColors->porosityModel());
@ -106,6 +103,8 @@ void RivCrossSectionPartMgr::updateCellResultColor(size_t timeStepIndex, RimEcli
}
else
{
CVF_ASSERT(m_nativeCrossSectionGenerator.notNull());
const cvf::ScalarMapper* mapper = cellResultColors->legendConfig()->scalarMapper();
cvf::ref<RigResultAccessor> resultAccessor = RigResultAccessorFactory::createResultAccessor(cellResultColors->reservoirView()->eclipseCase()->reservoirData(),
@ -137,6 +136,7 @@ const int priMesh = 3;
//--------------------------------------------------------------------------------------------------
void RivCrossSectionPartMgr::generatePartGeometry()
{
if (m_nativeCrossSectionGenerator.isNull()) return;
bool useBufferObjects = true;
// Surface geometry
@ -199,6 +199,8 @@ void RivCrossSectionPartMgr::generatePartGeometry()
//--------------------------------------------------------------------------------------------------
void RivCrossSectionPartMgr::updatePartEffect()
{
if (m_nativeCrossSectionGenerator.isNull()) return;
// Set deCrossSection effect
caf::SurfaceEffectGenerator geometryEffgen(m_defaultColor, caf::PO_1);
@ -258,3 +260,59 @@ void RivCrossSectionPartMgr::appendMeshLinePartsToModel(cvf::ModelBasicList* mod
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivCrossSectionPartMgr::computeData()
{
m_grid = mainGrid();
CVF_ASSERT(m_grid.notNull());
std::vector< std::vector <cvf::Vec3d> > polyLine = m_rimCrossSection->polyLines();
if (polyLine.size() > 0)
{
cvf::Vec3d direction = extrusionDirection(polyLine[0]);
m_nativeCrossSectionGenerator = new RivCrossSectionGeometryGenerator(polyLine[0], direction, m_grid.p());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigMainGrid* RivCrossSectionPartMgr::mainGrid()
{
RigMainGrid* grid = NULL;
RimEclipseView* eclipseView = NULL;
m_rimCrossSection->firstAnchestorOrThisOfType(eclipseView);
if (eclipseView)
{
grid = eclipseView->eclipseCase()->reservoirData()->mainGrid();
}
return grid;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3d RivCrossSectionPartMgr::extrusionDirection(const std::vector<cvf::Vec3d>& polyline) const
{
CVF_ASSERT(m_rimCrossSection);
cvf::Vec3d dir = cvf::Vec3d::Z_AXIS;
if (m_rimCrossSection->direction == RimCrossSection::CS_VERTICAL &&
polyline.size() > 1)
{
// Use first and last point of polyline to approximate orientation of polyline
// Then cross with Z axis to find extrusion direction
cvf::Vec3d polyLineDir = polyline[polyline.size() - 1] - polyline[0];
cvf::Vec3d up = cvf::Vec3d::Z_AXIS;
dir = polyLineDir ^ up;
}
return dir;
}

View File

@ -18,12 +18,14 @@
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RivCrossSectionGeometryGenerator.h"
#include "cvfBase.h"
#include "cvfObject.h"
//#include "RimCrossSection.h"
#include "RivCrossSectionGeometryGenerator.h"
#include "cvfColor4.h"
#include "cvfVector3.h"
namespace cvf
{
@ -32,9 +34,9 @@ namespace cvf
class Part;
}
class RigMainGrid;
class RimEclipseCellColors;
class RimCellEdgeColors;
class RimCrossSectionCollection;
class RimCrossSection;
//==================================================================================================
@ -45,10 +47,7 @@ class RimCrossSection;
class RivCrossSectionPartMgr : public cvf::Object
{
public:
RivCrossSectionPartMgr(const RigMainGrid* grid,
const RimCrossSectionCollection* rimCrossSectionCollection,
const RimCrossSection* rimCrossSection,
const std::vector<cvf::Vec3d>& polyLine);
RivCrossSectionPartMgr(const RimCrossSection* rimCrossSection);
void applySingleColorEffect();
void updateCellResultColor(size_t timeStepIndex, RimEclipseCellColors* cellResultColors);
@ -59,10 +58,15 @@ public:
private:
void updatePartEffect();
void generatePartGeometry();
void computeData();
RigMainGrid* mainGrid();
cvf::Vec3d extrusionDirection(const std::vector<cvf::Vec3d>& polyline) const;
private:
cvf::cref<RigMainGrid> m_grid;
const RimCrossSection* m_rimCrossSection;
const RimCrossSectionCollection* m_rimCrossSectionCollection;
const RimCrossSection* m_rimCrossSection;
cvf::Color3f m_defaultColor;

View File

@ -28,6 +28,7 @@
#include "RimProject.h"
#include "RimWellPath.h"
#include "RivCrossSectionPartMgr.h"
namespace caf {
@ -78,7 +79,14 @@ RimCrossSection::RimCrossSection()
//--------------------------------------------------------------------------------------------------
void RimCrossSection::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
m_crossSectionPartMgr = NULL;
RimView* rimView = NULL;
this->firstAnchestorOrThisOfType(rimView);
if (rimView)
{
rimView->scheduleCreateDisplayModelAndRedraw();
}
}
//--------------------------------------------------------------------------------------------------
@ -213,3 +221,13 @@ std::vector< std::vector <cvf::Vec3d> > RimCrossSection::polyLines() const
return line;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivCrossSectionPartMgr* RimCrossSection::crossSectionPartMgr()
{
if (m_crossSectionPartMgr.isNull()) m_crossSectionPartMgr = new RivCrossSectionPartMgr(this);
return m_crossSectionPartMgr.p();
}

View File

@ -25,12 +25,13 @@
#include "cafPdmPtrField.h"
#include "cvfBase.h"
#include "cvfObject.h"
#include "cvfVector3.h"
class RimEclipseWell;
class RimEclipseWellCollection;
class RimWellPath;
class RivCrossSectionPartMgr;
//==================================================================================================
//
@ -72,6 +73,8 @@ public:
virtual caf::PdmFieldHandle* userDescriptionField();
virtual caf::PdmFieldHandle* objectToggleField();
RivCrossSectionPartMgr* crossSectionPartMgr();
protected:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering);
@ -80,4 +83,7 @@ protected:
private:
RimEclipseWellCollection* simulationWellCollection();
private:
cvf::ref<RivCrossSectionPartMgr> m_crossSectionPartMgr;
};

View File

@ -20,6 +20,7 @@
#include "RimCrossSectionCollection.h"
#include "RimCrossSection.h"
#include "RivCrossSectionPartMgr.h"
CAF_PDM_SOURCE_INIT(RimCrossSectionCollection, "CrossSectionCollection");
@ -45,3 +46,43 @@ caf::PdmFieldHandle* RimCrossSectionCollection::objectToggleField()
{
return &isActive;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCrossSectionCollection::applySingleColorEffect()
{
for (size_t csIdx = 0; csIdx < crossSections.size(); ++csIdx)
{
RimCrossSection* cs = crossSections[csIdx];
cs->crossSectionPartMgr()->applySingleColorEffect();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCrossSectionCollection::updateCellResultColor(size_t timeStepIndex, RimEclipseCellColors* cellResultColors)
{
for (size_t csIdx = 0; csIdx < crossSections.size(); ++csIdx)
{
RimCrossSection* cs = crossSections[csIdx];
cs->crossSectionPartMgr()->updateCellResultColor(timeStepIndex, cellResultColors);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCrossSectionCollection::appendPartsToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform)
{
for (size_t csIdx = 0; csIdx < crossSections.size(); ++csIdx)
{
RimCrossSection* cs = crossSections[csIdx];
if (cs->isActive)
{
cs->crossSectionPartMgr()->appendNativeCrossSectionFacesToModel(model, scaleTransform);
cs->crossSectionPartMgr()->appendMeshLinePartsToModel(model, scaleTransform);
}
}
}

View File

@ -24,6 +24,12 @@
#include "cafPdmField.h"
class RimCrossSection;
class RimEclipseCellColors;
namespace cvf {
class ModelBasicList;
class Transform;
}
//==================================================================================================
//
@ -40,6 +46,11 @@ public:
caf::PdmField<bool> isActive;
caf::PdmChildArrayField<RimCrossSection*> crossSections;
void applySingleColorEffect();
void updateCellResultColor(size_t timeStepIndex, RimEclipseCellColors* cellResultColors);
void appendPartsToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform);
protected:
//virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
//virtual void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName);

View File

@ -31,6 +31,7 @@
#include "Rim3dOverlayInfoConfig.h"
#include "RimCellEdgeColors.h"
#include "RimCellRangeFilterCollection.h"
#include "RimCrossSection.h"
#include "RimCrossSectionCollection.h"
#include "RimEclipseCase.h"
#include "RimEclipseCellColors.h"
@ -71,7 +72,6 @@
#include <QMessageBox>
#include <limits.h>
#include "RivCrossSectionPartMgr.h"
@ -418,21 +418,13 @@ void RimEclipseView::createDisplayModel()
}
// Hack to do testing of cross section
{
#if 0
cvf::ref<cvf::ModelBasicList> tempMod = new cvf::ModelBasicList;
m_pipesPartManager->appendDynamicGeometryPartsToModel(tempMod.p(), 3);
if (m_csPartmgr.isNull()) m_csPartmgr = new RivCrossSectionPartMgr(m_reservoir->reservoirData()->mainGrid(), NULL, NULL,
(*m_pipesPartManager->centerLineOfWellBranches(0))[0]);
for (size_t frameIdx = 0; frameIdx < frameModels.size(); ++frameIdx)
{
m_csPartmgr->appendNativeCrossSectionFacesToModel(frameModels[frameIdx].p(), m_reservoirGridPartManager->scaleTransform());
m_csPartmgr->appendMeshLinePartsToModel(frameModels[frameIdx].p(), m_reservoirGridPartManager->scaleTransform());
}
#endif
}
// Cross sections
m_crossSectionModel->removeAllParts();
crossSectionCollection->appendPartsToModel(m_crossSectionModel.p(), m_reservoirGridPartManager->scaleTransform());
m_viewer->addStaticModel(m_crossSectionModel.p());
// Compute triangle count, Debug only
/*
@ -660,9 +652,14 @@ void RimEclipseView::updateCurrentTimeStep()
this->updateFaultColors();
// Hack to do testing of cross section
if ((this->hasUserRequestedAnimation() && this->cellResult()->hasResult()) || this->cellResult()->isTernarySaturationSelected())
{
// this->m_csPartmgr->updateCellResultColor(m_currentTimeStep, this->cellResult());
crossSectionCollection->updateCellResultColor(m_currentTimeStep, this->cellResult());
}
else
{
crossSectionCollection->applySingleColorEffect();
}
// Well pipes

View File

@ -182,7 +182,6 @@ private:
cvf::ref<RivReservoirViewPartMgr> m_reservoirGridPartManager;
cvf::ref<RivReservoirPipesPartMgr> m_pipesPartManager;
cvf::ref<RivCrossSectionPartMgr> m_csPartmgr;
std::vector<RivCellSetEnum> m_visibleGridParts;
};

View File

@ -122,6 +122,13 @@ RimView::RimView(void)
crossSectionCollection = new RimCrossSectionCollection();
m_previousGridModeMeshLinesWasFaults = false;
m_crossSectionModel = new cvf::ModelBasicList;
m_crossSectionModel->setName("CrossSectionModel");
m_highlightModelBasicList = new cvf::ModelBasicList;
m_highlightModelBasicList->setName("HighlightModel");
}
//--------------------------------------------------------------------------------------------------
@ -276,7 +283,7 @@ void RimView::createDisplayModelAndRedraw()
this->clampCurrentTimestep();
createDisplayModel();
createOverlayDisplayModel();
createHighlightAndGridBoxDisplayModel();
updateDisplayModelVisibility();
if (cameraPosition().isIdentity())
@ -518,7 +525,7 @@ void RimView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QV
}
else if (changedField == &showGridBox)
{
createOverlayDisplayModelAndRedraw();
createHighlightAndGridBoxDisplayModelWithRedraw();
}
else if (changedField == &m_disableLighting)
{
@ -801,9 +808,9 @@ void RimView::updateGridBoxData()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView::createOverlayDisplayModelAndRedraw()
void RimView::createHighlightAndGridBoxDisplayModelWithRedraw()
{
createOverlayDisplayModel();
createHighlightAndGridBoxDisplayModel();
if (m_viewer)
{
@ -814,26 +821,24 @@ void RimView::createOverlayDisplayModelAndRedraw()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView::createOverlayDisplayModel()
void RimView::createHighlightAndGridBoxDisplayModel()
{
m_viewer->removeAllStaticModels();
m_viewer->removeStaticModel(m_highlightModelBasicList.p());
m_viewer->removeStaticModel(m_viewer->gridBoxModel());
m_highlightModelBasicList->removeAllParts();
cvf::Collection<cvf::Part> parts;
createPartCollectionFromSelection(&parts);
if (parts.size() > 0)
{
cvf::String highlightModelName = "HighLightModel";
cvf::ref<cvf::ModelBasicList> highlightModelBasicList = new cvf::ModelBasicList;
highlightModelBasicList->setName(highlightModelName);
for (size_t i = 0; i < parts.size(); i++)
{
highlightModelBasicList->addPart(parts[i].p());
m_highlightModelBasicList->addPart(parts[i].p());
}
highlightModelBasicList->updateBoundingBoxesRecursive();
m_viewer->addStaticModel(highlightModelBasicList.p());
m_highlightModelBasicList->updateBoundingBoxesRecursive();
m_viewer->addStaticModel(m_highlightModelBasicList.p());
}
if (showGridBox)

View File

@ -135,7 +135,7 @@ public:
virtual void scheduleGeometryRegen(RivCellSetEnum geometryType) = 0;
void scheduleCreateDisplayModelAndRedraw();
void createDisplayModelAndRedraw();
void createOverlayDisplayModelAndRedraw();
void createHighlightAndGridBoxDisplayModelWithRedraw();
RimViewController* viewController() const;
bool isMasterView() const;
@ -165,7 +165,7 @@ protected:
virtual void createDisplayModel() = 0;
void createOverlayDisplayModel();
void createHighlightAndGridBoxDisplayModel();
void updateGridBoxData();
virtual void createPartCollectionFromSelection(cvf::Collection<cvf::Part>* parts) = 0;
@ -200,6 +200,9 @@ protected:
cvf::ref<cvf::UByteArray> m_currentReservoirCellVisibility;
cvf::ref<cvf::ModelBasicList> m_crossSectionModel;
cvf::ref<cvf::ModelBasicList> m_highlightModelBasicList;
private:
RimViewLinker* viewLinkerIfMasterView() const;

View File

@ -200,7 +200,7 @@ void RiuSelectionChangedHandler::scheduleUpdateForAllVisibleViews() const
for (size_t i = 0; i < visibleViews.size(); i++)
{
visibleViews[i]->createOverlayDisplayModelAndRedraw();
visibleViews[i]->createHighlightAndGridBoxDisplayModelWithRedraw();
}
}
}