35 m_color(255, 255, 255, 255),
42 CRenderizable::~CRenderizable() =
default;
44 void CRenderizable::writeToStreamRender(
58 const uint8_t serialization_version = 1;
60 const bool all_scales_equal =
61 (m_scale_x == m_scale_y && m_scale_z == m_scale_x);
62 const bool all_scales_unity = (all_scales_equal && m_scale_x == 1.0f);
64 const uint8_t magic_signature[2] = {
70 serialization_version |
71 (all_scales_unity ? 0xC0 : (all_scales_equal ? 0xA0 : 0x80)))};
73 out << magic_signature[0] << magic_signature[1];
76 const auto nameLen =
static_cast<uint16_t
>(m_name.size());
78 if (nameLen)
out.WriteBuffer(m_name.c_str(), m_name.size());
81 out << m_color.R << m_color.G << m_color.B << m_color.A;
84 out << (float)m_pose.x() << (float)m_pose.y() << (float)m_pose.z()
85 << (float)m_pose.yaw() << (float)m_pose.pitch() << (float)m_pose.roll();
87 if (!all_scales_unity)
92 out << m_scale_x << m_scale_y << m_scale_z;
95 out << m_show_name << m_visible;
96 out << m_representativePoint;
114 uint8_t magic_signature[2];
116 in >> magic_signature[0] >> magic_signature[1];
118 const bool is_new_format =
119 (magic_signature[0] == 0xFF) && ((magic_signature[1] & 0x80) != 0);
124 uint8_t serialization_version = (magic_signature[1] & 0x1F);
125 const bool all_scales_unity = ((magic_signature[1] & 0x40) != 0);
126 const bool all_scales_equal_but_not_unity =
127 ((magic_signature[1] & 0x20) != 0);
129 switch (serialization_version)
137 m_name.resize(nameLen);
138 if (nameLen) in.
ReadBuffer((
void*)(&m_name[0]), m_name.size());
141 in >> m_color.R >> m_color.G >> m_color.B >> m_color.A;
145 in >> x >> y >> z >> yaw >>
pitch >>
roll;
149 m_pose.setYawPitchRoll(yaw,
pitch,
roll);
151 if (all_scales_unity)
152 m_scale_x = m_scale_y = m_scale_z = 1;
155 if (all_scales_equal_but_not_unity)
158 m_scale_y = m_scale_z = m_scale_x;
161 in >> m_scale_x >> m_scale_y >> m_scale_z;
164 in >> m_show_name >> m_visible;
165 if (serialization_version >= 1)
166 in >> m_representativePoint;
173 "Can't parse CRenderizable standard data field: corrupt " 174 "data stream or format in a newer MRPT format? " 175 "(serialization version=%u)",
176 static_cast<unsigned int>(serialization_version));
213 m_pose.setFromValues(o.
x(), o.
y(), o.z(), 0, 0, 0);
219 m_pose.setFromValues(o.
x(), o.
y(), 0, 0, 0, 0);
238 CText& CRenderizable::labelObject()
const 242 m_label_obj = std::make_shared<mrpt::opengl::CText>();
A 2D text (bitmap rendering): it always "faces the observer" despite it's at some 3D location...
#define IMPLEMENTS_VIRTUAL_SERIALIZABLE(class_name, base_class, NS)
This must be inserted as implementation of some required members for virtual CSerializable classes: ...
#define THROW_EXCEPTION(msg)
bool traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::math::TPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
The base class of 3D objects that can be directly rendered through OpenGL.
double x() const
Common members of all points & poses classes.
A class used to store a 2D point.
A class used to store a 3D point.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
mrpt::vision::TStereoCalibResults out
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
The namespace for 3D scene representation and rendering.
size_t ReadBuffer(void *Buffer, size_t Count)
Reads a block of bytes from the stream into Buffer.
TPoint3D_< float > TPoint3Df
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
void setString(const std::string &s)
Sets the text to display.