mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3698 Scale bar. Take 1. Only vertical variant implemented so far
This commit is contained in:
parent
76abf0fe01
commit
d8a466a9ef
@ -121,6 +121,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimContourMapProjection.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimContourMapView.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimContourMapViewCollection.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimContourMapNameConfig.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimScaleLegendConfig.h
|
||||
)
|
||||
|
||||
|
||||
@ -246,6 +247,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimContourMapProjection.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimContourMapView.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimContourMapViewCollection.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimContourMapNameConfig.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimScaleLegendConfig.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "RimFaultInViewCollection.h"
|
||||
#include "RimGridCollection.h"
|
||||
#include "RimSimWellInViewCollection.h"
|
||||
|
||||
#include "RimScaleLegendConfig.h"
|
||||
#include "cafPdmUiTreeOrdering.h"
|
||||
|
||||
#include "cvfCamera.h"
|
||||
@ -54,7 +54,8 @@ RimContourMapView::RimContourMapView()
|
||||
CAF_PDM_InitFieldNoDefault(&m_contourMapProjection, "ContourMapProjection", "Contour Map Projection", "", "", "");
|
||||
m_contourMapProjection = new RimContourMapProjection();
|
||||
|
||||
CAF_PDM_InitField(&m_showAxisLines, "ShowAxisLines", true, "Show Axis Lines", "", "", "");
|
||||
CAF_PDM_InitField(&m_showAxisLines, "ShowAxisLines", true, "Show Axis Lines", "", "", "");
|
||||
CAF_PDM_InitField(&m_showScaleLegend, "ShowScaleLegend", true, "Show Scale Legend", "", "", "");
|
||||
|
||||
m_gridCollection->setActive(false); // This is also not added to the tree view, so cannot be enabled.
|
||||
setFaultVisParameters();
|
||||
@ -63,9 +64,11 @@ RimContourMapView::RimContourMapView()
|
||||
m_nameConfig = new RimContourMapNameConfig(this);
|
||||
|
||||
m_contourMapProjectionPartMgr = new RivContourMapProjectionPartMgr(contourMapProjection(), this);
|
||||
|
||||
|
||||
((RiuViewerToViewInterface*)this)->setCameraPosition(defaultViewMatrix);
|
||||
|
||||
//CAF_PDM_InitFieldNoDefault(&m_scaleLegendConfig, "ScaleLegendConfig", "Scale Legend Config", "", "", "");
|
||||
//m_scaleLegendConfig = new RimScaleLegendConfig();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -168,6 +171,7 @@ void RimContourMapView::defineUiOrdering(QString uiConfigName, caf::PdmUiOrderin
|
||||
viewGroup->add(this->userDescriptionField());
|
||||
viewGroup->add(this->backgroundColorField());
|
||||
viewGroup->add(&m_showAxisLines);
|
||||
viewGroup->add(&m_showScaleLegend);
|
||||
|
||||
caf::PdmUiGroup* nameGroup = uiOrdering.addNewGroup("Contour Map Name");
|
||||
m_nameConfig->uiOrdering(uiConfigName, *nameGroup);
|
||||
@ -278,6 +282,9 @@ void RimContourMapView::updateLegends()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//m_viewer->addColorLegendToBottomLeftCorner(m_scaleLegendConfig->titledOverlayFrame());
|
||||
m_viewer->showScaleLegend(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "RimNameConfig.h"
|
||||
|
||||
class RimContourMapNameConfig;
|
||||
class RimScaleLegendConfig;
|
||||
class RivContourMapProjectionPartMgr;
|
||||
|
||||
class RimContourMapView : public RimEclipseView, public RimNameConfigHolderInterface
|
||||
@ -58,7 +59,8 @@ private:
|
||||
cvf::ref<RivContourMapProjectionPartMgr> m_contourMapProjectionPartMgr;
|
||||
caf::PdmChildField<RimContourMapProjection*> m_contourMapProjection;
|
||||
caf::PdmField<bool> m_showAxisLines;
|
||||
caf::PdmField<bool> m_showScaleLegend;
|
||||
caf::PdmChildField<RimContourMapNameConfig*> m_nameConfig;
|
||||
|
||||
//caf::PdmChildField<RimScaleLegendConfig*> m_scaleLegendConfig;
|
||||
};
|
||||
|
||||
|
683
ApplicationCode/ProjectDataModel/RimScaleLegendConfig.cpp
Normal file
683
ApplicationCode/ProjectDataModel/RimScaleLegendConfig.cpp
Normal file
@ -0,0 +1,683 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RimScaleLegendConfig.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaColorTables.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "RimCellEdgeColors.h"
|
||||
#include "RimEclipseCellColors.h"
|
||||
#include "RimEnsembleCurveSet.h"
|
||||
#include "RimEnsembleCurveSetCollection.h"
|
||||
#include "RimEnsembleCurveSetColorManager.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimGeoMechResultDefinition.h"
|
||||
#include "RimIntersectionCollection.h"
|
||||
#include "RimStimPlanColors.h"
|
||||
#include "RimViewLinker.h"
|
||||
|
||||
#include "cafTitledOverlayFrame.h"
|
||||
#include "cafCategoryLegend.h"
|
||||
#include "cafCategoryMapper.h"
|
||||
#include "cafOverlayScaleLegend.h"
|
||||
|
||||
#include "cafFactory.h"
|
||||
#include "cafPdmFieldCvfColor.h"
|
||||
#include "cafPdmFieldCvfMat4d.h"
|
||||
#include "cafPdmUiComboBoxEditor.h"
|
||||
#include "cafPdmUiLineEditor.h"
|
||||
|
||||
#include "cvfScalarMapperContinuousLinear.h"
|
||||
#include "cvfScalarMapperContinuousLog.h"
|
||||
#include "cvfScalarMapperDiscreteLinear.h"
|
||||
#include "cvfScalarMapperDiscreteLog.h"
|
||||
#include "cvfqtUtils.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
using ColorManager = RimEnsembleCurveSetColorManager;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
CAF_PDM_SOURCE_INIT(RimScaleLegendConfig, "ScaleLegend");
|
||||
|
||||
|
||||
namespace caf {
|
||||
template<>
|
||||
void RimScaleLegendConfig::ColorRangeEnum::setUp()
|
||||
{
|
||||
addItem(RimScaleLegendConfig::NORMAL, "NORMAL", "Full color, Red on top");
|
||||
addItem(RimScaleLegendConfig::OPPOSITE_NORMAL, "OPPOSITE_NORMAL", "Full color, Blue on top");
|
||||
addItem(RimScaleLegendConfig::WHITE_PINK, "WHITE_PIMK", "White to pink");
|
||||
addItem(RimScaleLegendConfig::PINK_WHITE, "PINK_WHITE", "Pink to white");
|
||||
addItem(RimScaleLegendConfig::BLUE_WHITE_RED, "BLUE_WHITE_RED", "Blue, white, red");
|
||||
addItem(RimScaleLegendConfig::RED_WHITE_BLUE, "RED_WHITE_BLUE", "Red, white, blue");
|
||||
addItem(RimScaleLegendConfig::WHITE_BLACK, "WHITE_BLACK", "White to black");
|
||||
addItem(RimScaleLegendConfig::BLACK_WHITE, "BLACK_WHITE", "Black to white");
|
||||
addItem(RimScaleLegendConfig::CATEGORY, "CATEGORY", "Category colors");
|
||||
addItem(RimScaleLegendConfig::ANGULAR, "ANGULAR", "Full color cyclic");
|
||||
addItem(RimScaleLegendConfig::STIMPLAN, "STIMPLAN", "StimPlan colors");
|
||||
addItem(RimScaleLegendConfig::RED_LIGHT_DARK, "RED_DARK_LIGHT", "Red Light to Dark");
|
||||
addItem(RimScaleLegendConfig::GREEN_LIGHT_DARK, "GREEN_DARK_LIGHT", "Green Light to Dark");
|
||||
addItem(RimScaleLegendConfig::BLUE_LIGHT_DARK, "BLUE_DARK_LIGHT", "Blue Light to Dark");
|
||||
addItem(RimScaleLegendConfig::GREEN_RED, "GREEN_RED", "Green to Red");
|
||||
addItem(RimScaleLegendConfig::BLUE_MAGENTA, "BLUE_MAGENTA", "Blue to Magenta");
|
||||
setDefault(RimScaleLegendConfig::NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimScaleLegendConfig::RimScaleLegendConfig()
|
||||
: m_globalAutoMax(cvf::UNDEFINED_DOUBLE),
|
||||
m_globalAutoMin(cvf::UNDEFINED_DOUBLE),
|
||||
m_localAutoMax(cvf::UNDEFINED_DOUBLE),
|
||||
m_localAutoMin(cvf::UNDEFINED_DOUBLE),
|
||||
m_globalAutoPosClosestToZero(0),
|
||||
m_globalAutoNegClosestToZero(0),
|
||||
m_localAutoPosClosestToZero(0),
|
||||
m_localAutoNegClosestToZero(0),
|
||||
m_isAllTimeStepsRangeDisabled(false)
|
||||
{
|
||||
CAF_PDM_InitObject("Legend Definition", ":/Legend.png", "", "");
|
||||
CAF_PDM_InitField(&m_showLegend, "ShowLegend", true, "Show Legend", "", "", "");
|
||||
m_showLegend.uiCapability()->setUiHidden(true);
|
||||
CAF_PDM_InitField(&m_numLevels, "NumberOfLevels", 8, "Number of Levels", "", "A hint on how many tick marks you whish.","");
|
||||
CAF_PDM_InitField(&m_precision, "Precision", 4, "Significant Digits", "", "The number of significant digits displayed in the legend numbers","");
|
||||
|
||||
CAF_PDM_InitField(&m_colorRangeMode, "ColorRangeMode", ColorRangeEnum(NORMAL) , "Colors", "", "", "");
|
||||
CAF_PDM_InitField(&m_rangeMode, "RangeType", RangeModeEnum(AUTOMATIC_ALLTIMESTEPS), "Range Type", "", "Switches between automatic and user defined range on the legend", "");
|
||||
CAF_PDM_InitField(&m_userDefinedMaxValue, "UserDefinedMax", 1.0, "Max", "", "Max value of the legend", "");
|
||||
CAF_PDM_InitField(&m_userDefinedMinValue, "UserDefinedMin", 0.0, "Min", "", "Min value of the legend (if mapping is logarithmic only positive values are valid)", "");
|
||||
CAF_PDM_InitField(&resultVariableName, "ResultVariableUsage", QString(""), "", "", "", "");
|
||||
resultVariableName.uiCapability()->setUiHidden(true);
|
||||
|
||||
cvf::Font* standardFont = RiaApplication::instance()->standardFont();
|
||||
m_scaleLegend = new caf::OverlayScaleLegend(standardFont);
|
||||
|
||||
updateFieldVisibility();
|
||||
updateLegend();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimScaleLegendConfig::~RimScaleLegendConfig()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
|
||||
{
|
||||
if (changedField == &m_numLevels)
|
||||
{
|
||||
int upperLimit = std::numeric_limits<int>::max();
|
||||
m_numLevels = cvf::Math::clamp(m_numLevels.v(), 1, upperLimit);
|
||||
}
|
||||
else if (changedField == &m_rangeMode)
|
||||
{
|
||||
if (m_rangeMode == USER_DEFINED)
|
||||
{
|
||||
if (m_userDefinedMaxValue == m_userDefinedMaxValue.defaultValue() && m_globalAutoMax != cvf::UNDEFINED_DOUBLE)
|
||||
{
|
||||
m_userDefinedMaxValue = roundToNumSignificantDigits(m_globalAutoMax, m_precision);
|
||||
}
|
||||
if (m_userDefinedMinValue == m_userDefinedMinValue.defaultValue() && m_globalAutoMin != cvf::UNDEFINED_DOUBLE)
|
||||
{
|
||||
m_userDefinedMinValue = roundToNumSignificantDigits(m_globalAutoMin, m_precision);
|
||||
}
|
||||
}
|
||||
|
||||
updateFieldVisibility();
|
||||
}
|
||||
|
||||
updateLegend();
|
||||
|
||||
RimGridView* view = nullptr;
|
||||
this->firstAncestorOrThisOfType(view);
|
||||
|
||||
if (view)
|
||||
{
|
||||
RimViewLinker* viewLinker = view->assosiatedViewLinker();
|
||||
if (viewLinker)
|
||||
{
|
||||
viewLinker->updateCellResult();
|
||||
}
|
||||
|
||||
view->updateCurrentTimeStepAndRedraw();
|
||||
|
||||
view->crossSectionCollection()->scheduleCreateDisplayModelAndRedraw2dIntersectionViews();
|
||||
}
|
||||
|
||||
// Update stim plan templates if relevant
|
||||
RimStimPlanColors* stimPlanColors;
|
||||
firstAncestorOrThisOfType(stimPlanColors);
|
||||
if (stimPlanColors)
|
||||
{
|
||||
stimPlanColors->updateStimPlanTemplates();
|
||||
}
|
||||
|
||||
// Update ensemble curve set if relevant
|
||||
RimEnsembleCurveSet* ensembleCurveSet;
|
||||
firstAncestorOrThisOfType(ensembleCurveSet);
|
||||
if (ensembleCurveSet)
|
||||
{
|
||||
ensembleCurveSet->onLegendDefinitionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::updateLegend()
|
||||
{
|
||||
//
|
||||
|
||||
double adjustedMin = cvf::UNDEFINED_DOUBLE;
|
||||
double adjustedMax = cvf::UNDEFINED_DOUBLE;
|
||||
|
||||
double posClosestToZero = cvf::UNDEFINED_DOUBLE;
|
||||
double negClosestToZero = cvf::UNDEFINED_DOUBLE;
|
||||
|
||||
if (m_rangeMode == AUTOMATIC_ALLTIMESTEPS)
|
||||
{
|
||||
adjustedMin = roundToNumSignificantDigits(m_globalAutoMin, m_precision);
|
||||
adjustedMax = roundToNumSignificantDigits(m_globalAutoMax, m_precision);
|
||||
|
||||
posClosestToZero = m_globalAutoPosClosestToZero;
|
||||
negClosestToZero = m_globalAutoNegClosestToZero;
|
||||
}
|
||||
else if (m_rangeMode == AUTOMATIC_CURRENT_TIMESTEP)
|
||||
{
|
||||
adjustedMin = roundToNumSignificantDigits(m_localAutoMin, m_precision);
|
||||
adjustedMax = roundToNumSignificantDigits(m_localAutoMax, m_precision);
|
||||
|
||||
posClosestToZero = m_localAutoPosClosestToZero;
|
||||
negClosestToZero = m_localAutoNegClosestToZero;
|
||||
}
|
||||
else
|
||||
{
|
||||
adjustedMin = roundToNumSignificantDigits(m_userDefinedMinValue, m_precision);
|
||||
adjustedMax = roundToNumSignificantDigits(m_userDefinedMaxValue, m_precision);
|
||||
|
||||
posClosestToZero = m_globalAutoPosClosestToZero;
|
||||
negClosestToZero = m_globalAutoNegClosestToZero;
|
||||
}
|
||||
|
||||
cvf::Color3ubArray legendColors = colorArrayFromColorType(m_colorRangeMode());
|
||||
|
||||
double decadesInRange = 0;
|
||||
|
||||
{
|
||||
// For linear mapping, use the max value as reference for num valid digits
|
||||
double absRange = CVF_MAX(cvf::Math::abs(adjustedMax), cvf::Math::abs(adjustedMin));
|
||||
decadesInRange = log10(absRange);
|
||||
}
|
||||
|
||||
decadesInRange = cvf::Math::ceil(decadesInRange);
|
||||
|
||||
// Using Fixed format
|
||||
//caf::OverlayScaleLegend::NumberFormat nft = m_tickNumberFormat();
|
||||
//m_scaleLegend->setTickFormat((caf::OverlayScaleLegend::NumberFormat)nft);
|
||||
|
||||
// Set the fixed number of digits after the decimal point to the number needed to show all the significant digits.
|
||||
int numDecimalDigits = m_precision();
|
||||
m_scaleLegend->setTickPrecision(cvf::Math::clamp(numDecimalDigits, 0, 20));
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
RiaPreferences* preferences = app->preferences();
|
||||
m_scaleLegend->enableBackground(preferences->showLegendBackground());
|
||||
|
||||
if (m_globalAutoMax != cvf::UNDEFINED_DOUBLE )
|
||||
{
|
||||
m_userDefinedMaxValue.uiCapability()->setUiName(QString("Max ") + "(" + QString::number(m_globalAutoMax, 'g', m_precision) + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_userDefinedMaxValue.uiCapability()->setUiName(QString());
|
||||
}
|
||||
|
||||
if (m_globalAutoMin != cvf::UNDEFINED_DOUBLE )
|
||||
{
|
||||
m_userDefinedMinValue.uiCapability()->setUiName(QString("Min ") + "(" + QString::number(m_globalAutoMin, 'g', m_precision) + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_userDefinedMinValue.uiCapability()->setUiName(QString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::disableAllTimeStepsRange(bool doDisable)
|
||||
{
|
||||
// If we enable AllTimesteps, and we have used current timestep, then "restore" the default
|
||||
if (m_isAllTimeStepsRangeDisabled && !doDisable && m_rangeMode == AUTOMATIC_CURRENT_TIMESTEP) m_rangeMode = AUTOMATIC_ALLTIMESTEPS;
|
||||
|
||||
m_isAllTimeStepsRangeDisabled = doDisable;
|
||||
|
||||
if (doDisable && m_rangeMode == AUTOMATIC_ALLTIMESTEPS) m_rangeMode = AUTOMATIC_CURRENT_TIMESTEP;
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::setAutomaticRanges(double globalMin, double globalMax, double localMin, double localMax)
|
||||
{
|
||||
double candidateGlobalAutoMin = roundToNumSignificantDigits(globalMin, m_precision);
|
||||
double candidateGlobalAutoMax = roundToNumSignificantDigits(globalMax, m_precision);
|
||||
|
||||
double candidateLocalAutoMin = roundToNumSignificantDigits(localMin, m_precision);
|
||||
double candidateLocalAutoMax = roundToNumSignificantDigits(localMax, m_precision);
|
||||
|
||||
m_globalAutoMin = candidateGlobalAutoMin;
|
||||
m_globalAutoMax = candidateGlobalAutoMax;
|
||||
|
||||
m_localAutoMin = candidateLocalAutoMin;
|
||||
m_localAutoMax = candidateLocalAutoMax;
|
||||
|
||||
updateLegend();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::initAfterRead()
|
||||
{
|
||||
updateFieldVisibility();
|
||||
}
|
||||
|
||||
caf::PdmFieldHandle* RimScaleLegendConfig::objectToggleField()
|
||||
{
|
||||
return &m_showLegend;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::updateFieldVisibility()
|
||||
{
|
||||
bool showRangeItems = true;
|
||||
|
||||
m_numLevels.uiCapability()->setUiHidden(!showRangeItems);
|
||||
m_precision.uiCapability()->setUiHidden(!showRangeItems);
|
||||
m_rangeMode.uiCapability()->setUiHidden(!showRangeItems);
|
||||
|
||||
if (showRangeItems && m_rangeMode == USER_DEFINED)
|
||||
{
|
||||
m_userDefinedMaxValue.uiCapability()->setUiHidden(false);
|
||||
m_userDefinedMinValue.uiCapability()->setUiHidden(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_userDefinedMaxValue.uiCapability()->setUiHidden(true);
|
||||
m_userDefinedMinValue.uiCapability()->setUiHidden(true);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::setColorRange(ColorRangesType colorMode)
|
||||
{
|
||||
m_colorRangeMode = colorMode;
|
||||
updateLegend();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::recreateLegend()
|
||||
{
|
||||
// Due to possible visualization bug, we need to recreate the legend if the last viewer
|
||||
// has been removed, (and thus the opengl resources has been deleted) The text in
|
||||
// the legend disappeared because of this, so workaround: recreate the legend when needed:
|
||||
|
||||
cvf::Font* standardFont = RiaApplication::instance()->standardFont();
|
||||
m_scaleLegend = new caf::OverlayScaleLegend(standardFont);
|
||||
|
||||
updateLegend();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Rounding the double value to given number of significant digits
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RimScaleLegendConfig::roundToNumSignificantDigits(double domainValue, double numSignificantDigits)
|
||||
{
|
||||
double absDomainValue = cvf::Math::abs(domainValue);
|
||||
if (absDomainValue == 0.0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double logDecValue = log10(absDomainValue);
|
||||
logDecValue = cvf::Math::ceil(logDecValue);
|
||||
|
||||
double factor = pow(10.0, numSignificantDigits - logDecValue);
|
||||
|
||||
double tmp = domainValue * factor;
|
||||
double integerPart;
|
||||
double fraction = modf(tmp, &integerPart);
|
||||
|
||||
if (cvf::Math::abs(fraction)>= 0.5) (integerPart >= 0) ? integerPart++: integerPart-- ;
|
||||
|
||||
double newDomainValue = integerPart / factor;
|
||||
|
||||
return newDomainValue;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::setClosestToZeroValues(double globalPosClosestToZero, double globalNegClosestToZero, double localPosClosestToZero, double localNegClosestToZero)
|
||||
{
|
||||
bool needsUpdate = false;
|
||||
const double epsilon = std::numeric_limits<double>::epsilon();
|
||||
|
||||
if (cvf::Math::abs(globalPosClosestToZero - m_globalAutoPosClosestToZero) > epsilon)
|
||||
{
|
||||
needsUpdate = true;
|
||||
}
|
||||
if (cvf::Math::abs(globalNegClosestToZero - m_globalAutoNegClosestToZero) > epsilon)
|
||||
{
|
||||
needsUpdate = true;
|
||||
}
|
||||
if (cvf::Math::abs(localPosClosestToZero - m_localAutoPosClosestToZero) > epsilon)
|
||||
{
|
||||
needsUpdate = true;
|
||||
}
|
||||
if (cvf::Math::abs(localNegClosestToZero - m_localAutoNegClosestToZero) > epsilon)
|
||||
{
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
if (needsUpdate)
|
||||
{
|
||||
m_globalAutoPosClosestToZero = globalPosClosestToZero;
|
||||
m_globalAutoNegClosestToZero = globalNegClosestToZero;
|
||||
m_localAutoPosClosestToZero = localPosClosestToZero;
|
||||
m_localAutoNegClosestToZero = localNegClosestToZero;
|
||||
|
||||
if (m_globalAutoPosClosestToZero == HUGE_VAL) m_globalAutoPosClosestToZero = 0;
|
||||
if (m_globalAutoNegClosestToZero == -HUGE_VAL) m_globalAutoNegClosestToZero = 0;
|
||||
if (m_localAutoPosClosestToZero == HUGE_VAL) m_localAutoPosClosestToZero = 0;
|
||||
if (m_localAutoNegClosestToZero == -HUGE_VAL) m_localAutoNegClosestToZero = 0;
|
||||
|
||||
updateLegend();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::setTitle(const QString& title)
|
||||
{
|
||||
auto cvfTitle = cvfqt::Utils::toString(title);
|
||||
m_scaleLegend->setTitle(cvfTitle);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimScaleLegendConfig::showLegend() const
|
||||
{
|
||||
return m_showLegend;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::setShowLegend(bool show)
|
||||
{
|
||||
m_showLegend = show;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::TitledOverlayFrame* RimScaleLegendConfig::titledOverlayFrame()
|
||||
{
|
||||
return m_scaleLegend.p();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const caf::TitledOverlayFrame* RimScaleLegendConfig::titledOverlayFrame() const
|
||||
{
|
||||
return m_scaleLegend.p();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::OverlayItem* RimScaleLegendConfig::overlayItem()
|
||||
{
|
||||
return m_scaleLegend.p();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const cvf::OverlayItem* RimScaleLegendConfig::overlayItem() const
|
||||
{
|
||||
return m_scaleLegend.p();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimLegendConfig::RangeModeType RimScaleLegendConfig::rangeMode() const
|
||||
{
|
||||
return m_rangeMode();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::setCurrentScale(double scale)
|
||||
{
|
||||
m_currentScale = scale;
|
||||
|
||||
// Update legend
|
||||
updateLegend();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::setUiValuesFromLegendConfig(const RimScaleLegendConfig* otherLegendConfig)
|
||||
{
|
||||
QString serializedObjectString = otherLegendConfig->writeObjectToXmlString();
|
||||
this->readObjectFromXmlString(serializedObjectString, caf::PdmDefaultObjectFactory::instance());
|
||||
this->updateLegend();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Color3ubArray RimScaleLegendConfig::colorArrayFromColorType(ColorRangesType colorType)
|
||||
{
|
||||
switch (colorType)
|
||||
{
|
||||
case RimScaleLegendConfig::NORMAL:
|
||||
return RiaColorTables::normalPaletteColors().color3ubArray();
|
||||
break;
|
||||
case RimScaleLegendConfig::OPPOSITE_NORMAL:
|
||||
return RiaColorTables::normalPaletteOppositeOrderingColors().color3ubArray();
|
||||
break;
|
||||
case RimScaleLegendConfig::WHITE_PINK:
|
||||
return RiaColorTables::whitePinkPaletteColors().color3ubArray();
|
||||
break;
|
||||
case RimScaleLegendConfig::PINK_WHITE:
|
||||
return RiaColorTables::pinkWhitePaletteColors().color3ubArray();
|
||||
break;
|
||||
case RimScaleLegendConfig::WHITE_BLACK:
|
||||
return RiaColorTables::whiteBlackPaletteColors().color3ubArray();
|
||||
break;
|
||||
case RimScaleLegendConfig::BLACK_WHITE:
|
||||
return RiaColorTables::blackWhitePaletteColors().color3ubArray();
|
||||
break;
|
||||
case RimScaleLegendConfig::BLUE_WHITE_RED:
|
||||
return RiaColorTables::blueWhiteRedPaletteColors().color3ubArray();
|
||||
break;
|
||||
case RimScaleLegendConfig::RED_WHITE_BLUE:
|
||||
return RiaColorTables::redWhiteBluePaletteColors().color3ubArray();
|
||||
break;
|
||||
case RimScaleLegendConfig::CATEGORY:
|
||||
return RiaColorTables::categoryPaletteColors().color3ubArray();
|
||||
break;
|
||||
case RimScaleLegendConfig::ANGULAR:
|
||||
return RiaColorTables::angularPaletteColors().color3ubArray();
|
||||
break;
|
||||
case RimScaleLegendConfig::STIMPLAN:
|
||||
return RiaColorTables::stimPlanPaletteColors().color3ubArray();
|
||||
break;
|
||||
default:
|
||||
//if (ColorManager::isEnsembleColorRange(colorType)) return ColorManager::EnsembleColorRanges().at(colorType);
|
||||
break;
|
||||
}
|
||||
|
||||
return RiaColorTables::normalPaletteColors().color3ubArray();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimScaleLegendConfig::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
|
||||
{
|
||||
{
|
||||
caf::PdmUiOrdering * formatGr = uiOrdering.addNewGroup("Format");
|
||||
formatGr->add(&m_numLevels);
|
||||
formatGr->add(&m_precision);
|
||||
formatGr->add(&m_colorRangeMode);
|
||||
|
||||
caf::PdmUiOrdering * mappingGr = uiOrdering.addNewGroup("Mapping");
|
||||
mappingGr->add(&m_rangeMode);
|
||||
mappingGr->add(&m_userDefinedMaxValue);
|
||||
mappingGr->add(&m_userDefinedMinValue);
|
||||
}
|
||||
|
||||
updateFieldVisibility();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QList<caf::PdmOptionItemInfo> RimScaleLegendConfig::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly)
|
||||
{
|
||||
bool hasStimPlanParent = false;
|
||||
bool hasEnsembleCurveSetParent = false;
|
||||
|
||||
RimStimPlanColors* stimPlanColors = nullptr;
|
||||
this->firstAncestorOrThisOfType(stimPlanColors);
|
||||
if (stimPlanColors) hasStimPlanParent = true;
|
||||
|
||||
RimEnsembleCurveSet* ensembleCurveSet = nullptr;
|
||||
this->firstAncestorOrThisOfType(ensembleCurveSet);
|
||||
if (ensembleCurveSet) hasEnsembleCurveSetParent = true;
|
||||
|
||||
bool isCategoryResult = false;
|
||||
{
|
||||
RimEclipseCellColors* eclCellColors = nullptr;
|
||||
this->firstAncestorOrThisOfType(eclCellColors);
|
||||
RimGeoMechResultDefinition* gmCellColors = nullptr;
|
||||
this->firstAncestorOrThisOfType(gmCellColors);
|
||||
RimCellEdgeColors* eclCellEdgColors = nullptr;
|
||||
this->firstAncestorOrThisOfType(eclCellEdgColors);
|
||||
|
||||
if ( ( eclCellColors && eclCellColors->hasCategoryResult())
|
||||
|| ( gmCellColors && gmCellColors->hasCategoryResult())
|
||||
|| ( eclCellEdgColors && eclCellEdgColors->hasCategoryResult())
|
||||
|| ( ensembleCurveSet && ensembleCurveSet->currentEnsembleParameterType() == EnsembleParameter::TYPE_TEXT) )
|
||||
{
|
||||
isCategoryResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
QList<caf::PdmOptionItemInfo> options;
|
||||
|
||||
if (fieldNeedingOptions == &m_colorRangeMode)
|
||||
{
|
||||
// This is an app enum field, see cafInternalPdmFieldTypeSpecializations.h for the default specialization of this type
|
||||
std::vector<ColorRangesType> rangeTypes;
|
||||
if (!hasEnsembleCurveSetParent)
|
||||
{
|
||||
rangeTypes.push_back(NORMAL);
|
||||
rangeTypes.push_back(OPPOSITE_NORMAL);
|
||||
rangeTypes.push_back(WHITE_PINK);
|
||||
rangeTypes.push_back(PINK_WHITE);
|
||||
rangeTypes.push_back(BLUE_WHITE_RED);
|
||||
rangeTypes.push_back(RED_WHITE_BLUE);
|
||||
rangeTypes.push_back(WHITE_BLACK);
|
||||
rangeTypes.push_back(BLACK_WHITE);
|
||||
rangeTypes.push_back(ANGULAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
//for (const auto& col : ColorManager::EnsembleColorRanges())
|
||||
//{
|
||||
// rangeTypes.push_back(col.first);
|
||||
//}
|
||||
}
|
||||
|
||||
if (hasStimPlanParent) rangeTypes.push_back(STIMPLAN);
|
||||
|
||||
if (isCategoryResult)
|
||||
{
|
||||
rangeTypes.push_back(CATEGORY);
|
||||
}
|
||||
|
||||
for(ColorRangesType colType: rangeTypes)
|
||||
{
|
||||
options.push_back(caf::PdmOptionItemInfo(ColorRangeEnum::uiText(colType), colType));
|
||||
}
|
||||
}
|
||||
else if (fieldNeedingOptions == &m_rangeMode)
|
||||
{
|
||||
if (!m_isAllTimeStepsRangeDisabled)
|
||||
{
|
||||
QString uiText;
|
||||
if(!hasEnsembleCurveSetParent) uiText = RangeModeEnum::uiText(RimScaleLegendConfig::AUTOMATIC_ALLTIMESTEPS);
|
||||
else uiText = "Auto Range";
|
||||
|
||||
options.push_back(caf::PdmOptionItemInfo(uiText, RimScaleLegendConfig::AUTOMATIC_ALLTIMESTEPS));
|
||||
}
|
||||
if (!hasStimPlanParent && !hasEnsembleCurveSetParent)
|
||||
{
|
||||
options.push_back(caf::PdmOptionItemInfo(RangeModeEnum::uiText(RimScaleLegendConfig::AUTOMATIC_CURRENT_TIMESTEP), RimScaleLegendConfig::AUTOMATIC_CURRENT_TIMESTEP));
|
||||
}
|
||||
options.push_back(caf::PdmOptionItemInfo(RangeModeEnum::uiText(RimScaleLegendConfig::USER_DEFINED), RimScaleLegendConfig::USER_DEFINED));
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
156
ApplicationCode/ProjectDataModel/RimScaleLegendConfig.h
Normal file
156
ApplicationCode/ProjectDataModel/RimScaleLegendConfig.h
Normal file
@ -0,0 +1,156 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RimLegendConfig.h"
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cvfArray.h"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
class ScalarMapperContinuousLog;
|
||||
class ScalarMapperContinuousLinear;
|
||||
class OverlayItem;
|
||||
class ScalarMapperDiscreteLinear;
|
||||
class ScalarMapperDiscreteLog;
|
||||
class ScalarMapper;
|
||||
class String;
|
||||
}
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class TitledOverlayFrame;
|
||||
class CategoryLegend;
|
||||
class CategoryMapper;
|
||||
class OverlayScaleLegend;
|
||||
}
|
||||
|
||||
class Rim3dView;
|
||||
class RimEnsembleCurveSet;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimScaleLegendConfig : public RimLegendConfig
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
public:
|
||||
RimScaleLegendConfig();
|
||||
~RimScaleLegendConfig() override;
|
||||
|
||||
caf::PdmField<QString> resultVariableName; // Used internally to describe the variable this legend setup is used for
|
||||
|
||||
enum ColorRangesType
|
||||
{
|
||||
NORMAL,
|
||||
OPPOSITE_NORMAL,
|
||||
WHITE_PINK,
|
||||
PINK_WHITE,
|
||||
WHITE_BLACK,
|
||||
BLACK_WHITE,
|
||||
BLUE_WHITE_RED,
|
||||
RED_WHITE_BLUE,
|
||||
CATEGORY,
|
||||
ANGULAR,
|
||||
STIMPLAN,
|
||||
|
||||
GREEN_RED,
|
||||
BLUE_MAGENTA,
|
||||
RED_LIGHT_DARK,
|
||||
GREEN_LIGHT_DARK,
|
||||
BLUE_LIGHT_DARK
|
||||
};
|
||||
|
||||
typedef caf::AppEnum<ColorRangesType> ColorRangeEnum;
|
||||
|
||||
void recreateLegend();
|
||||
|
||||
void setColorRange(ColorRangesType colorMode);
|
||||
ColorRangesType colorRange() { return m_colorRangeMode();}
|
||||
void disableAllTimeStepsRange(bool doDisable);
|
||||
|
||||
void setAutomaticRanges(double globalMin, double globalMax, double localMin, double localMax);
|
||||
void setClosestToZeroValues(double globalPosClosestToZero, double globalNegClosestToZero, double localPosClosestToZero, double localNegClosestToZero);
|
||||
|
||||
void setTitle(const QString& title);
|
||||
|
||||
void setUiValuesFromLegendConfig(const RimScaleLegendConfig* otherLegendConfig);
|
||||
|
||||
bool showLegend() const;
|
||||
void setShowLegend(bool show);
|
||||
|
||||
const caf::TitledOverlayFrame* titledOverlayFrame() const override;
|
||||
caf::TitledOverlayFrame* titledOverlayFrame() override;
|
||||
|
||||
const cvf::OverlayItem* overlayItem() const;
|
||||
cvf::OverlayItem* overlayItem();
|
||||
|
||||
RangeModeType rangeMode() const;
|
||||
|
||||
void setCurrentScale(double scale);
|
||||
|
||||
private:
|
||||
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
||||
void initAfterRead() override;
|
||||
caf::PdmFieldHandle* objectToggleField() override;
|
||||
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) override;
|
||||
|
||||
void updateLegend();
|
||||
void updateFieldVisibility();
|
||||
double roundToNumSignificantDigits(double value, double precision);
|
||||
|
||||
friend class RimViewLinker;
|
||||
|
||||
static cvf::Color3ubArray colorArrayFromColorType(ColorRangesType colorType);
|
||||
|
||||
private:
|
||||
cvf::ref<caf::OverlayScaleLegend> m_scaleLegend;
|
||||
|
||||
double m_globalAutoMax;
|
||||
double m_globalAutoMin;
|
||||
double m_localAutoMax;
|
||||
double m_localAutoMin;
|
||||
|
||||
double m_globalAutoPosClosestToZero;
|
||||
double m_globalAutoNegClosestToZero;
|
||||
double m_localAutoPosClosestToZero;
|
||||
double m_localAutoNegClosestToZero;
|
||||
|
||||
bool m_isAllTimeStepsRangeDisabled;
|
||||
|
||||
// Fields
|
||||
caf::PdmField<bool> m_showLegend;
|
||||
caf::PdmField<int> m_numLevels;
|
||||
caf::PdmField<int> m_precision;
|
||||
caf::PdmField<RangeModeEnum> m_rangeMode;
|
||||
caf::PdmField<double> m_userDefinedMaxValue;
|
||||
caf::PdmField<double> m_userDefinedMinValue;
|
||||
caf::PdmField<caf::AppEnum<ColorRangesType> > m_colorRangeMode;
|
||||
|
||||
double m_currentScale; // [meters/pixel]
|
||||
};
|
@ -48,6 +48,7 @@
|
||||
#include "cafDisplayCoordTransform.h"
|
||||
#include "cafEffectGenerator.h"
|
||||
#include "cafFrameAnimationControl.h"
|
||||
#include "cafOverlayScaleLegend.h"
|
||||
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfFont.h"
|
||||
@ -188,6 +189,8 @@ RiuViewer::RiuViewer(const QGLFormat& format, QWidget* parent)
|
||||
m_showWindowEdgeAxes = false;
|
||||
|
||||
m_selectionVisualizerManager = new caf::PdmUiSelectionVisualizer3d(this);
|
||||
|
||||
m_scaleLegend = new caf::OverlayScaleLegend(standardFont);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -745,6 +748,10 @@ void RiuViewer::optimizeClippingPlanes()
|
||||
}
|
||||
|
||||
m_gridBoxGenerator->updateFromCamera(mainCamera());
|
||||
|
||||
m_scaleLegend->setDisplayCoordTransform(m_rimView->displayCoordTransform().p());
|
||||
m_scaleLegend->updateFromCamera(mainCamera());
|
||||
|
||||
caf::Viewer::optimizeClippingPlanes();
|
||||
}
|
||||
|
||||
@ -950,6 +957,21 @@ std::vector<cvf::ref<cvf::Part>> RiuViewer::visibleParts()
|
||||
return partsMatchingEnableMask;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuViewer::showScaleLegend(bool show)
|
||||
{
|
||||
if (show)
|
||||
{
|
||||
addColorLegendToBottomLeftCorner(m_scaleLegend.p());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mainRendering->removeOverlayItem(m_scaleLegend.p());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -44,6 +44,7 @@ class QProgressBar;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class OverlayScaleLegend;
|
||||
class TitledOverlayFrame;
|
||||
class PdmUiSelectionVisualizer3d;
|
||||
}
|
||||
@ -118,6 +119,8 @@ public:
|
||||
|
||||
std::vector<cvf::ref<cvf::Part>> visibleParts();
|
||||
|
||||
void showScaleLegend(bool show);
|
||||
|
||||
public slots:
|
||||
void slotSetCurrentFrame(int frameIndex) override;
|
||||
void slotEndAnimation() override;
|
||||
@ -173,5 +176,7 @@ private:
|
||||
|
||||
cvf::Vec3d m_cursorPositionDomainCoords;
|
||||
bool m_isNavigationRotationEnabled;
|
||||
|
||||
cvf::ref<caf::OverlayScaleLegend> m_scaleLegend;
|
||||
};
|
||||
|
||||
|
@ -18,6 +18,8 @@ add_library( ${PROJECT_NAME}
|
||||
cafCategoryLegend.h
|
||||
cafOverlayScalarMapperLegend.h
|
||||
cafOverlayScalarMapperLegend.cpp
|
||||
cafOverlayScaleLegend.h
|
||||
cafOverlayScaleLegend.cpp
|
||||
cafInternalLegendRenderTools.h
|
||||
cafInternalLegendRenderTools.cpp
|
||||
cafCategoryMapper.cpp
|
||||
|
683
Fwk/AppFwk/cafVizExtensions/cafOverlayScaleLegend.cpp
Normal file
683
Fwk/AppFwk/cafVizExtensions/cafOverlayScaleLegend.cpp
Normal file
@ -0,0 +1,683 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2018- Ceetron Solutions AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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.
|
||||
//
|
||||
// This library 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 <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cafOverlayScaleLegend.h"
|
||||
#include "cvfOpenGL.h"
|
||||
#include "cvfOpenGLResourceManager.h"
|
||||
#include "cvfGeometryBuilderDrawableGeo.h"
|
||||
#include "cvfGeometryUtils.h"
|
||||
#include "cvfViewport.h"
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfTextDrawer.h"
|
||||
#include "cvfFont.h"
|
||||
#include "cvfShaderProgram.h"
|
||||
#include "cvfShaderProgramGenerator.h"
|
||||
#include "cvfShaderSourceProvider.h"
|
||||
#include "cvfShaderSourceRepository.h"
|
||||
#include "cvfUniform.h"
|
||||
#include "cvfMatrixState.h"
|
||||
#include "cvfBufferObjectManaged.h"
|
||||
#include "cvfGlyph.h"
|
||||
#include "cvfRenderStateDepth.h"
|
||||
#include "cvfRenderStateLine.h"
|
||||
|
||||
#include "cafInternalLegendRenderTools.h"
|
||||
#include "cafTickMarkGenerator.h"
|
||||
|
||||
#ifndef CVF_OPENGL_ES
|
||||
#include "cvfRenderState_FF.h"
|
||||
#endif
|
||||
|
||||
#include "cvfScalarMapper.h"
|
||||
#include <array>
|
||||
#include "cvfRenderStateBlending.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace caf {
|
||||
|
||||
using namespace cvf;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
/// \class cvf::OverlayColorLegend
|
||||
/// \ingroup Render
|
||||
///
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Constructor
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
OverlayScaleLegend::OverlayScaleLegend(Font* font)
|
||||
: TitledOverlayFrame(font, 200, 200)
|
||||
, m_tickNumberPrecision(4)
|
||||
, m_numberFormat(AUTO)
|
||||
, m_Layout(Vec2ui(200u, 200u))
|
||||
, m_font(font)
|
||||
{
|
||||
CVF_ASSERT(font);
|
||||
CVF_ASSERT(!font->isEmpty());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
OverlayScaleLegend::~OverlayScaleLegend()
|
||||
{
|
||||
// Empty destructor to avoid errors with undefined types when cvf::ref's destructor gets called
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Hardware rendering using shader programs
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScaleLegend::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
renderGeneric(oglContext, position, size, false);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Software rendering using software
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScaleLegend::renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
renderGeneric(oglContext, position, size, true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set up camera/viewport and render
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScaleLegend::renderGeneric(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software)
|
||||
{
|
||||
if (size.x() <= 0 || size.y() <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Camera camera;
|
||||
camera.setViewport(position.x(), position.y(), size.x(), size.y());
|
||||
camera.setProjectionAsPixelExact2D();
|
||||
camera.setViewMatrix(Mat4d::IDENTITY);
|
||||
camera.applyOpenGL();
|
||||
camera.viewport()->applyOpenGL(oglContext, Viewport::CLEAR_DEPTH);
|
||||
|
||||
m_Layout = LayoutInfo(size);
|
||||
layoutInfo(&m_Layout);
|
||||
m_textDrawer = new TextDrawer(this->font());
|
||||
|
||||
// Set up text drawer
|
||||
float maxLegendRightPos = 0;
|
||||
setupTextDrawer(m_textDrawer.p(), &m_Layout );
|
||||
|
||||
Vec2f backgroundSize(size);
|
||||
|
||||
// Do the actual rendering
|
||||
if (software)
|
||||
{
|
||||
if ( this->backgroundEnabled() )
|
||||
{
|
||||
InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext,
|
||||
backgroundSize,
|
||||
this->backgroundColor(),
|
||||
this->backgroundFrameColor());
|
||||
}
|
||||
renderLegendImmediateMode(oglContext, &m_Layout);
|
||||
m_textDrawer->renderSoftware(oglContext, camera);
|
||||
}
|
||||
else
|
||||
{
|
||||
const MatrixState matrixState(camera);
|
||||
if ( this->backgroundEnabled() )
|
||||
{
|
||||
InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext,
|
||||
matrixState,
|
||||
backgroundSize,
|
||||
this->backgroundColor(),
|
||||
this->backgroundFrameColor());
|
||||
}
|
||||
renderLegendUsingShaders(oglContext, &m_Layout, matrixState);
|
||||
m_textDrawer->render(oglContext, camera);
|
||||
}
|
||||
|
||||
CVF_CHECK_OGL(oglContext);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScaleLegend::setupTextDrawer(TextDrawer* textDrawer, const LayoutInfo* layout)
|
||||
{
|
||||
CVF_ASSERT(layout);
|
||||
|
||||
textDrawer->setVerticalAlignment(TextDrawer::CENTER);
|
||||
textDrawer->setTextColor(this->textColor());
|
||||
|
||||
m_visibleTickLabels.clear();
|
||||
|
||||
const float textX = layout->startPt.x() + layout->majorTickSize / 2.0f /* tickEndX*/ + layout->tickTextLeadSpace;
|
||||
|
||||
const float overlapTolerance = 1.2f * layout->charHeight;
|
||||
float lastVisibleTextY = 0.0;
|
||||
|
||||
size_t numTicks = layout->ticks.size();
|
||||
size_t it;
|
||||
for (it = 0; it < numTicks; it++)
|
||||
{
|
||||
if(!layout->ticks[it].isMajor) continue;
|
||||
|
||||
float textY = static_cast<float>(layout->startPt.y() + layout->ticks[it].displayValue);
|
||||
|
||||
// Always draw first and last tick label. For all others, skip drawing if text ends up
|
||||
// on top of the previous label.
|
||||
if (it != 0 && it != (numTicks - 1))
|
||||
{
|
||||
if (cvf::Math::abs(textY - lastVisibleTextY) < overlapTolerance)
|
||||
{
|
||||
m_visibleTickLabels.push_back(false);
|
||||
continue;
|
||||
}
|
||||
// Make sure it does not overlap the last tick as well
|
||||
|
||||
float lastTickY = static_cast<float>(layout->startPt.y() + layout->axisLength);
|
||||
|
||||
if (cvf::Math::abs(textY - lastTickY) < overlapTolerance)
|
||||
{
|
||||
m_visibleTickLabels.push_back(false);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
double tickValue = layout->ticks[it].domainValue;
|
||||
String valueString;
|
||||
switch (m_numberFormat)
|
||||
{
|
||||
case FIXED:
|
||||
valueString = String::number(tickValue, 'f', m_tickNumberPrecision);
|
||||
break;
|
||||
case SCIENTIFIC:
|
||||
valueString = String::number(tickValue, 'e', m_tickNumberPrecision);
|
||||
break;
|
||||
default:
|
||||
valueString = String::number(tickValue);
|
||||
break;
|
||||
}
|
||||
|
||||
Vec2f pos(textX, textY);
|
||||
textDrawer->addText(valueString, pos);
|
||||
|
||||
lastVisibleTextY = textY;
|
||||
m_visibleTickLabels.push_back(true);
|
||||
}
|
||||
|
||||
float titleY = static_cast<float>(layout->overallLegendSize.y()) - layout->margins.y() - layout->charHeight/2.0f;
|
||||
for (it = 0; it < this->titleStrings().size(); it++)
|
||||
{
|
||||
Vec2f pos(layout->margins.x(), titleY);
|
||||
textDrawer->addText(this->titleStrings()[it], pos);
|
||||
|
||||
titleY -= layout->lineSpacing;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Draw the legend using shader programs
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScaleLegend::renderLegendUsingShaders(OpenGLContext* oglContext, LayoutInfo* layout, const MatrixState& matrixState)
|
||||
{
|
||||
CVF_CALLSITE_OPENGL(oglContext);
|
||||
|
||||
CVF_TIGHT_ASSERT(layout);
|
||||
CVF_TIGHT_ASSERT(layout->overallLegendSize.x() > 0);
|
||||
CVF_TIGHT_ASSERT(layout->overallLegendSize.y() > 0);
|
||||
|
||||
RenderStateDepth depth(false);
|
||||
depth.applyOpenGL(oglContext);
|
||||
RenderStateLine line(static_cast<float>(this->lineWidth()));
|
||||
line.applyOpenGL(oglContext);
|
||||
|
||||
// All vertices. Initialized here to set Z to zero once and for all.
|
||||
static float vertexArray[] =
|
||||
{
|
||||
0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f
|
||||
};
|
||||
|
||||
// Per vector convenience pointers
|
||||
float* v0 = &vertexArray[0];
|
||||
float* v1 = &vertexArray[3];
|
||||
float* v2 = &vertexArray[6];
|
||||
float* v3 = &vertexArray[9];
|
||||
float* v4 = &vertexArray[12];
|
||||
|
||||
// Connects
|
||||
static const ushort trianglesConnects[] = { 0, 1, 4, 0, 4, 3 };
|
||||
|
||||
ref<ShaderProgram> shaderProgram = oglContext->resourceManager()->getLinkedUnlitColorShaderProgram(oglContext);
|
||||
CVF_TIGHT_ASSERT(shaderProgram.notNull());
|
||||
|
||||
if (shaderProgram->useProgram(oglContext))
|
||||
{
|
||||
shaderProgram->clearUniformApplyTracking();
|
||||
shaderProgram->applyFixedUniforms(oglContext, matrixState);
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glEnableVertexAttribArray(ShaderProgram::VERTEX);
|
||||
glVertexAttribPointer(ShaderProgram::VERTEX, 3, GL_FLOAT, GL_FALSE, 0, vertexArray);
|
||||
|
||||
// Draw axis
|
||||
{
|
||||
v0[0] = layout->startPt.x();
|
||||
v0[1] = layout->startPt.y();
|
||||
v1[0] = v0[0];
|
||||
v1[1] = v0[1] + layout->axisLength;
|
||||
|
||||
static const ushort axisConnects[] = { 0, 1 };
|
||||
|
||||
UniformFloat uniformColor("u_color", Color4f(this->lineColor()));
|
||||
shaderProgram->applyUniform(oglContext, uniformColor);
|
||||
|
||||
#ifdef CVF_OPENGL_ES
|
||||
glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, axisConnects);
|
||||
#else
|
||||
glDrawRangeElements(GL_LINES, 0, 3, 2, GL_UNSIGNED_SHORT, axisConnects);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Draw ticks
|
||||
for (const auto& tickInfo : layout->ticks)
|
||||
{
|
||||
if (tickInfo.isMajor)
|
||||
{
|
||||
v0[0] = layout->startPt.x() - layout->majorTickSize / 2.0f;
|
||||
v0[1] = static_cast<float>(tickInfo.displayValue) + layout->startPt.y();
|
||||
v1[0] = v0[0] + layout->majorTickSize;
|
||||
v1[1] = v0[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
v0[0] = layout->startPt.x() - layout->minorTickSize / 2.0f;
|
||||
v0[1] = static_cast<float>(tickInfo.displayValue) + layout->startPt.y();
|
||||
v1[0] = v0[0] + layout->minorTickSize;
|
||||
v1[1] = v0[1];
|
||||
}
|
||||
|
||||
static const ushort tickConnects[] = {0, 1};
|
||||
|
||||
UniformFloat uniformColor("u_color", Color4f(this->lineColor()));
|
||||
shaderProgram->applyUniform(oglContext, uniformColor);
|
||||
|
||||
#ifdef CVF_OPENGL_ES
|
||||
glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, axisConnects);
|
||||
#else
|
||||
glDrawRangeElements(GL_LINES, 0, 3, 2, GL_UNSIGNED_SHORT, tickConnects);
|
||||
#endif
|
||||
}
|
||||
|
||||
glDisableVertexAttribArray(ShaderProgram::VERTEX);
|
||||
|
||||
CVF_TIGHT_ASSERT(shaderProgram.notNull());
|
||||
shaderProgram->useNoProgram(oglContext);
|
||||
|
||||
// Reset render states
|
||||
RenderStateDepth resetDepth;
|
||||
resetDepth.applyOpenGL(oglContext);
|
||||
|
||||
RenderStateLine resetLine;
|
||||
resetLine.applyOpenGL(oglContext);
|
||||
|
||||
CVF_CHECK_OGL(oglContext);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Draw the legend using immediate mode OpenGL
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScaleLegend::renderLegendImmediateMode(OpenGLContext* oglContext, LayoutInfo* layout)
|
||||
{
|
||||
#if 0
|
||||
#ifdef CVF_OPENGL_ES
|
||||
CVF_UNUSED(layout);
|
||||
CVF_FAIL_MSG("Not supported on OpenGL ES");
|
||||
#else
|
||||
CVF_TIGHT_ASSERT(layout);
|
||||
CVF_TIGHT_ASSERT(layout->overallLegendSize.x() > 0);
|
||||
CVF_TIGHT_ASSERT(layout->overallLegendSize.y() > 0);
|
||||
|
||||
RenderStateDepth depth(false);
|
||||
depth.applyOpenGL(oglContext);
|
||||
|
||||
RenderStateLighting_FF lighting(false);
|
||||
lighting.applyOpenGL(oglContext);
|
||||
|
||||
// All vertices. Initialized here to set Z to zero once and for all.
|
||||
static float vertexArray[] =
|
||||
{
|
||||
0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f,
|
||||
};
|
||||
|
||||
// Per vector convenience pointers
|
||||
float* v0 = &vertexArray[0];
|
||||
float* v1 = &vertexArray[3];
|
||||
float* v2 = &vertexArray[6];
|
||||
float* v3 = &vertexArray[9];
|
||||
float* v4 = &vertexArray[12];
|
||||
|
||||
// Constant coordinates
|
||||
v0[0] = v3[0] = layout->tickStartX;
|
||||
v1[0] = v4[0] = layout->tickMidX;
|
||||
|
||||
// Render color bar as one colored quad per pixel
|
||||
|
||||
int legendHeightPixelCount = static_cast<int>(layout->tickYPixelPos->get(m_tickValues.size() - 1) - layout->tickYPixelPos->get(0) + 0.01);
|
||||
if (m_scalarMapper.notNull())
|
||||
{
|
||||
int iPx;
|
||||
for (iPx = 0; iPx < legendHeightPixelCount; iPx++)
|
||||
{
|
||||
const Color3ub& clr = m_scalarMapper->mapToColor(m_scalarMapper->domainValue((iPx+0.5)/legendHeightPixelCount));
|
||||
float y0 = static_cast<float>(layout->colorBarRect.min().y() + iPx);
|
||||
float y1 = static_cast<float>(layout->colorBarRect.min().y() + iPx + 1);
|
||||
|
||||
// Dynamic coordinates for rectangle
|
||||
v0[1] = v1[1] = y0;
|
||||
v3[1] = v4[1] = y1;
|
||||
|
||||
// Draw filled rectangle elements
|
||||
glColor3ubv(clr.ptr());
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glVertex3fv(v0);
|
||||
glVertex3fv(v1);
|
||||
glVertex3fv(v4);
|
||||
glVertex3fv(v3);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
// Render frame
|
||||
|
||||
// Dynamic coordinates for tickmarks-lines
|
||||
bool isRenderingFrame = true;
|
||||
if (isRenderingFrame)
|
||||
{
|
||||
v0[0] = v2[0] = layout->colorBarRect.min().x()-0.5f;
|
||||
v1[0] = v3[0] = layout->colorBarRect.max().x()-0.5f;
|
||||
v0[1] = v1[1] = layout->colorBarRect.min().y()-0.5f;
|
||||
v2[1] = v3[1] = layout->colorBarRect.max().y()-0.5f;
|
||||
|
||||
glColor3fv(this->textColor().ptr());
|
||||
glBegin(GL_LINES);
|
||||
glVertex3fv(v0);
|
||||
glVertex3fv(v1);
|
||||
glVertex3fv(v1);
|
||||
glVertex3fv(v3);
|
||||
glVertex3fv(v3);
|
||||
glVertex3fv(v2);
|
||||
glVertex3fv(v2);
|
||||
glVertex3fv(v0);
|
||||
glEnd();
|
||||
|
||||
}
|
||||
|
||||
// Render tickmarks
|
||||
bool isRenderingTicks = true;
|
||||
|
||||
if (isRenderingTicks)
|
||||
{
|
||||
// Constant coordinates
|
||||
v0[0] = layout->tickStartX;
|
||||
v1[0] = layout->tickMidX - 0.5f*(layout->tickEndX - layout->tickMidX) - 0.5f;
|
||||
v2[0] = layout->tickMidX;
|
||||
v3[0] = layout->tickEndX - 0.5f*(layout->tickEndX - layout->tickMidX) - 0.5f;
|
||||
v4[0] = layout->tickEndX;
|
||||
|
||||
size_t ic;
|
||||
for (ic = 0; ic < m_tickValues.size(); ic++)
|
||||
{
|
||||
float y0 = static_cast<float>(layout->colorBarRect.min().y() + layout->tickYPixelPos->get(ic) - 0.5f);
|
||||
|
||||
// Dynamic coordinates for tickmarks-lines
|
||||
v0[1] = v1[1] = v2[1] = v3[1] = v4[1] = y0;
|
||||
|
||||
glColor3fv(this->textColor().ptr());
|
||||
glBegin(GL_LINES);
|
||||
if ( m_visibleTickLabels[ic])
|
||||
{
|
||||
glVertex3fv(v0);
|
||||
glVertex3fv(v4);
|
||||
}
|
||||
else
|
||||
{
|
||||
glVertex3fv(v2);
|
||||
glVertex3fv(v3);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
// Reset render states
|
||||
RenderStateLighting_FF resetLighting;
|
||||
resetLighting.applyOpenGL(oglContext);
|
||||
RenderStateDepth resetDepth;
|
||||
resetDepth.applyOpenGL(oglContext);
|
||||
|
||||
CVF_CHECK_OGL(oglContext);
|
||||
#endif // CVF_OPENGL_ES
|
||||
#endif // 0
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Get layout information
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScaleLegend::layoutInfo(LayoutInfo* layout)
|
||||
{
|
||||
CVF_TIGHT_ASSERT(layout);
|
||||
|
||||
ref<Glyph> glyph = this->font()->getGlyph(L'A');
|
||||
layout->charHeight = static_cast<float>(glyph->height());
|
||||
layout->lineSpacing = layout->charHeight*1.5f;
|
||||
layout->margins = Vec2f(8.0f, 8.0f);
|
||||
layout->tickTextLeadSpace = 5.0f;
|
||||
layout->majorTickSize = 9.0f;
|
||||
layout->minorTickSize = 5.0f;
|
||||
|
||||
float maxAxisLength = static_cast<float>(layout->overallLegendSize.y())
|
||||
- 2*layout->margins.y()
|
||||
- static_cast<float>(this->titleStrings().size()) * layout->lineSpacing
|
||||
- layout->lineSpacing;
|
||||
|
||||
auto currentScale = m_currentScale != 0.0 ? m_currentScale : 1.0;
|
||||
layout->startPt = {layout->margins.x() + layout->majorTickSize / 2.0f, layout->margins.y() + layout->charHeight / 2.0f };
|
||||
|
||||
layout->ticks.clear();
|
||||
size_t numTicks = m_ticksInDomain.size();
|
||||
|
||||
if (numTicks > 1)
|
||||
{
|
||||
double tickSpacingInDomain = m_ticksInDomain[1] - m_ticksInDomain[0];
|
||||
bool finished = false;
|
||||
for (size_t i = 0; i < numTicks; i++)
|
||||
{
|
||||
for (size_t j = 0; j < 2; j++)
|
||||
{
|
||||
double tickInDomain = m_ticksInDomain[i] + ((double)j * tickSpacingInDomain / 2.0);
|
||||
double tickInDisplay = tickInDomain * currentScale;
|
||||
|
||||
if (tickInDisplay - layout->startPt.y() < maxAxisLength)
|
||||
{
|
||||
layout->ticks.emplace_back(LayoutInfo::Tick(tickInDisplay, tickInDomain, j == 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (finished) break;
|
||||
}
|
||||
layout->axisLength = static_cast<float>(layout->ticks.back().displayValue);
|
||||
}
|
||||
else
|
||||
layout->axisLength = 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScaleLegend::setTickPrecision(int precision)
|
||||
{
|
||||
m_tickNumberPrecision = precision;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScaleLegend::setTickFormat(NumberFormat format)
|
||||
{
|
||||
m_numberFormat = format;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Vec2ui OverlayScaleLegend::preferredSize()
|
||||
{
|
||||
LayoutInfo layout({200,200}); // Use default size
|
||||
layoutInfo(&layout);
|
||||
|
||||
float prefferredYSize = 400;
|
||||
|
||||
//float prefferredYSize = 2 * layout.margins.y()
|
||||
// + layout.lineSpacing * this->titleStrings().size()
|
||||
// + 1.5f * layout.lineSpacing * m_tickValues.size();
|
||||
|
||||
unsigned int maxTickTextWidth = 0;
|
||||
for (double tickValue : m_ticksInDomain )
|
||||
{
|
||||
String valueString;
|
||||
switch ( m_numberFormat )
|
||||
{
|
||||
case FIXED:
|
||||
valueString = String::number(tickValue, 'f', m_tickNumberPrecision);
|
||||
break;
|
||||
case SCIENTIFIC:
|
||||
valueString = String::number(tickValue, 'e', m_tickNumberPrecision);
|
||||
break;
|
||||
default:
|
||||
valueString = String::number(tickValue);
|
||||
break;
|
||||
}
|
||||
unsigned int textWidth = this->font()->textExtent(valueString).x();
|
||||
maxTickTextWidth = maxTickTextWidth < textWidth ? textWidth : maxTickTextWidth;
|
||||
}
|
||||
|
||||
float prefferredXSize = layout.margins.x() + layout.tickTextLeadSpace + maxTickTextWidth;
|
||||
|
||||
for (const cvf::String& titleLine : titleStrings())
|
||||
{
|
||||
float titleWidth = this->font()->textExtent(titleLine).x() + 2*layout.margins.x();
|
||||
prefferredXSize = prefferredXSize < titleWidth ? titleWidth : prefferredXSize;
|
||||
}
|
||||
|
||||
prefferredXSize = std::min(prefferredXSize, 400.0f);
|
||||
|
||||
return { (unsigned int)(std::ceil(prefferredXSize)), (unsigned int)(std::ceil(prefferredYSize)) };
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScaleLegend::setDisplayCoordTransform(const caf::DisplayCoordTransform* displayCoordTransform)
|
||||
{
|
||||
m_dispalyCoordsTransform = displayCoordTransform;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScaleLegend::updateFromCamera(const Camera* camera)
|
||||
{
|
||||
auto windowSize = Vec2ui(camera->viewport()->width(), camera->viewport()->height());
|
||||
|
||||
Vec3d windowOrigoInDomain;
|
||||
Vec3d windowMaxInDomain;
|
||||
camera->unproject(Vec3d(0, 0, 0), &windowOrigoInDomain);
|
||||
camera->unproject(Vec3d(windowSize.x(), windowSize.y(), 0), &windowMaxInDomain);
|
||||
|
||||
if (m_dispalyCoordsTransform.notNull())
|
||||
{
|
||||
windowOrigoInDomain = m_dispalyCoordsTransform->transformToDomainCoord(windowOrigoInDomain);
|
||||
windowMaxInDomain = m_dispalyCoordsTransform->transformToDomainCoord(windowMaxInDomain);
|
||||
}
|
||||
|
||||
Vec3d windowOrigoPoint;
|
||||
Vec3d windowMaxPoint;
|
||||
camera->project(windowOrigoInDomain, &windowOrigoPoint);
|
||||
camera->project(windowMaxInDomain, &windowMaxPoint);
|
||||
|
||||
m_currentScale = (windowMaxPoint.y() - windowOrigoPoint.y()) / (windowMaxInDomain.y() - windowOrigoInDomain.y());
|
||||
|
||||
auto textSize = m_font->textExtent(String::number(-1.999e-17));
|
||||
int xTickMaxCount = windowSize.x() / (2 * textSize.x());
|
||||
int yTickMaxCount = windowSize.y() / (2 * textSize.x());
|
||||
|
||||
double minDomainYStepSize = (windowMaxInDomain.y() - windowOrigoInDomain.y()) / yTickMaxCount;
|
||||
caf::TickMarkGenerator yTickCreator(windowOrigoInDomain.y(), windowMaxInDomain.y(), minDomainYStepSize);
|
||||
auto ticks = yTickCreator.tickMarkValues();
|
||||
|
||||
m_ticksInDomain.clear();
|
||||
for (const auto& tick : ticks)
|
||||
{
|
||||
m_ticksInDomain.push_back(tick - ticks.front());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cvf
|
||||
|
162
Fwk/AppFwk/cafVizExtensions/cafOverlayScaleLegend.h
Normal file
162
Fwk/AppFwk/cafVizExtensions/cafOverlayScaleLegend.h
Normal file
@ -0,0 +1,162 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2018- Ceetron Solutions AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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.
|
||||
//
|
||||
// This library 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 <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafDisplayCoordTransform.h"
|
||||
#include "cafTitledOverlayFrame.h"
|
||||
#include "cvfOverlayItem.h"
|
||||
#include "cvfArray.h"
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfString.h"
|
||||
#include "cvfRect.h"
|
||||
|
||||
namespace cvf {
|
||||
class Font;
|
||||
class ShaderProgram;
|
||||
class MatrixState;
|
||||
class TextDrawer;
|
||||
class ScalarMapper;
|
||||
}
|
||||
|
||||
namespace caf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
// Overlay color legend
|
||||
//
|
||||
//==================================================================================================
|
||||
class OverlayScaleLegend : public caf::TitledOverlayFrame
|
||||
{
|
||||
using Font = cvf::Font;
|
||||
using ScalarMapper = cvf::ScalarMapper;
|
||||
using OpenGLContext = cvf::OpenGLContext;
|
||||
using Vec2i = cvf::Vec2i;
|
||||
using Vec2ui = cvf::Vec2ui;
|
||||
using Color3f = cvf::Color3f;
|
||||
using Color4f = cvf::Color4f;
|
||||
using String = cvf::String;
|
||||
using DoubleArray = cvf::DoubleArray;
|
||||
using MatrixState = cvf::MatrixState;
|
||||
using Vec2f = cvf::Vec2f;
|
||||
using Rectf = cvf::Rectf;
|
||||
using TextDrawer = cvf::TextDrawer;
|
||||
using Camera = cvf::Camera;
|
||||
|
||||
public:
|
||||
OverlayScaleLegend(Font* font);
|
||||
virtual ~OverlayScaleLegend();
|
||||
|
||||
void setTickPrecision(int precision);
|
||||
enum NumberFormat { AUTO, SCIENTIFIC, FIXED};
|
||||
void setTickFormat(NumberFormat format);
|
||||
|
||||
virtual cvf::Vec2ui preferredSize() override;
|
||||
|
||||
void setDisplayCoordTransform(const caf::DisplayCoordTransform* displayCoordTransform);
|
||||
void updateFromCamera(const Camera* camera);
|
||||
|
||||
protected:
|
||||
void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size) override;
|
||||
void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size) override;
|
||||
|
||||
struct LayoutInfo
|
||||
{
|
||||
struct Tick
|
||||
{
|
||||
Tick(double displayValue, double domainValue, bool isMajor)
|
||||
: displayValue(displayValue)
|
||||
, domainValue(domainValue)
|
||||
, isMajor(isMajor) {}
|
||||
double displayValue;
|
||||
double domainValue;
|
||||
bool isMajor;
|
||||
};
|
||||
|
||||
LayoutInfo(const Vec2ui& setSize)
|
||||
{
|
||||
overallLegendSize = setSize;
|
||||
}
|
||||
|
||||
float charHeight;
|
||||
float lineSpacing;
|
||||
Vec2f margins;
|
||||
float tickTextLeadSpace;
|
||||
|
||||
//Rectf colorBarRect;
|
||||
Vec2f startPt;
|
||||
float axisLength;
|
||||
float majorTickSize;
|
||||
float minorTickSize;
|
||||
|
||||
std::vector<Tick> ticks;
|
||||
|
||||
Vec2ui overallLegendSize;
|
||||
};
|
||||
|
||||
void layoutInfo(LayoutInfo* layout);
|
||||
|
||||
void renderGeneric(OpenGLContext* oglContext,
|
||||
const Vec2i& position,
|
||||
const Vec2ui& size,
|
||||
bool software);
|
||||
void renderLegendUsingShaders(OpenGLContext* oglContext,
|
||||
LayoutInfo* layout,
|
||||
const MatrixState& matrixState);
|
||||
void renderLegendImmediateMode(OpenGLContext* oglContext,
|
||||
LayoutInfo* layout);
|
||||
void setupTextDrawer(TextDrawer* textDrawer,
|
||||
const LayoutInfo* layout);
|
||||
|
||||
protected:
|
||||
std::vector<bool> m_visibleTickLabels; // Skip tick labels ending up on top of previous visible label
|
||||
int m_tickNumberPrecision;
|
||||
NumberFormat m_numberFormat;
|
||||
|
||||
LayoutInfo m_Layout;
|
||||
cvf::ref<TextDrawer> m_textDrawer;
|
||||
cvf::cref<ScalarMapper> m_scalarMapper;
|
||||
|
||||
cvf::ref<Font> m_font;
|
||||
|
||||
cvf::cref<caf::DisplayCoordTransform> m_dispalyCoordsTransform;
|
||||
double m_currentScale = 0.0; // [pixels/length]
|
||||
std::vector<double> m_ticksInDomain;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user