MRPT  2.0.2
CText3D.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "opengl-precomp.h" // Precompiled header
11 
12 #include <mrpt/opengl/CText3D.h>
14 
15 #include "gltext.h"
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 using namespace std;
20 
22 
24  const std::string& str, const std::string& fontName, const float scale,
25  const mrpt::opengl::TOpenGLFontStyle text_style, const double text_spacing,
26  const double text_kerning)
27  : m_str(str),
28  m_fontName(fontName),
29  m_text_style(text_style),
30  m_text_spacing(text_spacing),
31  m_text_kerning(text_kerning)
32 {
33  this->setScale(scale);
34 }
35 
36 CText3D::~CText3D() = default;
37 
39 {
43  vbd.clear();
44  tris.clear();
45  cbd.clear();
46 
49  m_str, tris, vbd, m_text_style, m_text_spacing, m_text_kerning);
50 
51  // All lines & triangles, the same color:
52  cbd.assign(vbd.size(), m_color);
53  for (auto& tri : m_triangles) tri.setColor(m_color);
54 }
55 
56 uint8_t CText3D::serializeGetVersion() const { return 0; }
58 {
59  writeToStreamRender(out);
60  out << m_str << m_fontName << (uint32_t)m_text_style << m_text_spacing
61  << m_text_kerning;
62 }
63 
65 {
66  switch (version)
67  {
68  case 0:
69  {
70  readFromStreamRender(in);
71 
72  uint32_t i;
73  in >> m_str >> m_fontName >> i >> m_text_spacing >> m_text_kerning;
74 
75  m_text_style = TOpenGLFontStyle(i);
76  }
77  break;
78  default:
80  };
82 }
83 
86 {
87  bb_min.x = 0;
88  bb_min.y = 0;
89  bb_min.z = 0;
90 
91  bb_max.x = m_str.size() * m_scale_x;
92  bb_max.y = 1;
93  bb_max.z = 0;
94 
95  // Convert to coordinates of my parent:
96  m_pose.composePoint(bb_min, bb_min);
97  m_pose.composePoint(bb_max, bb_max);
98 }
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CText3D.cpp:56
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
STL namespace.
void onUpdateBuffers_Text() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CText3D.cpp:38
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
TOpenGLFontStyle
Different style for vectorized font rendering.
Definition: opengl_fonts.h:19
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CText3D.cpp:57
std::pair< double, double > glDrawText(const std::string &text, std::vector< mrpt::opengl::TTriangle > &tris, std::vector< mrpt::math::TPoint3Df > &render_lines, TEXT_STYLE style, double spacing, double kerning)
renders a string in GL using the current settings.
Definition: gltext.cpp:153
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
List of lines.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::vision::TStereoCalibResults out
void glSetFont(const std::string &fontname)
sets the font to use for future font rendering commands.
Definition: gltext.cpp:146
A 3D text (rendered with OpenGL primitives), with selectable font face and drawing style...
Definition: CText3D.h:42
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
const auto bb_max
std::vector< mrpt::opengl::TTriangle > m_triangles
List of triangles.
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
Definition: CText3D.cpp:84
const auto bb_min
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CText3D.cpp:64
std::vector< mrpt::img::TColor > m_color_buffer_data



Page generated by Doxygen 1.8.14 for MRPT 2.0.2 Git: 9b4fd2465 Mon May 4 16:59:08 2020 +0200 at lun may 4 17:26:07 CEST 2020