2015-11-09 17:42:55 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) Statoil ASA
|
|
|
|
|
// Copyright (C) Ceetron Solutions AS
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2015-11-09 17:42:55 +01:00
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2015-11-09 17:42:55 +01:00
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2015-11-09 17:42:55 +01:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RivSingleCellPartGenerator.h"
|
|
|
|
|
|
2025-09-19 16:31:58 +02:00
|
|
|
#include "RigCell.h"
|
2017-01-10 09:51:39 +01:00
|
|
|
#include "RigEclipseCaseData.h"
|
2015-11-11 13:38:54 +01:00
|
|
|
#include "RigFemPartCollection.h"
|
|
|
|
|
#include "RigGeoMechCaseData.h"
|
2017-01-09 19:51:15 +01:00
|
|
|
#include "RigGridBase.h"
|
2015-11-11 13:38:54 +01:00
|
|
|
|
|
|
|
|
#include "RimGeoMechCase.h"
|
|
|
|
|
|
|
|
|
|
#include "RivFemPartGeometryGenerator.h"
|
2017-02-17 14:52:56 +01:00
|
|
|
#include "RivPartPriority.h"
|
2015-11-09 17:42:55 +01:00
|
|
|
|
|
|
|
|
#include "cafEffectGenerator.h"
|
|
|
|
|
#include "cvfPart.h"
|
2025-09-19 16:31:58 +02:00
|
|
|
#include "cvfPrimitiveSetIndexedUInt.h"
|
2015-11-09 17:42:55 +01:00
|
|
|
#include "cvfRenderStateDepth.h"
|
|
|
|
|
#include "cvfStructGridGeometryGenerator.h"
|
|
|
|
|
|
2025-09-19 16:31:58 +02:00
|
|
|
using namespace cvf;
|
|
|
|
|
|
2015-11-09 17:42:55 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-11-09 17:42:55 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-11-28 10:31:01 +01:00
|
|
|
RivSingleCellPartGenerator::RivSingleCellPartGenerator( RigEclipseCaseData* rigCaseData,
|
|
|
|
|
size_t gridIndex,
|
|
|
|
|
size_t cellIndex,
|
|
|
|
|
const cvf::Vec3d& displayModelOffset )
|
2019-09-06 10:40:57 +02:00
|
|
|
: m_rigCaseData( rigCaseData )
|
|
|
|
|
, m_gridIndex( gridIndex )
|
|
|
|
|
, m_cellIndex( cellIndex )
|
|
|
|
|
, m_geoMechCase( nullptr )
|
2019-11-28 10:31:01 +01:00
|
|
|
, m_displayModelOffset( displayModelOffset )
|
2015-11-11 13:38:54 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-11-11 13:38:54 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-11-28 10:31:01 +01:00
|
|
|
RivSingleCellPartGenerator::RivSingleCellPartGenerator( RimGeoMechCase* rimGeoMechCase,
|
|
|
|
|
size_t gridIndex,
|
|
|
|
|
size_t cellIndex,
|
|
|
|
|
const cvf::Vec3d& displayModelOffset )
|
2019-09-06 10:40:57 +02:00
|
|
|
: m_geoMechCase( rimGeoMechCase )
|
|
|
|
|
, m_gridIndex( gridIndex )
|
|
|
|
|
, m_cellIndex( cellIndex )
|
|
|
|
|
, m_rigCaseData( nullptr )
|
2019-11-28 10:31:01 +01:00
|
|
|
, m_displayModelOffset( displayModelOffset )
|
2015-11-09 17:42:55 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-19 16:31:58 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RivSingleCellPartGenerator::setShowLgrMeshLines( bool enable )
|
|
|
|
|
{
|
|
|
|
|
m_showLgrMeshLines = enable;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-09 17:42:55 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-11-09 17:42:55 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
cvf::ref<cvf::Part> RivSingleCellPartGenerator::createPart( const cvf::Color3f color )
|
2015-11-09 17:42:55 +01:00
|
|
|
{
|
|
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
2025-09-19 16:31:58 +02:00
|
|
|
part->setName( cvf::String( "Highlight part for cell index " ) + cvf::String( (cvf::int64)m_cellIndex ) );
|
2019-09-06 10:40:57 +02:00
|
|
|
part->setDrawable( createMeshDrawable().p() );
|
2015-11-09 17:42:55 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
cvf::ref<cvf::Effect> eff;
|
|
|
|
|
caf::MeshEffectGenerator effGen( color );
|
2015-11-09 17:42:55 +01:00
|
|
|
eff = effGen.generateUnCachedEffect();
|
|
|
|
|
|
|
|
|
|
cvf::ref<cvf::RenderStateDepth> depth = new cvf::RenderStateDepth;
|
2019-09-06 10:40:57 +02:00
|
|
|
depth->enableDepthTest( false );
|
|
|
|
|
eff->setRenderState( depth.p() );
|
2015-11-09 17:42:55 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
part->setEffect( eff.p() );
|
2015-11-09 17:42:55 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
part->setPriority( RivPartPriority::PartType::Highlight );
|
2015-11-11 13:38:54 +01:00
|
|
|
|
2015-11-09 17:42:55 +01:00
|
|
|
return part;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-11-09 17:42:55 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
cvf::ref<cvf::DrawableGeo> RivSingleCellPartGenerator::createMeshDrawable()
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( m_rigCaseData && m_cellIndex != cvf::UNDEFINED_SIZE_T )
|
2015-11-09 17:42:55 +01:00
|
|
|
{
|
2025-09-19 16:31:58 +02:00
|
|
|
if ( m_showLgrMeshLines )
|
|
|
|
|
{
|
|
|
|
|
return createMeshDrawableFromLgrGridCells();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
return cvf::StructGridGeometryGenerator::createMeshDrawableFromSingleCell( m_rigCaseData->grid( m_gridIndex ),
|
2019-11-28 10:31:01 +01:00
|
|
|
m_cellIndex,
|
|
|
|
|
m_displayModelOffset );
|
2015-11-09 17:42:55 +01:00
|
|
|
}
|
2019-09-06 10:40:57 +02:00
|
|
|
else if ( m_geoMechCase && m_cellIndex != cvf::UNDEFINED_SIZE_T )
|
2015-11-11 13:38:54 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
CVF_ASSERT( m_geoMechCase->geoMechData() );
|
|
|
|
|
CVF_ASSERT( m_geoMechCase->geoMechData()->femParts()->partCount() > static_cast<int>( m_gridIndex ) );
|
2015-11-11 13:38:54 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
RigFemPart* femPart = m_geoMechCase->geoMechData()->femParts()->part( m_gridIndex );
|
|
|
|
|
CVF_ASSERT( femPart );
|
2015-11-11 13:38:54 +01:00
|
|
|
|
2020-02-12 11:43:15 +01:00
|
|
|
return RivFemPartGeometryGenerator::createMeshDrawableFromSingleElement( femPart, m_cellIndex, m_displayModelOffset );
|
2015-11-11 13:38:54 +01:00
|
|
|
}
|
2015-11-09 17:42:55 +01:00
|
|
|
|
2018-02-18 18:56:43 +01:00
|
|
|
return nullptr;
|
2015-11-09 17:42:55 +01:00
|
|
|
}
|
2025-09-19 16:31:58 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
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
|
2025-09-25 02:38:19 +00:00
|
|
|
RigGridBase::cellFaceVertexIndices( cvf::StructGridInterface::NEG_I, faceConn );
|
2025-09-19 16:31:58 +02:00
|
|
|
|
|
|
|
|
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
|
2025-09-25 02:38:19 +00:00
|
|
|
RigGridBase::cellFaceVertexIndices( cvf::StructGridInterface::POS_I, faceConn );
|
2025-09-19 16:31:58 +02:00
|
|
|
|
|
|
|
|
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() )
|
|
|
|
|
{
|
2025-09-25 02:38:19 +00:00
|
|
|
RigGridBase::cellFaceVertexIndices( cvf::StructGridInterface::POS_J, faceConn );
|
2025-09-19 16:31:58 +02:00
|
|
|
|
|
|
|
|
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() )
|
|
|
|
|
{
|
2025-09-25 02:38:19 +00:00
|
|
|
RigGridBase::cellFaceVertexIndices( cvf::StructGridInterface::NEG_J, faceConn );
|
2025-09-19 16:31:58 +02:00
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
2025-09-25 02:38:19 +00:00
|
|
|
if ( !cvfVertices.notNull() || cvfVertices->size() == 0 ) return nullptr;
|
2025-09-19 16:31:58 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|