From 1db6def2c4ff6ec0d020272aa6f0626efda9e07d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 25 Feb 2015 19:31:20 +0000 Subject: [PATCH] From Jamie Robertson, "I've been using osgSim::ScalarBar to display fixed range color values (e.g. red from 1-2, green from 3-4 etc), by setting the _numColors the same as the number of actual colors in the ColorRange. Currently if you do this you get strange looking results as the colors are calculated for values in the centre of each color step, so if your steps are large, the colors are interpolated sigificantly (see screen grab of red, green and blue colors for illustration). I've attached a fix which just uses the original color values whenever _numColors equals the number of actual defined colors in the ColorRange. I doubt anyone would want interpolated colors in these circumstances." git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14720 16af8721-9629-0410-8352-f15c8da7e697 --- src/osgSim/ScalarBar.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/osgSim/ScalarBar.cpp b/src/osgSim/ScalarBar.cpp index 4d3f3248f..8e52fb0d9 100644 --- a/src/osgSim/ScalarBar.cpp +++ b/src/osgSim/ScalarBar.cpp @@ -124,7 +124,7 @@ void ScalarBar::createDrawables() { // Remove any existing Drawables removeDrawables(0, getNumDrawables()); - + if (_numColors==0) return; osg::Matrix matrix; @@ -167,11 +167,15 @@ void ScalarBar::createDrawables() osg::ref_ptr cs(new osg::Vec4Array); cs->reserve(4*_numColors); const float halfIncr = incr*0.5; - for(i=0; i<_numColors; ++i) + // Check whether to use interpolated colors or retain the original + // color values if _numColors equals the number of ColorRange colors defined + ColorRange *cr = dynamic_cast(_stc.get()); + bool fixedColors = cr && (_numColors == static_cast(cr->getColors().size())); + for (i = 0; i<_numColors; ++i) { // We add half an increment to the color look-up to get the color - // square in the middle of the 'block'. - osg::Vec4 c = _stc->getColor(_stc->getMin() + (i*incr) + halfIncr); + // square in the middle of the 'block' unless using fixed colors. + osg::Vec4 c = fixedColors ? cr->getColors()[i] : _stc->getColor(_stc->getMin() + (i*incr) + halfIncr); cs->push_back(c); cs->push_back(c); cs->push_back(c);