Create mesh lines based on for lgr cells

If the angular cell count is low, especially 1, the geometry representation of a cell requires refinement in angular(J) direction. Show this geometry as a cylinder segment when holding CTRL and clicking on the radial geometry.
This commit is contained in:
Magne Sjaastad committed 2025-09-24 10:20:56 +02:00
1 parent 6ef5db2530
commit a2e94a0c83
5 files changed
+146 -1

No files matched your search

@@ -19,6 +19,7 @@
#include "RivSingleCellPartGenerator.h"
#include "RigCell.h"
#include "RigEclipseCaseData.h"
#include "RigFemPartCollection.h"
#include "RigGeoMechCaseData.h"
@@ -31,9 +32,12 @@
#include "cafEffectGenerator.h"
#include "cvfPart.h"
#include "cvfPrimitiveSetIndexedUInt.h"
#include "cvfRenderStateDepth.h"
#include "cvfStructGridGeometryGenerator.h"
using namespace cvf;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -64,13 +68,21 @@ RivSingleCellPartGenerator::RivSingleCellPartGenerator( RimGeoMechCase* rimGeo
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivSingleCellPartGenerator::setShowLgrMeshLines( bool enable )
{
m_showLgrMeshLines = enable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::Part> RivSingleCellPartGenerator::createPart( const cvf::Color3f color )
{
cvf::ref<cvf::Part> part = new cvf::Part;
part->setName( cvf::String( "Hightlight part for cell index " ) + cvf::String( (cvf::int64)m_cellIndex ) );
part->setName( cvf::String( "Highlight part for cell index " ) + cvf::String( (cvf::int64)m_cellIndex ) );
part->setDrawable( createMeshDrawable().p() );
cvf::ref<cvf::Effect> eff;
@@ -95,6 +107,11 @@ cvf::ref<cvf::DrawableGeo> RivSingleCellPartGenerator::createMeshDrawable()
{
if ( m_rigCaseData && m_cellIndex != cvf::UNDEFINED_SIZE_T )
{
if ( m_showLgrMeshLines )
{
return createMeshDrawableFromLgrGridCells();
}
return cvf::StructGridGeometryGenerator::createMeshDrawableFromSingleCell( m_rigCaseData->grid( m_gridIndex ),
m_cellIndex,
m_displayModelOffset );
@@ -112,3 +129,117 @@ cvf::ref<cvf::DrawableGeo> RivSingleCellPartGenerator::createMeshDrawable()
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::DrawableGeo> RivSingleCellPartGenerator::createMeshDrawableFromLgrGridCells()
{
if ( !m_rigCaseData ) return nullptr;
if ( m_cellIndex == cvf::UNDEFINED_SIZE_T ) return nullptr;
auto currentGrid = m_rigCaseData->grid( m_gridIndex );
if ( !currentGrid ) return nullptr;
auto currentCell = currentGrid->cell( m_cellIndex );
auto cellIndexInMainGrid = currentCell.parentCellIndex();
std::vector<size_t> lgrCellIndices;
for ( size_t i = 0; i < currentGrid->cellCount(); i++ )
{
const auto cell = currentGrid->cell( i );
auto parentCellIndex = cell.parentCellIndex();
if ( parentCellIndex == cellIndexInMainGrid )
{
lgrCellIndices.push_back( i );
}
}
std::vector<cvf::Vec3d> quadVertices;
std::vector<cvf::Vec3d> lineVertexPairs;
for ( auto cellIndex : lgrCellIndices )
{
std::array<cvf::Vec3d, 8> cornerVerts = currentGrid->cellCornerVertices( cellIndex );
cvf::ubyte faceConn[4];
// Show grid lines for vertical lines along the radius of the cylinder segment
currentGrid->cellFaceVertexIndices( cvf::StructGridInterface::NEG_I, faceConn );
lineVertexPairs.push_back( cornerVerts[faceConn[1]] );
lineVertexPairs.push_back( cornerVerts[faceConn[2]] );
lineVertexPairs.push_back( cornerVerts[faceConn[3]] );
lineVertexPairs.push_back( cornerVerts[faceConn[0]] );
// Show grid lines for vertical lines along the radius of the cylinder segment
currentGrid->cellFaceVertexIndices( cvf::StructGridInterface::POS_I, faceConn );
lineVertexPairs.push_back( cornerVerts[faceConn[0]] );
lineVertexPairs.push_back( cornerVerts[faceConn[1]] );
lineVertexPairs.push_back( cornerVerts[faceConn[2]] );
lineVertexPairs.push_back( cornerVerts[faceConn[3]] );
// Show quad lines for min/max J faces
if ( cellIndex == lgrCellIndices.back() )
{
currentGrid->cellFaceVertexIndices( cvf::StructGridInterface::POS_J, faceConn );
quadVertices.push_back( cornerVerts[faceConn[0]] );
quadVertices.push_back( cornerVerts[faceConn[1]] );
quadVertices.push_back( cornerVerts[faceConn[2]] );
quadVertices.push_back( cornerVerts[faceConn[3]] );
}
if ( cellIndex == lgrCellIndices.front() )
{
currentGrid->cellFaceVertexIndices( cvf::StructGridInterface::NEG_J, faceConn );
quadVertices.push_back( cornerVerts[faceConn[0]] );
quadVertices.push_back( cornerVerts[faceConn[1]] );
quadVertices.push_back( cornerVerts[faceConn[2]] );
quadVertices.push_back( cornerVerts[faceConn[3]] );
}
}
std::vector<cvf::Vec3f> displayVertices;
for ( const auto& v : quadVertices )
{
displayVertices.push_back( cvf::Vec3f( v - m_displayModelOffset ) );
}
cvf::ref<cvf::Vec3fArray> cvfVertices = new cvf::Vec3fArray;
cvfVertices->assign( displayVertices );
if ( !( cvfVertices.notNull() && cvfVertices->size() != 0 ) ) return nullptr;
ref<UIntArray> indices = StructGridGeometryGenerator::lineIndicesFromQuadVertexArray( cvfVertices.p() );
// Add vertex pairs as lines
const auto quadVertexCount = cvfVertices->size();
const auto indicesCount = indices->size();
cvfVertices->resize( quadVertexCount + lineVertexPairs.size() );
indices->resize( indicesCount + lineVertexPairs.size() );
size_t iIndex = indicesCount;
size_t vIndex = quadVertexCount;
for ( const auto& v : lineVertexPairs )
{
indices->set( iIndex++, static_cast<cvf::uint>( vIndex ) );
cvfVertices->set( vIndex++, cvf::Vec3f( v - m_displayModelOffset ) );
}
ref<DrawableGeo> geo = new DrawableGeo;
geo->setVertexArray( cvfVertices.p() );
ref<PrimitiveSetIndexedUInt> prim = new PrimitiveSetIndexedUInt( PT_LINES );
prim->setIndices( indices.p() );
geo->addPrimitiveSet( prim.p() );
return geo;
}