Skip to content

Commit

Permalink
Add annotation label support to surface intersection lines
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Sep 12, 2023
1 parent 3b7f871 commit dcd3130
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -213,19 +215,22 @@ void RivSeismicSectionPartMgr::appendSurfaceIntersectionLines( cvf::ModelBasicLi
surface->loadDataIfRequired();
if ( !surface->surfaceData() ) continue;

std::vector<cvf::Vec3d> 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<cvf::Vec3d> polyLine;
std::vector<cvf::Vec3d> 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<cvf::DrawableGeo> drawableGeo =
RivPolylineGenerator::createLineAlongPolylineDrawable( polyLineDisplayCoords, closePolyLine );
Expand All @@ -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 );
}
}
}
66 changes: 66 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Rim3dView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );

Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -678,6 +694,8 @@ void Rim3dView::updateDisplayModelForCurrentTimeStepAndRedraw()
restoreComparisonView();
}

updateScreenSpaceModel();

nativeOrOverrideViewer()->update();
}

Expand Down Expand Up @@ -742,6 +760,8 @@ void Rim3dView::createDisplayModelAndRedraw()
viewer()->setMainScene( nullptr, true );
viewer()->removeAllFrames( true );
}

updateScreenSpaceModel();
}

if ( RiuMainWindow::instance() )
Expand Down Expand Up @@ -899,6 +919,14 @@ bool Rim3dView::isLightingDisabled() const
return m_disableLighting();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Rim3dView::onViewNavigationChanged()
{
updateScreenSpaceModel();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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();
}
}
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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<cvf::Part> 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() );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Rim3dView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand All @@ -272,6 +277,7 @@ class Rim3dView : public RimViewWindow, public RiuViewerToViewInterface, public
cvf::ref<cvf::ModelBasicList> m_seismicVizModel;
cvf::ref<RivWellPathsPartMgr> m_wellPathsPartManager;
cvf::ref<cvf::ModelBasicList> m_highlightVizModel;
cvf::ref<cvf::ModelBasicList> m_screenSpaceModel;

caf::PdmField<double> m_scaleZ;
caf::PdmField<double> m_customScaleZ;
Expand Down Expand Up @@ -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

Expand All @@ -332,6 +339,10 @@ class Rim3dView : public RimViewWindow, public RiuViewerToViewInterface, public
caf::PdmField<bool> m_showZScaleLabel;
caf::PdmPtrField<Rim3dView*> m_comparisonView;

caf::PdmField<bool> m_useCustomAnnotationStrategy;
caf::PdmField<caf::AppEnum<RivAnnotationTools::LabelPositionStrategy>> m_annotationStrategy;
caf::PdmField<int> m_annotationCountHint;

caf::PdmField<caf::FontTools::RelativeSizeEnum> m_fontSize;

// 3D display model data
Expand Down

0 comments on commit dcd3130

Please sign in to comment.