Merge pull request #5421 from OPM/feature-reservoir-surfaces-picking

Feature reservoir surfaces picking
This commit is contained in:
Jacob Støren 2020-01-28 15:30:46 +01:00 committed by GitHub
commit 82ef81b51f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 194 additions and 113 deletions

View File

@ -36,6 +36,7 @@
#include "RivFemPickSourceInfo.h"
#include "RivGeoMechVizLogic.h"
#include "RivMeshLinesSourceInfo.h"
#include "RivReservoirSurfaceIntersectionSourceInfo.h"
#include "RivSimWellPipeSourceInfo.h"
#include "RivSourceInfo.h"
#include "RivTextLabelSourceInfo.h"
@ -350,6 +351,14 @@ bool RicHoloLensExportImpl::isGrid( const cvf::Part* part )
}
}
{
auto sourceInfoOfType = dynamic_cast<const RivReservoirSurfaceIntersectionSourceInfo*>( sourceInfo );
if ( sourceInfoOfType )
{
return true;
}
}
{
auto sourceInfoOfType = dynamic_cast<const RivExtrudedCurveIntersectionSourceInfo*>( sourceInfo );
if ( sourceInfoOfType )

View File

@ -396,9 +396,12 @@ void RivSurfacePartMgr::generateNativePartGeometry()
drawGeo->setVertexArray( cvfVertices.p() );
drawGeo->computeNormals();
cvf::ref<RivObjectSourceInfo> objectSourceInfo = new RivObjectSourceInfo( m_surfaceInView );
m_nativeTrianglesPart = new cvf::Part();
m_nativeTrianglesPart->setName( "Native Reservoir Surface" );
m_nativeTrianglesPart->setDrawable( drawGeo.p() );
m_nativeTrianglesPart->setSourceInfo( objectSourceInfo.p() );
m_nativeVertexToCellIndexMap.clear();
}

View File

@ -29,6 +29,7 @@
#include "RimGeoMechCellColors.h"
#include "RimGeoMechView.h"
#include "RimIntersectionResultDefinition.h"
#include "RimSurfaceInView.h"
#include "Riu3dSelectionManager.h"
#include "RiuViewerCommands.h"
@ -37,6 +38,7 @@
#include "RivExtrudedCurveIntersectionSourceInfo.h"
#include "RivFemPartGeometryGenerator.h"
#include "RivFemPickSourceInfo.h"
#include "RivReservoirSurfaceIntersectionSourceInfo.h"
#include "RivSourceInfo.h"
#include "RigEclipseCaseData.h"
@ -124,9 +126,10 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
int gmFace = -1;
bool intersectionHit = false;
std::array<cvf::Vec3f, 3> intersectionTriangleHit;
RimGeoMechResultDefinition* geomResDef = nullptr;
RimEclipseResultDefinition* eclResDef = nullptr;
size_t timestepIndex = cvf::UNDEFINED_SIZE_T;
RimGeoMechResultDefinition* geomResDef = nullptr;
RimEclipseResultDefinition* eclResDef = nullptr;
size_t timestepIndex = cvf::UNDEFINED_SIZE_T;
RimIntersectionResultDefinition* sepInterResDef = nullptr;
// clang-format off
if ( const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>( firstHitPart->sourceInfo() ) )
@ -146,61 +149,62 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
gridIndex = femSourceInfo->femPartIndex();
gridLocalCellIndex = femSourceInfo->triangleToElmMapper()->elementIndex( firstPartTriangleIndex );
gmFace = femSourceInfo->triangleToElmMapper()->elementFace( firstPartTriangleIndex );
}
else if ( const RivReservoirSurfaceIntersectionSourceInfo* surfeIntersectSourceInfo =
dynamic_cast<const RivReservoirSurfaceIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) )
{
RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView,
surfeIntersectSourceInfo->intersection()->activeSeparateResultDefinition(),
surfeIntersectSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&gridLocalCellIndex,
&gridIndex );
intersectionHit = true;
intersectionTriangleHit = surfeIntersectSourceInfo->triangle( firstPartTriangleIndex );
sepInterResDef = surfeIntersectSourceInfo->intersection()->activeSeparateResultDefinition();
}
else if ( const RivExtrudedCurveIntersectionSourceInfo* intersectionSourceInfo =
dynamic_cast<const RivExtrudedCurveIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) )
{
RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView,
intersectionSourceInfo,
firstPartTriangleIndex,
&gridLocalCellIndex,
&gridIndex );
RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView,
intersectionSourceInfo->intersection()->activeSeparateResultDefinition(),
intersectionSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&gridLocalCellIndex,
&gridIndex );
intersectionHit = true;
intersectionTriangleHit = intersectionSourceInfo->triangle( firstPartTriangleIndex );
if ( RimIntersectionResultDefinition* sepInterResDef = intersectionSourceInfo->intersection()->activeSeparateResultDefinition() )
{
if ( sepInterResDef->isEclipseResultDefinition() )
{
eclResDef = sepInterResDef->eclipseResultDefinition();
}
else
{
geomResDef = sepInterResDef->geoMechResultDefinition();
}
timestepIndex = sepInterResDef->timeStep();
}
sepInterResDef = intersectionSourceInfo->intersection()->activeSeparateResultDefinition();
}
else if ( const RivBoxIntersectionSourceInfo* intersectionBoxSourceInfo =
dynamic_cast<const RivBoxIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) )
{
RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView,
intersectionBoxSourceInfo,
firstPartTriangleIndex,
&gridLocalCellIndex,
&gridIndex );
RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView,
intersectionBoxSourceInfo->intersectionBox()->activeSeparateResultDefinition(),
intersectionBoxSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&gridLocalCellIndex,
&gridIndex );
intersectionHit = true;
intersectionTriangleHit = intersectionBoxSourceInfo->triangle( firstPartTriangleIndex );
if ( RimIntersectionResultDefinition* sepInterResDef = intersectionBoxSourceInfo->intersectionBox()->activeSeparateResultDefinition() )
{
if ( sepInterResDef->isEclipseResultDefinition() )
{
eclResDef = sepInterResDef->eclipseResultDefinition();
}
else
{
geomResDef = sepInterResDef->geoMechResultDefinition();
}
timestepIndex = sepInterResDef->timeStep();
}
sepInterResDef = intersectionBoxSourceInfo->intersectionBox()->activeSeparateResultDefinition();
}
// clang-format on
if ( sepInterResDef )
{
if ( sepInterResDef->isEclipseResultDefinition() )
{
eclResDef = sepInterResDef->eclipseResultDefinition();
}
else
{
geomResDef = sepInterResDef->geoMechResultDefinition();
}
timestepIndex = sepInterResDef->timeStep();
}
if ( gridLocalCellIndex == cvf::UNDEFINED_SIZE_T )
{
Riu3dSelectionManager::instance()->deleteAllItems();

View File

@ -19,11 +19,16 @@
#include "RiuPickItemInfo.h"
#include "cvfDrawableGeo.h"
#include "cvfEffect.h"
#include "cvfHitItem.h"
#include "cvfHitItemCollection.h"
#include "cvfPart.h"
#include "cvfRenderState.h"
#include "cvfRenderStatePolygonOffset.h"
#include "cvfTransform.h"
double RiuPickItemInfo::sm_rayDistanceTolerance = 1e-5;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -33,6 +38,7 @@ RiuPickItemInfo RiuPickItemInfo::extractPickItemInfo( const cvf::HitItem* hitIte
pickInfo.m_pickedPart = hitItem->part();
pickInfo.m_globalPickedPoint = hitItem->intersectionPoint();
pickInfo.m_distanceAlongRay = hitItem->distanceAlongRay();
if ( pickInfo.m_pickedPart ) pickInfo.m_sourceInfo = pickInfo.m_pickedPart->sourceInfo();
const cvf::HitDetailDrawableGeo* detail = dynamic_cast<const cvf::HitDetailDrawableGeo*>( hitItem->detail() );
@ -52,13 +58,70 @@ RiuPickItemInfo RiuPickItemInfo::extractPickItemInfo( const cvf::HitItem* hitIte
///
//--------------------------------------------------------------------------------------------------
std::vector<RiuPickItemInfo> RiuPickItemInfo::convertToPickItemInfos( const cvf::HitItemCollection& hitItems,
const cvf::Vec3d& globalRayOrigin )
const cvf::Vec3d& globalRayOrigin,
double coincidentRayDistanceTolerance )
{
std::vector<RiuPickItemInfo> pickItemInfos;
pickItemInfos.reserve( hitItems.count() );
sm_rayDistanceTolerance = coincidentRayDistanceTolerance;
std::set<RiuPickItemInfo> pickItemInfosSorted;
for ( size_t i = 0; i < hitItems.count(); i++ )
{
pickItemInfos.emplace_back( RiuPickItemInfo( hitItems.item( i ), globalRayOrigin ) );
pickItemInfosSorted.insert( RiuPickItemInfo( hitItems.item( i ), globalRayOrigin ) );
}
std::vector<RiuPickItemInfo> pickItemInfos;
pickItemInfos.insert( pickItemInfos.begin(), pickItemInfosSorted.begin(), pickItemInfosSorted.end() );
return pickItemInfos;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
float RiuPickItemInfo::polygonOffsetUnit() const
{
float polyOffsetUnit = 0;
if ( m_pickedPart )
{
cvf::Effect* eff = const_cast<cvf::Part*>( m_pickedPart )->effect();
if ( eff )
{
cvf::RenderState* rendState = eff->renderStateOfType( cvf::RenderState::POLYGON_OFFSET );
if ( rendState )
{
auto polyOffsetRenderState = static_cast<cvf::RenderStatePolygonOffset*>( rendState );
polyOffsetUnit = polyOffsetRenderState->units();
}
}
}
return polyOffsetUnit;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuPickItemInfo::operator<( const RiuPickItemInfo& other ) const
{
if ( fabs( m_distanceAlongRay - other.distanceAlongRay() ) > sm_rayDistanceTolerance )
{
return m_distanceAlongRay < other.distanceAlongRay();
}
else if ( this->polygonOffsetUnit() != other.polygonOffsetUnit() )
{
return this->polygonOffsetUnit() < other.polygonOffsetUnit();
}
else if ( m_faceIdx != other.faceIdx() )
{
return m_faceIdx < other.faceIdx();
}
else if ( m_pickedPart != other.pickedPart() )
{
return m_pickedPart < other.pickedPart();
}
return false;
}

View File

@ -85,9 +85,14 @@ public:
return m_globalRayOrigin;
}
float polygonOffsetUnit() const;
bool operator<( const RiuPickItemInfo& other ) const;
static RiuPickItemInfo extractPickItemInfo( const cvf::HitItem* hitItem );
static std::vector<RiuPickItemInfo> convertToPickItemInfos( const cvf::HitItemCollection& hitItems,
const cvf::Vec3d& globalRayOrigin );
const cvf::Vec3d& globalRayOrigin,
double coincidentRayDistanceTolerance = 1e-3 );
private:
double m_distanceAlongRay;
@ -97,4 +102,6 @@ private:
cvf::Vec3d m_globalRayOrigin;
const cvf::Object* m_sourceInfo;
cvf::uint m_faceIdx;
static double sm_rayDistanceTolerance;
};

View File

@ -66,6 +66,7 @@
#include "RimProject.h"
#include "RimSimWellInView.h"
#include "RimStimPlanFractureTemplate.h"
#include "RimSurfaceInView.h"
#include "RimTextAnnotation.h"
#include "RimViewController.h"
#include "RimWellPath.h"
@ -82,6 +83,7 @@
#include "RivFemPickSourceInfo.h"
#include "RivObjectSourceInfo.h"
#include "RivPartPriority.h"
#include "RivReservoirSurfaceIntersectionSourceInfo.h"
#include "RivSimWellConnectionSourceInfo.h"
#include "RivSimWellPipeSourceInfo.h"
#include "RivSourceInfo.h"
@ -269,15 +271,22 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event )
if ( firstHitPart && firstPartTriangleIndex != cvf::UNDEFINED_UINT )
{
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>( firstHitPart->sourceInfo() );
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>( firstHitPart->sourceInfo() );
const RivFemPickSourceInfo* femSourceInfo = dynamic_cast<const RivFemPickSourceInfo*>(
firstHitPart->sourceInfo() );
const RivReservoirSurfaceIntersectionSourceInfo* surfIntersectSourceInfo =
dynamic_cast<const RivReservoirSurfaceIntersectionSourceInfo*>( firstHitPart->sourceInfo() );
const RivExtrudedCurveIntersectionSourceInfo* crossSectionSourceInfo =
dynamic_cast<const RivExtrudedCurveIntersectionSourceInfo*>( firstHitPart->sourceInfo() );
const RivBoxIntersectionSourceInfo* intersectionBoxSourceInfo = dynamic_cast<const RivBoxIntersectionSourceInfo*>(
firstHitPart->sourceInfo() );
if ( rivSourceInfo || femSourceInfo || crossSectionSourceInfo || intersectionBoxSourceInfo )
if ( rivSourceInfo || femSourceInfo || crossSectionSourceInfo || intersectionBoxSourceInfo ||
surfIntersectSourceInfo )
{
if ( rivSourceInfo )
{
@ -294,13 +303,33 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event )
m_currentGridIdx = femSourceInfo->femPartIndex();
m_currentCellIndex = femSourceInfo->triangleToElmMapper()->elementIndex( firstPartTriangleIndex );
}
else if ( surfIntersectSourceInfo )
{
findCellAndGridIndex( mainOrComparisonView,
surfIntersectSourceInfo->intersection()->activeSeparateResultDefinition(),
surfIntersectSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&m_currentCellIndex,
&m_currentGridIdx );
m_currentFaceIndex = cvf::StructGridInterface::NO_FACE;
RiuSelectionItem* selItem = new RiuGeneralSelectionItem( surfIntersectSourceInfo->intersection() );
Riu3dSelectionManager::instance()->setSelectedItem( selItem, Riu3dSelectionManager::RUI_TEMPORARY );
if ( gridView )
{
// menuBuilder << "RicHideSurfaceFeature"; // Not yet created...
// menuBuilder.addSeparator();
}
}
else if ( crossSectionSourceInfo )
{
findCellAndGridIndex( mainOrComparisonView,
crossSectionSourceInfo,
firstPartTriangleIndex,
crossSectionSourceInfo->intersection()->activeSeparateResultDefinition(),
crossSectionSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&m_currentCellIndex,
&m_currentGridIdx );
m_currentFaceIndex = cvf::StructGridInterface::NO_FACE;
RiuSelectionItem* selItem = new RiuGeneralSelectionItem( crossSectionSourceInfo->intersection() );
@ -321,10 +350,11 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event )
else if ( intersectionBoxSourceInfo )
{
findCellAndGridIndex( mainOrComparisonView,
intersectionBoxSourceInfo,
firstPartTriangleIndex,
intersectionBoxSourceInfo->intersectionBox()->activeSeparateResultDefinition(),
intersectionBoxSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&m_currentCellIndex,
&m_currentGridIdx );
m_currentFaceIndex = cvf::StructGridInterface::NO_FACE;
RiuSelectionItem* selItem = new RiuGeneralSelectionItem( intersectionBoxSourceInfo->intersectionBox() );
@ -757,7 +787,19 @@ void RiuViewerCommands::handlePickAction( int winPosX, int winPosY, Qt::Keyboard
{
RiuMainWindow::instance()->selectAsCurrentItem( textAnnot, true );
}
RimSurfaceInView* surf = dynamic_cast<RimSurfaceInView*>( rivObjectSourceInfo->object() );
if ( surf )
{
RiuMainWindow::instance()->selectAsCurrentItem( surf, true );
}
}
else if ( const RivReservoirSurfaceIntersectionSourceInfo* surfIntersectSourceInfo =
dynamic_cast<const RivReservoirSurfaceIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) )
{
RiuMainWindow::instance()->selectAsCurrentItem( surfIntersectSourceInfo->intersection() );
}
else if ( const RivExtrudedCurveIntersectionSourceInfo* crossSectionSourceInfo =
dynamic_cast<const RivExtrudedCurveIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) )
{
@ -981,21 +1023,19 @@ void RiuViewerCommands::removeDefaultPickEventHandler( RicDefaultPickEventHandle
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::findCellAndGridIndex( Rim3dView* mainOrComparisonView,
const RivExtrudedCurveIntersectionSourceInfo* crossSectionSourceInfo,
cvf::uint firstPartTriangleIndex,
size_t* cellIndex,
size_t* gridIndex )
void RiuViewerCommands::findCellAndGridIndex( Rim3dView* mainOrComparisonView,
RimIntersectionResultDefinition* sepInterResDef,
size_t globalCellIndex,
size_t* cellIndex,
size_t* gridIndex )
{
CVF_ASSERT( cellIndex && gridIndex );
RimEclipseCase* eclipseCase = nullptr;
if ( RimIntersectionResultDefinition* sepInterResDef =
crossSectionSourceInfo->intersection()->activeSeparateResultDefinition() )
if ( sepInterResDef )
{
if ( sepInterResDef->isEclipseResultDefinition() )
{
@ -1007,8 +1047,6 @@ void RiuViewerCommands::findCellAndGridIndex( Rim3dView*
eclipseCase = dynamic_cast<RimEclipseCase*>( mainOrComparisonView->ownerCase() );
}
size_t globalCellIndex = crossSectionSourceInfo->triangleToCellIndex()[firstPartTriangleIndex];
if ( eclipseCase )
{
const RigCell& cell = eclipseCase->mainGrid()->globalCellArray()[globalCellIndex];
@ -1017,47 +1055,7 @@ void RiuViewerCommands::findCellAndGridIndex( Rim3dView*
}
else
{
*cellIndex = crossSectionSourceInfo->triangleToCellIndex()[firstPartTriangleIndex];
*gridIndex = 0;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::findCellAndGridIndex( Rim3dView* mainOrComparisonView,
const RivBoxIntersectionSourceInfo* intersectionBoxSourceInfo,
cvf::uint firstPartTriangleIndex,
size_t* cellIndex,
size_t* gridIndex )
{
CVF_ASSERT( cellIndex && gridIndex );
RimEclipseCase* eclipseCase = nullptr;
if ( RimIntersectionResultDefinition* sepInterResDef =
intersectionBoxSourceInfo->intersectionBox()->activeSeparateResultDefinition() )
{
if ( sepInterResDef->isEclipseResultDefinition() )
{
eclipseCase = dynamic_cast<RimEclipseCase*>( sepInterResDef->activeCase() );
}
}
else
{
eclipseCase = dynamic_cast<RimEclipseCase*>( mainOrComparisonView->ownerCase() );
}
size_t globalCellIndex = intersectionBoxSourceInfo->triangleToCellIndex()[firstPartTriangleIndex];
if ( eclipseCase )
{
const RigCell& cell = eclipseCase->mainGrid()->globalCellArray()[globalCellIndex];
*cellIndex = cell.gridLocalCellIndex();
*gridIndex = cell.hostGrid()->gridIndex();
}
else
{
*cellIndex = intersectionBoxSourceInfo->triangleToCellIndex()[firstPartTriangleIndex];
*cellIndex = globalCellIndex;
*gridIndex = 0;
}
}

View File

@ -32,9 +32,11 @@ class RimGeoMechView;
class RimExtrudedCurveIntersection;
class Rim3dView;
class RiuViewer;
class RivReservoirSurfaceIntersectionSourceInfo;
class RivBoxIntersectionSourceInfo;
class RivExtrudedCurveIntersectionSourceInfo;
class RiuPickItemInfo;
class RimIntersectionResultDefinition;
class QMouseEvent;
@ -73,16 +75,11 @@ public:
const std::vector<RiuPickItemInfo>& pickItemInfos,
size_t* indexToFirstNoneNncItem,
size_t* indexToNncItemNearFirsItem );
static void findCellAndGridIndex( Rim3dView* mainOrComparisonView,
const RivExtrudedCurveIntersectionSourceInfo* intersectionSourceInfo,
cvf::uint firstPartTriangleIndex,
size_t* cellIndex,
size_t* gridIndex );
static void findCellAndGridIndex( Rim3dView* mainOrComparisonView,
const RivBoxIntersectionSourceInfo* intersectionBoxSourceInfo,
cvf::uint firstPartTriangleIndex,
size_t* cellIndex,
size_t* gridIndex );
static void findCellAndGridIndex( Rim3dView* mainOrComparisonView,
RimIntersectionResultDefinition* sepInterResDef,
size_t globalCellIndex,
size_t* cellIndex,
size_t* gridIndex );
private:
void ijkFromCellIndex( Rim3dView* mainOrComparisonView,