#5318 Surface Intersection geometry with results

This commit is contained in:
Jacob Støren
2020-01-17 13:23:37 +01:00
parent 67b47bd07e
commit d32db574cb
15 changed files with 925 additions and 95 deletions

View File

@@ -18,13 +18,9 @@
#include "RivSurfacePartMgr.h"
#include "RigSurface.h"
#include "RimSurface.h"
#include "RimSurfaceInView.h"
#include "RiaApplication.h"
#include "RiaPreferences.h"
#include "RigHexIntersectionTools.h"
#include "RigResultAccessor.h"
#include "RigResultAccessorFactory.h"
#include "RimCase.h"
#include "RimEclipseCase.h"
#include "RimEclipseCellColors.h"
@@ -34,11 +30,26 @@
#include "RimGeoMechResultDefinition.h"
#include "RimGeoMechView.h"
#include "RimRegularLegendConfig.h"
#include "RimSurface.h"
#include "RimSurfaceInView.h"
#include "RimTernaryLegendConfig.h"
#include "RigHexIntersectionTools.h"
#include "RigResultAccessor.h"
#include "RigResultAccessorFactory.h"
#include "RigSurface.h"
#include "RivHexGridIntersectionTools.h"
#include "RivIntersectionResultsColoringTools.h"
#include "RivMeshLinesSourceInfo.h"
#include "RivPartPriority.h"
#include "RivReservoirSurfaceIntersectionSourceInfo.h"
#include "RivScalarMapperUtils.h"
#include "RivSurfaceIntersectionGeometryGenerator.h"
#include "RivTernaryScalarMapper.h"
#include "cafEffectGenerator.h"
#include "cvfDrawableGeo.h"
#include "cvfModelBasicList.h"
#include "cvfPart.h"
@@ -50,6 +61,12 @@
RivSurfacePartMgr::RivSurfacePartMgr( RimSurfaceInView* surface )
: m_surfaceInView( surface )
{
CVF_ASSERT( surface );
m_intersectionFacesTextureCoords = new cvf::Vec2fArray;
cvf::ref<RivIntersectionHexGridInterface> hexGrid = m_surfaceInView->createHexGridInterface();
m_intersectionGenerator = new RivSurfaceIntersectionGeometryGenerator( m_surfaceInView, hexGrid.p() );
}
//--------------------------------------------------------------------------------------------------
@@ -82,84 +99,136 @@ void RivSurfacePartMgr::appendNativeGeometryPartsToModel( cvf::ModelBasicList* m
//--------------------------------------------------------------------------------------------------
void RivSurfacePartMgr::updateCellResultColor( size_t timeStepIndex )
{
if ( !m_vertexToCellIndexMap.size() )
if ( m_intersectionFaces.notNull() )
{
generateVertexToCellIndexMap();
RivIntersectionResultsColoringTools::calculateIntersectionResultColors( timeStepIndex,
false,
m_surfaceInView,
m_intersectionGenerator.p(),
nullptr,
nullptr,
m_intersectionFaces.p(),
m_intersectionFacesTextureCoords.p() );
}
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 )
if ( m_nativeTrianglesPart.notNull() )
{
RimEclipseView* eclipseView = nullptr;
m_surfaceInView->firstAncestorOrThisOfType( eclipseView );
if ( eclipseView )
if ( !m_nativeVertexToCellIndexMap.size() )
{
eclipseResDef = eclipseView->cellResult();
if ( !scalarColorMapper ) scalarColorMapper = eclipseView->cellResult()->legendConfig()->scalarMapper();
if ( !ternaryColorMapper )
ternaryColorMapper = eclipseView->cellResult()->ternaryLegendConfig()->scalarMapper();
generateNativeVertexToCellIndexMap();
}
RimGeoMechView* geoView;
m_surfaceInView->firstAncestorOrThisOfType( geoView );
RimGridView* gridView = nullptr;
m_surfaceInView->firstAncestorOrThisOfType( gridView );
if ( geoView )
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 )
{
geomResultDef = geoView->cellResult();
if ( !scalarColorMapper ) scalarColorMapper = geoView->cellResult()->legendConfig()->scalarMapper();
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> nativeFacesTextureCoords = 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( nativeFacesTextureCoords.p(),
m_nativeVertexToCellIndexMap,
resultAccessor.p(),
scalarColorMapper );
RivScalarMapperUtils::applyTextureResultsToPart( m_nativeTrianglesPart.p(),
nativeFacesTextureCoords.p(),
scalarColorMapper,
1.0,
caf::FC_NONE,
isLightingDisabled );
}
}
}
}
cvf::ref<cvf::Vec2fArray> intersectionFacesTextureCoords = new cvf::Vec2fArray();
if ( eclipseResDef )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivSurfacePartMgr::appendIntersectionGeometryPartsToModel( cvf::ModelBasicList* model,
cvf::Transform* scaleTransform )
{
if ( m_intersectionFaces.isNull() )
{
if ( !eclipseResDef->isTernarySaturationSelected() )
{
RigEclipseCaseData* eclipseCaseData = eclipseResDef->eclipseCase()->eclipseCaseData();
generatePartGeometry();
}
cvf::ref<RigResultAccessor> resultAccessor;
if ( m_intersectionFaces.notNull() )
{
m_intersectionFaces->setTransform( scaleTransform );
model->addPart( m_intersectionFaces.p() );
}
if ( !RiaDefines::isPerCellFaceResult( eclipseResDef->resultVariable() ) )
// Mesh Lines
{
resultAccessor = RigResultAccessorFactory::createFromResultDefinition( eclipseCaseData,
0,
timeStepIndex,
eclipseResDef );
}
if ( m_intersectionGridLines.isNull() )
{
generatePartGeometry();
}
if ( resultAccessor.isNull() )
{
resultAccessor = new RigHugeValResultAccessor;
}
if ( m_intersectionGridLines.notNull() )
{
m_intersectionGridLines->setTransform( scaleTransform );
model->addPart( m_intersectionGridLines.p() );
}
RivSurfacePartMgr::calculateVertexTextureCoordinates( intersectionFacesTextureCoords.p(),
m_vertexToCellIndexMap,
resultAccessor.p(),
scalarColorMapper );
RivScalarMapperUtils::applyTextureResultsToPart( m_nativeTrianglesPart.p(),
intersectionFacesTextureCoords.p(),
scalarColorMapper,
1.0,
caf::FC_NONE,
isLightingDisabled );
}
if ( m_intersectionFaultGridLines.notNull() )
{
m_intersectionFaultGridLines->setTransform( scaleTransform );
model->addPart( m_intersectionFaultGridLines.p() );
}
}
@@ -168,12 +237,130 @@ void RivSurfacePartMgr::updateCellResultColor( size_t timeStepIndex )
//--------------------------------------------------------------------------------------------------
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() );
if ( m_nativeTrianglesPart.notNull() )
{
m_nativeTrianglesPart->setEffect( eff.p() );
}
if ( m_intersectionFaces.notNull() )
{
m_intersectionFaces->setEffect( eff.p() );
}
}
// Update mesh colors as well, in case of change
RiaPreferences* prefs = RiaApplication::instance()->preferences();
if ( m_intersectionGridLines.notNull() )
{
cvf::ref<cvf::Effect> eff;
caf::MeshEffectGenerator CrossSectionEffGen( prefs->defaultGridLineColors() );
eff = CrossSectionEffGen.generateCachedEffect();
m_intersectionGridLines->setEffect( eff.p() );
}
if ( m_intersectionFaultGridLines.notNull() )
{
cvf::ref<cvf::Effect> eff;
caf::MeshEffectGenerator CrossSectionEffGen( prefs->defaultFaultGridLineColors() );
eff = CrossSectionEffGen.generateCachedEffect();
m_intersectionFaultGridLines->setEffect( eff.p() );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivSurfacePartMgr::generatePartGeometry()
{
if ( m_intersectionGenerator.isNull() ) return;
bool useBufferObjects = true;
// Surface geometry
{
cvf::ref<cvf::DrawableGeo> geo = m_intersectionGenerator->generateSurface();
if ( geo.notNull() )
{
geo->computeNormals();
if ( useBufferObjects )
{
geo->setRenderMode( cvf::DrawableGeo::BUFFER_OBJECT );
}
cvf::ref<cvf::Part> part = new cvf::Part;
part->setName( "Reservoir Surface" );
part->setDrawable( geo.p() );
// Set mapping from triangle face index to cell index
cvf::ref<RivReservoirSurfaceIntersectionSourceInfo> si = new RivReservoirSurfaceIntersectionSourceInfo(
m_intersectionGenerator.p() );
part->setSourceInfo( si.p() );
part->updateBoundingBox();
part->setEnableMask( intersectionCellFaceBit );
part->setPriority( RivPartPriority::PartType::Intersection );
m_intersectionFaces = part;
}
}
// Cell Mesh geometry
{
cvf::ref<cvf::DrawableGeo> geoMesh = m_intersectionGenerator->createMeshDrawable();
if ( geoMesh.notNull() )
{
if ( useBufferObjects )
{
geoMesh->setRenderMode( cvf::DrawableGeo::BUFFER_OBJECT );
}
cvf::ref<cvf::Part> part = new cvf::Part;
part->setName( "Surface intersection mesh" );
part->setDrawable( geoMesh.p() );
part->updateBoundingBox();
part->setEnableMask( intersectionCellMeshBit );
part->setPriority( RivPartPriority::PartType::MeshLines );
part->setSourceInfo( new RivMeshLinesSourceInfo( m_surfaceInView ) );
m_intersectionGridLines = part;
}
}
// Fault Mesh geometry
{
cvf::ref<cvf::DrawableGeo> geoMesh = m_intersectionGenerator->createFaultMeshDrawable();
if ( geoMesh.notNull() )
{
if ( useBufferObjects )
{
geoMesh->setRenderMode( cvf::DrawableGeo::BUFFER_OBJECT );
}
cvf::ref<cvf::Part> part = new cvf::Part;
part->setName( "Surface faultmesh" );
part->setDrawable( geoMesh.p() );
part->updateBoundingBox();
part->setEnableMask( intersectionFaultMeshBit );
part->setPriority( RivPartPriority::PartType::FaultMeshLines );
part->setSourceInfo( new RivMeshLinesSourceInfo( m_surfaceInView ) );
m_intersectionFaultGridLines = part;
}
}
applySingleColor();
}
//--------------------------------------------------------------------------------------------------
@@ -205,20 +392,21 @@ void RivSurfacePartMgr::generateNativePartGeometry()
drawGeo->computeNormals();
m_nativeTrianglesPart = new cvf::Part();
m_nativeTrianglesPart->setName( "Native Reservoir Surface" );
m_nativeTrianglesPart->setDrawable( drawGeo.p() );
m_vertexToCellIndexMap.clear();
m_nativeVertexToCellIndexMap.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivSurfacePartMgr::generateVertexToCellIndexMap()
void RivSurfacePartMgr::generateNativeVertexToCellIndexMap()
{
cvf::ref<RivIntersectionHexGridInterface> hexGrid = m_surfaceInView->createHexGridInterface();
const std::vector<cvf::Vec3d>& vertices = m_usedSurfaceData->vertices();
m_vertexToCellIndexMap.resize( vertices.size(), -1 );
m_nativeVertexToCellIndexMap.resize( vertices.size(), -1 );
for ( size_t vxIdx = 0; vxIdx < vertices.size(); ++vxIdx )
{
@@ -234,7 +422,7 @@ void RivSurfacePartMgr::generateVertexToCellIndexMap()
if ( RigHexIntersectionTools::isPointInCell( vertices[vxIdx], cellCorners ) )
{
m_vertexToCellIndexMap[vxIdx] = cellIdx;
m_nativeVertexToCellIndexMap[vxIdx] = cellIdx;
break;
}
}