OpenSceneGraph 3.6.5
ScalarBar
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGSIM_SCALARBAR
15#define OSGSIM_SCALARBAR 1
16
17#include <osgSim/Export>
18#include <osgSim/ColorRange> // The default ScalarsToColors is a ColorRange
19#include <osg/Geode>
20#include <string>
21
22namespace osgSim
23{
44{
45
46public:
47
53
60 {
61 virtual std::string printScalar(float scalar);
62 };
63
71 {
72 std::string _fontFile;
73 std::pair<int,int> _fontResolution;
76
78 _fontFile("fonts/arial.ttf"),
79 _fontResolution(40,40),
80 _characterSize(0.0f),
81 _color(1.0f,1.0f,1.0f,1.0f)
82 {
83 }
84 };
85
88 _numColors(256),
89 _numLabels(11),
90 _stc(new ColorRange(0.0f,1.0f)),
91 _title("Scalar Bar"),
92 _position(0.0f,0.0f,0.0f),
93 _width(1.0f),
94 _aspectRatio(0.03),
97 {
99 }
100
119 ScalarBar(int numColors, int numLabels, ScalarsToColors* stc,
120 const std::string& title,
121 Orientation orientation = HORIZONTAL,
122 float aspectRatio=0.25,
124 osg::Geode(),
125 _numColors(numColors),
126 _numLabels(numLabels),
127 _stc(stc),
128 _title(title),
129 _position(0.0f,0.0f,0.0f),
130 _width(1.0f),
131 _aspectRatio(aspectRatio),
132 _orientation(orientation),
133 _sp(sp)
134 {
136 }
137
139 ScalarBar(const ScalarBar& rhs, const osg::CopyOp& co): osg::Geode(rhs,co),
142 _stc(rhs._stc), // Consider clone for deep copy?
143 _title(rhs._title),
144 _position(rhs._position),
145 _width(rhs._width),
148 _sp(rhs._sp), // Consider clone for deep copy?
150 {
151 }
152
153
155
157 void setNumColors(int numColors);
158
160 int getNumColors() const;
161
165 void setNumLabels(int numLabels);
166
168 int getNumLabels() const;
169
172
175
177 void setTitle(const std::string& title);
178
180 const std::string& getTitle() const;
181
182
184 void setPosition(const osg::Vec3& pos);
185
187 const osg::Vec3& getPosition() const { return _position; }
188
190 void setWidth(float width);
191
193 float getWidth() const { return _width; }
194
197 void setAspectRatio(float aspectRatio);
198
200 float getAspectRatio() const;
201
202
205
208
209
215
218
221
224
227
228protected:
229 virtual ~ScalarBar();
230
234 std::string _title;
236 float _width;
241
243
244};
245
246}
247
248#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
Vec3f Vec3
Definition Vec3:21
Vec4f Vec4
Definition Vec4:21
The osgSim library is a NodeKit that extends the core scene graph to support nodes and drawables that...
Definition BlinkSequence:27
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
A Geode is a "geometry node", that is, a leaf node on the scene graph that can have "renderable thing...
Definition Geode:29
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Base class for providing reference counted objects.
Definition Referenced:44
ColorRange is a ScalarsToColors object to define a color spectrum for a scalar range.
Definition ColorRange:32
ScalarBar()
Default constructor.
Definition ScalarBar:87
ScalarBar(int numColors, int numLabels, ScalarsToColors *stc, const std::string &title, Orientation orientation=HORIZONTAL, float aspectRatio=0.25, ScalarPrinter *sp=new ScalarPrinter)
Construct a ScalarBar with the supplied parameters.
Definition ScalarBar:119
int getNumLabels() const
Get the number of labels displayed along the ScalarBar.
float _width
Definition ScalarBar:236
TextProperties _textProperties
Definition ScalarBar:240
const ScalarPrinter * getScalarPrinter() const
Get the ScalarPrinter object.
void setAspectRatio(float aspectRatio)
Set the aspect ration (y/x) for the displayed bar.
float getAspectRatio() const
Get the aspect ration (y/x) for the displayed bar.
const TextProperties & getTextProperties() const
Get the TextProperties for the labels & title.
ScalarBar::Orientation getOrientation() const
Get the orientation of the ScalarBar.
void setTextProperties(const TextProperties &tp)
Set the TextProperties for the labels & title.
int getNumColors() const
Get the number of distinct colours on the ScalarBar.
float _aspectRatio
Definition ScalarBar:237
float getWidth() const
Get the width of the scalar bar.
Definition ScalarBar:193
META_Node(osgSim, ScalarBar)
void setTitle(const std::string &title)
Set the title for the ScalarBar, set "" for no title.
int _numColors
Definition ScalarBar:231
osg::ref_ptr< ScalarPrinter > _sp
Definition ScalarBar:239
std::string _title
Definition ScalarBar:234
Orientation
ScalarBar orientation specification.
Definition ScalarBar:49
@ VERTICAL
a vertically ascending scalar bar (y-axis)
Definition ScalarBar:51
@ HORIZONTAL
a horizontally ascending scalar bar (x-axis)
Definition ScalarBar:50
virtual ~ScalarBar()
const std::string & getTitle() const
Get the title for the ScalarBar.
void setOrientation(ScalarBar::Orientation orientation)
Set the orientation of the ScalarBar.
const ScalarsToColors * getScalarsToColors() const
Get the ScalarsToColors mapping object from the ScalarBar.
const osg::Vec3 & getPosition() const
Get the position of scalar bar.
Definition ScalarBar:187
void setScalarPrinter(ScalarPrinter *sp)
Set a ScalarPrinter object for the ScalarBar.
osg::Vec3 _position
Definition ScalarBar:235
void setWidth(float width)
Set the width of the scalar bar.
void setScalarsToColors(ScalarsToColors *stc)
Set the ScalarsToColors mapping object for the ScalarBar.
int _numLabels
Definition ScalarBar:232
void setNumColors(int numColors)
Set the number of distinct colours on the ScalarBar.
void setNumLabels(int numLabels)
Set the number of labels to display along the ScalarBar.
ScalarBar(const ScalarBar &rhs, const osg::CopyOp &co)
Copy constructor.
Definition ScalarBar:139
void setPosition(const osg::Vec3 &pos)
Set the position of scalar bar's lower left corner.
void update()
force update the drawables used to render the scalar bar.
Definition ScalarBar:226
osg::ref_ptr< ScalarsToColors > _stc
Definition ScalarBar:233
Orientation _orientation
Definition ScalarBar:238
Users may provide their own ScalarPrinter by deriving from this base class and overriding the printSc...
Definition ScalarBar:60
virtual std::string printScalar(float scalar)
TextProperties allows users to specify a number of properties for the text used to display the labels...
Definition ScalarBar:71
osg::Vec4 _color
Definition ScalarBar:75
std::string _fontFile
Definition ScalarBar:72
std::pair< int, int > _fontResolution
Definition ScalarBar:73
TextProperties()
Definition ScalarBar:77
float _characterSize
Definition ScalarBar:74
ScalarsToColors defines the interface to map a scalar value to a color, and provides a default implem...
Definition ScalarsToColors:31
#define OSGSIM_EXPORT
Definition Export:38

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.