ScalarBar
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* 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
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGSIM_SCALARBAR
#define OSGSIM_SCALARBAR 1
#include <osgSim/Export>
#include <osgSim/ColorRange> // The default ScalarsToColors is a ColorRange
#include <osg/Geode>
#include <string>
namespace osgSim
{
class OSGSIM_EXPORT ScalarBar: public osg::Geode
{
public:
enum Orientation{
HORIZONTAL,
VERTICAL
};
struct OSGSIM_EXPORT ScalarPrinter: public osg::Referenced
{
virtual std::string printScalar(float scalar);
};
struct TextProperties
{
std::string _fontFile;
std::pair<int,int> _fontResolution;
float _characterSize;
osg::Vec4 _color;
TextProperties():
_fontFile("fonts/arial.ttf"),
_fontResolution(40,40),
_characterSize(0.0f),
_color(1.0f,1.0f,1.0f,1.0f)
{
}
};
ScalarBar(): osg::Geode(),
_numColors(256),
_numLabels(11),
_stc(new ColorRange(0.0f,1.0f)),
_title("Scalar Bar"),
_position(0.0f,0.0f,0.0f),
_width(1.0f),
_aspectRatio(0.03),
_orientation(HORIZONTAL),
_sp(new ScalarPrinter)
{
createDrawables();
}
ScalarBar(int numColors, int numLabels, ScalarsToColors* stc,
const std::string& title,
Orientation orientation = HORIZONTAL,
float aspectRatio=0.25,
ScalarPrinter* sp=new ScalarPrinter):
osg::Geode(),
_numColors(numColors),
_numLabels(numLabels),
_stc(stc),
_title(title),
_position(0.0f,0.0f,0.0f),
_width(1.0f),
_aspectRatio(aspectRatio),
_orientation(orientation),
_sp(sp)
{
createDrawables();
}
ScalarBar(const ScalarBar& rhs, const osg::CopyOp& co): osg::Geode(rhs,co),
_numColors(rhs._numColors),
_numLabels(rhs._numLabels),
_stc(rhs._stc), // Consider clone for deep copy?
_title(rhs._title),
_position(rhs._position),
_width(rhs._width),
_aspectRatio(rhs._aspectRatio),
_orientation(rhs._orientation),
_sp(rhs._sp), // Consider clone for deep copy?
_textProperties(rhs._textProperties)
{
}
META_Node(osgSim, ScalarBar);
void setNumColors(int numColors);
int getNumColors() const;
void setNumLabels(int numLabels);
int getNumLabels() const;
void setScalarsToColors(ScalarsToColors* stc);
const ScalarsToColors* getScalarsToColors() const;
void setTitle(const std::string& title);
const std::string& getTitle() const;
void setPosition(const osg::Vec3& pos);
const osg::Vec3& getPosition() const { return _position; }
void setWidth(float width);
float getWidth() const { return _width; }
void setAspectRatio(float aspectRatio);
float getAspectRatio() const;
void setOrientation(ScalarBar::Orientation orientation);
ScalarBar::Orientation getOrientation() const;
void setScalarPrinter(ScalarPrinter* sp);
const ScalarPrinter* getScalarPrinter() const;
void setTextProperties(const TextProperties& tp);
const TextProperties& getTextProperties() const;
void update() { createDrawables(); }
protected:
virtual ~ScalarBar();
int _numColors;
int _numLabels;
osg::ref_ptr<ScalarsToColors> _stc;
std::string _title;
osg::Vec3 _position;
float _width;
float _aspectRatio;
Orientation _orientation;
osg::ref_ptr<ScalarPrinter> _sp;
TextProperties _textProperties;
void createDrawables();
};
}
#endif
ColorRange
Geode
osgSim::ColorRange
Definition ColorRange:32
osgSim::ScalarBar::ScalarBar
ScalarBar()
Definition ScalarBar:87
osgSim::ScalarBar::ScalarBar
ScalarBar(int numColors, int numLabels, ScalarsToColors *stc, const std::string &title, Orientation orientation=HORIZONTAL, float aspectRatio=0.25, ScalarPrinter *sp=new ScalarPrinter)
Definition ScalarBar:119
osgSim::ScalarBar::getNumLabels
int getNumLabels() const
osgSim::ScalarBar::_width
float _width
Definition ScalarBar:236
osgSim::ScalarBar::createDrawables
void createDrawables()
osgSim::ScalarBar::_textProperties
TextProperties _textProperties
Definition ScalarBar:240
osgSim::ScalarBar::getScalarPrinter
const ScalarPrinter * getScalarPrinter() const
osgSim::ScalarBar::setAspectRatio
void setAspectRatio(float aspectRatio)
osgSim::ScalarBar::getAspectRatio
float getAspectRatio() const
osgSim::ScalarBar::getTextProperties
const TextProperties & getTextProperties() const
osgSim::ScalarBar::getOrientation
ScalarBar::Orientation getOrientation() const
osgSim::ScalarBar::setTextProperties
void setTextProperties(const TextProperties &tp)
osgSim::ScalarBar::getNumColors
int getNumColors() const
osgSim::ScalarBar::_aspectRatio
float _aspectRatio
Definition ScalarBar:237
osgSim::ScalarBar::getWidth
float getWidth() const
Definition ScalarBar:193
osgSim::ScalarBar::META_Node
META_Node(osgSim, ScalarBar)
osgSim::ScalarBar::setTitle
void setTitle(const std::string &title)
osgSim::ScalarBar::_numColors
int _numColors
Definition ScalarBar:231
osgSim::ScalarBar::_sp
osg::ref_ptr< ScalarPrinter > _sp
Definition ScalarBar:239
osgSim::ScalarBar::_title
std::string _title
Definition ScalarBar:234
osgSim::ScalarBar::Orientation
Orientation
Definition ScalarBar:49
osgSim::ScalarBar::VERTICAL
@ VERTICAL
a vertically ascending scalar bar (y-axis)
Definition ScalarBar:51
osgSim::ScalarBar::HORIZONTAL
@ HORIZONTAL
a horizontally ascending scalar bar (x-axis)
Definition ScalarBar:50
osgSim::ScalarBar::~ScalarBar
virtual ~ScalarBar()
osgSim::ScalarBar::getTitle
const std::string & getTitle() const
osgSim::ScalarBar::setOrientation
void setOrientation(ScalarBar::Orientation orientation)
osgSim::ScalarBar::getScalarsToColors
const ScalarsToColors * getScalarsToColors() const
osgSim::ScalarBar::getPosition
const osg::Vec3 & getPosition() const
Definition ScalarBar:187
osgSim::ScalarBar::setScalarPrinter
void setScalarPrinter(ScalarPrinter *sp)
osgSim::ScalarBar::_position
osg::Vec3 _position
Definition ScalarBar:235
osgSim::ScalarBar::setWidth
void setWidth(float width)
osgSim::ScalarBar::setScalarsToColors
void setScalarsToColors(ScalarsToColors *stc)
osgSim::ScalarBar::_numLabels
int _numLabels
Definition ScalarBar:232
osgSim::ScalarBar::setNumColors
void setNumColors(int numColors)
osgSim::ScalarBar::setNumLabels
void setNumLabels(int numLabels)
osgSim::ScalarBar::ScalarBar
ScalarBar(const ScalarBar &rhs, const osg::CopyOp &co)
Definition ScalarBar:139
osgSim::ScalarBar::setPosition
void setPosition(const osg::Vec3 &pos)
osgSim::ScalarBar::update
void update()
Definition ScalarBar:226
osgSim::ScalarBar::_stc
osg::ref_ptr< ScalarsToColors > _stc
Definition ScalarBar:233
osgSim::ScalarBar::_orientation
Orientation _orientation
Definition ScalarBar:238
osgSim::ScalarsToColors
Definition ScalarsToColors:31
osg::CopyOp
Definition CopyOp:41
osg::Geode
Definition Geode:29
osg::Geode::Geode
Geode()
osg::Referenced
Definition Referenced:44
osg::ref_ptr
Definition ref_ptr:32
osgSim
Definition BlinkSequence:27
osg
Definition AlphaFunc:19
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::Vec4
Vec4f Vec4
Definition Vec4:21
Export
OSGSIM_EXPORT
#define OSGSIM_EXPORT
Definition osgSim/Export:38
osgSim::ScalarBar::ScalarPrinter
Definition ScalarBar:60
osgSim::ScalarBar::ScalarPrinter::printScalar
virtual std::string printScalar(float scalar)
osgSim::ScalarBar::TextProperties
Definition ScalarBar:71
osgSim::ScalarBar::TextProperties::_color
osg::Vec4 _color
Definition ScalarBar:75
osgSim::ScalarBar::TextProperties::_fontFile
std::string _fontFile
Definition ScalarBar:72
osgSim::ScalarBar::TextProperties::_fontResolution
std::pair< int, int > _fontResolution
Definition ScalarBar:73
osgSim::ScalarBar::TextProperties::TextProperties
TextProperties()
Definition ScalarBar:77
osgSim::ScalarBar::TextProperties::_characterSize
float _characterSize
Definition ScalarBar:74