#5418 Consolidate near identical code

This commit is contained in:
Jacob Støren 2020-01-28 10:37:22 +01:00
parent f1ab745097
commit 0720ab3453
3 changed files with 24 additions and 163 deletions

View File

@ -153,24 +153,24 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
else if ( const RivReservoirSurfaceIntersectionSourceInfo* surfeIntersectSourceInfo =
dynamic_cast<const RivReservoirSurfaceIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) )
{
RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView,
surfeIntersectSourceInfo,
firstPartTriangleIndex,
&gridLocalCellIndex,
&gridIndex );
RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView,
surfeIntersectSourceInfo->intersection()->activeSeparateResultDefinition(),
surfeIntersectSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&gridLocalCellIndex,
&gridIndex );
intersectionHit = true;
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 );
@ -179,11 +179,11 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
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 );

View File

@ -306,17 +306,11 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event )
else if ( surfIntersectSourceInfo )
{
findCellAndGridIndex( mainOrComparisonView,
surfIntersectSourceInfo,
firstPartTriangleIndex,
surfIntersectSourceInfo->intersection()->activeSeparateResultDefinition(),
surfIntersectSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&m_currentCellIndex,
&m_currentGridIdx );
// findCellAndGridIndex( mainOrComparisonView,
// surfIntersectSourceInfo->intersection()->activeSeparateResultDefinition(),
// surfIntersectSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
// &m_currentCellIndex,
// &m_currentGridIdx );
m_currentFaceIndex = cvf::StructGridInterface::NO_FACE;
RiuSelectionItem* selItem = new RiuGeneralSelectionItem( surfIntersectSourceInfo->intersection() );
@ -331,10 +325,11 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event )
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() );
@ -355,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() );
@ -1064,126 +1060,6 @@ void RiuViewerCommands::findCellAndGridIndex( Rim3dView* m
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::findCellAndGridIndex( Rim3dView* mainOrComparisonView,
const RivReservoirSurfaceIntersectionSourceInfo* crossSectionSourceInfo,
cvf::uint firstPartTriangleIndex,
size_t* cellIndex,
size_t* gridIndex )
{
CVF_ASSERT( cellIndex && gridIndex );
RimEclipseCase* eclipseCase = nullptr;
if ( RimIntersectionResultDefinition* sepInterResDef =
crossSectionSourceInfo->intersection()->activeSeparateResultDefinition() )
{
if ( sepInterResDef->isEclipseResultDefinition() )
{
eclipseCase = dynamic_cast<RimEclipseCase*>( sepInterResDef->activeCase() );
}
}
else
{
eclipseCase = dynamic_cast<RimEclipseCase*>( mainOrComparisonView->ownerCase() );
}
size_t globalCellIndex = crossSectionSourceInfo->triangleToCellIndex()[firstPartTriangleIndex];
if ( eclipseCase )
{
const RigCell& cell = eclipseCase->mainGrid()->globalCellArray()[globalCellIndex];
*cellIndex = cell.gridLocalCellIndex();
*gridIndex = cell.hostGrid()->gridIndex();
}
else
{
*cellIndex = crossSectionSourceInfo->triangleToCellIndex()[firstPartTriangleIndex];
*gridIndex = 0;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::findCellAndGridIndex( Rim3dView* mainOrComparisonView,
const RivExtrudedCurveIntersectionSourceInfo* crossSectionSourceInfo,
cvf::uint firstPartTriangleIndex,
size_t* cellIndex,
size_t* gridIndex )
{
CVF_ASSERT( cellIndex && gridIndex );
RimEclipseCase* eclipseCase = nullptr;
if ( RimIntersectionResultDefinition* sepInterResDef =
crossSectionSourceInfo->intersection()->activeSeparateResultDefinition() )
{
if ( sepInterResDef->isEclipseResultDefinition() )
{
eclipseCase = dynamic_cast<RimEclipseCase*>( sepInterResDef->activeCase() );
}
}
else
{
eclipseCase = dynamic_cast<RimEclipseCase*>( mainOrComparisonView->ownerCase() );
}
size_t globalCellIndex = crossSectionSourceInfo->triangleToCellIndex()[firstPartTriangleIndex];
if ( eclipseCase )
{
const RigCell& cell = eclipseCase->mainGrid()->globalCellArray()[globalCellIndex];
*cellIndex = cell.gridLocalCellIndex();
*gridIndex = cell.hostGrid()->gridIndex();
}
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];
*gridIndex = 0;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -80,21 +80,6 @@ public:
size_t globalCellIndex,
size_t* cellIndex,
size_t* gridIndex );
static void findCellAndGridIndex( Rim3dView* mainOrComparisonView,
const RivReservoirSurfaceIntersectionSourceInfo* crossSectionSourceInfo,
cvf::uint firstPartTriangleIndex,
size_t* cellIndex,
size_t* gridIndex );
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 );
private:
void ijkFromCellIndex( Rim3dView* mainOrComparisonView,