//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimLegendConfig::updateLegend() { double adjustedMin = cvf::UNDEFINED_DOUBLE; double adjustedMax = cvf::UNDEFINED_DOUBLE; if (m_rangeMode == AUTOMATIC_ALLTIMESTEPS) { adjustedMin = adjust(m_globalAutoMin, m_precision); adjustedMax = adjust(m_globalAutoMax, m_precision); } else if (m_rangeMode == AUTOMATIC_CURRENT_TIMESTEP) { adjustedMin = adjust(m_localAutoMin, m_precision); adjustedMax = adjust(m_localAutoMax, m_precision); } else { adjustedMin = adjust(m_userDefinedMinValue, m_precision); adjustedMax = adjust(m_userDefinedMaxValue, m_precision); } m_linDiscreteScalarMapper->setRange(adjustedMin, adjustedMax); m_logDiscreteScalarMapper->setRange(adjustedMin, adjustedMax); m_logSmoothScalarMapper->setRange(adjustedMin, adjustedMax); m_linSmoothScalarMapper->setRange(adjustedMin, adjustedMax); cvf::Color3ubArray legendColors; switch (m_colorRangeMode()) { case NORMAL: { legendColors.reserve(7); legendColors.add(cvf::Color3ub( 0, 0, 255)); legendColors.add(cvf::Color3ub( 0, 127, 255)); legendColors.add(cvf::Color3ub( 0, 255, 255)); legendColors.add(cvf::Color3ub( 0, 255, 0)); legendColors.add(cvf::Color3ub(255, 255, 0)); legendColors.add(cvf::Color3ub(255, 127, 0)); legendColors.add(cvf::Color3ub(255, 0, 0)); } break; case OPPOSITE_NORMAL: { legendColors.reserve(7); legendColors.add(cvf::Color3ub(255, 0, 0)); legendColors.add(cvf::Color3ub(255, 127, 0)); legendColors.add(cvf::Color3ub(255, 255, 0)); legendColors.add(cvf::Color3ub( 0, 255, 0)); legendColors.add(cvf::Color3ub( 0, 255, 255)); legendColors.add(cvf::Color3ub( 0, 127, 255)); legendColors.add(cvf::Color3ub( 0, 0, 255)); } break; case BLACK_WHITE: case WHITE_BLACK: { legendColors.reserve(2); if (m_colorRangeMode() == BLACK_WHITE) { legendColors.add(cvf::Color3ub::BLACK); legendColors.add(cvf::Color3ub::WHITE); } else { legendColors.add(cvf::Color3ub::WHITE); legendColors.add(cvf::Color3ub::BLACK); } } break; case PINK_WHITE: case WHITE_PINK: { legendColors.reserve(2); if (m_colorRangeMode() == PINK_WHITE) { legendColors.add(cvf::Color3ub::DEEP_PINK); legendColors.add(cvf::Color3ub::WHITE); } else { legendColors.add(cvf::Color3ub::WHITE); legendColors.add(cvf::Color3ub::DEEP_PINK); } } break; } m_linDiscreteScalarMapper->setColors(legendColors); m_logDiscreteScalarMapper->setColors(legendColors); m_logSmoothScalarMapper->setColors(legendColors); m_linSmoothScalarMapper->setColors(legendColors); m_linDiscreteScalarMapper->setLevelCount(m_numLevels, true); m_logDiscreteScalarMapper->setLevelCount(m_numLevels, true); m_logSmoothScalarMapper->setLevelCount(m_numLevels, true); m_linSmoothScalarMapper->setLevelCount(m_numLevels, true); switch(m_mappingMode()) { case LINEAR_DISCRETE: m_currentScalarMapper = m_linDiscreteScalarMapper.p(); break; case LINEAR_CONTINUOUS: m_currentScalarMapper = m_linSmoothScalarMapper.p(); break; case LOG10_CONTINUOUS: m_currentScalarMapper = m_logSmoothScalarMapper.p(); break; case LOG10_DISCRETE: m_currentScalarMapper = m_logDiscreteScalarMapper.p(); break; default: break; } m_legend->setScalarMapper(m_currentScalarMapper.p()); if (m_globalAutoMax != cvf::UNDEFINED_DOUBLE ) { m_userDefinedMaxValue.setUiName(QString("Max ") + "(" + QString::number(m_globalAutoMax, 'g', m_precision) + ")"); } else { m_userDefinedMaxValue.setUiName(QString()); } if (m_globalAutoMin != cvf::UNDEFINED_DOUBLE ) { m_userDefinedMinValue.setUiName(QString("Min ") + "(" + QString::number(m_globalAutoMin, 'g', m_precision) + ")"); } else { m_userDefinedMinValue.setUiName(QString()); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimLegendConfig::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; } m_linDiscreteScalarMapper->setRange(adjustedMin, adjustedMax); m_linSmoothScalarMapper->setRange(adjustedMin, adjustedMax); if (m_mappingMode == LOG10_CONTINUOUS || m_mappingMode == LOG10_DISCRETE) { if (adjustedMin != adjustedMax) { if (adjustedMin == 0) { if (adjustedMax > adjustedMin) { adjustedMin = posClosestToZero; } else { adjustedMin = negClosestToZero; } } else if (adjustedMax == 0) { if (adjustedMin > adjustedMax) { adjustedMax = posClosestToZero; } else { adjustedMax = negClosestToZero; } } else if (adjustedMin < 0 && adjustedMax > 0) { adjustedMin = posClosestToZero; } else if (adjustedMax < 0 && adjustedMin > 0) { adjustedMin = negClosestToZero; } } } m_logDiscreteScalarMapper->setRange(adjustedMin, adjustedMax); m_logSmoothScalarMapper->setRange(adjustedMin, adjustedMax); cvf::Color3ubArray legendColors; switch (m_colorRangeMode()) { case NORMAL: { legendColors.reserve(7); legendColors.add(cvf::Color3ub( 0, 0, 255)); legendColors.add(cvf::Color3ub( 0, 127, 255)); legendColors.add(cvf::Color3ub( 0, 255, 255)); legendColors.add(cvf::Color3ub( 0, 255, 0)); legendColors.add(cvf::Color3ub(255, 255, 0)); legendColors.add(cvf::Color3ub(255, 127, 0)); legendColors.add(cvf::Color3ub(255, 0, 0)); } break; case OPPOSITE_NORMAL: { legendColors.reserve(7); legendColors.add(cvf::Color3ub(255, 0, 0)); legendColors.add(cvf::Color3ub(255, 127, 0)); legendColors.add(cvf::Color3ub(255, 255, 0)); legendColors.add(cvf::Color3ub( 0, 255, 0)); legendColors.add(cvf::Color3ub( 0, 255, 255)); legendColors.add(cvf::Color3ub( 0, 127, 255)); legendColors.add(cvf::Color3ub( 0, 0, 255)); } break; case BLACK_WHITE: case WHITE_BLACK: { legendColors.reserve(2); if (m_colorRangeMode() == BLACK_WHITE) { legendColors.add(cvf::Color3ub::BLACK); legendColors.add(cvf::Color3ub::WHITE); } else { legendColors.add(cvf::Color3ub::WHITE); legendColors.add(cvf::Color3ub::BLACK); } } break; case PINK_WHITE: case WHITE_PINK: { legendColors.reserve(2); if (m_colorRangeMode() == PINK_WHITE) { legendColors.add(cvf::Color3ub::DEEP_PINK); legendColors.add(cvf::Color3ub::WHITE); } else { legendColors.add(cvf::Color3ub::WHITE); legendColors.add(cvf::Color3ub::DEEP_PINK); } } break; case BLUE_WHITE_RED: case RED_WHITE_BLUE: { legendColors.reserve(3); if (m_colorRangeMode() == BLUE_WHITE_RED) { legendColors.add(cvf::Color3ub::BLUE); legendColors.add(cvf::Color3ub::WHITE); legendColors.add(cvf::Color3ub::RED); } else { legendColors.add(cvf::Color3ub::RED); legendColors.add(cvf::Color3ub::WHITE); legendColors.add(cvf::Color3ub::BLUE); } } break; } m_linDiscreteScalarMapper->setColors(legendColors); m_logDiscreteScalarMapper->setColors(legendColors); m_logSmoothScalarMapper->setColors(legendColors); m_linSmoothScalarMapper->setColors(legendColors); m_linDiscreteScalarMapper->setLevelCount(m_numLevels, true); m_logDiscreteScalarMapper->setLevelCount(m_numLevels, true); m_logSmoothScalarMapper->setLevelCount(m_numLevels, true); m_linSmoothScalarMapper->setLevelCount(m_numLevels, true); switch(m_mappingMode()) { case LINEAR_DISCRETE: m_currentScalarMapper = m_linDiscreteScalarMapper.p(); break; case LINEAR_CONTINUOUS: m_currentScalarMapper = m_linSmoothScalarMapper.p(); break; case LOG10_CONTINUOUS: m_currentScalarMapper = m_logSmoothScalarMapper.p(); break; case LOG10_DISCRETE: m_currentScalarMapper = m_logDiscreteScalarMapper.p(); break; default: break; } m_legend->setScalarMapper(m_currentScalarMapper.p()); double decadesInRange = 0; if (m_mappingMode == LOG10_CONTINUOUS || m_mappingMode == LOG10_DISCRETE) { // For log mapping, use the min value as reference for num valid digits decadesInRange = cvf::Math::abs(adjustedMin) < cvf::Math::abs(adjustedMax) ? cvf::Math::abs(adjustedMin) : cvf::Math::abs(adjustedMax); decadesInRange = log10(decadesInRange); } else { // 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 NumberFormatType nft = m_tickNumberFormat(); m_legend->setTickFormat((cvf::OverlayScalarMapperLegend::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(); if (nft != SCIENTIFIC) { numDecimalDigits -= static_cast<int>(decadesInRange); } m_legend->setTickPrecision(cvf::Math::clamp(numDecimalDigits, 0, 20)); if (m_globalAutoMax != cvf::UNDEFINED_DOUBLE ) { m_userDefinedMaxValue.setUiName(QString("Max ") + "(" + QString::number(m_globalAutoMax, 'g', m_precision) + ")"); } else { m_userDefinedMaxValue.setUiName(QString()); } if (m_globalAutoMin != cvf::UNDEFINED_DOUBLE ) { m_userDefinedMinValue.setUiName(QString("Min ") + "(" + QString::number(m_globalAutoMin, 'g', m_precision) + ")"); } else { m_userDefinedMinValue.setUiName(QString()); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimLegendConfig::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; } m_linDiscreteScalarMapper->setRange(adjustedMin, adjustedMax); m_linSmoothScalarMapper->setRange(adjustedMin, adjustedMax); if (m_mappingMode == LOG10_CONTINUOUS || m_mappingMode == LOG10_DISCRETE) { if (adjustedMin != adjustedMax) { if (adjustedMin == 0) { if (adjustedMax > adjustedMin) { adjustedMin = posClosestToZero; } else { adjustedMin = negClosestToZero; } } else if (adjustedMax == 0) { if (adjustedMin > adjustedMax) { adjustedMax = posClosestToZero; } else { adjustedMax = negClosestToZero; } } else if (adjustedMin < 0 && adjustedMax > 0) { adjustedMin = posClosestToZero; } else if (adjustedMax < 0 && adjustedMin > 0) { adjustedMin = negClosestToZero; } } } m_logDiscreteScalarMapper->setRange(adjustedMin, adjustedMax); m_logSmoothScalarMapper->setRange(adjustedMin, adjustedMax); cvf::Color3ubArray legendColors; switch (m_colorRangeMode()) { case NORMAL: { legendColors.reserve(7); legendColors.add(cvf::Color3ub( 0, 0, 255)); legendColors.add(cvf::Color3ub( 0, 127, 255)); legendColors.add(cvf::Color3ub( 0, 255, 255)); legendColors.add(cvf::Color3ub( 0, 255, 0)); legendColors.add(cvf::Color3ub(255, 255, 0)); legendColors.add(cvf::Color3ub(255, 127, 0)); legendColors.add(cvf::Color3ub(255, 0, 0)); } break; case OPPOSITE_NORMAL: { legendColors.reserve(7); legendColors.add(cvf::Color3ub(255, 0, 0)); legendColors.add(cvf::Color3ub(255, 127, 0)); legendColors.add(cvf::Color3ub(255, 255, 0)); legendColors.add(cvf::Color3ub( 0, 255, 0)); legendColors.add(cvf::Color3ub( 0, 255, 255)); legendColors.add(cvf::Color3ub( 0, 127, 255)); legendColors.add(cvf::Color3ub( 0, 0, 255)); } break; case BLACK_WHITE: case WHITE_BLACK: { legendColors.reserve(2); if (m_colorRangeMode() == BLACK_WHITE) { legendColors.add(cvf::Color3ub::BLACK); legendColors.add(cvf::Color3ub::WHITE); } else { legendColors.add(cvf::Color3ub::WHITE); legendColors.add(cvf::Color3ub::BLACK); } } break; case PINK_WHITE: case WHITE_PINK: { legendColors.reserve(2); if (m_colorRangeMode() == PINK_WHITE) { legendColors.add(cvf::Color3ub::DEEP_PINK); legendColors.add(cvf::Color3ub::WHITE); } else { legendColors.add(cvf::Color3ub::WHITE); legendColors.add(cvf::Color3ub::DEEP_PINK); } } break; case BLUE_WHITE_RED: case RED_WHITE_BLUE: { legendColors.reserve(3); if (m_colorRangeMode() == BLUE_WHITE_RED) { legendColors.add(cvf::Color3ub::BLUE); legendColors.add(cvf::Color3ub::WHITE); legendColors.add(cvf::Color3ub::RED); } else { legendColors.add(cvf::Color3ub::RED); legendColors.add(cvf::Color3ub::WHITE); legendColors.add(cvf::Color3ub::BLUE); } } break; case CATEGORY: { // Based on http://stackoverflow.com/questions/470690/how-to-automatically-generate-n-distinct-colors // and Kelly Colors and sorted by hue // See also http://www.w3schools.com/colors/ for palettes etc. legendColors.reserve(20); legendColors.add(cvf::Color3ub(128, 62, 117)); // hwb(310, 24%, 50%) strong_purple legendColors.add(cvf::Color3ub(212, 28, 132)); // hwb(326, 11%, 17%) strong_purplish_red legendColors.add(cvf::Color3ub(246, 118, 142)); // hwb(349, 46%, 4%) strong_purplish_pink legendColors.add(cvf::Color3ub(193, 0, 32)); // hwb(350, 0%, 24%) vivid_red legendColors.add(cvf::Color3ub(127, 24, 13)); // hwb( 6, 5%, 50%) strong_reddish_brown legendColors.add(cvf::Color3ub(241, 58, 19)); // hwb( 11, 7%, 5%) vivid_reddish_orange legendColors.add(cvf::Color3ub(255, 122, 92)); // hwb( 11, 36%, 0%) strong_yellowish_pink legendColors.add(cvf::Color3ub(129, 112, 102)); // hwb( 22, 40%, 49%) medium_gray legendColors.add(cvf::Color3ub(255, 104, 0)); // hwb( 24, 0%, 0%) vivid_orange legendColors.add(cvf::Color3ub( 89, 51, 21)); // hwb( 26, 8%, 65%) deep_yellowish_brown legendColors.add(cvf::Color3ub(255, 142, 0)); // hwb( 33, 0%, 0%) vivid_orange_yellow legendColors.add(cvf::Color3ub(206, 162, 98)); // hwb( 36, 38%, 19%) grayish_yellow legendColors.add(cvf::Color3ub(244, 200, 0)); // hwb( 49, 0%, 4%) vivid_greenish_yellow legendColors.add(cvf::Color3ub(147, 170, 0)); // hwb( 68, 0%, 33%) vivid_yellowish_green legendColors.add(cvf::Color3ub( 59, 84, 23)); // hwb( 85, 9%, 67%) dark_olive_green legendColors.add(cvf::Color3ub( 0, 125, 52)); // hwb(145, 0%, 51%) vivid_green legendColors.add(cvf::Color3ub( 54, 125, 123)); // hwb(178, 21%, 51%) vivid_blueish_green legendColors.add(cvf::Color3ub( 0, 83, 138)); // hwb(204, 0%, 46%) strong_blue legendColors.add(cvf::Color3ub(166, 189, 215)); // hwb(212, 65%, 16%) very_light_blue legendColors.add(cvf::Color3ub( 46, 76, 224)); // hwb(230, 18%, 12%) medium_blue } break; case ANGULAR: { legendColors.reserve(9); legendColors.add(cvf::Color3ub(255, 0, 255)); legendColors.add(cvf::Color3ub(0, 0, 255)); legendColors.add(cvf::Color3ub(0, 127, 255)); legendColors.add(cvf::Color3ub(0, 255, 255)); legendColors.add(cvf::Color3ub(0, 255, 0)); legendColors.add(cvf::Color3ub(255, 255, 0)); legendColors.add(cvf::Color3ub(255, 127, 0)); legendColors.add(cvf::Color3ub(255, 0, 0)); legendColors.add(cvf::Color3ub(255, 0, 255)); } break; } m_linDiscreteScalarMapper->setColors(legendColors); m_logDiscreteScalarMapper->setColors(legendColors); m_logSmoothScalarMapper->setColors(legendColors); m_linSmoothScalarMapper->setColors(legendColors); m_linDiscreteScalarMapper->setLevelCount(m_numLevels, true); m_logDiscreteScalarMapper->setLevelCount(m_numLevels, true); m_logSmoothScalarMapper->setLevelCount(m_numLevels, true); m_linSmoothScalarMapper->setLevelCount(m_numLevels, true); switch(m_mappingMode()) { case LINEAR_DISCRETE: m_currentScalarMapper = m_linDiscreteScalarMapper.p(); break; case LINEAR_CONTINUOUS: m_currentScalarMapper = m_linSmoothScalarMapper.p(); break; case LOG10_CONTINUOUS: m_currentScalarMapper = m_logSmoothScalarMapper.p(); break; case LOG10_DISCRETE: m_currentScalarMapper = m_logDiscreteScalarMapper.p(); break; case CATEGORY_INTEGER: m_categoryMapper->setCategoriesWithNames(m_categories, m_categoryNames); m_categoryMapper->setInterpolateColors(legendColors); m_currentScalarMapper = m_categoryMapper.p(); break; default: break; } if (m_currentScalarMapper != m_categoryMapper.p()) { m_scalarMapperLegend->setScalarMapper(m_currentScalarMapper.p()); } double decadesInRange = 0; if (m_mappingMode == LOG10_CONTINUOUS || m_mappingMode == LOG10_DISCRETE) { // For log mapping, use the min value as reference for num valid digits decadesInRange = cvf::Math::abs(adjustedMin) < cvf::Math::abs(adjustedMax) ? cvf::Math::abs(adjustedMin) : cvf::Math::abs(adjustedMax); decadesInRange = log10(decadesInRange); } else { // 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 NumberFormatType nft = m_tickNumberFormat(); m_scalarMapperLegend->setTickFormat((cvf::OverlayScalarMapperLegend::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(); if (nft != SCIENTIFIC) { numDecimalDigits -= static_cast<int>(decadesInRange); } m_scalarMapperLegend->setTickPrecision(cvf::Math::clamp(numDecimalDigits, 0, 20)); 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()); } }