mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#7909 Surface Extraction : Add watertight option to grid extraction
This commit is contained in:
parent
1afba6c436
commit
5c564c152a
@ -46,6 +46,8 @@ RimGridCaseSurface::RimGridCaseSurface()
|
||||
|
||||
CAF_PDM_InitScriptableField( &m_oneBasedSliceIndex, "SliceIndex", 1, "Slice Index (K)", "", "", "" );
|
||||
m_oneBasedSliceIndex.uiCapability()->setUiEditorTypeName( caf::PdmUiSliderEditor::uiEditorTypeName() );
|
||||
|
||||
CAF_PDM_InitScriptableField( &m_watertight, "Watertight", false, "Watertight Surface (fill gaps)", "", "", "" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -84,7 +86,7 @@ bool RimGridCaseSurface::onLoadData()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSurface* RimGridCaseSurface::createCopy()
|
||||
{
|
||||
RimGridCaseSurface* newSurface = dynamic_cast<RimGridCaseSurface*>(
|
||||
auto* newSurface = dynamic_cast<RimGridCaseSurface*>(
|
||||
xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
||||
newSurface->setCase( m_case.value() ); // TODO: case seems to get lost in the xml copy, investigate later
|
||||
|
||||
@ -122,7 +124,7 @@ void RimGridCaseSurface::defineEditorAttribute( const caf::PdmFieldHandle* field
|
||||
{
|
||||
RimSurface::defineEditorAttribute( field, uiConfigName, attribute );
|
||||
|
||||
caf::PdmUiSliderEditorAttribute* myAttr = dynamic_cast<caf::PdmUiSliderEditorAttribute*>( attribute );
|
||||
auto* myAttr = dynamic_cast<caf::PdmUiSliderEditorAttribute*>( attribute );
|
||||
if ( myAttr && m_case )
|
||||
{
|
||||
const cvf::StructGridInterface* grid = RigReservoirGridTools::mainGrid( m_case );
|
||||
@ -142,7 +144,7 @@ void RimGridCaseSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedFie
|
||||
{
|
||||
RimSurface::fieldChangedByUi( changedField, oldValue, newValue );
|
||||
|
||||
if ( changedField == &m_case || changedField == &m_oneBasedSliceIndex )
|
||||
if ( changedField == &m_case || changedField == &m_oneBasedSliceIndex || changedField == &m_watertight )
|
||||
{
|
||||
clearCachedNativeData();
|
||||
updateSurfaceData();
|
||||
@ -156,13 +158,13 @@ void RimGridCaseSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedFie
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimGridCaseSurface::extractDataFromGrid()
|
||||
void RimGridCaseSurface::extractStructuredSurfaceFromGridData()
|
||||
{
|
||||
clearCachedNativeData();
|
||||
|
||||
if ( m_case )
|
||||
{
|
||||
RimEclipseCase* eclCase = dynamic_cast<RimEclipseCase*>( m_case() );
|
||||
auto* eclCase = dynamic_cast<RimEclipseCase*>( m_case() );
|
||||
if ( eclCase && eclCase->mainGrid() )
|
||||
{
|
||||
const RigMainGrid* grid = eclCase->mainGrid();
|
||||
@ -248,15 +250,15 @@ void RimGridCaseSurface::extractDataFromGrid()
|
||||
cvf::ubyte faceConn[4];
|
||||
grid->cellFaceVertexIndices( faceType, faceConn );
|
||||
|
||||
structGridVertexIndices.push_back(
|
||||
std::make_pair( static_cast<cvf::uint>( column + 1 ), static_cast<cvf::uint>( row + 1 ) ) );
|
||||
structGridVertexIndices.emplace_back( static_cast<cvf::uint>( column + 1 ),
|
||||
static_cast<cvf::uint>( row + 1 ) );
|
||||
|
||||
vertices.push_back( cornerVerts[faceConn[cellFaceIndex]] );
|
||||
|
||||
if ( row < maxRow && column < maxColumn )
|
||||
{
|
||||
cvf::uint triangleIndexLeft = static_cast<cvf::uint>( column * ( maxRow + 1 ) + row );
|
||||
cvf::uint triangleIndexRight = static_cast<cvf::uint>( ( column + 1 ) * ( maxRow + 1 ) + row );
|
||||
auto triangleIndexLeft = static_cast<cvf::uint>( column * ( maxRow + 1 ) + row );
|
||||
auto triangleIndexRight = static_cast<cvf::uint>( ( column + 1 ) * ( maxRow + 1 ) + row );
|
||||
|
||||
triangleIndices.push_back( triangleIndexLeft );
|
||||
triangleIndices.push_back( triangleIndexLeft + 1 );
|
||||
@ -277,6 +279,141 @@ void RimGridCaseSurface::extractDataFromGrid()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimGridCaseSurface::extractGridDataUsingFourVerticesPerCell()
|
||||
{
|
||||
clearCachedNativeData();
|
||||
|
||||
if ( !m_case ) return;
|
||||
|
||||
auto* eclCase = dynamic_cast<RimEclipseCase*>( m_case() );
|
||||
if ( eclCase && eclCase->mainGrid() )
|
||||
{
|
||||
const RigMainGrid* grid = eclCase->mainGrid();
|
||||
|
||||
size_t minI = 0;
|
||||
size_t minJ = 0;
|
||||
size_t maxI = grid->cellCountI();
|
||||
size_t maxJ = grid->cellCountJ();
|
||||
|
||||
size_t zeroBasedLayerIndex = static_cast<size_t>( m_oneBasedSliceIndex ) - 1;
|
||||
|
||||
cvf::StructGridInterface::FaceType faceType = cvf::StructGridInterface::NEG_K;
|
||||
|
||||
std::vector<unsigned> triangleIndices;
|
||||
std::vector<cvf::Vec3d> vertices;
|
||||
|
||||
for ( size_t i = minI; i <= maxI; i++ )
|
||||
{
|
||||
for ( size_t j = minJ; j <= maxJ; j++ )
|
||||
{
|
||||
if ( !grid->isCellValid( i, j, zeroBasedLayerIndex ) ) continue;
|
||||
|
||||
size_t currentCellIndex = grid->cellIndexFromIJK( i, j, zeroBasedLayerIndex );
|
||||
const auto& cell = grid->cell( currentCellIndex );
|
||||
if ( cell.isInvalid() ) continue;
|
||||
|
||||
cvf::Vec3d currentCornerVerts[8];
|
||||
|
||||
{
|
||||
cvf::ubyte currentFaceConn[4];
|
||||
grid->cellCornerVertices( currentCellIndex, currentCornerVerts );
|
||||
grid->cellFaceVertexIndices( faceType, currentFaceConn );
|
||||
|
||||
auto currentCellStartIndex = static_cast<unsigned>( vertices.size() );
|
||||
|
||||
for ( auto fc : currentFaceConn )
|
||||
{
|
||||
vertices.push_back( currentCornerVerts[fc] );
|
||||
}
|
||||
|
||||
triangleIndices.push_back( currentCellStartIndex );
|
||||
triangleIndices.push_back( currentCellStartIndex + 1 );
|
||||
triangleIndices.push_back( currentCellStartIndex + 2 );
|
||||
|
||||
triangleIndices.push_back( currentCellStartIndex );
|
||||
triangleIndices.push_back( currentCellStartIndex + 2 );
|
||||
triangleIndices.push_back( currentCellStartIndex + 3 );
|
||||
}
|
||||
|
||||
if ( m_watertight() )
|
||||
{
|
||||
if ( grid->findFaultFromCellIndexAndCellFace( currentCellIndex, cvf::StructGridInterface::POS_I ) )
|
||||
{
|
||||
auto nextCell = grid->cell( currentCellIndex ).neighborCell( cvf::StructGridInterface::POS_I );
|
||||
if ( !nextCell.isInvalid() )
|
||||
{
|
||||
size_t nextCellIndex = nextCell.mainGridCellIndex();
|
||||
cvf::Vec3d nextCellCornerVerts[8];
|
||||
grid->cellCornerVertices( nextCellIndex, nextCellCornerVerts );
|
||||
|
||||
auto startIndex = static_cast<unsigned>( vertices.size() );
|
||||
{
|
||||
auto edgeVertexIndices =
|
||||
grid->edgeVertexIndices( faceType, cvf::StructGridInterface::POS_I );
|
||||
vertices.push_back( currentCornerVerts[edgeVertexIndices.first] );
|
||||
vertices.push_back( currentCornerVerts[edgeVertexIndices.second] );
|
||||
}
|
||||
{
|
||||
auto edgeVertexIndices =
|
||||
grid->edgeVertexIndices( faceType, cvf::StructGridInterface::NEG_I );
|
||||
vertices.push_back( nextCellCornerVerts[edgeVertexIndices.first] );
|
||||
vertices.push_back( nextCellCornerVerts[edgeVertexIndices.second] );
|
||||
}
|
||||
|
||||
triangleIndices.push_back( startIndex );
|
||||
triangleIndices.push_back( startIndex + 1 );
|
||||
triangleIndices.push_back( startIndex + 2 );
|
||||
|
||||
triangleIndices.push_back( startIndex );
|
||||
triangleIndices.push_back( startIndex + 2 );
|
||||
triangleIndices.push_back( startIndex + 3 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( grid->findFaultFromCellIndexAndCellFace( currentCellIndex, cvf::StructGridInterface::POS_J ) )
|
||||
{
|
||||
auto nextCell = grid->cell( currentCellIndex ).neighborCell( cvf::StructGridInterface::POS_J );
|
||||
if ( !nextCell.isInvalid() )
|
||||
{
|
||||
size_t nextCellIndex = nextCell.mainGridCellIndex();
|
||||
cvf::Vec3d nextCellCornerVerts[8];
|
||||
grid->cellCornerVertices( nextCellIndex, nextCellCornerVerts );
|
||||
|
||||
auto startIndex = static_cast<unsigned>( vertices.size() );
|
||||
{
|
||||
auto edgeVertexIndices =
|
||||
grid->edgeVertexIndices( faceType, cvf::StructGridInterface::POS_J );
|
||||
vertices.push_back( currentCornerVerts[edgeVertexIndices.first] );
|
||||
vertices.push_back( currentCornerVerts[edgeVertexIndices.second] );
|
||||
}
|
||||
{
|
||||
auto edgeVertexIndices =
|
||||
grid->edgeVertexIndices( faceType, cvf::StructGridInterface::NEG_J );
|
||||
vertices.push_back( nextCellCornerVerts[edgeVertexIndices.first] );
|
||||
vertices.push_back( nextCellCornerVerts[edgeVertexIndices.second] );
|
||||
}
|
||||
|
||||
triangleIndices.push_back( startIndex );
|
||||
triangleIndices.push_back( startIndex + 1 );
|
||||
triangleIndices.push_back( startIndex + 2 );
|
||||
|
||||
triangleIndices.push_back( startIndex );
|
||||
triangleIndices.push_back( startIndex + 2 );
|
||||
triangleIndices.push_back( startIndex + 3 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_vertices = vertices;
|
||||
m_triangleIndices = triangleIndices;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -357,7 +494,7 @@ bool RimGridCaseSurface::updateSurfaceData()
|
||||
{
|
||||
if ( m_vertices.empty() || m_triangleIndices.empty() || m_structGridIndices.empty() )
|
||||
{
|
||||
extractDataFromGrid();
|
||||
extractGridDataUsingFourVerticesPerCell();
|
||||
}
|
||||
|
||||
RigSurface* surfaceData = nullptr;
|
||||
@ -413,7 +550,7 @@ bool RimGridCaseSurface::exportStructSurfaceFromGridCase( std::vector<cvf::Vec3d
|
||||
{
|
||||
if ( m_vertices.empty() || m_triangleIndices.empty() || m_structGridIndices.empty() )
|
||||
{
|
||||
extractDataFromGrid();
|
||||
extractStructuredSurfaceFromGridData();
|
||||
}
|
||||
|
||||
if ( m_vertices.empty() ) return false;
|
||||
|
@ -62,7 +62,12 @@ protected:
|
||||
private:
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
|
||||
void extractDataFromGrid();
|
||||
// Extract 4 vertices per grid cell
|
||||
void extractGridDataUsingFourVerticesPerCell();
|
||||
|
||||
// This method will populate m_structGridIndices used when exporting to PTL file format
|
||||
// Fault geometry will be smoothed using this method
|
||||
void extractStructuredSurfaceFromGridData();
|
||||
|
||||
bool findValidCellIndex( const RigMainGrid* grid,
|
||||
const cvf::StructGridInterface::FaceType faceType,
|
||||
@ -75,6 +80,7 @@ private:
|
||||
private:
|
||||
caf::PdmPtrField<RimCase*> m_case;
|
||||
caf::PdmField<int> m_oneBasedSliceIndex;
|
||||
caf::PdmField<bool> m_watertight;
|
||||
|
||||
std::vector<unsigned> m_triangleIndices;
|
||||
std::vector<cvf::Vec3d> m_vertices;
|
||||
|
Loading…
Reference in New Issue
Block a user