mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 07:26:03 -06:00
#5316 Prototype of results mapping on native surface nodes only
This commit is contained in:
parent
17f2c71a11
commit
5b1b7e630a
@ -22,7 +22,22 @@
|
|||||||
#include "RimSurface.h"
|
#include "RimSurface.h"
|
||||||
#include "RimSurfaceInView.h"
|
#include "RimSurfaceInView.h"
|
||||||
|
|
||||||
|
#include "RigHexIntersectionTools.h"
|
||||||
|
#include "RigResultAccessor.h"
|
||||||
|
#include "RigResultAccessorFactory.h"
|
||||||
#include "RimCase.h"
|
#include "RimCase.h"
|
||||||
|
#include "RimEclipseCase.h"
|
||||||
|
#include "RimEclipseCellColors.h"
|
||||||
|
#include "RimEclipseResultDefinition.h"
|
||||||
|
#include "RimEclipseView.h"
|
||||||
|
#include "RimGeoMechCellColors.h"
|
||||||
|
#include "RimGeoMechResultDefinition.h"
|
||||||
|
#include "RimGeoMechView.h"
|
||||||
|
#include "RimRegularLegendConfig.h"
|
||||||
|
#include "RimTernaryLegendConfig.h"
|
||||||
|
#include "RivHexGridIntersectionTools.h"
|
||||||
|
#include "RivScalarMapperUtils.h"
|
||||||
|
#include "RivTernaryScalarMapper.h"
|
||||||
#include "cafEffectGenerator.h"
|
#include "cafEffectGenerator.h"
|
||||||
#include "cvfDrawableGeo.h"
|
#include "cvfDrawableGeo.h"
|
||||||
#include "cvfModelBasicList.h"
|
#include "cvfModelBasicList.h"
|
||||||
@ -50,10 +65,7 @@ void RivSurfacePartMgr::appendNativeGeometryPartsToModel( cvf::ModelBasicList* m
|
|||||||
if ( m_nativeTrianglesPart.notNull() )
|
if ( m_nativeTrianglesPart.notNull() )
|
||||||
{
|
{
|
||||||
m_nativeTrianglesPart->setTransform( scaleTransform );
|
m_nativeTrianglesPart->setTransform( scaleTransform );
|
||||||
|
this->applySingleColor();
|
||||||
caf::SurfaceEffectGenerator surfaceGen( cvf::Color4f( m_surfaceInView->surface()->color() ), caf::PO_1 );
|
|
||||||
cvf::ref<cvf::Effect> eff = surfaceGen.generateCachedEffect();
|
|
||||||
m_nativeTrianglesPart->setEffect( eff.p() );
|
|
||||||
|
|
||||||
model->addPart( m_nativeTrianglesPart.p() );
|
model->addPart( m_nativeTrianglesPart.p() );
|
||||||
|
|
||||||
@ -65,6 +77,105 @@ void RivSurfacePartMgr::appendNativeGeometryPartsToModel( cvf::ModelBasicList* m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RivSurfacePartMgr::updateCellResultColor( size_t timeStepIndex )
|
||||||
|
{
|
||||||
|
if ( !m_vertexToCellIndexMap.size() )
|
||||||
|
{
|
||||||
|
generateVertexToCellIndexMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
RimGridView* gridView = nullptr;
|
||||||
|
m_surfaceInView->firstAncestorOrThisOfType( gridView );
|
||||||
|
|
||||||
|
if ( !gridView ) return;
|
||||||
|
|
||||||
|
bool isLightingDisabled = gridView->isLightingDisabled();
|
||||||
|
|
||||||
|
RimEclipseResultDefinition* eclipseResDef = nullptr;
|
||||||
|
RimGeoMechResultDefinition* geomResultDef = nullptr;
|
||||||
|
const cvf::ScalarMapper* scalarColorMapper = nullptr;
|
||||||
|
const RivTernaryScalarMapper* ternaryColorMapper = nullptr;
|
||||||
|
|
||||||
|
// Ordinary result
|
||||||
|
|
||||||
|
if ( !eclipseResDef && !geomResultDef )
|
||||||
|
{
|
||||||
|
RimEclipseView* eclipseView = nullptr;
|
||||||
|
m_surfaceInView->firstAncestorOrThisOfType( eclipseView );
|
||||||
|
|
||||||
|
if ( eclipseView )
|
||||||
|
{
|
||||||
|
eclipseResDef = eclipseView->cellResult();
|
||||||
|
if ( !scalarColorMapper ) scalarColorMapper = eclipseView->cellResult()->legendConfig()->scalarMapper();
|
||||||
|
if ( !ternaryColorMapper )
|
||||||
|
ternaryColorMapper = eclipseView->cellResult()->ternaryLegendConfig()->scalarMapper();
|
||||||
|
}
|
||||||
|
|
||||||
|
RimGeoMechView* geoView;
|
||||||
|
m_surfaceInView->firstAncestorOrThisOfType( geoView );
|
||||||
|
|
||||||
|
if ( geoView )
|
||||||
|
{
|
||||||
|
geomResultDef = geoView->cellResult();
|
||||||
|
if ( !scalarColorMapper ) scalarColorMapper = geoView->cellResult()->legendConfig()->scalarMapper();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cvf::ref<cvf::Vec2fArray> intersectionFacesTextureCoords = new cvf::Vec2fArray();
|
||||||
|
|
||||||
|
if ( eclipseResDef )
|
||||||
|
{
|
||||||
|
if ( !eclipseResDef->isTernarySaturationSelected() )
|
||||||
|
{
|
||||||
|
RigEclipseCaseData* eclipseCaseData = eclipseResDef->eclipseCase()->eclipseCaseData();
|
||||||
|
|
||||||
|
cvf::ref<RigResultAccessor> resultAccessor;
|
||||||
|
|
||||||
|
if ( !RiaDefines::isPerCellFaceResult( eclipseResDef->resultVariable() ) )
|
||||||
|
|
||||||
|
{
|
||||||
|
resultAccessor = RigResultAccessorFactory::createFromResultDefinition( eclipseCaseData,
|
||||||
|
0,
|
||||||
|
timeStepIndex,
|
||||||
|
eclipseResDef );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( resultAccessor.isNull() )
|
||||||
|
{
|
||||||
|
resultAccessor = new RigHugeValResultAccessor;
|
||||||
|
}
|
||||||
|
|
||||||
|
RivSurfacePartMgr::calculateVertexTextureCoordinates( intersectionFacesTextureCoords.p(),
|
||||||
|
m_vertexToCellIndexMap,
|
||||||
|
resultAccessor.p(),
|
||||||
|
scalarColorMapper );
|
||||||
|
|
||||||
|
RivScalarMapperUtils::applyTextureResultsToPart( m_nativeTrianglesPart.p(),
|
||||||
|
intersectionFacesTextureCoords.p(),
|
||||||
|
scalarColorMapper,
|
||||||
|
1.0,
|
||||||
|
caf::FC_NONE,
|
||||||
|
isLightingDisabled );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RivSurfacePartMgr::applySingleColor()
|
||||||
|
{
|
||||||
|
if ( m_nativeTrianglesPart.notNull() )
|
||||||
|
{
|
||||||
|
caf::SurfaceEffectGenerator surfaceGen( cvf::Color4f( m_surfaceInView->surface()->color() ), caf::PO_1 );
|
||||||
|
cvf::ref<cvf::Effect> eff = surfaceGen.generateCachedEffect();
|
||||||
|
m_nativeTrianglesPart->setEffect( eff.p() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -95,4 +206,67 @@ void RivSurfacePartMgr::generateNativePartGeometry()
|
|||||||
|
|
||||||
m_nativeTrianglesPart = new cvf::Part();
|
m_nativeTrianglesPart = new cvf::Part();
|
||||||
m_nativeTrianglesPart->setDrawable( drawGeo.p() );
|
m_nativeTrianglesPart->setDrawable( drawGeo.p() );
|
||||||
|
|
||||||
|
m_vertexToCellIndexMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RivSurfacePartMgr::generateVertexToCellIndexMap()
|
||||||
|
{
|
||||||
|
cvf::ref<RivIntersectionHexGridInterface> hexGrid = m_surfaceInView->createHexGridInterface();
|
||||||
|
|
||||||
|
const std::vector<cvf::Vec3d>& vertices = m_usedSurfaceData->vertices();
|
||||||
|
m_vertexToCellIndexMap.resize( vertices.size(), -1 );
|
||||||
|
|
||||||
|
for ( size_t vxIdx = 0; vxIdx < vertices.size(); ++vxIdx )
|
||||||
|
{
|
||||||
|
cvf::BoundingBox box;
|
||||||
|
box.add( vertices[vxIdx] );
|
||||||
|
std::vector<size_t> cellCandidates;
|
||||||
|
hexGrid->findIntersectingCells( box, &cellCandidates );
|
||||||
|
|
||||||
|
for ( size_t cellIdx : cellCandidates )
|
||||||
|
{
|
||||||
|
cvf::Vec3d cellCorners[8];
|
||||||
|
hexGrid->cellCornerVertices( cellIdx, cellCorners );
|
||||||
|
|
||||||
|
if ( RigHexIntersectionTools::isPointInCell( vertices[vxIdx], cellCorners ) )
|
||||||
|
{
|
||||||
|
m_vertexToCellIndexMap[vxIdx] = cellIdx;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// Calculates the texture coordinates in a "nearly" one dimensional texture.
|
||||||
|
/// Undefined values are coded with a y-texturecoordinate value of 1.0 instead of the normal 0.5
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RivSurfacePartMgr::calculateVertexTextureCoordinates( cvf::Vec2fArray* textureCoords,
|
||||||
|
const std::vector<size_t>& vertexToCellIdxMap,
|
||||||
|
const RigResultAccessor* resultAccessor,
|
||||||
|
const cvf::ScalarMapper* mapper )
|
||||||
|
{
|
||||||
|
if ( !resultAccessor ) return;
|
||||||
|
|
||||||
|
size_t numVertices = vertexToCellIdxMap.size();
|
||||||
|
|
||||||
|
textureCoords->resize( numVertices );
|
||||||
|
cvf::Vec2f* rawPtr = textureCoords->ptr();
|
||||||
|
|
||||||
|
#pragma omp parallel for
|
||||||
|
for ( int vxIdx = 0; vxIdx < numVertices; vxIdx++ )
|
||||||
|
{
|
||||||
|
double cellScalarValue = resultAccessor->cellScalarGlobIdx( vertexToCellIdxMap[vxIdx] );
|
||||||
|
cvf::Vec2f texCoord = mapper->mapToTextureCoord( cellScalarValue );
|
||||||
|
if ( cellScalarValue == HUGE_VAL || cellScalarValue != cellScalarValue ) // a != a is true for NAN's
|
||||||
|
{
|
||||||
|
texCoord[1] = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
rawPtr[vxIdx] = texCoord;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cafPdmPointer.h"
|
#include "cafPdmPointer.h"
|
||||||
|
#include "cvfArray.h"
|
||||||
#include "cvfObject.h"
|
#include "cvfObject.h"
|
||||||
|
|
||||||
namespace cvf
|
namespace cvf
|
||||||
@ -31,6 +32,7 @@ class DrawableGeo;
|
|||||||
|
|
||||||
class RimSurfaceInView;
|
class RimSurfaceInView;
|
||||||
class RigSurface;
|
class RigSurface;
|
||||||
|
class RigResultAccessor;
|
||||||
|
|
||||||
class RivSurfacePartMgr : public cvf::Object
|
class RivSurfacePartMgr : public cvf::Object
|
||||||
{
|
{
|
||||||
@ -38,13 +40,23 @@ public:
|
|||||||
explicit RivSurfacePartMgr( RimSurfaceInView* surface );
|
explicit RivSurfacePartMgr( RimSurfaceInView* surface );
|
||||||
|
|
||||||
void appendNativeGeometryPartsToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform );
|
void appendNativeGeometryPartsToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform );
|
||||||
|
void updateCellResultColor( size_t timeStepIndex );
|
||||||
|
void applySingleColor();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void generateNativePartGeometry();
|
void generateNativePartGeometry();
|
||||||
|
void generateVertexToCellIndexMap();
|
||||||
|
|
||||||
|
static void calculateVertexTextureCoordinates( cvf::Vec2fArray* textureCoords,
|
||||||
|
const std::vector<size_t>& vertexToCellIdxMap,
|
||||||
|
const RigResultAccessor* resultAccessor,
|
||||||
|
const cvf::ScalarMapper* mapper );
|
||||||
|
|
||||||
caf::PdmPointer<RimSurfaceInView> m_surfaceInView;
|
caf::PdmPointer<RimSurfaceInView> m_surfaceInView;
|
||||||
cvf::ref<RigSurface> m_usedSurfaceData; // Store the reference to the old data, to know when new data has arrived.
|
cvf::ref<RigSurface> m_usedSurfaceData; // Store the reference to the old data, to know when new data has arrived.
|
||||||
|
|
||||||
cvf::ref<cvf::Part> m_nativeTrianglesPart;
|
cvf::ref<cvf::Part> m_nativeTrianglesPart;
|
||||||
cvf::ref<cvf::Part> m_nativeMeshLinesPart;
|
cvf::ref<cvf::Part> m_nativeMeshLinesPart;
|
||||||
|
|
||||||
|
std::vector<size_t> m_vertexToCellIndexMap;
|
||||||
};
|
};
|
||||||
|
@ -803,10 +803,11 @@ void RimEclipseView::updateVisibleGeometriesAndCellColors()
|
|||||||
|
|
||||||
this->updateFaultColors();
|
this->updateFaultColors();
|
||||||
|
|
||||||
m_intersectionCollection->updateCellResultColor( ( this->hasUserRequestedAnimation() &&
|
bool hasGeneralCellResult = ( this->hasUserRequestedAnimation() && this->cellResult()->hasResult() ) ||
|
||||||
this->cellResult()->hasResult() ) ||
|
this->cellResult()->isTernarySaturationSelected();
|
||||||
this->cellResult()->isTernarySaturationSelected(),
|
|
||||||
m_currentTimeStep );
|
m_intersectionCollection->updateCellResultColor( hasGeneralCellResult, m_currentTimeStep );
|
||||||
|
m_surfaceCollection->updateCellResultColor( hasGeneralCellResult, m_currentTimeStep );
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -21,6 +21,10 @@
|
|||||||
#include "RimGridView.h"
|
#include "RimGridView.h"
|
||||||
#include "RimSurface.h"
|
#include "RimSurface.h"
|
||||||
|
|
||||||
|
#include "RigFemPartCollection.h"
|
||||||
|
#include "RimEclipseView.h"
|
||||||
|
#include "RimGeoMechView.h"
|
||||||
|
#include "RivHexGridIntersectionTools.h"
|
||||||
#include "RivSurfacePartMgr.h"
|
#include "RivSurfacePartMgr.h"
|
||||||
|
|
||||||
CAF_PDM_SOURCE_INIT( RimSurfaceInView, "SurfaceInView" );
|
CAF_PDM_SOURCE_INIT( RimSurfaceInView, "SurfaceInView" );
|
||||||
@ -134,3 +138,53 @@ caf::PdmFieldHandle* RimSurfaceInView::objectToggleField()
|
|||||||
{
|
{
|
||||||
return &m_isActive;
|
return &m_isActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
cvf::ref<RivIntersectionHexGridInterface> RimSurfaceInView::createHexGridInterface()
|
||||||
|
{
|
||||||
|
// RimIntersectionResultDefinition* resDef = activeSeparateResultDefinition();
|
||||||
|
// if ( resDef && resDef->activeCase() )
|
||||||
|
//{
|
||||||
|
// // Eclipse case
|
||||||
|
//
|
||||||
|
// RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>( resDef->activeCase() );
|
||||||
|
// if ( eclipseCase && eclipseCase->eclipseCaseData() )
|
||||||
|
// {
|
||||||
|
// return new RivEclipseIntersectionGrid( eclipseCase->eclipseCaseData()->mainGrid(),
|
||||||
|
// eclipseCase->eclipseCaseData()->activeCellInfo(
|
||||||
|
// resDef->eclipseResultDefinition()->porosityModel() ),
|
||||||
|
// this->isInactiveCellsVisible() );
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Geomech case
|
||||||
|
//
|
||||||
|
// RimGeoMechCase* geomCase = dynamic_cast<RimGeoMechCase*>( resDef->activeCase() );
|
||||||
|
//
|
||||||
|
// if ( geomCase && geomCase->geoMechData() && geomCase->geoMechData()->femParts() )
|
||||||
|
// {
|
||||||
|
// RigFemPart* femPart = geomCase->geoMechData()->femParts()->part( 0 );
|
||||||
|
// return new RivFemIntersectionGrid( femPart );
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
RimEclipseView* eclipseView;
|
||||||
|
this->firstAncestorOrThisOfType( eclipseView );
|
||||||
|
if ( eclipseView )
|
||||||
|
{
|
||||||
|
RigMainGrid* grid = eclipseView->mainGrid();
|
||||||
|
return new RivEclipseIntersectionGrid( grid, eclipseView->currentActiveCellInfo(), true );
|
||||||
|
}
|
||||||
|
|
||||||
|
RimGeoMechView* geoView;
|
||||||
|
this->firstAncestorOrThisOfType( geoView );
|
||||||
|
if ( geoView && geoView->femParts() && geoView->femParts()->partCount() )
|
||||||
|
{
|
||||||
|
RigFemPart* femPart = geoView->femParts()->part( 0 );
|
||||||
|
|
||||||
|
return new RivFemIntersectionGrid( femPart );
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
class RimSurface;
|
class RimSurface;
|
||||||
class RivSurfacePartMgr;
|
class RivSurfacePartMgr;
|
||||||
|
class RivIntersectionHexGridInterface;
|
||||||
|
|
||||||
class RimSurfaceInView : public caf::PdmObject
|
class RimSurfaceInView : public caf::PdmObject
|
||||||
{
|
{
|
||||||
@ -45,10 +46,12 @@ public:
|
|||||||
void clearGeometry();
|
void clearGeometry();
|
||||||
RivSurfacePartMgr* surfacePartMgr();
|
RivSurfacePartMgr* surfacePartMgr();
|
||||||
|
|
||||||
|
cvf::ref<RivIntersectionHexGridInterface> createHexGridInterface();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
caf::PdmFieldHandle* userDescriptionField() override;
|
caf::PdmFieldHandle* userDescriptionField() override;
|
||||||
caf::PdmFieldHandle* objectToggleField() override;
|
caf::PdmFieldHandle* objectToggleField() override;
|
||||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
void fieldChangedByUi(const caf::PdmFieldHandle* changedField,
|
||||||
const QVariant& oldValue,
|
const QVariant& oldValue,
|
||||||
const QVariant& newValue ) override;
|
const QVariant& newValue ) override;
|
||||||
|
|
||||||
|
@ -147,3 +147,28 @@ caf::PdmFieldHandle* RimSurfaceInViewCollection::objectToggleField()
|
|||||||
{
|
{
|
||||||
return &m_isActive;
|
return &m_isActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimSurfaceInViewCollection::updateCellResultColor( bool hasGeneralCellResult, size_t timeStepIndex )
|
||||||
|
{
|
||||||
|
if ( !this->m_isActive() ) return;
|
||||||
|
|
||||||
|
for ( RimSurfaceInView* surf : m_surfacesInView )
|
||||||
|
{
|
||||||
|
if ( surf->isActive() )
|
||||||
|
{
|
||||||
|
bool hasSeparateInterResult = false; // surf->activeSeparateResultDefinition() &&
|
||||||
|
// surf->activeSeparateResultDefinition()->hasResult();
|
||||||
|
if ( hasSeparateInterResult || hasGeneralCellResult )
|
||||||
|
{
|
||||||
|
surf->surfacePartMgr()->updateCellResultColor( timeStepIndex );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
surf->surfacePartMgr()->applySingleColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
void updateFromSurfaceCollection();
|
void updateFromSurfaceCollection();
|
||||||
|
|
||||||
void appendPartsToModel( cvf::ModelBasicList* surfaceVizModel, cvf::Transform* scaleTransform );
|
void appendPartsToModel( cvf::ModelBasicList* surfaceVizModel, cvf::Transform* scaleTransform );
|
||||||
|
void updateCellResultColor( bool hasGeneralCellResult, size_t timeStepIndex );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
caf::PdmFieldHandle* objectToggleField() override;
|
caf::PdmFieldHandle* objectToggleField() override;
|
||||||
|
Loading…
Reference in New Issue
Block a user