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 
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  {
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;
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 
116 
117 private:
118  osg::ref_ptr<osg::Geode> m_geode;
119  osg::ref_ptr<osgText::Text> m_textNode;
120 
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
SurgSim::Graphics::OsgTextRepresentation::doUpdate
void doUpdate(double dt) override
Definition: OsgTextRepresentation.cpp:106
SurgSim::Graphics::OsgTextRepresentation::setBackgroundMargin
void setBackgroundMargin(double margin) override
Set the margin between background and text.
Definition: OsgTextRepresentation.cpp:216
SurgSim::Graphics::OsgTextRepresentation::m_textNode
osg::ref_ptr< osgText::Text > m_textNode
node for text display
Definition: OsgTextRepresentation.h:119
SurgSim::Graphics::OsgTextRepresentation::setBackgroundColor
void setBackgroundColor(Math::Vector4d color) override
Set the color of the background (if drawn)
Definition: OsgTextRepresentation.cpp:205
SurgSim::Graphics::OsgTextRepresentation::getFontSize
double getFontSize() const override
Definition: OsgTextRepresentation.cpp:277
SurgSim::Graphics::OsgTextRepresentation::setMaximumWidth
void setMaximumWidth(double width) override
Sets a maximum width to the text display, the text should be broken up into multiple lines if the it ...
Definition: OsgTextRepresentation.cpp:251
SurgSim::Graphics::OsgTextRepresentation::getOptionalMaximumWidth
SurgSim::DataStructures::OptionalValue< double > getOptionalMaximumWidth() override
Get the current status of the width.
Definition: OsgTextRepresentation.cpp:184
SurgSim::DataStructures::OptionalValue< double >
SurgSim::Graphics::OsgTextRepresentation::m_parameterMutex
boost::mutex m_parameterMutex
protect changes of parameters
Definition: OsgTextRepresentation.h:127
SurgSim::Graphics::OsgTextRepresentation::setOptionalMaximumWidth
void setOptionalMaximumWidth(SurgSim::DataStructures::OptionalValue< double > maximum) override
Optionally sets a maximum width to the text display, the text should be broken up into multiple lines...
Definition: OsgTextRepresentation.cpp:177
SurgSim::Graphics::OsgTextRepresentation::getFont
std::shared_ptr< Font > getFont() const override
Definition: OsgTextRepresentation.cpp:172
SurgSim::Graphics::OsgTextRepresentation::m_needUpdate
bool m_needUpdate
indicate whether parameters need to be updated
Definition: OsgTextRepresentation.h:128
SurgSim::Graphics::OsgTextRepresentation::getText
std::string getText() const override
Definition: OsgTextRepresentation.cpp:101
SurgSim::Graphics::OsgTextRepresentation::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgTextRepresentation)
SurgSim::Graphics::OsgTextRepresentation::getAnchor
int getAnchor() const
SurgSim::Graphics::OsgTextRepresentation
Osg implementation of the TextRepresentation, to be used with OsgFont assets.
Definition: OsgTextRepresentation.h:56
osg
Definition: OculusView.h:25
SurgSim::Graphics::OsgTextRepresentation::setDrawBackground
void setDrawBackground(bool value) override
Draw a filled background behind the text.
Definition: OsgTextRepresentation.cpp:189
SurgSim::Graphics::OsgTextRepresentation::m_offset
SurgSim::Math::Vector3d m_offset
Definition: OsgTextRepresentation.h:131
OptionalValue.h
SurgSim::Graphics::OsgTextRepresentation::OsgTextRepresentationTests_MaximumWidth_Test
friend class OsgTextRepresentationTests_MaximumWidth_Test
Definition: OsgTextRepresentation.h:66
SurgSim::Math::Vector3d
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
SurgSim::Graphics::OsgTextRepresentation::m_optionalWidth
SurgSim::DataStructures::OptionalValue< double > m_optionalWidth
information about the maximum width
Definition: OsgTextRepresentation.h:123
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::OsgTextRepresentation::m_anchor
int m_anchor
Definition: OsgTextRepresentation.h:129
SurgSim::Graphics::OsgTextRepresentation::setAnchor
void setAnchor(int anchor)
SurgSim::Graphics::OsgTextRepresentation::setUseScreenSpace
void setUseScreenSpace(bool value) override
If set to true all the coordinate values are in screen-space coordinates (i.e.
Definition: OsgTextRepresentation.cpp:226
SurgSim::Graphics::OsgTextRepresentation::OsgTextRepresentation
OsgTextRepresentation(const std::string &name)
Constructor.
Definition: OsgTextRepresentation.cpp:43
SurgSim::Math::Vector4d
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:61
SurgSim::Graphics::OsgTextRepresentation::isDrawingBackground
bool isDrawingBackground() const override
Definition: OsgTextRepresentation.cpp:200
SurgSim::Graphics::OsgTextRepresentation::getBackgroundMargin
double getBackgroundMargin() const override
Definition: OsgTextRepresentation.cpp:221
SurgSim::Graphics::OsgTextRepresentation::loadFont
void loadFont(const std::string &fileName) override
Load the font with the given file name, this will overwrite the current font.
Definition: OsgTextRepresentation.cpp:149
SurgSim::Graphics::OsgTextRepresentation::~OsgTextRepresentation
~OsgTextRepresentation()
Destructor.
Definition: OsgTextRepresentation.cpp:76
SurgSim::Graphics::OsgTextRepresentation::getBackgroundColor
Math::Vector4d getBackgroundColor() override
Definition: OsgTextRepresentation.cpp:210
SurgSim::Graphics::TextRepresentation
A text to be displayed on the screen in screen space coordinates, use setPose() to set the position b...
Definition: TextRepresentation.h:39
SurgSim::Graphics::OsgTextRepresentation::getLocation
void getLocation(double *x, double *y) const override
Gets the location in screen space.
Definition: OsgTextRepresentation.cpp:85
SurgSim::Graphics::OsgTextRepresentation::getMaximumWidth
double getMaximumWidth() override
Definition: OsgTextRepresentation.cpp:265
SurgSim::Graphics::OsgTextRepresentation::m_geode
osg::ref_ptr< osg::Geode > m_geode
node used to render text
Definition: OsgTextRepresentation.h:118
SurgSim::Graphics::OsgTextRepresentation::setFontSize
void setFontSize(double size) override
Set the vertical size of the font.
Definition: OsgTextRepresentation.cpp:270
SurgSim::Graphics::OsgTextRepresentation::isUsingScreenSpace
bool isUsingScreenSpace() const override
Definition: OsgTextRepresentation.cpp:244
SurgSim::Graphics::OsgTextRepresentation::m_characterSize
double m_characterSize
the font height
Definition: OsgTextRepresentation.h:125
SurgSim::Graphics::OsgTextRepresentation::m_font
std::shared_ptr< OsgFont > m_font
font used for rendering
Definition: OsgTextRepresentation.h:122
SurgSim::Graphics::OsgTextRepresentation::setColor
void setColor(SurgSim::Math::Vector4d color) override
Set the color for the text.
Definition: OsgTextRepresentation.cpp:282
SurgSim::Graphics::OsgTextRepresentation::ANCHOR_TOP_LEFT
@ ANCHOR_TOP_LEFT
Definition: OsgTextRepresentation.h:94
SurgSim::Graphics::OsgTextRepresentation::getColor
SurgSim::Math::Vector4d getColor() const override
Definition: OsgTextRepresentation.cpp:287
SurgSim::Graphics::OsgTextRepresentation::setLocation
void setLocation(double x, double y) override
Sets the location in screen space.
Definition: OsgTextRepresentation.cpp:80
TextRepresentation.h
SurgSim::Graphics::OsgTextRepresentation::m_text
std::string m_text
Text set by the user.
Definition: OsgTextRepresentation.h:121
SurgSim::Graphics::OsgTextRepresentation::ANCHOR_CENTER
@ ANCHOR_CENTER
Definition: OsgTextRepresentation.h:95
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
osgText
Definition: OsgFont.h:23
SurgSim::Graphics::OsgTextRepresentation::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: OsgTextRepresentation.cpp:128
SurgSim::Graphics::OsgTextRepresentation::setFont
void setFont(std::shared_ptr< SurgSim::Framework::Asset > font) override
Replace the current font with the one passed.
Definition: OsgTextRepresentation.cpp:156
SurgSim::Graphics::OsgTextRepresentation::Anchor
Anchor
Definition: OsgTextRepresentation.h:92
OsgRepresentation.h
SurgSim::Graphics::OsgRepresentation
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55
SurgSim::Graphics::OsgTextRepresentation::setText
void setText(const std::string &text) override
Sets the text to be shown on the screen.
Definition: OsgTextRepresentation.cpp:94