//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- Color3ub ScalarMapperDiscreteLog::mapToColor(double scalarValue) const { double discVal = ScalarMapperDiscreteLinear::discretizeToLevelBelow(scalarValue, m_sortedLevels); std::set<double>::reverse_iterator it = m_sortedLevels.rbegin(); it++; double levelUnderMax = *it; double normDiscVal = normalizedValue(discVal); double normSemiMaxVal = normalizedValue(levelUnderMax); double adjustedNormVal = 0; if (normSemiMaxVal != 0) adjustedNormVal = normDiscVal/normSemiMaxVal; adjustedNormVal = cvf::Math::clamp(adjustedNormVal, 0.0, 1.0); return colorFromUserColorGradient(adjustedNormVal); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- Color3ub ScalarMapperRangeBased::mapToColor(double scalarValue) const { size_t colorIdx = static_cast<size_t>(normalizedValue(scalarValue) * (m_textureSize - 1)); CVF_TIGHT_ASSERT(colorIdx < m_colors.size()); return m_colors[colorIdx]; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- Vec2f CategoryMapper::mapToTextureCoord(double categoryValue) const { double normVal = normalizedValue(categoryValue); double s = normVal*m_maxTexCoord; // Clamp to the currently legal texture coord range // Might need to add code to correct for float precision, but that is probably not the main enemy. // Our real problem is the fact that in most cases the texture coords get treated with even less precision // on the graphics hardware. What we would really like is to guess at the HW precision and then correct for that. // Currently the workaround is done in updateTexture() which pads the upper end of the texture when we're not filling // all the texture pixels. s = Math::clamp(s, 0.0, m_maxTexCoord); return Vec2f(static_cast<float>(s), 0.5f); }
//-------------------------------------------------------------------------------------------------- /// Calculates a set of humanly readable levels. Works very well for linear, and ok for logarithmic. /// The logarithmic needs a bit more tweaking, so should override this method for linear but not yet done. //-------------------------------------------------------------------------------------------------- void ScalarMapperRangeBased::majorTickValues( std::vector<double>* domainValues) const { CVF_ASSERT(domainValues != NULL); CVF_ASSERT(m_rangeMin != cvf::UNDEFINED_DOUBLE && m_rangeMax != cvf::UNDEFINED_DOUBLE); if (m_userDefinedLevelValues.empty()) { domainValues->push_back(domainValue(0)); if (m_levelCount > 1) { double stepSizeNorm = 1.0/m_levelCount; size_t i; if (m_adjustLevels) // adjust levels { double prevDomValue = domainValue(0); for (i = 1; i < m_levelCount + 5; ++i) { double prevNormPos = normalizedValue(prevDomValue); double newNormPos = prevNormPos + stepSizeNorm; double domValue = domainValue(newNormPos); double domStep = domValue - prevDomValue; double newLevel; //newLevel = prevDomValue + adjust(domStep, domStep, m_decadeLevelCount); newLevel = domValue; // Must handle first level specially to get a good absolute staring point // For log domain this must be done all the time, and it does not hamper linear, so.. do it always newLevel = adjust(newLevel, domStep, m_decadeLevelCount); if (normalizedValue(newLevel) > 1.0 - stepSizeNorm*0.4) break; domainValues->push_back(newLevel); prevDomValue = newLevel; } } else { for (i = 1; i < m_levelCount; ++i) { domainValues->push_back(domainValue(stepSizeNorm*i)); } } } domainValues->push_back(domainValue(1)); } else { // Use the user defined levels between max and min. // (max and min values are set from the user defined levels if not set explicitly) domainValues->push_back(m_rangeMin); std::set<double>::iterator it; for (it = m_userDefinedLevelValues.begin(); it != m_userDefinedLevelValues.end(); ++it) { if (*it <= m_rangeMin ) continue; if (*it >= m_rangeMax ) continue; domainValues->push_back(*it); } domainValues->push_back(m_rangeMax); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- Color3ub ScalarMapperRangeBased::mapToColor(double scalarValue) const { return colorFromUserColorGradient(normalizedValue(scalarValue)); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- Vec2f ScalarMapperRangeBased::mapToTextureCoord(double scalarValue) const { return Vec2f(static_cast<float>(normalizedValue(scalarValue)), 0.5f); }