Debian Codegraph @

libs/opengl/src/CGridPlaneXY.cpp

raw
1 /* +------------------------------------------------------------------------+
2 | Mobile Robot Programming Toolkit (MRPT) |
3 | https://www.mrpt.org/ |
4 | |
5 | Copyright (c) 2005-2026, 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/CGridPlaneXY.h>
13 #include <mrpt/serialization/CArchive.h>
14
15 using namespace mrpt;
16 using namespace mrpt::opengl;
17 using namespace std;
18
19 IMPLEMENTS_SERIALIZABLE(CGridPlaneXY, CRenderizableShaderWireFrame, mrpt::opengl)
20
21 /** Constructor */
22 CGridPlaneXY::CGridPlaneXY(
23 float xMin,
24 float xMax,
25 float yMin,
26 float yMax,
27 float z,
28 float frequency,
29 float lineWidth,
30 bool antiAliasing) :
31 m_xMin(xMin), m_xMax(xMax), m_yMin(yMin), m_yMax(yMax), m_plane_z(z), m_frequency(frequency)
32 {
33 m_lineWidth = lineWidth;
34 m_antiAliasing = antiAliasing;
35 }
36
37 void CGridPlaneXY::onUpdateBuffers_Wireframe()
38 {
39 ASSERT_GT_(m_frequency, 0);
40
41 m_vertex_buffer_data.clear();
42 m_color_buffer_data.clear();
43 std::unique_lock<std::shared_mutex> wfWriteLock(
44 CRenderizableShaderWireFrame::m_wireframeMtx.data);
45
46 for (float y = m_yMin; y <= m_yMax; y += m_frequency)
47 {
48 m_vertex_buffer_data.emplace_back(m_xMin, y, m_plane_z);
49 m_vertex_buffer_data.emplace_back(m_xMax, y, m_plane_z);
50 }
51
52 for (float x = m_xMin; x <= m_xMax; x += m_frequency)
53 {
54 m_vertex_buffer_data.emplace_back(x, m_yMin, m_plane_z);
55 m_vertex_buffer_data.emplace_back(x, m_yMax, m_plane_z);
56 }
57 // The same color to all vertices:
58 m_color_buffer_data.assign(m_vertex_buffer_data.size(), getColor_u8());
59 }
60
61 uint8_t CGridPlaneXY::serializeGetVersion() const { return 1; }
62 void CGridPlaneXY::serializeTo(mrpt::serialization::CArchive& out) const
63 {
64 writeToStreamRender(out);
65 out << m_xMin << m_xMax;
66 out << m_yMin << m_yMax << m_plane_z;
67 out << m_frequency;
68 out << m_lineWidth << m_antiAliasing; // v1
69 }
70
71 void CGridPlaneXY::serializeFrom(mrpt::serialization::CArchive& in, uint8_t version)
72 {
73 switch (version)
74 {
75 case 0:
76 case 1:
77 {
78 readFromStreamRender(in);
79 in >> m_xMin >> m_xMax;
80 in >> m_yMin >> m_yMax >> m_plane_z;
81 in >> m_frequency;
82 if (version >= 1)
83 in >> m_lineWidth >> m_antiAliasing;
84 else
85 {
86 m_lineWidth = 1.0f;
87 m_antiAliasing = true;
88 }
89 }
90 break;
91 default:
92 MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version);
93 };
94 CRenderizable::notifyChange();
95 }
96
97 auto CGridPlaneXY::internalBoundingBoxLocal() const -> mrpt::math::TBoundingBoxf
98 {
99 return mrpt::math::TBoundingBoxf::FromUnsortedPoints({m_xMin, m_yMin, 0}, {m_xMax, m_yMax, 0});
100 }