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
This commit is contained in:
@@ -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<osg::Vec4Array> 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<ColorRange*>(_stc.get());
|
||||
bool fixedColors = cr && (_numColors == static_cast<int>(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);
|
||||
|
||||
Reference in New Issue
Block a user