#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 = else if ( const RivReservoirSurfaceIntersectionSourceInfo* surfeIntersectSourceInfo =
dynamic_cast<const RivReservoirSurfaceIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) ) dynamic_cast<const RivReservoirSurfaceIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) )
{ {
RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView, RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView,
surfeIntersectSourceInfo, surfeIntersectSourceInfo->intersection()->activeSeparateResultDefinition(),
firstPartTriangleIndex, surfeIntersectSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&gridLocalCellIndex, &gridLocalCellIndex,
&gridIndex ); &gridIndex );
intersectionHit = true; intersectionHit = true;
intersectionTriangleHit = surfeIntersectSourceInfo->triangle( firstPartTriangleIndex ); intersectionTriangleHit = surfeIntersectSourceInfo->triangle( firstPartTriangleIndex );
sepInterResDef = surfeIntersectSourceInfo->intersection()->activeSeparateResultDefinition(); sepInterResDef = surfeIntersectSourceInfo->intersection()->activeSeparateResultDefinition();
} }
else if ( const RivExtrudedCurveIntersectionSourceInfo* intersectionSourceInfo = else if ( const RivExtrudedCurveIntersectionSourceInfo* intersectionSourceInfo =
dynamic_cast<const RivExtrudedCurveIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) ) dynamic_cast<const RivExtrudedCurveIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) )
{ {
RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView, RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView,
intersectionSourceInfo, intersectionSourceInfo->intersection()->activeSeparateResultDefinition(),
firstPartTriangleIndex, intersectionSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&gridLocalCellIndex, &gridLocalCellIndex,
&gridIndex ); &gridIndex );
intersectionHit = true; intersectionHit = true;
intersectionTriangleHit = intersectionSourceInfo->triangle( firstPartTriangleIndex ); intersectionTriangleHit = intersectionSourceInfo->triangle( firstPartTriangleIndex );
@ -179,11 +179,11 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
else if ( const RivBoxIntersectionSourceInfo* intersectionBoxSourceInfo = else if ( const RivBoxIntersectionSourceInfo* intersectionBoxSourceInfo =
dynamic_cast<const RivBoxIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) ) dynamic_cast<const RivBoxIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) )
{ {
RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView, RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView,
intersectionBoxSourceInfo, intersectionBoxSourceInfo->intersectionBox()->activeSeparateResultDefinition(),
firstPartTriangleIndex, intersectionBoxSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&gridLocalCellIndex, &gridLocalCellIndex,
&gridIndex ); &gridIndex );
intersectionHit = true; intersectionHit = true;
intersectionTriangleHit = intersectionBoxSourceInfo->triangle( firstPartTriangleIndex ); intersectionTriangleHit = intersectionBoxSourceInfo->triangle( firstPartTriangleIndex );

View File

@ -306,17 +306,11 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event )
else if ( surfIntersectSourceInfo ) else if ( surfIntersectSourceInfo )
{ {
findCellAndGridIndex( mainOrComparisonView, findCellAndGridIndex( mainOrComparisonView,
surfIntersectSourceInfo, surfIntersectSourceInfo->intersection()->activeSeparateResultDefinition(),
firstPartTriangleIndex, surfIntersectSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&m_currentCellIndex, &m_currentCellIndex,
&m_currentGridIdx ); &m_currentGridIdx );
// findCellAndGridIndex( mainOrComparisonView,
// surfIntersectSourceInfo->intersection()->activeSeparateResultDefinition(),
// surfIntersectSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
// &m_currentCellIndex,
// &m_currentGridIdx );
m_currentFaceIndex = cvf::StructGridInterface::NO_FACE; m_currentFaceIndex = cvf::StructGridInterface::NO_FACE;
RiuSelectionItem* selItem = new RiuGeneralSelectionItem( surfIntersectSourceInfo->intersection() ); RiuSelectionItem* selItem = new RiuGeneralSelectionItem( surfIntersectSourceInfo->intersection() );
@ -331,10 +325,11 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event )
else if ( crossSectionSourceInfo ) else if ( crossSectionSourceInfo )
{ {
findCellAndGridIndex( mainOrComparisonView, findCellAndGridIndex( mainOrComparisonView,
crossSectionSourceInfo, crossSectionSourceInfo->intersection()->activeSeparateResultDefinition(),
firstPartTriangleIndex, crossSectionSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&m_currentCellIndex, &m_currentCellIndex,
&m_currentGridIdx ); &m_currentGridIdx );
m_currentFaceIndex = cvf::StructGridInterface::NO_FACE; m_currentFaceIndex = cvf::StructGridInterface::NO_FACE;
RiuSelectionItem* selItem = new RiuGeneralSelectionItem( crossSectionSourceInfo->intersection() ); RiuSelectionItem* selItem = new RiuGeneralSelectionItem( crossSectionSourceInfo->intersection() );
@ -355,10 +350,11 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event )
else if ( intersectionBoxSourceInfo ) else if ( intersectionBoxSourceInfo )
{ {
findCellAndGridIndex( mainOrComparisonView, findCellAndGridIndex( mainOrComparisonView,
intersectionBoxSourceInfo, intersectionBoxSourceInfo->intersectionBox()->activeSeparateResultDefinition(),
firstPartTriangleIndex, intersectionBoxSourceInfo->triangleToCellIndex()[firstPartTriangleIndex],
&m_currentCellIndex, &m_currentCellIndex,
&m_currentGridIdx ); &m_currentGridIdx );
m_currentFaceIndex = cvf::StructGridInterface::NO_FACE; m_currentFaceIndex = cvf::StructGridInterface::NO_FACE;
RiuSelectionItem* selItem = new RiuGeneralSelectionItem( intersectionBoxSourceInfo->intersectionBox() ); 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 globalCellIndex,
size_t* cellIndex, size_t* cellIndex,
size_t* gridIndex ); 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: private:
void ijkFromCellIndex( Rim3dView* mainOrComparisonView, void ijkFromCellIndex( Rim3dView* mainOrComparisonView,