From dcd31302c3e4047d4b145124555d998ed8c8c64c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 12 Sep 2023 12:54:04 +0200 Subject: [PATCH] Add annotation label support to surface intersection lines --- .../Seismic/RivSeismicSectionPartMgr.cpp | 31 +++++++-- .../ProjectDataModel/Rim3dView.cpp | 66 +++++++++++++++++++ .../ProjectDataModel/Rim3dView.h | 11 ++++ 3 files changed, 104 insertions(+), 4 deletions(-) diff --git a/ApplicationLibCode/ModelVisualization/Seismic/RivSeismicSectionPartMgr.cpp b/ApplicationLibCode/ModelVisualization/Seismic/RivSeismicSectionPartMgr.cpp index e50d3a7422..e3f104621d 100644 --- a/ApplicationLibCode/ModelVisualization/Seismic/RivSeismicSectionPartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/Seismic/RivSeismicSectionPartMgr.cpp @@ -32,6 +32,8 @@ #include "RigSurfaceResampler.h" #include "RigTexturedSection.h" +#include "RivAnnotationSourceInfo.h" +#include "RivObjectSourceInfo.h" #include "RivPartPriority.h" #include "RivPolylineGenerator.h" #include "RivPolylinePartMgr.h" @@ -213,19 +215,22 @@ void RivSeismicSectionPartMgr::appendSurfaceIntersectionLines( cvf::ModelBasicLi surface->loadDataIfRequired(); if ( !surface->surfaceData() ) continue; + std::vector completePolyLine; + cvf::Part* firstPart = nullptr; + auto texSection = m_section->texturedSection(); for ( int i = 0; i < texSection->partsCount(); i++ ) { const auto& texturePart = texSection->part( i ); - std::vector polyLine; + std::vector polyLineForSection; // Each part of the seismic section is a rectangle, use two corners of the rectangle to create a polyline - polyLine.push_back( texturePart.rect[0] ); - polyLine.push_back( texturePart.rect[1] ); + polyLineForSection.push_back( texturePart.rect[0] ); + polyLineForSection.push_back( texturePart.rect[1] ); bool closePolyLine = false; - auto polyLineDisplayCoords = projectPolyLineOntoSurface( polyLine, surface, displayCoordTransform ); + auto polyLineDisplayCoords = projectPolyLineOntoSurface( polyLineForSection, surface, displayCoordTransform ); cvf::ref drawableGeo = RivPolylineGenerator::createLineAlongPolylineDrawable( polyLineDisplayCoords, closePolyLine ); @@ -251,6 +256,24 @@ void RivSeismicSectionPartMgr::appendSurfaceIntersectionLines( cvf::ModelBasicLi part->setPriority( RivPartPriority::PartType::MeshLines ); model->addPart( part.p() ); + + if ( !firstPart ) firstPart = part.p(); + for ( const auto& coords : polyLineDisplayCoords ) + { + completePolyLine.insert( completePolyLine.end(), coords.begin(), coords.end() ); + } + } + + if ( firstPart ) + { + // Add annotation info to be used to display label in Rim3dView::onViewNavigationChanged() + // Set the source info on one part only, as this data is only used for display of labels + auto annoObj = new RivAnnotationSourceInfo( surface->fullName().toStdString(), completePolyLine ); + annoObj->setLabelPositionStrategyHint( RivAnnotationTools::LabelPositionStrategy::RIGHT ); + annoObj->setShowColor( true ); + annoObj->setColor( surface->color() ); + + firstPart->setSourceInfo( annoObj ); } } } diff --git a/ApplicationLibCode/ProjectDataModel/Rim3dView.cpp b/ApplicationLibCode/ProjectDataModel/Rim3dView.cpp index ec37eb8060..34b9f9c561 100644 --- a/ApplicationLibCode/ProjectDataModel/Rim3dView.cpp +++ b/ApplicationLibCode/ProjectDataModel/Rim3dView.cpp @@ -153,6 +153,14 @@ Rim3dView::Rim3dView() CAF_PDM_InitFieldNoDefault( &m_fontSize, "FontSize", "Font Size" ); + CAF_PDM_InitFieldNoDefault( &m_annotationStrategy, "AnnotationStrategy", "Annotation Strategy" ); + CAF_PDM_InitField( &m_annotationCountHint, "AnnotationCountHint", 5, "Annotation Count Hint" ); + CAF_PDM_InitField( &m_useCustomAnnotationStrategy, + "UseCustomAnnotationStrategy", + false, + "Use Custom Annotation Strategy", + "Specify the strategy to be applied on all screen space annotations." ); + m_seismicVizModel = new cvf::ModelBasicList; m_seismicVizModel->setName( "SeismicSectionModel" ); @@ -509,6 +517,14 @@ void Rim3dView::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOr gridGroup->add( &meshMode ); gridGroup->add( &surfaceMode ); + caf::PdmUiGroup* annotationGroup = uiOrdering.addNewGroup( "Annotations" ); + annotationGroup->add( &m_useCustomAnnotationStrategy ); + annotationGroup->add( &m_annotationStrategy ); + annotationGroup->add( &m_annotationCountHint ); + m_annotationStrategy.uiCapability()->setUiReadOnly( !m_useCustomAnnotationStrategy ); + m_annotationCountHint.uiCapability()->setUiReadOnly( + !m_useCustomAnnotationStrategy || ( m_annotationStrategy() != RivAnnotationTools::LabelPositionStrategy::COUNT_HINT ) ); + uiOrdering.skipRemainingFields( true ); } @@ -678,6 +694,8 @@ void Rim3dView::updateDisplayModelForCurrentTimeStepAndRedraw() restoreComparisonView(); } + updateScreenSpaceModel(); + nativeOrOverrideViewer()->update(); } @@ -742,6 +760,8 @@ void Rim3dView::createDisplayModelAndRedraw() viewer()->setMainScene( nullptr, true ); viewer()->removeAllFrames( true ); } + + updateScreenSpaceModel(); } if ( RiuMainWindow::instance() ) @@ -899,6 +919,14 @@ bool Rim3dView::isLightingDisabled() const return m_disableLighting(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void Rim3dView::onViewNavigationChanged() +{ + updateScreenSpaceModel(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1022,6 +1050,14 @@ void Rim3dView::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const { createDisplayModelAndRedraw(); } + else if ( changedField == &m_annotationCountHint || changedField == &m_annotationStrategy || changedField == &m_useCustomAnnotationStrategy ) + { + if ( m_viewer ) + { + updateScreenSpaceModel(); + m_viewer->update(); + } + } } //-------------------------------------------------------------------------------------------------- @@ -1637,6 +1673,36 @@ void Rim3dView::appendAnnotationsToModel() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void Rim3dView::updateScreenSpaceModel() +{ + if ( !m_viewer || !m_viewer->mainCamera() ) return; + + if ( m_screenSpaceModel.isNull() ) + { + m_screenSpaceModel = new cvf::ModelBasicList; + m_screenSpaceModel->setName( "ScreenSpaceModel" ); + } + m_screenSpaceModel->removeAllParts(); + + // Build annotation parts and put into screen space model + cvf::Collection partCollection; + m_viewer->currentScene()->allParts( &partCollection ); + + RivAnnotationTools annoTool; + if ( m_useCustomAnnotationStrategy ) + { + annoTool.setOverrideLabelPositionStrategy( m_annotationStrategy() ); + annoTool.setCountHint( m_annotationCountHint() ); + } + + annoTool.addAnnotationLabels( partCollection, m_viewer->mainCamera(), m_screenSpaceModel.p() ); + + nativeOrOverrideViewer()->addStaticModelOnce( m_screenSpaceModel.p(), isUsingOverrideViewer() ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Rim3dView.h b/ApplicationLibCode/ProjectDataModel/Rim3dView.h index e87831424f..d27dbb01c8 100644 --- a/ApplicationLibCode/ProjectDataModel/Rim3dView.h +++ b/ApplicationLibCode/ProjectDataModel/Rim3dView.h @@ -19,10 +19,13 @@ #pragma once #include "RiaDefines.h" + #include "RimNameConfig.h" #include "RimViewWindow.h" + #include "RiuViewerToViewInterface.h" +#include "RivAnnotationTools.h" #include "RivCellSetEnum.h" #include "cafAppEnum.h" @@ -247,6 +250,8 @@ class Rim3dView : public RimViewWindow, public RiuViewerToViewInterface, public virtual cvf::Transform* scaleTransform() = 0; + void onViewNavigationChanged() override; + protected: caf::PdmFieldHandle* userDescriptionField() override; caf::PdmFieldHandle* backgroundColorField(); @@ -272,6 +277,7 @@ class Rim3dView : public RimViewWindow, public RiuViewerToViewInterface, public cvf::ref m_seismicVizModel; cvf::ref m_wellPathsPartManager; cvf::ref m_highlightVizModel; + cvf::ref m_screenSpaceModel; caf::PdmField m_scaleZ; caf::PdmField m_customScaleZ; @@ -306,6 +312,7 @@ class Rim3dView : public RimViewWindow, public RiuViewerToViewInterface, public void appendMeasurementToModel(); void appendCellFiltersToModel(); void appendAnnotationsToModel(); + void updateScreenSpaceModel(); // Pure private methods : Override viewer and comparison view @@ -332,6 +339,10 @@ class Rim3dView : public RimViewWindow, public RiuViewerToViewInterface, public caf::PdmField m_showZScaleLabel; caf::PdmPtrField m_comparisonView; + caf::PdmField m_useCustomAnnotationStrategy; + caf::PdmField> m_annotationStrategy; + caf::PdmField m_annotationCountHint; + caf::PdmField m_fontSize; // 3D display model data