| 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/CEllipsoidInverseDepth3D.h> |
| 13 |
#include <mrpt/serialization/CArchive.h> |
| 14 |
|
| 15 |
using namespace mrpt; |
| 16 |
using namespace mrpt::opengl; |
| 17 |
using namespace mrpt::math; |
| 18 |
using namespace std; |
| 19 |
|
| 20 |
IMPLEMENTS_SERIALIZABLE(CEllipsoidInverseDepth3D, CRenderizableShaderWireFrame, mrpt::opengl) |
| 21 |
|
| 22 |
/*--------------------------------------------------------------- |
| 23 |
transformFromParameterSpace |
| 24 |
---------------------------------------------------------------*/ |
| 25 |
void CEllipsoidInverseDepth3D::transformFromParameterSpace( |
| 26 |
const std::vector<BASE::array_parameter_t>& in_pts, |
| 27 |
std::vector<BASE::array_point_t>& out_pts) const |
| 28 |
{ |
| 29 |
MRPT_START |
| 30 |
|
| 31 |
// (inv_range,yaw,pitch) --> (x,y,z) |
| 32 |
const size_t N = in_pts.size(); |
| 33 |
out_pts.resize(N); |
| 34 |
for (size_t i = 0; i < N; i++) |
| 35 |
{ |
| 36 |
const float inv_range = in_pts[i][0]; |
| 37 |
const float yaw = in_pts[i][1]; |
| 38 |
const float pitch = in_pts[i][2]; |
| 39 |
|
| 40 |
const float range = |
| 41 |
inv_range < 0 ? m_underflowMaxRange : (inv_range != 0 ? 1.f / inv_range : 0); |
| 42 |
|
| 43 |
out_pts[i][0] = range * cosf(yaw) * cosf(pitch); |
| 44 |
out_pts[i][1] = range * sinf(yaw) * cosf(pitch); |
| 45 |
out_pts[i][2] = -range * sinf(pitch); |
| 46 |
} |
| 47 |
|
| 48 |
MRPT_END |
| 49 |
} |
| 50 |
|
| 51 |
uint8_t CEllipsoidInverseDepth3D::serializeGetVersion() const { return 0; } |
| 52 |
void CEllipsoidInverseDepth3D::serializeTo(mrpt::serialization::CArchive& out) const |
| 53 |
{ |
| 54 |
writeToStreamRender(out); |
| 55 |
BASE::thisclass_writeToStream(out); |
| 56 |
|
| 57 |
out << m_underflowMaxRange; |
| 58 |
} |
| 59 |
|
| 60 |
void CEllipsoidInverseDepth3D::serializeFrom(mrpt::serialization::CArchive& in, uint8_t version) |
| 61 |
{ |
| 62 |
switch (version) |
| 63 |
{ |
| 64 |
case 0: |
| 65 |
{ |
| 66 |
readFromStreamRender(in); |
| 67 |
BASE::thisclass_readFromStream(in); |
| 68 |
|
| 69 |
in >> m_underflowMaxRange; |
| 70 |
} |
| 71 |
break; |
| 72 |
default: |
| 73 |
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version); |
| 74 |
}; |
| 75 |
CRenderizable::notifyChange(); |
| 76 |
} |