diff --git a/ApplicationLibCode/ModelVisualization/RivContourMapProjectionPartMgr.cpp b/ApplicationLibCode/ModelVisualization/RivContourMapProjectionPartMgr.cpp index 7bd447aa74..9a3558ea1b 100644 --- a/ApplicationLibCode/ModelVisualization/RivContourMapProjectionPartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/RivContourMapProjectionPartMgr.cpp @@ -1,28 +1,41 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2018- 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + #include "RivContourMapProjectionPartMgr.h" #include "RiaColorTools.h" #include "RiaFontCache.h" -#include "RiaWeightedMeanCalculator.h" -#include "RigCellGeometryTools.h" + +#include "RigContourMapGrid.h" #include "RigContourPolygonsTools.h" + #include "RivMeshLinesSourceInfo.h" #include "RivPartPriority.h" #include "RivScalarMapperUtils.h" -#include "RimContourMapProjection.h" -#include "RimGridView.h" -#include "RimRegularLegendConfig.h" - #include "cafCategoryMapper.h" #include "cafEffectGenerator.h" #include "cafFixedAtlasFont.h" #include "cvfCamera.h" +#include "cvfColor3.h" #include "cvfDrawableText.h" -#include "cvfGeometryBuilderFaceList.h" -#include "cvfGeometryTools.h" -#include "cvfGeometryUtils.h" -#include "cvfMeshEdgeExtractor.h" +#include "cvfModelBasicList.h" #include "cvfPart.h" #include "cvfPrimitiveSetIndexedUInt.h" #include "cvfRay.h" @@ -34,35 +47,28 @@ #include #include + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RivContourMapProjectionPartMgr::RivContourMapProjectionPartMgr( RimContourMapProjection* contourMapProjection, RimGridView* contourMap ) +RivContourMapProjectionPartMgr::RivContourMapProjectionPartMgr( caf::PdmObject* pdmObject ) { - m_contourMapProjection = contourMapProjection; - m_parentContourMap = contourMap; + m_pdmObject = pdmObject; m_labelEffect = new cvf::Effect; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RivContourMapProjectionPartMgr::createProjectionGeometry() -{ - m_contourMapProjection->generateGeometryIfNecessary(); - - m_contourLinePolygons = m_contourMapProjection->contourPolygons(); - m_contourMapTriangles = m_contourMapProjection->trianglesWithVertexValues(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RivContourMapProjectionPartMgr::appendProjectionToModel( cvf::ModelBasicList* model, - const caf::DisplayCoordTransform* displayCoordTransform ) const + const caf::DisplayCoordTransform* displayCoordTransform, + const std::vector& vertices, + const RigContourMapGrid& contourMapGrid, + const cvf::Color3f& backgroundColor, + cvf::ScalarMapper* scalarMapper ) const { - cvf::ref mapPart = createProjectionMapPart( displayCoordTransform ); + cvf::ref mapPart = createProjectionMapPart( displayCoordTransform, vertices, contourMapGrid, backgroundColor, scalarMapper ); if ( mapPart.notNull() ) { model->addPart( mapPart.p() ); @@ -73,9 +79,12 @@ void RivContourMapProjectionPartMgr::appendProjectionToModel( cvf::ModelBasicLis /// //-------------------------------------------------------------------------------------------------- void RivContourMapProjectionPartMgr::appendPickPointVisToModel( cvf::ModelBasicList* model, - const caf::DisplayCoordTransform* displayCoordTransform ) const + const caf::DisplayCoordTransform* displayCoordTransform, + const cvf::Vec2d& pickPoint, + const RigContourMapGrid& contourMapGrid ) const + { - cvf::ref drawable = createPickPointVisDrawable( displayCoordTransform ); + cvf::ref drawable = createPickPointVisDrawable( displayCoordTransform, pickPoint, contourMapGrid ); if ( drawable.notNull() && drawable->boundingBox().isValid() ) { caf::MeshEffectGenerator meshEffectGen( cvf::Color3::MAGENTA ); @@ -87,7 +96,7 @@ void RivContourMapProjectionPartMgr::appendPickPointVisToModel( cvf::ModelBasicL part->setName( "RivContourMapProjectionPartMgr::appendPickPointVisToModel" ); part->setDrawable( drawable.p() ); part->setEffect( effect.p() ); - part->setSourceInfo( new RivMeshLinesSourceInfo( m_contourMapProjection.p() ) ); + part->setSourceInfo( new RivMeshLinesSourceInfo( m_pdmObject.p() ) ); model->addPart( part.p() ); } @@ -96,7 +105,8 @@ void RivContourMapProjectionPartMgr::appendPickPointVisToModel( cvf::ModelBasicL //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::ref RivContourMapProjectionPartMgr::createTextureCoords( const std::vector& values ) const +cvf::ref RivContourMapProjectionPartMgr::createTextureCoords( const std::vector& values, + cvf::ScalarMapper* scalarMapper ) const { cvf::ref textureCoords = new cvf::Vec2fArray( values.size() ); @@ -105,7 +115,7 @@ cvf::ref RivContourMapProjectionPartMgr::createTextureCoords( c { if ( values[i] != std::numeric_limits::infinity() ) { - cvf::Vec2f textureCoord = m_contourMapProjection->legendConfig()->scalarMapper()->mapToTextureCoord( values[i] ); + cvf::Vec2f textureCoord = scalarMapper->mapToTextureCoord( values[i] ); textureCoord.y() = 0.0; ( *textureCoords )[i] = textureCoord; } @@ -122,22 +132,28 @@ cvf::ref RivContourMapProjectionPartMgr::createTextureCoords( c //-------------------------------------------------------------------------------------------------- void RivContourMapProjectionPartMgr::appendContourLinesToModel( const cvf::Camera* camera, cvf::ModelBasicList* model, - const caf::DisplayCoordTransform* displayCoordTransform ) + const caf::DisplayCoordTransform* displayCoordTransform, + const std::vector& contourLinePolygons, + const RigContourMapGrid& contourMapGrid, + cvf::ScalarMapper* mapper, + bool showContourLines, + bool showContourLabels, + RiaNumberFormat::NumberFormatType numberFormat, + int precision ) { - if ( m_contourMapProjection->showContourLines() ) + if ( showContourLines ) { - cvf::ScalarMapper* mapper = m_contourMapProjection->legendConfig()->scalarMapper(); - std::vector> labelBBoxes; std::vector> labelDrawables; - if ( m_contourMapProjection->showContourLabels() ) + if ( showContourLabels ) { - labelDrawables = createContourLabels( camera, displayCoordTransform, &labelBBoxes ); + labelDrawables = + createContourLabels( camera, displayCoordTransform, &labelBBoxes, contourLinePolygons, contourMapGrid, mapper, numberFormat, precision ); } std::vector>> contourDrawablesForAllLevels = - createContourPolygons( displayCoordTransform, labelBBoxes ); + createContourPolygons( displayCoordTransform, labelBBoxes, contourLinePolygons, mapper, contourMapGrid ); std::vector tickValues; mapper->majorTickValues( &tickValues ); @@ -164,14 +180,14 @@ void RivContourMapProjectionPartMgr::appendContourLinesToModel( const cvf::Camer part->setDrawable( contourDrawable.p() ); part->setEffect( effect.p() ); part->setPriority( RivPartPriority::MeshLines ); - part->setSourceInfo( new RivMeshLinesSourceInfo( m_contourMapProjection.p() ) ); + part->setSourceInfo( new RivMeshLinesSourceInfo( m_pdmObject.p() ) ); model->addPart( part.p() ); } } } - if ( m_contourMapProjection->showContourLabels() ) + if ( showContourLabels ) { for ( auto labelDrawableRef : labelDrawables ) { @@ -180,7 +196,7 @@ void RivContourMapProjectionPartMgr::appendContourLinesToModel( const cvf::Camer part->setDrawable( labelDrawableRef.p() ); part->setEffect( m_labelEffect.p() ); part->setPriority( RivPartPriority::Text ); - part->setSourceInfo( new RivMeshLinesSourceInfo( m_contourMapProjection.p() ) ); + part->setSourceInfo( new RivMeshLinesSourceInfo( m_pdmObject.p() ) ); model->addPart( part.p() ); } } @@ -211,9 +227,12 @@ cvf::ref RivContourMapProjectionPartMgr::createTextLabel( con //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::ref RivContourMapProjectionPartMgr::createProjectionMapPart( const caf::DisplayCoordTransform* displayCoordTransform ) const +cvf::ref RivContourMapProjectionPartMgr::createProjectionMapPart( const caf::DisplayCoordTransform* displayCoordTransform, + const std::vector& vertices, + const RigContourMapGrid& contourMapGrid, + const cvf::Color3f& backgroundColor, + cvf::ScalarMapper* scalarMapper ) const { - const std::vector& vertices = m_contourMapTriangles; if ( vertices.size() < 3u ) { return cvf::ref(); @@ -223,7 +242,7 @@ cvf::ref RivContourMapProjectionPartMgr::createProjectionMapPart( con std::vector values( vertices.size() ); for ( uint i = 0; i < vertices.size(); ++i ) { - cvf::Vec3d globalVertex = cvf::Vec3d( vertices[i].x(), vertices[i].y(), vertices[i].z() ) + m_contourMapProjection->origin3d(); + cvf::Vec3d globalVertex = cvf::Vec3d( vertices[i].x(), vertices[i].y(), vertices[i].z() ) + contourMapGrid.origin3d(); cvf::Vec3f displayVertexPos( displayCoordTransform->transformToDisplayCoord( globalVertex ) ); ( *vertexArray )[i] = displayVertexPos; ( *faceList )[i] = i; @@ -240,18 +259,10 @@ cvf::ref RivContourMapProjectionPartMgr::createProjectionMapPart( con part->setName( "RivContourMapProjectionPartMgr::createProjectionMapPart" ); part->setDrawable( geo.p() ); - cvf::ScalarMapper* mapper = m_contourMapProjection->legendConfig()->scalarMapper(); + cvf::ref textureCoords = createTextureCoords( values, scalarMapper ); + RivScalarMapperUtils::applyTextureResultsToPart( part.p(), textureCoords.p(), scalarMapper, 1.0f, caf::FC_NONE, true, backgroundColor ); - cvf::ref textureCoords = createTextureCoords( values ); - RivScalarMapperUtils::applyTextureResultsToPart( part.p(), - textureCoords.p(), - mapper, - 1.0f, - caf::FC_NONE, - true, - m_parentContourMap->backgroundColor() ); - - part->setSourceInfo( new RivObjectSourceInfo( m_contourMapProjection.p() ) ); + part->setSourceInfo( new RivObjectSourceInfo( m_pdmObject.p() ) ); part->setPriority( RivPartPriority::BaseLevel ); return part; } @@ -261,41 +272,43 @@ cvf::ref RivContourMapProjectionPartMgr::createProjectionMapPart( con //-------------------------------------------------------------------------------------------------- std::vector>> RivContourMapProjectionPartMgr::createContourPolygons( const caf::DisplayCoordTransform* displayCoordTransform, - const std::vector>& labelBBoxes ) const + const std::vector>& labelBBoxes, + const std::vector& contourLinePolygons, + cvf::ScalarMapper* scalarMapper, + const RigContourMapGrid& contourMapGrid ) const { - const cvf::ScalarMapper* mapper = m_contourMapProjection->legendConfig()->scalarMapper(); - std::vector tickValues; - mapper->majorTickValues( &tickValues ); + std::vector tickValues; + scalarMapper->majorTickValues( &tickValues ); std::vector>> contourDrawablesForAllLevels; contourDrawablesForAllLevels.resize( tickValues.size() ); - for ( size_t i = 1; i < m_contourLinePolygons.size(); ++i ) + for ( size_t i = 1; i < contourLinePolygons.size(); ++i ) { std::vector> contourDrawables; - for ( size_t j = 0; j < m_contourLinePolygons[i].size(); ++j ) + for ( size_t j = 0; j < contourLinePolygons[i].size(); ++j ) { - if ( m_contourLinePolygons[i][j].vertices.empty() ) continue; + if ( contourLinePolygons[i][j].vertices.empty() ) continue; // cvf::String::number does not allow precision on 'g' formats, so use Qt. - QString qLabelText = QString::number( m_contourLinePolygons[i][j].value, 'g', 2 ); + QString qLabelText = QString::number( contourLinePolygons[i][j].value, 'g', 2 ); cvf::String labelText = cvfqt::Utils::toString( qLabelText ); - size_t nVertices = m_contourLinePolygons[i][j].vertices.size(); + size_t nVertices = contourLinePolygons[i][j].vertices.size(); std::vector displayLines; displayLines.reserve( nVertices * 2 ); for ( size_t v = 0; v < nVertices; ++v ) { - cvf::Vec3d globalVertex1 = m_contourLinePolygons[i][j].vertices[v] + m_contourMapProjection->origin3d(); + cvf::Vec3d globalVertex1 = contourLinePolygons[i][j].vertices[v] + contourMapGrid.origin3d(); cvf::Vec3d displayVertex1 = displayCoordTransform->transformToDisplayCoord( globalVertex1 ); cvf::Vec3d globalVertex2; if ( v < nVertices - 1 ) - globalVertex2 = m_contourLinePolygons[i][j].vertices[v + 1] + m_contourMapProjection->origin3d(); + globalVertex2 = contourLinePolygons[i][j].vertices[v + 1] + contourMapGrid.origin3d(); else - globalVertex2 = m_contourLinePolygons[i][j].vertices[0] + m_contourMapProjection->origin3d(); + globalVertex2 = contourLinePolygons[i][j].vertices[0] + contourMapGrid.origin3d(); cvf::Vec3d displayVertex2 = displayCoordTransform->transformToDisplayCoord( globalVertex2 ); @@ -390,41 +403,45 @@ std::vector>> /// //-------------------------------------------------------------------------------------------------- std::vector> - RivContourMapProjectionPartMgr::createContourLabels( const cvf::Camera* camera, - const caf::DisplayCoordTransform* displayCoordTransform, - std::vector>* labelBBoxes ) const + RivContourMapProjectionPartMgr::createContourLabels( const cvf::Camera* camera, + const caf::DisplayCoordTransform* displayCoordTransform, + std::vector>* labelBBoxes, + const std::vector& contourLinePolygons, + const RigContourMapGrid& contourMapGrid, + const cvf::ScalarMapper* scalarMapper, + RiaNumberFormat::NumberFormatType numberFormat, + int precision ) const { CVF_ASSERT( camera && displayCoordTransform && labelBBoxes ); std::vector> labelDrawables; labelBBoxes->clear(); - labelBBoxes->resize( m_contourLinePolygons.size() ); + labelBBoxes->resize( contourLinePolygons.size() ); if ( !camera->viewport() || camera->viewport()->width() == 0 ) return labelDrawables; - const cvf::ScalarMapper* mapper = m_contourMapProjection->legendConfig()->scalarMapper(); - if ( mapper == nullptr ) return labelDrawables; + if ( scalarMapper == nullptr ) return labelDrawables; - if ( dynamic_cast( mapper ) != nullptr ) return labelDrawables; + if ( dynamic_cast( scalarMapper ) != nullptr ) return labelDrawables; std::vector tickValues; - mapper->majorTickValues( &tickValues ); + scalarMapper->majorTickValues( &tickValues ); const RigContourPolygonsTools::ContourPolygons* previousLevel = nullptr; - for ( int64_t i = (int64_t)m_contourLinePolygons.size() - 1; i > 0; --i ) + for ( int64_t i = (int64_t)contourLinePolygons.size() - 1; i > 0; --i ) { - cvf::Color3f backgroundColor( mapper->mapToColor( tickValues[i] ) ); + cvf::Color3f backgroundColor( scalarMapper->mapToColor( tickValues[i] ) ); cvf::Color3f textColor = RiaColorTools::contrastColor( backgroundColor ); cvf::ref label = createTextLabel( textColor, backgroundColor ); - for ( size_t j = 0; j < m_contourLinePolygons[i].size(); ++j ) + for ( size_t j = 0; j < contourLinePolygons[i].size(); ++j ) { - if ( m_contourLinePolygons[i][j].vertices.empty() ) continue; + if ( contourLinePolygons[i][j].vertices.empty() ) continue; - QString qLabelText = m_contourMapProjection->legendConfig()->valueToText( m_contourLinePolygons[i][j].value ); + QString qLabelText = RiaNumberFormat::valueToText( contourLinePolygons[i][j].value, numberFormat, precision ); cvf::String labelText = cvfqt::Utils::toString( qLabelText ); - size_t nVertices = m_contourLinePolygons[i][j].vertices.size(); + size_t nVertices = contourLinePolygons[i][j].vertices.size(); size_t nLabels = nVertices; double distanceSinceLastLabel = std::numeric_limits::infinity(); for ( size_t l = 0; l < nLabels; ++l ) @@ -432,19 +449,19 @@ std::vector> size_t nVertex = ( nVertices * l ) / nLabels; size_t nextVertex = ( nVertex + 1 ) % nVertices; - const cvf::Vec3d& localVertex1 = m_contourLinePolygons[i][j].vertices[nVertex]; - const cvf::Vec3d& localVertex2 = m_contourLinePolygons[i][j].vertices[nextVertex]; + const cvf::Vec3d& localVertex1 = contourLinePolygons[i][j].vertices[nVertex]; + const cvf::Vec3d& localVertex2 = contourLinePolygons[i][j].vertices[nextVertex]; cvf::Vec3d lineCenter = ( localVertex1 + localVertex2 ) * 0.5; - double tolerance = 1.0e-2 * m_contourMapProjection->sampleSpacing(); + double tolerance = 1.0e-2 * contourMapGrid.sampleSpacing(); if ( previousLevel && lineOverlapsWithPreviousContourLevel( lineCenter, *previousLevel, tolerance ) ) { continue; } - cvf::Vec3d globalVertex1 = localVertex1 + m_contourMapProjection->origin3d(); - cvf::Vec3d globalVertex2 = localVertex2 + m_contourMapProjection->origin3d(); + cvf::Vec3d globalVertex1 = localVertex1 + contourMapGrid.origin3d(); + cvf::Vec3d globalVertex2 = localVertex2 + contourMapGrid.origin3d(); cvf::Vec3d globalVertex = 0.5 * ( globalVertex1 + globalVertex2 ); @@ -510,7 +527,7 @@ std::vector> labelDrawables.push_back( label ); } - previousLevel = &m_contourLinePolygons[i]; + previousLevel = &contourLinePolygons[i]; } return labelDrawables; } @@ -518,10 +535,12 @@ std::vector> //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::ref - RivContourMapProjectionPartMgr::createPickPointVisDrawable( const caf::DisplayCoordTransform* displayCoordTransform ) const +cvf::ref RivContourMapProjectionPartMgr::createPickPointVisDrawable( const caf::DisplayCoordTransform* displayCoordTransform, + const cvf::Vec2d& pickPoint, + const RigContourMapGrid& contourMapGrid ) const { - std::vector pickPointPolygon = m_contourMapProjection->generatePickPointPolygon(); + std::vector pickPointPolygon = RigContourPolygonsTools::generatePickPointPolygon( pickPoint, contourMapGrid ); + if ( pickPointPolygon.empty() ) { return nullptr; @@ -530,7 +549,7 @@ cvf::ref for ( size_t i = 0; i < pickPointPolygon.size(); ++i ) { - cvf::Vec3d globalPoint = pickPointPolygon[i] + m_contourMapProjection->origin3d(); + cvf::Vec3d globalPoint = pickPointPolygon[i] + contourMapGrid.origin3d(); cvf::Vec3f displayPoint( displayCoordTransform->transformToDisplayCoord( globalPoint ) ); ( *vertexArray )[i] = displayPoint; } diff --git a/ApplicationLibCode/ModelVisualization/RivContourMapProjectionPartMgr.h b/ApplicationLibCode/ModelVisualization/RivContourMapProjectionPartMgr.h index fe5c45b76e..237bd3d410 100644 --- a/ApplicationLibCode/ModelVisualization/RivContourMapProjectionPartMgr.h +++ b/ApplicationLibCode/ModelVisualization/RivContourMapProjectionPartMgr.h @@ -18,57 +18,96 @@ #pragma once -#include "RimContourMapProjection.h" +#include "RigContourPolygonsTools.h" + +#include "RiaNumberFormat.h" #include "cafDisplayCoordTransform.h" +#include "cafPdmObject.h" #include "cafPdmPointer.h" #include "cvfDrawableGeo.h" #include "cvfDrawableText.h" -#include "cvfModelBasicList.h" #include "cvfObject.h" +#include "cvfVector2.h" #include "cvfVector4.h" -class RimEclipseContourMapView; +class RigContourMapGrid; namespace cvf { class Effect; -} +class ScalarMapper; +class Color3f; +class ModelBasicList; +class Part; +} // namespace cvf class RivContourMapProjectionPartMgr : public cvf::Object { public: - RivContourMapProjectionPartMgr( RimContourMapProjection* contourMapProjection, RimGridView* contourMap ); + RivContourMapProjectionPartMgr( caf::PdmObject* contourMapProjection ); - void createProjectionGeometry(); - void appendProjectionToModel( cvf::ModelBasicList* model, const caf::DisplayCoordTransform* displayCoordTransform ) const; - void appendContourLinesToModel( const cvf::Camera* camera, - cvf::ModelBasicList* model, - const caf::DisplayCoordTransform* displayCoordTransform ); - void appendPickPointVisToModel( cvf::ModelBasicList* model, const caf::DisplayCoordTransform* displayCoordTransform ) const; + void appendProjectionToModel( cvf::ModelBasicList* model, + const caf::DisplayCoordTransform* displayCoordTransform, + const std::vector& vertices, + const RigContourMapGrid& contourMapGrid, + const cvf::Color3f& backgroundColor, + cvf::ScalarMapper* scalarMapper ) const; - cvf::ref createTextureCoords( const std::vector& values ) const; + void appendContourLinesToModel( const cvf::Camera* camera, + cvf::ModelBasicList* model, + const caf::DisplayCoordTransform* displayCoordTransform, + const std::vector& contourLinePolygons, + const RigContourMapGrid& contourMapGrid, + cvf::ScalarMapper* mapper, + bool showContourLines, + bool showContourLabels, + RiaNumberFormat::NumberFormatType numberFormat, + int precision ); + + void appendPickPointVisToModel( cvf::ModelBasicList* model, + const caf::DisplayCoordTransform* displayCoordTransform, + const cvf::Vec2d& pickPoint, + const RigContourMapGrid& contourMapGrid ) const; + + cvf::ref createTextureCoords( const std::vector& values, cvf::ScalarMapper* scalarMapper ) const; private: static cvf::ref createTextLabel( const cvf::Color3f& textColor, const cvf::Color3f& backgroundColor ); - cvf::ref createProjectionMapPart( const caf::DisplayCoordTransform* displayCoordTransform ) const; - std::vector>> createContourPolygons( const caf::DisplayCoordTransform* displayCoordTransform, - const std::vector>& labelBBoxes ) const; - std::vector> createContourLabels( const cvf::Camera* camera, - const caf::DisplayCoordTransform* displayCoordTransform, - std::vector>* labelBBoxes ) const; - cvf::ref createPickPointVisDrawable( const caf::DisplayCoordTransform* displayCoordTransform ) const; - static bool lineOverlapsWithPreviousContourLevel( const cvf::Vec3d& lineCenter, - const RimContourMapProjection::ContourPolygons& previousLevel, - double tolerance ); + cvf::ref createProjectionMapPart( const caf::DisplayCoordTransform* displayCoordTransform, + const std::vector& vertices, + const RigContourMapGrid& contourMapGrid, + const cvf::Color3f& backgroundColor, + cvf::ScalarMapper* scalarMapper ) const; + + std::vector>> + createContourPolygons( const caf::DisplayCoordTransform* displayCoordTransform, + const std::vector>& labelBBoxes, + const std::vector& contourLinePolygons, + cvf::ScalarMapper* scalarMapper, + const RigContourMapGrid& contourMapGrid ) const; + + std::vector> createContourLabels( const cvf::Camera* camera, + const caf::DisplayCoordTransform* displayCoordTransform, + std::vector>* labelBBoxes, + const std::vector& contourLinePolygons, + const RigContourMapGrid& contourMapGrid, + const cvf::ScalarMapper* scalarMapper, + RiaNumberFormat::NumberFormatType numberFormat, + int precision ) const; + + cvf::ref createPickPointVisDrawable( const caf::DisplayCoordTransform* displayCoordTransform, + const cvf::Vec2d& pickPoint, + const RigContourMapGrid& contourMapGrid ) const; + + static bool lineOverlapsWithPreviousContourLevel( const cvf::Vec3d& lineCenter, + const RigContourPolygonsTools::ContourPolygons& previousLevel, + double tolerance ); private: - caf::PdmPointer m_contourMapProjection; - caf::PdmPointer m_parentContourMap; + caf::PdmPointer m_pdmObject; - std::vector m_contourLinePolygons; - std::vector m_contourMapTriangles; - std::vector> m_labelBoundingBoxes; - cvf::ref m_labelEffect; + std::vector> m_labelBoundingBoxes; + cvf::ref m_labelEffect; }; diff --git a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapView.cpp b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapView.cpp index d7eaf4b47f..dc550251c6 100644 --- a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapView.cpp +++ b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapView.cpp @@ -67,7 +67,7 @@ RimGeoMechContourMapView::RimGeoMechContourMapView() setDefaultCustomName(); - m_contourMapProjectionPartMgr = new RivContourMapProjectionPartMgr( contourMapProjection(), this ); + m_contourMapProjectionPartMgr = new RivContourMapProjectionPartMgr( contourMapProjection() ); ( (RiuViewerToViewInterface*)this )->setCameraPosition( sm_defaultViewMatrix ); @@ -283,7 +283,7 @@ void RimGeoMechContourMapView::createContourMapGeometry() { if ( nativeOrOverrideViewer() && m_contourMapProjection->isChecked() ) { - m_contourMapProjectionPartMgr->createProjectionGeometry(); + m_contourMapProjection->generateGeometryIfNecessary(); } } @@ -305,7 +305,13 @@ void RimGeoMechContourMapView::appendContourMapProjectionToModel() cvf::ref transForm = displayCoordTransform(); - m_contourMapProjectionPartMgr->appendProjectionToModel( contourMapProjectionModelBasicList.p(), transForm.p() ); + m_contourMapProjectionPartMgr->appendProjectionToModel( contourMapProjectionModelBasicList.p(), + transForm.p(), + m_contourMapProjection->trianglesWithVertexValues(), + *m_contourMapProjection->mapGrid(), + backgroundColor(), + m_contourMapProjection->legendConfig()->scalarMapper() ); + contourMapProjectionModelBasicList->updateBoundingBoxesRecursive(); frameScene->addModel( contourMapProjectionModelBasicList.p() ); } @@ -330,7 +336,17 @@ void RimGeoMechContourMapView::appendContourLinesToModel() cvf::ref transForm = displayCoordTransform(); - m_contourMapProjectionPartMgr->appendContourLinesToModel( viewer()->mainCamera(), contourMapLabelModelBasicList.p(), transForm.p() ); + m_contourMapProjectionPartMgr->appendContourLinesToModel( viewer()->mainCamera(), + contourMapLabelModelBasicList.p(), + transForm.p(), + m_contourMapProjection->contourPolygons(), + *m_contourMapProjection->mapGrid(), + m_contourMapProjection->legendConfig()->scalarMapper(), + m_contourMapProjection->showContourLines(), + m_contourMapProjection->showContourLabels(), + m_contourMapProjection->legendConfig()->tickNumberFormat(), + m_contourMapProjection->legendConfig()->significantDigitsInData() ); + contourMapLabelModelBasicList->updateBoundingBoxesRecursive(); frameScene->addModel( contourMapLabelModelBasicList.p() ); } @@ -355,7 +371,11 @@ void RimGeoMechContourMapView::appendPickPointVisToModel() cvf::ref transForm = displayCoordTransform(); - m_contourMapProjectionPartMgr->appendPickPointVisToModel( contourMapProjectionModelBasicList.p(), transForm.p() ); + m_contourMapProjectionPartMgr->appendPickPointVisToModel( contourMapProjectionModelBasicList.p(), + transForm.p(), + m_contourMapProjection->pickPoint(), + *m_contourMapProjection->mapGrid() ); + contourMapProjectionModelBasicList->updateBoundingBoxesRecursive(); frameScene->addModel( contourMapProjectionModelBasicList.p() ); } diff --git a/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp b/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp index ba77b919f7..acf64a369d 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp @@ -188,37 +188,6 @@ void RimContourMapProjection::generateGeometryIfNecessary() progress.setProgress( 100 ); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector RimContourMapProjection::generatePickPointPolygon() -{ - std::vector points; - - if ( !m_pickPoint.isUndefined() ) - { -#ifndef NDEBUG - cvf::Vec2d cellDiagonal( sampleSpacing() * 0.5, sampleSpacing() * 0.5 ); - cvf::Vec2ui pickedCell = m_contourMapGrid->ijFromLocalPos( m_pickPoint ); - cvf::Vec2d cellCenter = m_contourMapGrid->cellCenterPosition( pickedCell.x(), pickedCell.y() ); - cvf::Vec2d cellCorner = cellCenter - cellDiagonal; - points.push_back( cvf::Vec3d( cellCorner, 0.0 ) ); - points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing(), 0.0 ), 0.0 ) ); - points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing(), 0.0 ), 0.0 ) ); - points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing(), sampleSpacing() ), 0.0 ) ); - points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing(), sampleSpacing() ), 0.0 ) ); - points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( 0.0, sampleSpacing() ), 0.0 ) ); - points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( 0.0, sampleSpacing() ), 0.0 ) ); - points.push_back( cvf::Vec3d( cellCorner, 0.0 ) ); -#endif - points.push_back( cvf::Vec3d( m_pickPoint - cvf::Vec2d( 0.5 * sampleSpacing(), 0.0 ), 0.0 ) ); - points.push_back( cvf::Vec3d( m_pickPoint + cvf::Vec2d( 0.5 * sampleSpacing(), 0.0 ), 0.0 ) ); - points.push_back( cvf::Vec3d( m_pickPoint - cvf::Vec2d( 0.0, 0.5 * sampleSpacing() ), 0.0 ) ); - points.push_back( cvf::Vec3d( m_pickPoint + cvf::Vec2d( 0.0, 0.5 * sampleSpacing() ), 0.0 ) ); - } - return points; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -314,6 +283,14 @@ const RigContourMapProjection* RimContourMapProjection::mapProjection() const return m_contourMapProjection.get(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const RigContourMapGrid* RimContourMapProjection::mapGrid() const +{ + return m_contourMapGrid.get(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -330,12 +307,20 @@ void RimContourMapProjection::setPickPoint( cvf::Vec2d globalPickPoint ) m_pickPoint = globalPickPoint - m_contourMapGrid->origin2d(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec2d RimContourMapProjection::pickPoint() const +{ + return m_pickPoint; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- cvf::Vec3d RimContourMapProjection::origin3d() const { - return m_contourMapGrid->expandedBoundingBox().min(); + return m_contourMapGrid->origin3d(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.h b/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.h index b11ee72035..551983515f 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.h +++ b/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.h @@ -53,8 +53,6 @@ public: void generateGeometryIfNecessary(); void clearGeometry(); - std::vector generatePickPointPolygon(); - const std::vector& contourPolygons() const; const std::vector& trianglesWithVertexValues(); @@ -75,6 +73,8 @@ public: bool isStraightSummationResult() const; void setPickPoint( cvf::Vec2d globalPickPoint ); + cvf::Vec2d pickPoint() const; + cvf::Vec3d origin3d() const; // Pure-virtual public methods which should be overridden by Eclipse and Geo-mechanical contour map implementations @@ -90,6 +90,7 @@ public: virtual cvf::ref getCellVisibility() const; const RigContourMapProjection* mapProjection() const; + const RigContourMapGrid* mapGrid() const; protected: // Protected virtual methods to be overridden by Eclipse and Geo-mechanical contour map implementations diff --git a/ApplicationLibCode/ProjectDataModel/RimEclipseContourMapView.cpp b/ApplicationLibCode/ProjectDataModel/RimEclipseContourMapView.cpp index abab36c1e7..5604bb9602 100644 --- a/ApplicationLibCode/ProjectDataModel/RimEclipseContourMapView.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimEclipseContourMapView.cpp @@ -77,7 +77,7 @@ RimEclipseContourMapView::RimEclipseContourMapView() setDefaultCustomName(); - m_contourMapProjectionPartMgr = new RivContourMapProjectionPartMgr( contourMapProjection(), this ); + m_contourMapProjectionPartMgr = new RivContourMapProjectionPartMgr( contourMapProjection() ); setCameraPosition( sm_defaultViewMatrix ); @@ -314,7 +314,7 @@ void RimEclipseContourMapView::createContourMapGeometry() { if ( nativeOrOverrideViewer() && m_contourMapProjection->isChecked() ) { - m_contourMapProjectionPartMgr->createProjectionGeometry(); + m_contourMapProjection->generateGeometryIfNecessary(); } } @@ -336,7 +336,13 @@ void RimEclipseContourMapView::appendContourMapProjectionToModel() cvf::ref transForm = displayCoordTransform(); - m_contourMapProjectionPartMgr->appendProjectionToModel( contourMapProjectionModelBasicList.p(), transForm.p() ); + m_contourMapProjectionPartMgr->appendProjectionToModel( contourMapProjectionModelBasicList.p(), + transForm.p(), + m_contourMapProjection->trianglesWithVertexValues(), + *m_contourMapProjection->mapGrid(), + backgroundColor(), + m_contourMapProjection->legendConfig()->scalarMapper() ); + contourMapProjectionModelBasicList->updateBoundingBoxesRecursive(); frameScene->addModel( contourMapProjectionModelBasicList.p() ); } @@ -361,7 +367,17 @@ void RimEclipseContourMapView::appendContourLinesToModel() cvf::ref transForm = displayCoordTransform(); - m_contourMapProjectionPartMgr->appendContourLinesToModel( viewer()->mainCamera(), contourMapLabelModelBasicList.p(), transForm.p() ); + m_contourMapProjectionPartMgr->appendContourLinesToModel( viewer()->mainCamera(), + contourMapLabelModelBasicList.p(), + transForm.p(), + m_contourMapProjection->contourPolygons(), + *m_contourMapProjection->mapGrid(), + m_contourMapProjection->legendConfig()->scalarMapper(), + m_contourMapProjection->showContourLines(), + m_contourMapProjection->showContourLabels(), + m_contourMapProjection->legendConfig()->tickNumberFormat(), + m_contourMapProjection->legendConfig()->significantDigitsInData() ); + contourMapLabelModelBasicList->updateBoundingBoxesRecursive(); frameScene->addModel( contourMapLabelModelBasicList.p() ); } @@ -386,7 +402,10 @@ void RimEclipseContourMapView::appendPickPointVisToModel() cvf::ref transForm = displayCoordTransform(); - m_contourMapProjectionPartMgr->appendPickPointVisToModel( contourMapProjectionModelBasicList.p(), transForm.p() ); + m_contourMapProjectionPartMgr->appendPickPointVisToModel( contourMapProjectionModelBasicList.p(), + transForm.p(), + m_contourMapProjection->pickPoint(), + *m_contourMapProjection->mapGrid() ); contourMapProjectionModelBasicList->updateBoundingBoxesRecursive(); frameScene->addModel( contourMapProjectionModelBasicList.p() ); } diff --git a/ApplicationLibCode/ProjectDataModel/RimRegularLegendConfig.cpp b/ApplicationLibCode/ProjectDataModel/RimRegularLegendConfig.cpp index 32e799bb2c..38a42dc942 100644 --- a/ApplicationLibCode/ProjectDataModel/RimRegularLegendConfig.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimRegularLegendConfig.cpp @@ -1161,6 +1161,22 @@ QString RimRegularLegendConfig::valueToText( double value ) const return RiaNumberFormat::valueToText( value, m_tickNumberFormat(), m_significantDigitsInData ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaNumberFormat::NumberFormatType RimRegularLegendConfig::tickNumberFormat() const +{ + return m_tickNumberFormat(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RimRegularLegendConfig::significantDigitsInData() const +{ + return m_significantDigitsInData; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/RimRegularLegendConfig.h b/ApplicationLibCode/ProjectDataModel/RimRegularLegendConfig.h index 78a9ed5307..37a07eae3e 100644 --- a/ApplicationLibCode/ProjectDataModel/RimRegularLegendConfig.h +++ b/ApplicationLibCode/ProjectDataModel/RimRegularLegendConfig.h @@ -127,10 +127,16 @@ public: RimColorLegend* colorLegend() const; void setMappingMode( MappingType mappingType ); MappingType mappingMode() { return m_mappingMode(); } - void setTickNumberFormat( RiaNumberFormat::NumberFormatType numberFormat ); - void resetUserDefinedValues(); - void setCenterLegendAroundZero( bool enable ); - void setUserDefinedRange( double minVal, double maxVal ); + + void setTickNumberFormat( RiaNumberFormat::NumberFormatType numberFormat ); + + RiaNumberFormat::NumberFormatType tickNumberFormat() const; + + int significantDigitsInData() const; + + void resetUserDefinedValues(); + void setCenterLegendAroundZero( bool enable ); + void setUserDefinedRange( double minVal, double maxVal ); void disableAllTimeStepsRange( bool doDisable ); diff --git a/ApplicationLibCode/ReservoirDataModel/RigContourPolygonsTools.cpp b/ApplicationLibCode/ReservoirDataModel/RigContourPolygonsTools.cpp index e859c873d7..518b8dc391 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigContourPolygonsTools.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigContourPolygonsTools.cpp @@ -19,13 +19,12 @@ #include "RigContourPolygonsTools.h" #include "RigCellGeometryTools.h" +#include "RigContourMapGrid.h" #include "cafContourLines.h" #include "cvfGeometryTools.h" -#include - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -186,3 +185,35 @@ bool RigContourPolygonsTools::lineOverlapsWithContourPolygons( const cvf::Vec3d& } return false; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RigContourPolygonsTools::generatePickPointPolygon( const cvf::Vec2d& pickPoint, const RigContourMapGrid& contourMapGrid ) +{ + std::vector points; + + if ( !pickPoint.isUndefined() ) + { + double sampleSpacing = contourMapGrid.sampleSpacing(); +#ifndef NDEBUG + cvf::Vec2d cellDiagonal( sampleSpacing * 0.5, sampleSpacing * 0.5 ); + cvf::Vec2ui pickedCell = contourMapGrid.ijFromLocalPos( pickPoint ); + cvf::Vec2d cellCenter = contourMapGrid.cellCenterPosition( pickedCell.x(), pickedCell.y() ); + cvf::Vec2d cellCorner = cellCenter - cellDiagonal; + points.push_back( cvf::Vec3d( cellCorner, 0.0 ) ); + points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing, 0.0 ), 0.0 ) ); + points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing, 0.0 ), 0.0 ) ); + points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing, sampleSpacing ), 0.0 ) ); + points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing, sampleSpacing ), 0.0 ) ); + points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( 0.0, sampleSpacing ), 0.0 ) ); + points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( 0.0, sampleSpacing ), 0.0 ) ); + points.push_back( cvf::Vec3d( cellCorner, 0.0 ) ); +#endif + points.push_back( cvf::Vec3d( pickPoint - cvf::Vec2d( 0.5 * sampleSpacing, 0.0 ), 0.0 ) ); + points.push_back( cvf::Vec3d( pickPoint + cvf::Vec2d( 0.5 * sampleSpacing, 0.0 ), 0.0 ) ); + points.push_back( cvf::Vec3d( pickPoint - cvf::Vec2d( 0.0, 0.5 * sampleSpacing ), 0.0 ) ); + points.push_back( cvf::Vec3d( pickPoint + cvf::Vec2d( 0.0, 0.5 * sampleSpacing ), 0.0 ) ); + } + return points; +} diff --git a/ApplicationLibCode/ReservoirDataModel/RigContourPolygonsTools.h b/ApplicationLibCode/ReservoirDataModel/RigContourPolygonsTools.h index c767dcd47a..654bcc6df5 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigContourPolygonsTools.h +++ b/ApplicationLibCode/ReservoirDataModel/RigContourPolygonsTools.h @@ -23,8 +23,6 @@ #include "cvfBoundingBox.h" class RigContourMapGrid; -class RimGridView; -class RimRegularLegendConfig; //================================================================================================== /// @@ -50,4 +48,6 @@ public: static void clipContourPolygons( ContourPolygons& contourPolygons, const ContourPolygons& clipBy ); static double sumPolygonArea( const ContourPolygons& contourPolygons ); static bool lineOverlapsWithContourPolygons( const cvf::Vec3d& lineCenter, const ContourPolygons& contourPolygons, double tolerance ); + + static std::vector generatePickPointPolygon( const cvf::Vec2d& pickPoint, const RigContourMapGrid& contourMapGrid ); };