Skip to content

Commit

Permalink
Add optional labels for every N-th measured depth on well paths
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Sep 12, 2023
1 parent 0bf560a commit cab14e5
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,16 @@ bool Riv3dWellLogDrawSurfaceGenerator::createDrawSurface( const caf::DisplayCoor
size_t indexToFirstVisibleSegment = 0u;
if ( wellPathCollection->wellPathClip )
{
double clipZDistance = wellPathCollection->wellPathClipZDistance;
cvf::Vec3d clipLocation = wellPathClipBoundingBox.max() + clipZDistance * cvf::Vec3d( 0, 0, 1 );
clipLocation = displayCoordTransform->transformToDisplayCoord( clipLocation );
double horizontalLengthAlongWellToClipPoint;
double clipZDistance = wellPathCollection->wellPathClipZDistance;
cvf::Vec3d clipLocation = wellPathClipBoundingBox.max() + clipZDistance * cvf::Vec3d( 0, 0, 1 );
clipLocation = displayCoordTransform->transformToDisplayCoord( clipLocation );
double horizontalLengthAlongWellToClipPoint = 0.0;
double measuredDepthAtFirstClipPoint = 0.0;

wellPathDisplayCoords = RigWellPath::clipPolylineStartAboveZ( wellPathDisplayCoords,
clipLocation.z(),
&horizontalLengthAlongWellToClipPoint,
&measuredDepthAtFirstClipPoint,
&indexToFirstVisibleSegment );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,21 @@ RivAnnotationSourceInfo::RivAnnotationSourceInfo( const std::string m_text, cons
: m_text( m_text )
, m_showColor( false )
, m_color( cvf::Color3f( cvf::Color3f::BLACK ) )
, m_anchorPointsDisplayCoord( displayCoords )
, m_labelPositionHint( RivAnnotationTools::LabelPositionStrategy::RIGHT )
, m_anchorPointsDisplayCoord( displayCoords )
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivAnnotationSourceInfo::RivAnnotationSourceInfo( const std::vector<std::string>& texts, const std::vector<cvf::Vec3d>& displayCoords )
: m_text( m_text )
, m_showColor( false )
, m_color( cvf::Color3f( cvf::Color3f::BLACK ) )
, m_labelPositionHint( RivAnnotationTools::LabelPositionStrategy::COUNT_HINT )
, m_anchorPointsDisplayCoord( displayCoords )
, m_texts( texts )
{
}

Expand Down Expand Up @@ -54,6 +67,14 @@ std::string RivAnnotationSourceInfo::text() const
return m_text;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<std::string> RivAnnotationSourceInfo::texts() const
{
return m_texts;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ class RivAnnotationSourceInfo : public cvf::Object
{
public:
RivAnnotationSourceInfo( const std::string m_text, const std::vector<cvf::Vec3d>& displayCoords );
RivAnnotationSourceInfo( const std::vector<std::string>& texts, const std::vector<cvf::Vec3d>& displayCoords );

RivAnnotationTools::LabelPositionStrategy labelPositionStrategyHint() const;
void setLabelPositionStrategyHint( RivAnnotationTools::LabelPositionStrategy strategy );

std::string text() const;
std::vector<cvf::Vec3d> anchorPointsDisplayCoords() const;
std::string text() const;
std::vector<std::string> texts() const;
std::vector<cvf::Vec3d> anchorPointsDisplayCoords() const;

bool showColor() const;
void setShowColor( bool showColor );
Expand All @@ -50,4 +52,5 @@ class RivAnnotationSourceInfo : public cvf::Object
cvf::Color3f m_color;
RivAnnotationTools::LabelPositionStrategy m_labelPositionHint;
std::vector<cvf::Vec3d> m_anchorPointsDisplayCoord;
std::vector<std::string> m_texts;
};
140 changes: 100 additions & 40 deletions ApplicationLibCode/ModelVisualization/RivAnnotationTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void caf::AppEnum<RivAnnotationTools::LabelPositionStrategy>::setUp()
//--------------------------------------------------------------------------------------------------
RivAnnotationTools::RivAnnotationTools()
: m_strategy( RivAnnotationTools::LabelPositionStrategy::UNDEFINED )
, m_labelCountHint( 0 )
, m_labelCountHint( 5 )
{
}

Expand Down Expand Up @@ -190,6 +190,55 @@ auto createLabel = []( const cvf::Camera* camera,
return info;
};

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
auto createLabelsFromAnnotationObjectTexts = []( const cvf::Camera* camera,
const RivAnnotationSourceInfo* annotationObject,
const double viewportWidth,
const double viewportHeight,
const double anchorLineScalingFactor ) -> std::vector<LabelInfo>
{
if ( !annotationObject || annotationObject->texts().empty() ) return {};

std::vector<LabelInfo> labelInfo;

std::vector<cvf::Vec3d> labelCoords;
std::vector<std::string> labelTexts;

const auto candidateCoords = annotationObject->anchorPointsDisplayCoords();
const auto candidateLabels = annotationObject->texts();

if ( candidateCoords.size() == candidateLabels.size() )
{
for ( size_t i = 0; i < annotationObject->anchorPointsDisplayCoords().size(); i++ )
{
const auto& displayCoord = candidateCoords[i];

cvf::Vec3d screenCoord;
camera->project( displayCoord, &screenCoord );

if ( screenCoord.x() > 0 && screenCoord.x() < viewportWidth && screenCoord.y() > 0 && screenCoord.y() < viewportHeight )
{
const auto& text = candidateLabels[i];
labelCoords.push_back( displayCoord );
labelTexts.push_back( text );
}
}

for ( size_t i = 0; i < labelCoords.size(); i++ )
{
const cvf::Vec3d lineAnchorPosition = labelCoords[i];
const cvf::Vec3d directionPointToCam = ( camera->position() - lineAnchorPosition ).getNormalized();
const cvf::Vec3d labelPosition = lineAnchorPosition + directionPointToCam * anchorLineScalingFactor;

labelInfo.push_back( { labelTexts[i], lineAnchorPosition, labelPosition } );
}
}

return labelInfo;
};

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -208,67 +257,77 @@ void RivAnnotationTools::addAnnotationLabels( const cvf::Collection<cvf::Part>&
{
std::vector<LabelInfo> labelInfo;

auto strategy = annotationObject->labelPositionStrategyHint();
if ( m_strategy != LabelPositionStrategy::UNDEFINED )
{
strategy = m_strategy;
}

const auto viewportWidth = camera->viewport()->width();
const auto viewportHeight = camera->viewport()->height();

if ( strategy == LabelPositionStrategy::RIGHT || strategy == LabelPositionStrategy::LEFT_AND_RIGHT )
if ( !annotationObject->texts().empty() )
{
// Close to the right edge of the visible screen area
const auto normalizedXPosition = 0.9;

auto labelCandidate = createLabel( camera, annotationObject, viewportWidth, normalizedXPosition, anchorLineScalingFactor );
if ( labelCandidate.has_value() ) labelInfo.push_back( labelCandidate.value() );
labelInfo =
createLabelsFromAnnotationObjectTexts( camera, annotationObject, viewportWidth, viewportHeight, anchorLineScalingFactor );
}

if ( strategy == LabelPositionStrategy::LEFT || strategy == LabelPositionStrategy::LEFT_AND_RIGHT )
else
{
// Close to the left edge of the visible screen area
const auto normalizedXPosition = 0.1;

auto labelCandidate = createLabel( camera, annotationObject, viewportWidth, normalizedXPosition, anchorLineScalingFactor );
if ( labelCandidate.has_value() ) labelInfo.push_back( labelCandidate.value() );
}
auto strategy = annotationObject->labelPositionStrategyHint();
if ( m_strategy != LabelPositionStrategy::UNDEFINED )
{
// Can override annotation object strategy defined in Rim3dView::updateScreenSpaceModel()
strategy = m_strategy;
}

if ( strategy == LabelPositionStrategy::COUNT_HINT || strategy == LabelPositionStrategy::ALL )
{
std::vector<cvf::Vec3d> visibleCoords;
for ( const auto& v : annotationObject->anchorPointsDisplayCoords() )
if ( strategy == LabelPositionStrategy::RIGHT || strategy == LabelPositionStrategy::LEFT_AND_RIGHT )
{
cvf::Vec3d screenCoord;
camera->project( v, &screenCoord );
// Close to the right edge of the visible screen area
const auto normalizedXPosition = 0.9;

if ( screenCoord.x() > 0 && screenCoord.x() < viewportWidth && screenCoord.y() > 0 && screenCoord.y() < viewportHeight )
visibleCoords.push_back( v );
auto labelCandidate = createLabel( camera, annotationObject, viewportWidth, normalizedXPosition, anchorLineScalingFactor );
if ( labelCandidate.has_value() ) labelInfo.push_back( labelCandidate.value() );
}

size_t stride = 1;
if ( strategy == LabelPositionStrategy::COUNT_HINT )
if ( strategy == LabelPositionStrategy::LEFT || strategy == LabelPositionStrategy::LEFT_AND_RIGHT )
{
stride = std::max( size_t( 1 ), visibleCoords.size() / std::max( 1, m_labelCountHint - 1 ) );
// Close to the left edge of the visible screen area
const auto normalizedXPosition = 0.1;

auto labelCandidate = createLabel( camera, annotationObject, viewportWidth, normalizedXPosition, anchorLineScalingFactor );
if ( labelCandidate.has_value() ) labelInfo.push_back( labelCandidate.value() );
}

for ( size_t i = 0; i < visibleCoords.size(); i += stride )
if ( strategy == LabelPositionStrategy::COUNT_HINT || strategy == LabelPositionStrategy::ALL )
{
size_t adjustedIndex = std::min( i, visibleCoords.size() - 1 );
std::vector<cvf::Vec3d> visibleCoords;
for ( const auto& v : annotationObject->anchorPointsDisplayCoords() )
{
cvf::Vec3d screenCoord;
camera->project( v, &screenCoord );

if ( screenCoord.x() > 0 && screenCoord.x() < viewportWidth && screenCoord.y() > 0 && screenCoord.y() < viewportHeight )
visibleCoords.push_back( v );
}

const cvf::Vec3d lineAnchorPosition = visibleCoords[adjustedIndex];
const cvf::Vec3d directionPointToCam = ( camera->position() - lineAnchorPosition ).getNormalized();
const cvf::Vec3d labelPosition = lineAnchorPosition + directionPointToCam * anchorLineScalingFactor;
size_t stride = 1;
if ( strategy == LabelPositionStrategy::COUNT_HINT )
{
stride = std::max( size_t( 1 ), visibleCoords.size() / std::max( 1, m_labelCountHint - 1 ) );
}

labelInfo.push_back( { annotationObject->text(), lineAnchorPosition, labelPosition } );
for ( size_t i = 0; i < visibleCoords.size(); i += stride )
{
size_t adjustedIndex = std::min( i, visibleCoords.size() - 1 );

const cvf::Vec3d lineAnchorPosition = visibleCoords[adjustedIndex];
const cvf::Vec3d directionPointToCam = ( camera->position() - lineAnchorPosition ).getNormalized();
const cvf::Vec3d labelPosition = lineAnchorPosition + directionPointToCam * anchorLineScalingFactor;

labelInfo.push_back( { annotationObject->text(), lineAnchorPosition, labelPosition } );
}
}
}

for ( const auto& [labelText, lineAnchorPosition, labelPosition] : labelInfo )
{
// Line part
{
// Line part

std::vector<cvf::Vec3d> points = { lineAnchorPosition, labelPosition };

auto anchorLineColor = cvf::Color3f::BLACK;
Expand All @@ -279,8 +338,9 @@ void RivAnnotationTools::addAnnotationLabels( const cvf::Collection<cvf::Part>&
}
}

// Text part
{
// Text part

auto backgroundColor = annotationObject->showColor() ? annotationObject->color() : cvf::Color3f::LIGHT_GRAY;
auto textColor = RiaColorTools::contrastColor( backgroundColor );
auto fontSize = 10;
Expand Down
28 changes: 28 additions & 0 deletions ApplicationLibCode/ModelVisualization/RivWellPathPartMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "RimWellPathValve.h"

#include "Riv3dWellLogPlanePartMgr.h"
#include "RivAnnotationSourceInfo.h"
#include "RivBoxGeometryGenerator.h"
#include "RivDrawableSpheres.h"
#include "RivFishbonesSubsPartMgr.h"
Expand Down Expand Up @@ -620,13 +621,15 @@ void RivWellPathPartMgr::buildWellPathParts( const caf::DisplayCoordTransform* d
m_pipeGeomGenerator->setCrossSectionVertexCount( wellPathCollection->wellPathCrossSectionVertexCount() );

double horizontalLengthAlongWellToClipPoint = 0.0;
double measuredDepthAtFirstClipPoint = 0.0;
size_t idxToFirstVisibleSegment = 0;
if ( wellPathCollection->wellPathClip )
{
double maxZClipHeight = wellPathClipBoundingBox.max().z() + wellPathCollection->wellPathClipZDistance;
clippedWellPathCenterLine = RigWellPath::clipPolylineStartAboveZ( wellpathCenterLine,
maxZClipHeight,
&horizontalLengthAlongWellToClipPoint,
&measuredDepthAtFirstClipPoint,
&idxToFirstVisibleSegment );
}
else
Expand Down Expand Up @@ -694,6 +697,31 @@ void RivWellPathPartMgr::buildWellPathParts( const caf::DisplayCoordTransform* d
cvf::ref<cvf::Effect> eff = gen.generateCachedEffect();

m_centerLinePart->setEffect( eff.p() );

if ( m_rimWellPath->measuredDepthLabelInterval().has_value() && clippedWellPathCenterLine.size() > 2 )
{
const double distanceBetweenLabels = m_rimWellPath->measuredDepthLabelInterval().value();

// Create a round number as start for measured depth label
const double startMeasuredDepth = ( int( measuredDepthAtFirstClipPoint / distanceBetweenLabels ) + 1 ) * distanceBetweenLabels;

std::vector<std::string> labelTexts;
std::vector<cvf::Vec3d> labelDisplayCoords;

double measuredDepth = startMeasuredDepth;
while ( measuredDepth < wellPathGeometry->measuredDepths().back() )
{
labelTexts.push_back( std::to_string( static_cast<int>( measuredDepth ) ) );
auto domainCoord = wellPathGeometry->interpolatedPointAlongWellPath( measuredDepth );

auto displayCoord = displayCoordTransform->transformToDisplayCoord( domainCoord );
labelDisplayCoords.push_back( displayCoord );

measuredDepth += distanceBetweenLabels;
}

m_centerLinePart->setSourceInfo( new RivAnnotationSourceInfo( labelTexts, labelDisplayCoords ) );
}
}

// Generate label with well-path name at a position that is slightly offset towards the end of the well path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,16 @@ void RivSeismicSectionPartMgr::appendSurfaceIntersectionLines( cvf::ModelBasicLi
}
}

// Add annotation info to be used to display label in Rim3dView::onViewNavigationChanged()
// Set the source info once, 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 );
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 );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,11 @@ std::vector<std::vector<cvf::Vec3d>> RimExtrudedCurveIntersection::polyLines( cv
if ( ownerCase && ownerCase->activeCellsBoundingBox().isValid() )
{
size_t dummy;
double dummyDouble;
lines[0] = RigWellPath::clipPolylineStartAboveZ( lines[0],
ownerCase->activeCellsBoundingBox().max().z(),
&horizontalProjectedLengthAlongWellPathToClipPoint,
&dummyDouble,
&dummy );
}
}
Expand Down
Loading

0 comments on commit cab14e5

Please sign in to comment.