| 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/containers/yaml.h> |
| 13 |
#include <mrpt/opengl/CCamera.h> |
| 14 |
#include <mrpt/opengl/opengl_api.h> |
| 15 |
#include <mrpt/serialization/CArchive.h> |
| 16 |
#include <mrpt/serialization/optional_serialization.h> |
| 17 |
|
| 18 |
using namespace mrpt; |
| 19 |
using namespace mrpt::opengl; |
| 20 |
using namespace mrpt::math; |
| 21 |
using namespace std; |
| 22 |
|
| 23 |
IMPLEMENTS_SERIALIZABLE(CCamera, CRenderizable, mrpt::opengl) |
| 24 |
|
| 25 |
uint8_t CCamera::serializeGetVersion() const { return 4; } |
| 26 |
void CCamera::serializeTo(mrpt::serialization::CArchive& out) const |
| 27 |
{ |
| 28 |
// Save data: |
| 29 |
out << m_pointingX << m_pointingY << m_pointingZ << m_eyeDistance << m_azimuthDeg |
| 30 |
<< m_elevationDeg << m_projectiveModel << m_projectiveFOVdeg; |
| 31 |
out << m_pinholeModel; // v2 |
| 32 |
out << m_useNoProjection; // v3 |
| 33 |
out << m_eyeRollDeg; // v4 |
| 34 |
} |
| 35 |
|
| 36 |
void CCamera::serializeFrom(mrpt::serialization::CArchive& in, uint8_t version) |
| 37 |
{ |
| 38 |
switch (version) |
| 39 |
{ |
| 40 |
case 1: |
| 41 |
case 2: |
| 42 |
case 3: |
| 43 |
case 4: |
| 44 |
{ |
| 45 |
// Load data: |
| 46 |
in >> m_pointingX >> m_pointingY >> m_pointingZ >> m_eyeDistance >> m_azimuthDeg >> |
| 47 |
m_elevationDeg >> m_projectiveModel >> m_projectiveFOVdeg; |
| 48 |
if (version >= 2) |
| 49 |
in >> m_pinholeModel; |
| 50 |
else |
| 51 |
m_pinholeModel.reset(); |
| 52 |
|
| 53 |
if (version >= 3) |
| 54 |
in >> m_useNoProjection; |
| 55 |
else |
| 56 |
m_useNoProjection = false; |
| 57 |
|
| 58 |
if (version >= 4) |
| 59 |
in >> m_eyeRollDeg; |
| 60 |
else |
| 61 |
m_eyeRollDeg = 0; |
| 62 |
} |
| 63 |
break; |
| 64 |
case 0: |
| 65 |
{ |
| 66 |
in >> m_pointingX >> m_pointingY >> m_pointingZ >> m_eyeDistance >> m_azimuthDeg >> |
| 67 |
m_elevationDeg; |
| 68 |
} |
| 69 |
break; |
| 70 |
default: |
| 71 |
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version); |
| 72 |
}; |
| 73 |
} |
| 74 |
|
| 75 |
/** In this class, returns a fixed box (max,max,max), (-max,-max,-max). */ |
| 76 |
auto CCamera::internalBoundingBoxLocal() const -> mrpt::math::TBoundingBoxf { return {}; } |
| 77 |
|
| 78 |
void CCamera::toYAMLMap(mrpt::containers::yaml& p) const |
| 79 |
{ |
| 80 |
CRenderizable::toYAMLMap(p); |
| 81 |
|
| 82 |
MCP_SAVE(p, m_pointingX); |
| 83 |
MCP_SAVE(p, m_pointingY); |
| 84 |
MCP_SAVE(p, m_pointingZ); |
| 85 |
MCP_SAVE(p, m_eyeDistance); |
| 86 |
MCP_SAVE(p, m_azimuthDeg); |
| 87 |
MCP_SAVE(p, m_elevationDeg); |
| 88 |
MCP_SAVE(p, m_projectiveModel); |
| 89 |
MCP_SAVE(p, m_projectiveFOVdeg); |
| 90 |
MCP_SAVE(p, m_useNoProjection); |
| 91 |
MCP_SAVE(p, m_eyeRollDeg); |
| 92 |
|
| 93 |
if (m_pinholeModel) p["pinholeModel"] = m_pinholeModel->asYAML(); |
| 94 |
} |