Debian Codegraph @

libs/opengl/src/CGridPlaneXZ.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/CGridPlaneXZ.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(CGridPlaneXZ, CRenderizableShaderWireFrame, mrpt::opengl)
20
21 /** Constructor */
22 CGridPlaneXZ::CGridPlaneXZ(
23 float xMin,
24 float xMax,
25 float zMin,
26 float zMax,
27 float y,
28 float frequency,
29 float lineWidth,
30 bool antiAliasing) :
31 m_xMin(xMin), m_xMax(xMax), m_zMin(zMin), m_zMax(zMax), m_plane_y(y), m_frequency(frequency)
32 {
33 m_lineWidth = lineWidth;
34 m_antiAliasing = antiAliasing;
35 }
36
37 void CGridPlaneXZ::onUpdateBuffers_Wireframe()
38 {
39 std::unique_lock<std::shared_mutex> wfWriteLock(
40 CRenderizableShaderWireFrame::m_wireframeMtx.data);
41
42 // Generate vertices:
43 m_vertex_buffer_data.clear();
44 m_color_buffer_data.clear();
45
46 for (float z = m_zMin; z <= m_zMax; z += m_frequency)
47 {
48 m_vertex_buffer_data.emplace_back(m_xMin, m_plane_y, z);
49 m_vertex_buffer_data.emplace_back(m_xMax, m_plane_y, 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_plane_y, m_zMin);
55 m_vertex_buffer_data.emplace_back(x, m_plane_y, m_zMax);
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 CGridPlaneXZ::serializeGetVersion() const { return 1; }
62 void CGridPlaneXZ::serializeTo(mrpt::serialization::CArchive& out) const
63 {
64 writeToStreamRender(out);
65 out << m_xMin << m_xMax;
66 out << m_zMin << m_zMax << m_plane_y;
67 out << m_frequency;
68 out << m_lineWidth << m_antiAliasing; // v1
69 }
70
71 void CGridPlaneXZ::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_zMin >> m_zMax >> m_plane_y;
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 CGridPlaneXZ::internalBoundingBoxLocal() const -> mrpt::math::TBoundingBoxf
98 {
99 return mrpt::math::TBoundingBoxf::FromUnsortedPoints({m_xMin, 0, m_zMin}, {m_xMax, 0, m_zMax});
100 }