| 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/CSimpleLine.h> |
| 13 |
#include <mrpt/opengl/opengl_api.h> |
| 14 |
#include <mrpt/serialization/CArchive.h> |
| 15 |
|
| 16 |
using namespace mrpt; |
| 17 |
using namespace mrpt::opengl; |
| 18 |
using namespace mrpt::math; |
| 19 |
using namespace std; |
| 20 |
|
| 21 |
IMPLEMENTS_SERIALIZABLE(CSimpleLine, CRenderizableShaderWireFrame, mrpt::opengl) |
| 22 |
|
| 23 |
CSimpleLine::CSimpleLine( |
| 24 |
float x0, |
| 25 |
float y0, |
| 26 |
float z0, |
| 27 |
float x1, |
| 28 |
float y1, |
| 29 |
float z1, |
| 30 |
float lineWidth, |
| 31 |
bool antiAliasing) : |
| 32 |
m_x0(x0), m_y0(y0), m_z0(z0), m_x1(x1), m_y1(y1), m_z1(z1) |
| 33 |
{ |
| 34 |
m_lineWidth = lineWidth; |
| 35 |
m_antiAliasing = antiAliasing; |
| 36 |
} |
| 37 |
|
| 38 |
void CSimpleLine::onUpdateBuffers_Wireframe() |
| 39 |
{ |
| 40 |
auto& vbd = CRenderizableShaderWireFrame::m_vertex_buffer_data; |
| 41 |
std::unique_lock<std::shared_mutex> wfWriteLock( |
| 42 |
CRenderizableShaderWireFrame::m_wireframeMtx.data); |
| 43 |
|
| 44 |
vbd.resize(2); |
| 45 |
|
| 46 |
vbd[0] = {m_x0, m_y0, m_z0}; |
| 47 |
vbd[1] = {m_x1, m_y1, m_z1}; |
| 48 |
|
| 49 |
// The same color to all vertices: |
| 50 |
m_color_buffer_data.assign(vbd.size(), getColor_u8()); |
| 51 |
} |
| 52 |
|
| 53 |
uint8_t CSimpleLine::serializeGetVersion() const { return 1; } |
| 54 |
void CSimpleLine::serializeTo(mrpt::serialization::CArchive& out) const |
| 55 |
{ |
| 56 |
writeToStreamRender(out); |
| 57 |
out << m_x0 << m_y0 << m_z0; |
| 58 |
out << m_x1 << m_y1 << m_z1 << m_lineWidth; |
| 59 |
out << m_antiAliasing; // Added in v1 |
| 60 |
} |
| 61 |
|
| 62 |
void CSimpleLine::serializeFrom(mrpt::serialization::CArchive& in, uint8_t version) |
| 63 |
{ |
| 64 |
switch (version) |
| 65 |
{ |
| 66 |
case 1: |
| 67 |
{ |
| 68 |
readFromStreamRender(in); |
| 69 |
in >> m_x0 >> m_y0 >> m_z0; |
| 70 |
in >> m_x1 >> m_y1 >> m_z1 >> m_lineWidth; |
| 71 |
if (version >= 1) |
| 72 |
in >> m_antiAliasing; |
| 73 |
else |
| 74 |
m_antiAliasing = true; |
| 75 |
} |
| 76 |
break; |
| 77 |
default: |
| 78 |
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version); |
| 79 |
}; |
| 80 |
CRenderizable::notifyChange(); |
| 81 |
} |
| 82 |
|
| 83 |
auto CSimpleLine::internalBoundingBoxLocal() const -> mrpt::math::TBoundingBoxf |
| 84 |
{ |
| 85 |
return mrpt::math::TBoundingBoxf::FromUnsortedPoints( |
| 86 |
{std::min(m_x0, m_x1), std::min(m_y0, m_y1), std::min(m_z0, m_z1)}, |
| 87 |
{std::max(m_x0, m_x1), std::max(m_y0, m_y1), std::max(m_z0, m_z1)}); |
| 88 |
} |