Debian Codegraph @

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