2018-12-19 14:41:17 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2011- Statoil ASA
|
|
|
|
|
// Copyright (C) 2013- Ceetron Solutions AS
|
|
|
|
|
// Copyright (C) 2011-2012 Ceetron AS
|
2019-01-15 10:53:54 +01:00
|
|
|
//
|
2018-12-19 14:41:17 +01:00
|
|
|
// 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.
|
2019-01-15 10:53:54 +01:00
|
|
|
//
|
2018-12-19 14:41:17 +01:00
|
|
|
// 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.
|
2019-01-15 10:53:54 +01:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-12-19 14:41:17 +01:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RivMeasurementPartMgr.h"
|
|
|
|
|
|
|
|
|
|
#include "RiaBoundingBoxTools.h"
|
2018-12-20 12:34:17 +01:00
|
|
|
#include "RiaColorTools.h"
|
|
|
|
|
#include "RiaFontCache.h"
|
2021-04-28 10:29:53 +02:00
|
|
|
#include "RiaGuiApplication.h"
|
2018-12-20 12:34:17 +01:00
|
|
|
#include "RiaPreferences.h"
|
2018-12-19 14:41:17 +01:00
|
|
|
|
|
|
|
|
#include "Rim3dView.h"
|
|
|
|
|
#include "RimMeasurement.h"
|
2019-01-15 10:53:54 +01:00
|
|
|
#include "RimProject.h"
|
2018-12-19 14:41:17 +01:00
|
|
|
|
2020-10-08 11:23:08 +02:00
|
|
|
#include "RiuGuiTheme.h"
|
|
|
|
|
|
2019-01-15 10:53:54 +01:00
|
|
|
#include "RivPartPriority.h"
|
2018-12-19 14:41:17 +01:00
|
|
|
#include "RivPolylineGenerator.h"
|
|
|
|
|
|
2019-02-04 14:23:16 +01:00
|
|
|
#include "cafDisplayCoordTransform.h"
|
|
|
|
|
#include "cafEffectGenerator.h"
|
|
|
|
|
#include "cafFixedAtlasFont.h"
|
|
|
|
|
|
2019-01-15 10:53:54 +01:00
|
|
|
#include "cvfBoundingBox.h"
|
2019-02-04 15:28:32 +01:00
|
|
|
#include "cvfCamera.h"
|
2019-01-15 10:53:54 +01:00
|
|
|
#include "cvfDrawableGeo.h"
|
|
|
|
|
#include "cvfDrawableText.h"
|
|
|
|
|
#include "cvfModelBasicList.h"
|
|
|
|
|
#include "cvfPart.h"
|
2018-12-19 14:41:17 +01:00
|
|
|
#include "cvfRenderStateDepth.h"
|
|
|
|
|
#include "cvfRenderStatePoint.h"
|
2018-12-20 12:34:17 +01:00
|
|
|
#include "cvfqtUtils.h"
|
2018-12-19 14:41:17 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-15 10:53:54 +01:00
|
|
|
///
|
2018-12-19 14:41:17 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
RivMeasurementPartMgr::RivMeasurementPartMgr( Rim3dView* view )
|
|
|
|
|
: m_rimView( view )
|
|
|
|
|
, m_measurement( nullptr )
|
2018-12-19 14:41:17 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-15 10:53:54 +01:00
|
|
|
///
|
2018-12-19 14:41:17 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 11:13:38 +01:00
|
|
|
RivMeasurementPartMgr::~RivMeasurementPartMgr()
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-12-19 14:41:17 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RivMeasurementPartMgr::appendGeometryPartsToModel( const cvf::Camera* camera,
|
|
|
|
|
cvf::ModelBasicList* model,
|
|
|
|
|
const caf::DisplayCoordTransform* displayCoordTransform,
|
|
|
|
|
const cvf::BoundingBox& boundingBox )
|
2018-12-19 14:41:17 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( m_measurement.isNull() )
|
2018-12-19 14:41:17 +01:00
|
|
|
{
|
2020-05-12 09:50:38 +02:00
|
|
|
m_measurement = RimProject::current()->measurement();
|
2018-12-19 14:41:17 +01:00
|
|
|
}
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( m_measurement.isNull() ) return;
|
|
|
|
|
if ( m_measurement->pointsInDomainCoords().empty() ) return;
|
2018-12-19 14:41:17 +01:00
|
|
|
|
|
|
|
|
// Check bounding box
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( !isPolylinesInBoundingBox( boundingBox ) ) return;
|
2018-12-19 14:41:17 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
buildPolyLineParts( camera, displayCoordTransform );
|
2018-12-19 14:41:17 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( m_linePart.notNull() )
|
2018-12-19 14:41:17 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
model->addPart( m_linePart.p() );
|
2018-12-19 14:41:17 +01:00
|
|
|
}
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( m_pointPart.notNull() )
|
2018-12-19 14:41:17 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
model->addPart( m_pointPart.p() );
|
2018-12-19 14:41:17 +01:00
|
|
|
}
|
2018-12-20 12:34:17 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( m_labelPart.notNull() )
|
2018-12-20 12:34:17 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
model->addPart( m_labelPart.p() );
|
2018-12-20 12:34:17 +01:00
|
|
|
}
|
2018-12-19 14:41:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-15 10:53:54 +01:00
|
|
|
///
|
2018-12-19 14:41:17 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RivMeasurementPartMgr::clearGeometryCache()
|
|
|
|
|
{
|
2019-01-15 10:53:54 +01:00
|
|
|
m_linePart = nullptr;
|
2018-12-19 14:41:17 +01:00
|
|
|
m_pointPart = nullptr;
|
2018-12-21 09:23:53 +01:00
|
|
|
m_labelPart = nullptr;
|
2018-12-19 14:41:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 10:48:40 +01:00
|
|
|
void RivMeasurementPartMgr::buildPolyLineParts( const cvf::Camera* camera, const caf::DisplayCoordTransform* displayCoordTransform )
|
2018-12-19 14:41:17 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
auto pointsInDisplay = displayCoordTransform->transformToDisplayCoords( m_measurement->pointsInDomainCoords() );
|
2018-12-19 14:41:17 +01:00
|
|
|
|
2018-12-20 12:34:17 +01:00
|
|
|
// Measurement lines
|
2018-12-19 14:41:17 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
cvf::ref<cvf::DrawableGeo> polylineGeo = RivPolylineGenerator::createLineAlongPolylineDrawable( pointsInDisplay );
|
|
|
|
|
if ( polylineGeo.notNull() )
|
2018-12-19 14:41:17 +01:00
|
|
|
{
|
|
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
2019-09-06 10:40:57 +02:00
|
|
|
part->setName( "Cross Section Polyline" );
|
|
|
|
|
part->setDrawable( polylineGeo.p() );
|
2018-12-19 14:41:17 +01:00
|
|
|
|
|
|
|
|
part->updateBoundingBox();
|
2019-09-06 10:40:57 +02:00
|
|
|
part->setPriority( RivPartPriority::PartType::Highlight );
|
2018-12-19 14:41:17 +01:00
|
|
|
|
|
|
|
|
cvf::ref<cvf::Effect> eff;
|
2019-09-06 10:40:57 +02:00
|
|
|
caf::MeshEffectGenerator lineEffGen( cvf::Color3::MAGENTA );
|
2018-12-19 14:41:17 +01:00
|
|
|
eff = lineEffGen.generateUnCachedEffect();
|
|
|
|
|
|
|
|
|
|
cvf::ref<cvf::RenderStateDepth> depth = new cvf::RenderStateDepth;
|
2019-09-06 10:40:57 +02:00
|
|
|
depth->enableDepthTest( false );
|
|
|
|
|
eff->setRenderState( depth.p() );
|
2018-12-19 14:41:17 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
part->setEffect( eff.p() );
|
2018-12-19 14:41:17 +01:00
|
|
|
|
|
|
|
|
m_linePart = part;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 12:34:17 +01:00
|
|
|
// Measurement points
|
2023-02-26 10:48:40 +01:00
|
|
|
cvf::ref<cvf::DrawableGeo> polylinePointsGeo = RivPolylineGenerator::createPointsFromPolylineDrawable( pointsInDisplay );
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( polylinePointsGeo.notNull() )
|
2018-12-19 14:41:17 +01:00
|
|
|
{
|
|
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
2019-09-06 10:40:57 +02:00
|
|
|
part->setName( "Cross Section Polyline" );
|
|
|
|
|
part->setDrawable( polylinePointsGeo.p() );
|
2018-12-19 14:41:17 +01:00
|
|
|
|
|
|
|
|
part->updateBoundingBox();
|
2019-09-06 10:40:57 +02:00
|
|
|
part->setPriority( RivPartPriority::PartType::Highlight );
|
2018-12-19 14:41:17 +01:00
|
|
|
|
|
|
|
|
cvf::ref<cvf::Effect> eff;
|
2019-09-06 10:40:57 +02:00
|
|
|
caf::MeshEffectGenerator lineEffGen( cvf::Color3::MAGENTA );
|
2018-12-19 14:41:17 +01:00
|
|
|
eff = lineEffGen.generateUnCachedEffect();
|
|
|
|
|
|
|
|
|
|
cvf::ref<cvf::RenderStateDepth> depth = new cvf::RenderStateDepth;
|
2019-09-06 10:40:57 +02:00
|
|
|
depth->enableDepthTest( false );
|
|
|
|
|
eff->setRenderState( depth.p() );
|
2018-12-19 14:41:17 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
cvf::ref<cvf::RenderStatePoint> pointRendState = new cvf::RenderStatePoint( cvf::RenderStatePoint::FIXED_SIZE );
|
|
|
|
|
pointRendState->setSize( 5.0f );
|
|
|
|
|
eff->setRenderState( pointRendState.p() );
|
2018-12-19 14:41:17 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
part->setEffect( eff.p() );
|
2018-12-19 14:41:17 +01:00
|
|
|
|
|
|
|
|
m_pointPart = part;
|
|
|
|
|
}
|
2018-12-20 12:34:17 +01:00
|
|
|
|
|
|
|
|
// Text label
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( pointsInDisplay.size() > 1 )
|
2018-12-20 12:34:17 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
bool negativeXDir = false;
|
2023-02-26 10:48:40 +01:00
|
|
|
cvf::Vec3d lastV = pointsInDisplay[pointsInDisplay.size() - 1] - pointsInDisplay[pointsInDisplay.size() - 2];
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( lastV.x() < 0.0 )
|
2019-02-04 15:28:32 +01:00
|
|
|
{
|
|
|
|
|
negativeXDir = true;
|
|
|
|
|
}
|
2025-09-01 12:38:48 +02:00
|
|
|
QString text = m_measurement->label();
|
|
|
|
|
auto labelPosition = pointsInDisplay.back();
|
2019-02-04 15:28:32 +01:00
|
|
|
|
2025-09-01 12:38:48 +02:00
|
|
|
auto drawableText = RivPolylineGenerator::createOrientedLabel( negativeXDir, camera, labelPosition, text );
|
2018-12-20 12:34:17 +01:00
|
|
|
|
|
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
2025-09-01 12:38:48 +02:00
|
|
|
|
|
|
|
|
part->setName( "RivMeasurementPartMgr: " );
|
2019-09-06 10:40:57 +02:00
|
|
|
part->setDrawable( drawableText.p() );
|
2018-12-20 12:34:17 +01:00
|
|
|
|
|
|
|
|
cvf::ref<cvf::Effect> eff = new cvf::Effect();
|
2019-09-06 10:40:57 +02:00
|
|
|
part->setEffect( eff.p() );
|
|
|
|
|
part->setPriority( RivPartPriority::PartType::Text );
|
2018-12-20 12:34:17 +01:00
|
|
|
|
|
|
|
|
m_labelPart = part;
|
|
|
|
|
}
|
2018-12-19 14:41:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
bool RivMeasurementPartMgr::isPolylinesInBoundingBox( const cvf::BoundingBox& boundingBox )
|
2018-12-19 14:41:17 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
auto effectiveBoundingBox = RiaBoundingBoxTools::inflate( boundingBox, 3 );
|
|
|
|
|
for ( const auto& pt : m_measurement->pointsInDomainCoords() )
|
2018-12-19 14:41:17 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( effectiveBoundingBox.contains( pt ) ) return true;
|
2018-12-19 14:41:17 +01:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|