OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScalarBar.h
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 
22 namespace osgSim
23 {
44 {
45 
46 public:
47 
51  VERTICAL
52  };
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 
87  ScalarBar(): osg::Geode(),
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),
95  _orientation(HORIZONTAL),
96  _sp(new ScalarPrinter)
97  {
98  createDrawables();
99  }
100 
119  ScalarBar(int numColors, int numLabels, ScalarsToColors* stc,
120  const std::string& title,
121  Orientation orientation = HORIZONTAL,
122  float aspectRatio=0.25,
123  ScalarPrinter* sp=new ScalarPrinter):
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  {
135  createDrawables();
136  }
137 
139  ScalarBar(const ScalarBar& rhs, const osg::CopyOp& co): osg::Geode(rhs,co),
140  _numColors(rhs._numColors),
141  _numLabels(rhs._numLabels),
142  _stc(rhs._stc), // Consider clone for deep copy?
143  _title(rhs._title),
144  _position(rhs._position),
145  _width(rhs._width),
146  _aspectRatio(rhs._aspectRatio),
147  _orientation(rhs._orientation),
148  _sp(rhs._sp), // Consider clone for deep copy?
149  _textProperties(rhs._textProperties)
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 
171  void setScalarsToColors(ScalarsToColors* stc);
172 
174  const ScalarsToColors* getScalarsToColors() const;
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 
204  void setOrientation(ScalarBar::Orientation orientation);
205 
207  ScalarBar::Orientation getOrientation() const;
208 
209 
214  void setScalarPrinter(ScalarPrinter* sp);
215 
217  const ScalarPrinter* getScalarPrinter() const;
218 
220  void setTextProperties(const TextProperties& tp);
221 
223  const TextProperties& getTextProperties() const;
224 
226  void update() { createDrawables(); }
227 
228 protected:
229  virtual ~ScalarBar();
230 
234  std::string _title;
236  float _width;
241 
242  void createDrawables();
243 
244 };
245 
246 }
247 
248 #endif
std::string _title
Definition: ScalarBar.h:234
#define OSGSIM_EXPORT
Definition: Export.h:38
TextProperties _textProperties
Definition: ScalarBar.h:240
ScalarBar(int numColors, int numLabels, ScalarsToColors *stc, const std::string &title, Orientation orientation=HORIZONTAL, float aspectRatio=0.25, ScalarPrinter *sp=new ScalarPrinter)
Definition: ScalarBar.h:119
#define META_Node(library, name)
Definition: Node.h:59
std::pair< int, int > _fontResolution
Definition: ScalarBar.h:73
GLint GLenum GLsizei width
Definition: GLU.h:71
osg::ref_ptr< ScalarPrinter > _sp
Definition: ScalarBar.h:239
const osg::Vec3 & getPosition() const
Definition: ScalarBar.h:187
float getWidth() const
Definition: ScalarBar.h:193
ScalarBar(const ScalarBar &rhs, const osg::CopyOp &co)
Definition: ScalarBar.h:139
Definition: AlphaFunc.h:19
a horizontally ascending scalar bar (x-axis)
Definition: ScalarBar.h:50
osg::ref_ptr< ScalarsToColors > _stc
Definition: ScalarBar.h:233
osg::Vec3 _position
Definition: ScalarBar.h:235
Orientation _orientation
Definition: ScalarBar.h:238