Debian Codegraph @

libs/opengl/src/CEllipsoid2D.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/math/matrix_serialization.h>
13 #include <mrpt/opengl/CEllipsoid2D.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(CEllipsoid2D, CRenderizableShaderWireFrame, mrpt::opengl)
22
23 void CEllipsoid2D::transformFromParameterSpace(
24 const std::vector<BASE::array_parameter_t>& in_pts,
25 std::vector<BASE::array_point_t>& out_pts) const
26 {
27 // Euclidean space:
28 out_pts = in_pts;
29 }
30
31 uint8_t CEllipsoid2D::serializeGetVersion() const { return 0; }
32 void CEllipsoid2D::serializeTo(mrpt::serialization::CArchive& out) const
33 {
34 writeToStreamRender(out);
35 out << m_cov << m_drawSolid3D << m_quantiles << (uint32_t)m_numSegments << m_lineWidth;
36 }
37
38 void CEllipsoid2D::serializeFrom(mrpt::serialization::CArchive& in, uint8_t version)
39 {
40 switch (version)
41 {
42 case 0:
43 {
44 readFromStreamRender(in);
45 in >> m_cov;
46 in >> m_drawSolid3D >> m_quantiles;
47 m_numSegments = in.ReadAs<uint32_t>();
48 in >> m_lineWidth;
49
50 // Update cov. matrix cache:
51 setCovMatrix(m_cov);
52 }
53 break;
54 default:
55 MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version);
56 };
57 CRenderizable::notifyChange();
58 }
59
60 #if 0
61 static bool quickSolveEqn(double a, double b_2, double c, double& t)
62 {
63 double delta = square(b_2) - a * c;
64 if (delta == 0)
65 return (t = -b_2 / a) >= 0;
66 else if (delta > 0)
67 {
68 delta = sqrt(delta);
69 if ((t = (-b_2 - delta) / a) >= 0)
70 return true;
71 else
72 return (t = (-b_2 + delta) / a) >= 0;
73 }
74 else
75 return false;
76 }
77 #endif
78
79 bool CEllipsoid2D::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
80 {
81 #if 0 // Update, someday...
82 if (m_cov.rows() != 3) return false;
83 TLine3D lin, lin2;
84 createFromPoseX((o - getCPose()).asTPose(), lin);
85 lin.unitarize(); // By adding this line, distance from any point of the
86 // line to its base is exactly equal to the "t".
87 for (size_t i = 0; i < 3; i++)
88 {
89 lin2.pBase[i] = 0;
90 lin2.director[i] = 0;
91 for (size_t j = 0; j < 3; j++)
92 {
93 double vji = m_eigVec(j, i);
94 lin2.pBase[i] += vji * lin.pBase[j];
95 lin2.director[i] += vji * lin.director[j];
96 }
97 }
98 double a = 0, b_2 = 0, c = -square(m_quantiles);
99 for (size_t i = 0; i < 3; i++)
100 {
101 double ev = m_eigVal(i, i);
102 a += square(lin2.director[i] / ev);
103 b_2 += lin2.director[i] * lin2.pBase[i] / square(ev);
104 c += square(lin2.pBase[i] / ev);
105 }
106 return quickSolveEqn(a, b_2, c, dist);
107 #endif
108 return false;
109 }