diff --git a/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.h b/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.h index c8f854c156..379e9a6f0b 100644 --- a/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.h +++ b/ApplicationCode/ProjectDataModel/RimRegularLegendConfig.h @@ -144,7 +144,8 @@ public: const caf::TitledOverlayFrame* titledOverlayFrame() const override; caf::TitledOverlayFrame* titledOverlayFrame() override; - RangeModeType rangeMode() const; + RangeModeType rangeMode() const; + static cvf::Color3ubArray colorArrayFromColorType( ColorRangesType colorType ); private: void setNamedCategories( const std::vector& categoryNames, bool inverse ); @@ -164,8 +165,6 @@ private: friend class RimViewLinker; - static cvf::Color3ubArray colorArrayFromColorType( ColorRangesType colorType ); - caf::OverlayScalarMapperLegend* getOrCreateScalarMapperLegend(); caf::CategoryLegend* getOrCreateCategoryLegend(); diff --git a/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp b/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp index b5e19cb280..300e04c863 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp @@ -71,6 +71,8 @@ #include "RiuWellPathComponentPlotItem.h" #include "RiuQwtLinearScaleEngine.h" + +#include "cafPdmUiSliderEditor.h" #include "cvfAssert.h" #define RI_LOGPLOTTRACK_MINX_DEFAULT -10.0 @@ -174,6 +176,13 @@ RimWellLogTrack::RimWellLogTrack() m_minorTickInterval.uiCapability()->setUiHidden( true ); CAF_PDM_InitFieldNoDefault( &m_formationDisplay, "FormationDisplay", "Show Formations", "", "", "" ); + + CAF_PDM_InitFieldNoDefault( &m_colorShadingPalette, "ColorShadingPalette", "Colors", "", "", "" ); + m_colorShadingPalette = RimRegularLegendConfig::CATEGORY; + + CAF_PDM_InitField( &m_colorShadingTransparency, "ColorShadingTransparency", 50, "Color Transparency", "", "", "" ); + m_colorShadingTransparency.uiCapability()->setUiEditorTypeName( caf::PdmUiSliderEditor::uiEditorTypeName() ); + CAF_PDM_InitField( &m_showFormations_OBSOLETE, "ShowFormations", false, "Show Lines", "", "", "" ); m_showFormations_OBSOLETE.xmlCapability()->setIOWritable( false ); CAF_PDM_InitField( &m_showFormationLabels, "ShowFormationLabels", true, "Show Labels", "", "", "" ); @@ -368,7 +377,8 @@ void RimWellLogTrack::fieldChangedByUi( const caf::PdmFieldHandle* changedField, m_wellLogTrackPlotWidget->replot(); } - else if ( changedField == &m_formationDisplay || changedField == &m_formationSource ) + else if ( changedField == &m_formationDisplay || changedField == &m_formationSource || + changedField == &m_colorShadingTransparency || changedField == &m_colorShadingPalette ) { if ( changedField == &m_formationSource && m_formationSource == WELL_PICK_FILTER ) { @@ -650,6 +660,27 @@ QList RimWellLogTrack::calculateValueOptions( const caf: RimTools::wellPathOptionItems( &options ); options.push_front( caf::PdmOptionItemInfo( "None", nullptr ) ); } + else if ( fieldNeedingOptions == &m_colorShadingPalette ) + { + std::vector rangeTypes; + rangeTypes.push_back( RimRegularLegendConfig::NORMAL ); + rangeTypes.push_back( RimRegularLegendConfig::OPPOSITE_NORMAL ); + rangeTypes.push_back( RimRegularLegendConfig::WHITE_PINK ); + rangeTypes.push_back( RimRegularLegendConfig::PINK_WHITE ); + rangeTypes.push_back( RimRegularLegendConfig::BLUE_WHITE_RED ); + rangeTypes.push_back( RimRegularLegendConfig::RED_WHITE_BLUE ); + rangeTypes.push_back( RimRegularLegendConfig::WHITE_BLACK ); + rangeTypes.push_back( RimRegularLegendConfig::BLACK_WHITE ); + rangeTypes.push_back( RimRegularLegendConfig::ANGULAR ); + rangeTypes.push_back( RimRegularLegendConfig::CATEGORY ); + + for ( RimRegularLegendConfig::ColorRangesType colType : rangeTypes ) + { + options.push_back( + caf::PdmOptionItemInfo( RimRegularLegendConfig::ColorRangeEnum::uiText( colType ), colType ) ); + } + } + return options; } @@ -1296,6 +1327,15 @@ void RimWellLogTrack::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering caf::PdmUiGroup* formationGroup = uiOrdering.addNewGroup( "Zonation/Formation Names" ); formationGroup->add( &m_formationDisplay ); + if ( m_formationDisplay() & RiuPlotAnnotationTool::COLOR_SHADING || + m_formationDisplay() & RiuPlotAnnotationTool::COLORED_LINES ) + { + formationGroup->add( &m_colorShadingPalette ); + if ( m_formationDisplay() & RiuPlotAnnotationTool::COLOR_SHADING ) + { + formationGroup->add( &m_colorShadingTransparency ); + } + } formationGroup->add( &m_showFormationLabels ); if ( !m_formationsForCaseWithSimWellOnly ) @@ -1370,6 +1410,24 @@ void RimWellLogTrack::initAfterRead() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellLogTrack::defineEditorAttribute( const caf::PdmFieldHandle* field, + QString uiConfigName, + caf::PdmUiEditorAttribute* attribute ) +{ + if ( field == &m_colorShadingTransparency ) + { + auto sliderAttrib = dynamic_cast( attribute ); + if ( sliderAttrib ) + { + sliderAttrib->m_minimum = 0; + sliderAttrib->m_maximum = 100; + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1834,11 +1892,15 @@ void RimWellLogTrack::updateFormationNamesOnPlot() std::pair xRange = std::make_pair( m_visibleXRangeMin(), m_visibleXRangeMax() ); + caf::ColorTable colorTable( RimRegularLegendConfig::colorArrayFromColorType( m_colorShadingPalette() ) ); + m_annotationTool->attachFormationNames( this->viewer(), formationNamesToPlot, xRange, yValues, m_formationDisplay(), + colorTable, + ( ( 100 - m_colorShadingTransparency ) * 255 ) / 100, m_showFormationLabels() ); } else if ( m_formationSource() == WELL_PICK_FILTER ) diff --git a/ApplicationCode/ProjectDataModel/RimWellLogTrack.h b/ApplicationCode/ProjectDataModel/RimWellLogTrack.h index 02ead9c2d1..17b822ac57 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogTrack.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogTrack.h @@ -24,6 +24,8 @@ #include "RigWellPathFormations.h" #include "RiuPlotAnnotationTool.h" +#include "RimRegularLegendConfig.h" + #include "cafPdmChildArrayField.h" #include "cafPdmField.h" #include "cafPdmObject.h" @@ -178,6 +180,9 @@ private: caf::PdmFieldHandle* userDescriptionField() override; void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; void initAfterRead() override; + void defineEditorAttribute( const caf::PdmFieldHandle* field, + QString uiConfigName, + caf::PdmUiEditorAttribute* attribute ) override; void computeAndSetXRangeMinForLogarithmicScale(); @@ -230,6 +235,8 @@ private: caf::PdmField m_minorTickInterval; caf::PdmField> m_formationDisplay; + caf::PdmField m_colorShadingPalette; + caf::PdmField m_colorShadingTransparency; caf::PdmField m_showFormationLabels; caf::PdmField> m_formationSource; caf::PdmPtrField m_formationCase; diff --git a/ApplicationCode/UserInterface/RiuPlotAnnotationTool.cpp b/ApplicationCode/UserInterface/RiuPlotAnnotationTool.cpp index 583c773a76..2fbe1d043a 100644 --- a/ApplicationCode/UserInterface/RiuPlotAnnotationTool.cpp +++ b/ApplicationCode/UserInterface/RiuPlotAnnotationTool.cpp @@ -19,12 +19,17 @@ #include "RiuPlotAnnotationTool.h" #include "RiaColorTables.h" +#include "RiaColorTools.h" + +#include "cafCategoryMapper.h" +#include "cvfMath.h" + +#include "qwt_plot.h" +#include "qwt_plot_shapeitem.h" #include -#include "cvfMath.h" -#include "qwt_plot.h" -#include "qwt_plot_shapeitem.h" +#include //-------------------------------------------------------------------------------------------------- /// @@ -42,7 +47,9 @@ void RiuPlotAnnotationTool::attachFormationNames( QwtPlot* const std::pair xRange, const std::vector> yPositions, FormationDisplay formationDisplay, - bool showNames ) + const caf::ColorTable& colorTable, + int shadingAlphaByte, + bool showNames /*= true */ ) { detachAllAnnotations(); @@ -51,7 +58,12 @@ void RiuPlotAnnotationTool::attachFormationNames( QwtPlot* double delta = 0.5; - const caf::ColorTable& colors = RiaColorTables::contrastCategoryPaletteColors(); + std::vector categoryIndices( names.size() ); + std::iota( categoryIndices.begin(), categoryIndices.end(), 0 ); + + caf::CategoryMapper catMapper; + catMapper.setCategories( categoryIndices ); + catMapper.setInterpolateColors( colorTable.color3ubArray() ); for ( size_t i = 0; i < names.size(); i++ ) { @@ -61,15 +73,16 @@ void RiuPlotAnnotationTool::attachFormationNames( QwtPlot* if ( showNames ) { name = names[i]; - if ( names[i].toLower().indexOf( "top" ) == -1 ) + if ( ( formationDisplay & COLOR_SHADING ) == 0 && names[i].toLower().indexOf( "top" ) == -1 ) { name += " Top"; } } if ( formationDisplay & COLOR_SHADING ) { - QColor shadingColor = colors.cycledQColor( i ); - shadingColor.setAlpha( 150 ); + cvf::Color3ub cvfColor = catMapper.mapToColor( static_cast( i ) ); + QColor shadingColor( cvfColor.r(), cvfColor.g(), cvfColor.b(), shadingAlphaByte ); + QwtPlotShapeItem* shading = new QwtPlotShapeItem( name ); QwtInterval axisInterval = m_plot->axisInterval( QwtPlot::xBottom ); @@ -80,7 +93,7 @@ void RiuPlotAnnotationTool::attachFormationNames( QwtPlot* yPositions[i].second - yPositions[i].first ); shading->setRect( shadingRect ); - shading->setPen( shadingColor ); + shading->setPen( shadingColor, 0.0, Qt::NoPen ); shading->setBrush( QBrush( shadingColor ) ); shading->attach( m_plot ); shading->setZ( -100.0 ); @@ -89,18 +102,27 @@ void RiuPlotAnnotationTool::attachFormationNames( QwtPlot* } QColor lineColor( 0, 0, 0, 0 ); + QColor textColor( 0, 0, 0, 255 ); if ( formationDisplay & DARK_LINES || formationDisplay & COLORED_LINES ) { - lineColor = formationDisplay & DARK_LINES ? QColor( 0, 0, 100 ) : colors.cycledQColor( i ); + cvf::Color3ub cvfColor = catMapper.mapToColor( static_cast( i ) ); + QColor cycledColor( cvfColor.r(), cvfColor.g(), cvfColor.b() ); + + lineColor = formationDisplay & DARK_LINES ? QColor( 0, 0, 100 ) : cycledColor; + textColor = lineColor; } - RiuPlotAnnotationTool::horizontalDashedLineWithColor( line, lineColor, QColor( 0, 0, 0 ), name, yPositions[i].first ); + RiuPlotAnnotationTool::horizontalDashedLineWithColor( line, lineColor, textColor, name, yPositions[i].first ); line->attach( m_plot ); m_markers.push_back( std::move( line ) ); if ( ( i != names.size() - 1 ) && cvf::Math::abs( yPositions[i].second - yPositions[i + 1].first ) > delta ) { QwtPlotMarker* bottomLine( new QwtPlotMarker() ); - RiuPlotAnnotationTool::horizontalDashedLine( bottomLine, QString(), yPositions[i].second ); + RiuPlotAnnotationTool::horizontalDashedLineWithColor( bottomLine, + lineColor, + textColor, + QString(), + yPositions[i].second ); bottomLine->attach( m_plot ); m_markers.push_back( std::move( bottomLine ) ); diff --git a/ApplicationCode/UserInterface/RiuPlotAnnotationTool.h b/ApplicationCode/UserInterface/RiuPlotAnnotationTool.h index 693cc51314..c7cb77df1f 100644 --- a/ApplicationCode/UserInterface/RiuPlotAnnotationTool.h +++ b/ApplicationCode/UserInterface/RiuPlotAnnotationTool.h @@ -18,6 +18,8 @@ #pragma once +#include "cafColorTable.h" + #include "qwt_plot_marker.h" #include @@ -49,6 +51,8 @@ public: const std::pair xRange, const std::vector> yPositions, FormationDisplay formationDisplay, + const caf::ColorTable& colorTable, + int shadingAlphaByte, bool showNames = true ); void attachWellPicks( QwtPlot* plot, const std::vector& names, const std::vector yPositions ); diff --git a/Fwk/AppFwk/CommonCode/cafColorTable.cpp b/Fwk/AppFwk/CommonCode/cafColorTable.cpp index 3e6848cd4b..bac43bd585 100644 --- a/Fwk/AppFwk/CommonCode/cafColorTable.cpp +++ b/Fwk/AppFwk/CommonCode/cafColorTable.cpp @@ -34,18 +34,16 @@ // //################################################################################################## - #include "cafColorTable.h" #include +#include -namespace caf { - - - +namespace caf +{ //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- ColorTable::ColorTable(const std::vector& colors) : m_colors(colors) @@ -54,7 +52,16 @@ ColorTable::ColorTable(const std::vector& colors) } //-------------------------------------------------------------------------------------------------- -/// +/// +//-------------------------------------------------------------------------------------------------- +ColorTable::ColorTable(const cvf::Color3ubArray& colors) + : m_colors(colors.begin(), colors.end()) +{ + CVF_ASSERT(m_colors.size() > 0); +} + +//-------------------------------------------------------------------------------------------------- +/// //-------------------------------------------------------------------------------------------------- cvf::Color3f ColorTable::cycledColor3f(size_t itemIndex) const { @@ -62,7 +69,7 @@ cvf::Color3f ColorTable::cycledColor3f(size_t itemIndex) const } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- cvf::Color3ub ColorTable::cycledColor3ub(size_t itemIndex) const { @@ -72,7 +79,7 @@ cvf::Color3ub ColorTable::cycledColor3ub(size_t itemIndex) const } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- QColor ColorTable::cycledQColor(size_t itemIndex) const { @@ -81,7 +88,7 @@ QColor ColorTable::cycledQColor(size_t itemIndex) const } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- cvf::Color3ubArray ColorTable::color3ubArray() const { @@ -89,7 +96,7 @@ cvf::Color3ubArray ColorTable::color3ubArray() const } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- cvf::Color3fArray ColorTable::color3fArray() const { @@ -105,7 +112,7 @@ cvf::Color3fArray ColorTable::color3fArray() const } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- size_t ColorTable::size() const { @@ -113,7 +120,17 @@ size_t ColorTable::size() const } //-------------------------------------------------------------------------------------------------- -/// +/// +//-------------------------------------------------------------------------------------------------- +caf::ColorTable ColorTable::inverted() const +{ + std::vector invertedColors = m_colors; + std::reverse(invertedColors.begin(), invertedColors.end()); + return ColorTable(invertedColors); +} + +//-------------------------------------------------------------------------------------------------- +/// //-------------------------------------------------------------------------------------------------- cvf::Color3ub ColorTable::fromQColor(const QColor& color) { @@ -121,7 +138,7 @@ cvf::Color3ub ColorTable::fromQColor(const QColor& color) } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- cvf::Color3ubArray ColorTable::interpolateColorArray(const cvf::Color3ubArray& colorArray, size_t targetColorCount) { @@ -132,7 +149,7 @@ cvf::Color3ubArray ColorTable::interpolateColorArray(const cvf::Color3ubArray& c cvf::Color3ubArray colors; colors.reserve(targetColorCount); - const size_t inputColorsMaxIdx = inputColorCount - 1; + const size_t inputColorsMaxIdx = inputColorCount - 1; const size_t outputColorsMaxIdx = targetColorCount - 1; for (size_t outputLevelIdx = 0; outputLevelIdx < outputColorsMaxIdx; outputLevelIdx++) @@ -148,9 +165,9 @@ cvf::Color3ubArray ColorTable::interpolateColorArray(const cvf::Color3ubArray& c cvf::Color3ub c1 = colorArray[inputLevelIndex]; cvf::Color3ub c2 = colorArray[inputLevelIndex + 1]; - int r = static_cast(c1.r() + t*(c2.r() - c1.r()) + 0.5); - int g = static_cast(c1.g() + t*(c2.g() - c1.g()) + 0.5); - int b = static_cast(c1.b() + t*(c2.b() - c1.b()) + 0.5); + int r = static_cast(c1.r() + t * (c2.r() - c1.r()) + 0.5); + int g = static_cast(c1.g() + t * (c2.g() - c1.g()) + 0.5); + int b = static_cast(c1.b() + t * (c2.b() - c1.b()) + 0.5); r = cvf::Math::clamp(r, 0, 255); g = cvf::Math::clamp(g, 0, 255); @@ -163,7 +180,6 @@ cvf::Color3ubArray ColorTable::interpolateColorArray(const cvf::Color3ubArray& c colors.add(colorArray[colorArray.size() - 1]); return colors; - } } // namespace caf diff --git a/Fwk/AppFwk/CommonCode/cafColorTable.h b/Fwk/AppFwk/CommonCode/cafColorTable.h index d1181711a7..fee3ab1ca7 100644 --- a/Fwk/AppFwk/CommonCode/cafColorTable.h +++ b/Fwk/AppFwk/CommonCode/cafColorTable.h @@ -34,43 +34,44 @@ // //################################################################################################## - #pragma once -#include "cvfBase.h" #include "cvfArray.h" +#include "cvfBase.h" #include - class QColor; - -namespace caf { - +namespace caf +{ //================================================================================================== // -// +// // //================================================================================================== class ColorTable { public: explicit ColorTable(const std::vector& colors); + explicit ColorTable(const cvf::Color3ubArray& colors); - cvf::Color3f cycledColor3f(size_t itemIndex) const; - cvf::Color3ub cycledColor3ub(size_t itemIndex) const; - QColor cycledQColor(size_t itemIndex) const; + cvf::Color3f cycledColor3f(size_t itemIndex) const; + cvf::Color3ub cycledColor3ub(size_t itemIndex) const; + QColor cycledQColor(size_t itemIndex) const; - cvf::Color3ubArray color3ubArray() const; - cvf::Color3fArray color3fArray() const; + cvf::Color3ubArray color3ubArray() const; + cvf::Color3fArray color3fArray() const; - size_t size() const; + size_t size() const; + + ColorTable inverted() const; + + static cvf::Color3ub fromQColor(const QColor& color); + static cvf::Color3ubArray interpolateColorArray(const cvf::Color3ubArray& colorArray, size_t targetColorCount); - static cvf::Color3ub fromQColor(const QColor& color); - static cvf::Color3ubArray interpolateColorArray(const cvf::Color3ubArray& colorArray, size_t targetColorCount); private: const std::vector m_colors; }; -} +} // namespace caf