OsgTextRepresentation.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_GRAPHICS_OSGTEXTREPRESENTATION_H
17 #define SURGSIM_GRAPHICS_OSGTEXTREPRESENTATION_H
18 
19 #include <string>
20 
24 
25 #include <osg/Vec3>
26 #include <boost/thread/mutex.hpp>
27 
28 #if defined(_MSC_VER)
29 #pragma warning(push)
30 #pragma warning(disable:4250)
31 #endif
32 
33 namespace osg
34 {
35 class Geode;
36 }
37 
38 namespace osgText
39 {
40 class Text;
41 }
42 
43 namespace SurgSim
44 {
45 namespace Framework
46 {
47 class Asset;
48 }
49 namespace Graphics
50 {
51 class OsgFont;
52 
53 SURGSIM_STATIC_REGISTRATION(OsgTextRepresentation);
54 
57 {
58 public:
61  explicit OsgTextRepresentation(const std::string& name);
62 
65 
66  friend class OsgTextRepresentationTests_MaximumWidth_Test;
67 
69 
70  void setLocation(double x, double y) override;
71  void getLocation(double* x, double* y) const override;
72 
73  void setMaximumWidth(double width) override;
74  double getMaximumWidth() override;
75 
76  void setText(const std::string& text) override;
77  std::string getText() const override;
78 
79  void loadFont(const std::string& fileName) override;
80  void setFont(std::shared_ptr<SurgSim::Framework::Asset> font) override;
81  std::shared_ptr<Font> getFont() const override;
82 
83  void setColor(SurgSim::Math::Vector4d color) override;
84  SurgSim::Math::Vector4d getColor() const override;
85 
86  void setFontSize(double size) override;
87  double getFontSize() const override;
88 
89  void setUseScreenSpace(bool value) override;
90  bool isUsingScreenSpace() const override;
91 
92  enum Anchor
93  {
95  ANCHOR_CENTER
96  };
97 
98  void setAnchor(int anchor);
99  int getAnchor() const;
100 
101  void setDrawBackground(bool value) override;
102  bool isDrawingBackground() const override;
103 
104  void setBackgroundColor(Math::Vector4d color) override;
105  Math::Vector4d getBackgroundColor() override;
106 
107  void setBackgroundMargin(double margin) override;
108  double getBackgroundMargin() const override;
109 
110 protected:
111  void doUpdate(double dt) override;
112  bool doInitialize() override;
113 
114  void setOptionalMaximumWidth(SurgSim::DataStructures::OptionalValue<double> maximum) override;
115  SurgSim::DataStructures::OptionalValue<double> getOptionalMaximumWidth() override;
116 
117 private:
118  osg::ref_ptr<osg::Geode> m_geode;
119  osg::ref_ptr<osgText::Text> m_textNode;
120 
121  std::string m_text;
122  std::shared_ptr<OsgFont> m_font;
124 
126 
127  boost::mutex m_parameterMutex;
129  int m_anchor;
130 
132 };
133 
134 }; // Graphics
135 }; // SurgSim
136 
137 #if defined(_MSC_VER)
138 #pragma warning(pop)
139 #endif
140 
141 #endif
osg::ref_ptr< osgText::Text > m_textNode
node for text display
Definition: OsgTextRepresentation.h:119
SurgSim::Math::Vector3d m_offset
Definition: OsgTextRepresentation.h:131
Definition: CompoundShapeToGraphics.cpp:29
std::string m_text
Text set by the user.
Definition: OsgTextRepresentation.h:121
SurgSim::DataStructures::OptionalValue< double > m_optionalWidth
information about the maximum width
Definition: OsgTextRepresentation.h:123
Anchor
Definition: OsgTextRepresentation.h:92
std::shared_ptr< OsgFont > m_font
font used for rendering
Definition: OsgTextRepresentation.h:122
#define SURGSIM_CLASSNAME(ClassName)
Declare the class name of a class with the appropriate function header, do not use quotes...
Definition: Macros.h:21
osg::ref_ptr< osg::Geode > m_geode
node used to render text
Definition: OsgTextRepresentation.h:118
double m_characterSize
the font height
Definition: OsgTextRepresentation.h:125
A text to be displayed on the screen in screen space coordinates, use setPose() to set the position b...
Definition: TextRepresentation.h:39
Definition: OsgTextRepresentation.h:94
int m_anchor
Definition: OsgTextRepresentation.h:129
Definition: OsgFont.h:23
boost::mutex m_parameterMutex
protect changes of parameters
Definition: OsgTextRepresentation.h:127
Definition: OculusView.h:25
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:61
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
bool m_needUpdate
indicate whether parameters need to be updated
Definition: OsgTextRepresentation.h:128
Osg implementation of the TextRepresentation, to be used with OsgFont assets.
Definition: OsgTextRepresentation.h:56