| 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/CSetOfTexturedTriangles.h> |
| 13 |
#include <mrpt/opengl/opengl_api.h> |
| 14 |
#include <mrpt/serialization/CArchive.h> |
| 15 |
|
| 16 |
using namespace std; |
| 17 |
using namespace mrpt; |
| 18 |
using namespace mrpt::opengl; |
| 19 |
using namespace mrpt::math; |
| 20 |
|
| 21 |
IMPLEMENTS_SERIALIZABLE(CSetOfTexturedTriangles, CRenderizable, mrpt::opengl) |
| 22 |
|
| 23 |
void CSetOfTexturedTriangles::onUpdateBuffers_TexturedTriangles() |
| 24 |
{ |
| 25 |
// Nothing else to do: all data is already in m_triangles in my base class. |
| 26 |
} |
| 27 |
|
| 28 |
uint8_t CSetOfTexturedTriangles::serializeGetVersion() const { return 2; } |
| 29 |
void CSetOfTexturedTriangles::serializeTo(mrpt::serialization::CArchive& out) const |
| 30 |
{ |
| 31 |
std::shared_lock<std::shared_mutex> readLock(m_trianglesMtx.data); |
| 32 |
|
| 33 |
uint32_t n; |
| 34 |
|
| 35 |
writeToStreamRender(out); |
| 36 |
writeToStreamTexturedObject(out); |
| 37 |
|
| 38 |
n = (uint32_t)m_triangles.size(); |
| 39 |
|
| 40 |
out << n; |
| 41 |
|
| 42 |
for (uint32_t i = 0; i < n; i++) m_triangles[i].writeTo(out); |
| 43 |
} |
| 44 |
|
| 45 |
void CSetOfTexturedTriangles::serializeFrom(mrpt::serialization::CArchive& in, uint8_t version) |
| 46 |
{ |
| 47 |
std::unique_lock<std::shared_mutex> writeLock(m_trianglesMtx.data); |
| 48 |
|
| 49 |
switch (version) |
| 50 |
{ |
| 51 |
case 0: |
| 52 |
case 1: |
| 53 |
case 2: |
| 54 |
{ |
| 55 |
readFromStreamRender(in); |
| 56 |
if (version >= 2) |
| 57 |
{ |
| 58 |
readFromStreamTexturedObject(in); |
| 59 |
} |
| 60 |
else |
| 61 |
{ // Old version. |
| 62 |
THROW_EXCEPTION("deserializing old version not supported."); |
| 63 |
} |
| 64 |
|
| 65 |
uint32_t n; |
| 66 |
in >> n; |
| 67 |
m_triangles.resize(n); |
| 68 |
|
| 69 |
for (uint32_t i = 0; i < n; i++) m_triangles[i].readFrom(in); |
| 70 |
} |
| 71 |
break; |
| 72 |
default: |
| 73 |
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version); |
| 74 |
}; |
| 75 |
CRenderizable::notifyChange(); |
| 76 |
} |
| 77 |
|
| 78 |
bool CSetOfTexturedTriangles::traceRay( |
| 79 |
[[maybe_unused]] const mrpt::poses::CPose3D& o, [[maybe_unused]] double& dist) const |
| 80 |
{ |
| 81 |
throw std::runtime_error("TODO: TraceRay not implemented in CSetOfTexturedTriangles"); |
| 82 |
} |
| 83 |
|
| 84 |
auto CSetOfTexturedTriangles::internalBoundingBoxLocal() const -> mrpt::math::TBoundingBoxf |
| 85 |
{ |
| 86 |
return trianglesBoundingBox(); |
| 87 |
} |