#5285 Visualization and update of Surfaces

This commit is contained in:
Jacob Støren 2020-01-08 11:56:48 +01:00
parent e9086005d4
commit e6d96316d4
20 changed files with 369 additions and 35 deletions

View File

@ -71,6 +71,7 @@
#include "RimSummaryCaseMainCollection.h"
#include "RimSummaryCrossPlotCollection.h"
#include "RimSummaryPlot.h"
#include "RimSurfaceCollection.h"
#include "RimTextAnnotation.h"
#include "RimTextAnnotationInView.h"
#include "RimViewLinker.h"
@ -541,6 +542,8 @@ bool RiaApplication::loadProject( const QString& projectFileName,
fracture->loadDataAndUpdate();
}
}
oilField->surfaceCollection()->loadData();
}
// If load action is specified to recalculate statistics, do it now.

View File

@ -57,6 +57,7 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/ModelVisualization
${CMAKE_CURRENT_SOURCE_DIR}/ModelVisualization/GridBox
${CMAKE_CURRENT_SOURCE_DIR}/ModelVisualization/Intersections
${CMAKE_CURRENT_SOURCE_DIR}/ModelVisualization/Surfaces
${CMAKE_CURRENT_SOURCE_DIR}/UserInterface
${CMAKE_CURRENT_SOURCE_DIR}/CommandFileInterface
${CMAKE_CURRENT_SOURCE_DIR}/CommandFileInterface/Core
@ -142,6 +143,7 @@ list( APPEND REFERENCED_CMAKE_FILES
ModelVisualization/CMakeLists_files.cmake
ModelVisualization/GridBox/CMakeLists_files.cmake
ModelVisualization/Intersections/CMakeLists_files.cmake
ModelVisualization/Surfaces/CMakeLists_files.cmake
ModelVisualization/WindowEdgeAxesOverlayItem/CMakeLists_files.cmake
UserInterface/CMakeLists_files.cmake

View File

@ -89,7 +89,7 @@ void RicNewViewFeature::setupActionLook( QAction* actionToSetup )
//--------------------------------------------------------------------------------------------------
Rim3dView* RicNewViewFeature::createReservoirView( RimEclipseCase* eclipseCase, RimGeoMechCase* geomCase )
{
Rim3dView* insertedView = nullptr;
RimGridView* insertedView = nullptr;
if ( eclipseCase )
{
@ -100,6 +100,8 @@ Rim3dView* RicNewViewFeature::createReservoirView( RimEclipseCase* eclipseCase,
insertedView = geomCase->createAndAddReservoirView();
}
insertedView->updateSurfacesInViewTreeItems();
// Must be run before buildViewItems, as wells are created in this function
insertedView->loadDataAndUpdate();

View File

@ -0,0 +1,18 @@
set (SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RivSurfacePartMgr.h
)
set (SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RivSurfacePartMgr.cpp
)
list(APPEND CODE_HEADER_FILES
${SOURCE_GROUP_HEADER_FILES}
)
list(APPEND CODE_SOURCE_FILES
${SOURCE_GROUP_SOURCE_FILES}
)
source_group( "ModelVisualization\\Surfaces" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake )

View File

@ -0,0 +1,97 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- Equinor ASA
//
// 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.
//
// 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.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RivSurfacePartMgr.h"
#include "RigSurface.h"
#include "RimSurface.h"
#include "RimSurfaceInView.h"
#include "RimCase.h"
#include "cafEffectGenerator.h"
#include "cvfDrawableGeo.h"
#include "cvfModelBasicList.h"
#include "cvfPart.h"
#include "cvfPrimitiveSetIndexedUInt.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivSurfacePartMgr::RivSurfacePartMgr( RimSurfaceInView* surface )
: m_surfaceInView( surface )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivSurfacePartMgr::appendNativeGeometryPartsToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform )
{
if ( m_nativeTrianglesPart.isNull() || m_surfaceInView->surface()->surfaceData() != m_usedSurfaceData.p() )
{
generateNativePartGeometry();
}
if ( m_nativeTrianglesPart.notNull() )
{
m_nativeTrianglesPart->setTransform( scaleTransform );
caf::SurfaceEffectGenerator surfaceGen( cvf::Color4f( m_surfaceInView->surface()->color() ), caf::PO_1 );
cvf::ref<cvf::Effect> eff = surfaceGen.generateCachedEffect();
m_nativeTrianglesPart->setEffect( eff.p() );
model->addPart( m_nativeTrianglesPart.p() );
if ( m_nativeMeshLinesPart.notNull() )
{
m_nativeMeshLinesPart->setTransform( scaleTransform );
model->addPart( m_nativeMeshLinesPart.p() );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivSurfacePartMgr::generateNativePartGeometry()
{
RimCase* ownerCase;
m_surfaceInView->firstAncestorOrThisOfTypeAsserted( ownerCase );
cvf::Vec3d displayModOffsett = ownerCase->displayModelOffset();
m_usedSurfaceData = m_surfaceInView->surface()->surfaceData();
const std::vector<cvf::Vec3d>& vertices = m_usedSurfaceData->vertices();
cvf::ref<cvf::Vec3fArray> cvfVertices = new cvf::Vec3fArray( vertices.size() );
for ( size_t i = 0; i < vertices.size(); ++i )
{
( *cvfVertices )[i] = cvf::Vec3f( vertices[i] - displayModOffsett );
}
const std::vector<unsigned>& triangleIndices = m_usedSurfaceData->triangleIndices();
cvf::ref<cvf::UIntArray> cvfIndices = new cvf::UIntArray( triangleIndices );
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexSet = new cvf::PrimitiveSetIndexedUInt( cvf::PT_TRIANGLES );
indexSet->setIndices( cvfIndices.p() );
cvf::ref<cvf::DrawableGeo> drawGeo = new cvf::DrawableGeo;
drawGeo->addPrimitiveSet( indexSet.p() );
drawGeo->setVertexArray( cvfVertices.p() );
m_nativeTrianglesPart = new cvf::Part();
m_nativeTrianglesPart->setDrawable( drawGeo.p() );
}

View File

@ -17,12 +17,34 @@
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmPointer.h"
#include "cvfObject.h"
namespace cvf
{
class ModelBasicList;
class Transform;
class Part;
class ScalarMapper;
class DrawableGeo;
} // namespace cvf
class RimSurfaceInView;
class RigSurface;
class RivSurfacePartMgr : public cvf::Object
{
public:
RivSurfacePartMgr( const RimSurfaceInView* surface );
explicit RivSurfacePartMgr( RimSurfaceInView* surface );
void appendGeometryPartsToModel( cvf::ModelBasicList* model );
void appendNativeGeometryPartsToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform );
private:
void generateNativePartGeometry();
caf::PdmPointer<RimSurfaceInView> m_surfaceInView;
cvf::ref<RigSurface> m_usedSurfaceData; // Store the reference to the old data, to know when new data has arrived.
cvf::ref<cvf::Part> m_nativeTrianglesPart;
cvf::ref<cvf::Part> m_nativeMeshLinesPart;
};

View File

@ -539,6 +539,15 @@ void RimEclipseView::onCreateDisplayModel()
m_reservoirGridPartManager->scaleTransform() );
nativeOrOverrideViewer()->addStaticModelOnce( m_intersectionVizModel.p(), isUsingOverrideViewer() );
// Surfaces
m_surfaceVizModel->removeAllParts();
if ( m_surfaceCollection )
{
m_surfaceCollection->appendPartsToModel( m_surfaceVizModel.p(), m_reservoirGridPartManager->scaleTransform() );
nativeOrOverrideViewer()->addStaticModelOnce( m_surfaceVizModel.p(), isUsingOverrideViewer() );
}
// Well path model
m_wellPathPipeVizModel->removeAllParts();

View File

@ -298,6 +298,15 @@ void RimGeoMechView::onCreateDisplayModel()
m_intersectionCollection->appendPartsToModel( *this, m_intersectionVizModel.p(), scaleTransform() );
nativeOrOverrideViewer()->addStaticModelOnce( m_intersectionVizModel.p(), isUsingOverrideViewer() );
// Surfaces
m_surfaceVizModel->removeAllParts();
if ( m_surfaceCollection )
{
m_surfaceCollection->appendPartsToModel( m_surfaceVizModel.p(), scaleTransform() );
nativeOrOverrideViewer()->addStaticModelOnce( m_surfaceVizModel.p(), isUsingOverrideViewer() );
}
// If the animation was active before recreating everything, make viewer view current frame
if ( isTimeStepDependentDataVisibleInThisOrComparisonView() )

View File

@ -48,6 +48,7 @@
#include "RivSingleCellPartGenerator.h"
#include "cvfModel.h"
#include "cvfModelBasicList.h"
#include "cvfPart.h"
#include "cvfScene.h"
@ -103,6 +104,9 @@ RimGridView::RimGridView()
CAF_PDM_InitFieldNoDefault( &m_surfaceCollection, "SurfaceInViewCollection", "Surface Collection Field", "", "", "" );
m_surfaceCollection.uiCapability()->setUiTreeHidden( true );
m_surfaceVizModel = new cvf::ModelBasicList;
m_surfaceVizModel->setName( "SurfaceModel" );
}
//--------------------------------------------------------------------------------------------------

View File

@ -90,6 +90,8 @@ protected:
void initAfterRead() override;
protected:
cvf::ref<cvf::ModelBasicList> m_surfaceVizModel;
// Fields
caf::PdmChildField<RimIntersectionCollection*> m_intersectionCollection;

View File

@ -17,13 +17,14 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RimSurface.h"
#include "RimSurfaceCollection.h"
#include "RigSurface.h"
#include "cafUtils.h"
#include <QFileInfo>
#include <fstream>
#include <iosfwd>
#include <sstream>
#include <string>
CAF_PDM_SOURCE_INIT( RimSurface, "Surface" );
@ -56,6 +57,30 @@ void RimSurface::setSurfaceFilePath( const QString& filePath )
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimSurface::surfaceFilePath()
{
return m_surfaceDefinitionFilePath().path();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::setColor( const cvf::Color3f& color )
{
m_color = color;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Color3f RimSurface::color() const
{
return m_color();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -64,6 +89,14 @@ QString RimSurface::userDescription()
return m_userDescription();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigSurface* RimSurface::surfaceData()
{
return m_surfaceData.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -81,13 +114,17 @@ void RimSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
{
if ( changedField == &m_surfaceDefinitionFilePath )
{
updateDataFromFile();
updateSurfaceDataFromFile();
// Todo: Update visualization
RimSurfaceCollection* surfColl;
this->firstAncestorOrThisOfTypeAsserted( surfColl );
surfColl->updateViews( {this} );
}
else if ( changedField == &m_color )
{
// Todo: Update visualization
RimSurfaceCollection* surfColl;
this->firstAncestorOrThisOfTypeAsserted( surfColl );
surfColl->updateViews( {this} );
}
}
@ -102,7 +139,7 @@ struct SurfacePointData
//--------------------------------------------------------------------------------------------------
/// Returns false for fatal failure
//--------------------------------------------------------------------------------------------------
bool RimSurface::updateDataFromFile()
bool RimSurface::updateSurfaceDataFromFile()
{
std::ifstream stream( this->surfaceFilePath().toLatin1().data() );

View File

@ -35,16 +35,13 @@ public:
~RimSurface() override;
void setSurfaceFilePath( const QString& filePath );
QString surfaceFilePath()
{
return m_surfaceDefinitionFilePath().path();
}
void setColor( const cvf::Color3f& color )
{
m_color = color;
}
QString surfaceFilePath();
bool updateDataFromFile();
void setColor( const cvf::Color3f& color );
cvf::Color3f color() const;
bool updateSurfaceDataFromFile();
RigSurface* surfaceData();
QString userDescription();

View File

@ -91,7 +91,7 @@ RimSurface* RimSurfaceCollection::importSurfacesFromFiles( const QStringList& fi
newSurface->setSurfaceFilePath( newFileName );
newSurface->setColor( newColor );
if ( !newSurface->updateDataFromFile() )
if ( !newSurface->updateSurfaceDataFromFile() )
{
delete newSurface;
errorMessages += newFileName + "\n";
@ -132,20 +132,36 @@ std::vector<RimSurface*> RimSurfaceCollection::surfaces() const
return m_surfaces.childObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::loadData()
{
for ( auto surf : m_surfaces )
{
if ( !surf->updateSurfaceDataFromFile() )
{
// Error: could not open the surface file surf->surfaceFilePath();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::updateViews( const std::vector<RimSurface*>& surfsToReload )
{
RimProject* proj = RiaApplication::instance()->project();
std::vector<RimGridView*> views;
proj->allVisibleGridViews( views );
RimProject* proj = RiaApplication::instance()->project();
std::vector<Rim3dView*> views;
proj->allViews( views );
// Make sure the tree items are syncronized
for ( auto view : views )
{
view->updateSurfacesInViewTreeItems();
auto gridView = dynamic_cast<RimGridView*>( view );
if ( gridView ) gridView->updateSurfacesInViewTreeItems();
}
std::set<RimGridView*> viewsNeedingUpdate;

View File

@ -36,10 +36,10 @@ public:
std::vector<RimSurface*> surfaces() const;
void loadData();
void updateViews();
private:
void updateViews( const std::vector<RimSurface*>& surfsToReload );
private:
caf::PdmChildArrayField<RimSurface*> m_surfaces;
};

View File

@ -18,8 +18,11 @@
#include "RimSurfaceInView.h"
#include "RimGridView.h"
#include "RimSurface.h"
#include "RivSurfacePartMgr.h"
CAF_PDM_SOURCE_INIT( RimSurfaceInView, "SurfaceInView" );
//--------------------------------------------------------------------------------------------------
@ -75,6 +78,47 @@ void RimSurfaceInView::setSurface( RimSurface* surf )
m_surface = surf;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSurfaceInView::isActive()
{
return m_isActive();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInView::clearGeometry()
{
m_surfacePartMgr = nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivSurfacePartMgr* RimSurfaceInView::surfacePartMgr()
{
if ( m_surfacePartMgr.isNull() ) m_surfacePartMgr = new RivSurfacePartMgr( this );
return m_surfacePartMgr.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInView::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
if ( changedField == &m_isActive )
{
RimGridView* ownerView;
this->firstAncestorOrThisOfTypeAsserted( ownerView );
ownerView->scheduleCreateDisplayModelAndRedraw();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -22,7 +22,10 @@
#include "cafPdmProxyValueField.h"
#include "cafPdmPtrField.h"
#include "cvfObject.h"
class RimSurface;
class RivSurfacePartMgr;
class RimSurfaceInView : public caf::PdmObject
{
@ -37,12 +40,21 @@ public:
QString name() const;
RimSurface* surface() const;
void setSurface( RimSurface* surf );
bool isActive();
void clearGeometry();
RivSurfacePartMgr* surfacePartMgr();
private:
caf::PdmFieldHandle* userDescriptionField() override;
caf::PdmFieldHandle* objectToggleField() override;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue ) override;
caf::PdmProxyValueField<QString> m_name;
caf::PdmField<bool> m_isActive;
caf::PdmPtrField<RimSurface*> m_surface;
cvf::ref<RivSurfacePartMgr> m_surfacePartMgr;
};

View File

@ -19,11 +19,16 @@
#include "RimSurfaceInViewCollection.h"
#include "RiaApplication.h"
#include "RimGridView.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RimSurfaceCollection.h"
#include "RimSurfaceInView.h"
#include "RivSurfacePartMgr.h"
#include "cvfModelBasicList.h"
CAF_PDM_SOURCE_INIT( RimSurfaceInViewCollection, "SurfaceInViewCollection" );
//--------------------------------------------------------------------------------------------------
@ -86,6 +91,39 @@ void RimSurfaceInViewCollection::updateFromSurfaceCollection()
this->updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::appendPartsToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform )
{
if ( !m_isActive() ) return;
for ( RimSurfaceInView* surf : m_surfacesInView )
{
if ( surf->isActive() )
{
surf->surfacePartMgr()->appendNativeGeometryPartsToModel( model, scaleTransform );
}
}
model->updateBoundingBoxesRecursive();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
if ( changedField == &m_isActive )
{
RimGridView* ownerView;
this->firstAncestorOrThisOfTypeAsserted( ownerView );
ownerView->scheduleCreateDisplayModelAndRedraw();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -21,6 +21,13 @@
#include "cafPdmField.h"
#include "cafPdmObject.h"
namespace cvf
{
class ModelBasicList;
class Transform;
class ScalarMapper;
} // namespace cvf
class RimSurfaceInView;
class RimSurface;
@ -34,10 +41,15 @@ public:
void updateFromSurfaceCollection();
void appendPartsToModel( cvf::ModelBasicList* surfaceVizModel, cvf::Transform* scaleTransform );
private:
caf::PdmFieldHandle* objectToggleField() override;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue ) override;
bool hasSurfaceInViewForSurface(const RimSurface * surf) const;
bool hasSurfaceInViewForSurface( const RimSurface* surf ) const;
caf::PdmField<bool> m_isActive;
caf::PdmChildArrayField<RimSurfaceInView*> m_surfacesInView;

View File

@ -27,6 +27,22 @@ RigSurface::RigSurface() {}
//--------------------------------------------------------------------------------------------------
RigSurface::~RigSurface() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<unsigned>& RigSurface::triangleIndices()
{
return m_triangleIndices;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<cvf::Vec3d>& RigSurface::vertices()
{
return m_vertices;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -31,14 +31,8 @@ public:
RigSurface();
~RigSurface() override;
const std::vector<unsigned>& triangleVertices()
{
return m_triangleIndices;
}
const std::vector<cvf::Vec3d>& vertices()
{
return m_vertices;
}
const std::vector<unsigned>& triangleIndices();
const std::vector<cvf::Vec3d>& vertices();
void setTriangleData( const std::vector<unsigned>& tringleIndices, const std::vector<cvf::Vec3d>& vertices );
void addVerticeResult( const QString resultName, const std::vector<double>& resultValues );