-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupoint.cpp
More file actions
142 lines (118 loc) · 4.17 KB
/
upoint.cpp
File metadata and controls
142 lines (118 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
* Copyright (c) 2022 Jochen Meidow, Fraunhofer IOSB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "aabb.h"
#include "upoint.h"
#include "ustraightline.h"
#include <QDebug>
namespace Uncertain {
//! Construction of uncertain point vai 3-vector x and its covariance matrix
uPoint::uPoint( const Vector3d &x,
const Matrix3d &Cov_xx)
: BasicEntity2D (x, Cov_xx)
{
qDebug() << Q_FUNC_INFO;
Q_ASSERT_X( isCovMat(m_cov),
Q_FUNC_INFO,
"invalid covariance matrix");
}
//! Get axis-aligned bounding box
aabb uPoint::bbox() const
{
double u = m_val(0);
double v = m_val(1);
double w = m_val(2);
Eigen::Matrix<double,2,3> JJ;
JJ.col(0) << 1/w, 0;
JJ.col(1) << 0, 1/w;
JJ.col(2) << -u/(w*w), -v/(w*w);
Eigen::Matrix2d Cov_xx = JJ*m_cov*JJ.transpose();
double x = m_val(0)/m_val(2);
double y = m_val(1)/m_val(2);
double x_min = x -sqrt(Cov_xx(0,0));
double x_max = x +sqrt(Cov_xx(0,0));
double y_min = y -sqrt(Cov_xx(1,1));
double y_max = y +sqrt(Cov_xx(1,1));
return aabb{ x_min, x_max, y_min, y_max} ;
}
//! Get Euclidean distance to uncertain straight line 'ul'
uDistance uPoint::distanceEuclideanTo( const uStraightLine & ul) const
{
const Vector3d l = ul.v();
const Vector3d x = m_val;
const double n = l.head(2).norm(); // ||l_h||
const double d = m_val.dot(l) / (abs(m_val(2))*n);
Vector3d JJx;
Vector3d JJl;
JJx(0) = l(0)/(abs(x(2))*n);
JJx(1) = l(1)/(abs(x(2))*n);
JJx(2) = l(2)/(abs(x(2))*n) -x.dot(l)*sign(x(2))/( abs(x(2))*abs(x(2)) *n);
JJl(0) = x(0)/(abs(x(2))*n) -x.dot(l)*l(0) / (abs(x(2)) *n*n*n);
JJl(1) = x(1)/(abs(x(2))*n) -x.dot(l)*l(1) / (abs(x(2)) *n*n*n);
JJl(2) = x(2)/(abs(x(2))*n);
double var_d = JJx.dot(m_cov*JJx) +JJl.dot(ul.Cov()*JJl);
return {d,var_d};
}
//! Get uncertain point in homogeneous coordinates, Euclidean normalized
uPoint uPoint::euclidean() const
{
double u = m_val(0); // w'=u/w
double v = m_val(1); // v'=v/w
double w = m_val(2); // w'=w/w=1
Matrix3d JJ;
JJ.row(0) << 1/w, 0, -u/(w*w);
JJ.row(1) << 0, 1/w, -v/(w*w);
JJ.row(2) << 0, 0, 0;
return { m_val/m_val(2),
JJ*m_cov*JJ.adjoint() };
}
//! Get uncertain point, transformed via 3x3 transformation matrix
uPoint uPoint::transformed( const Matrix3d & TT) const
{
uPoint ux(*this);
ux.transform(TT);
return ux;
}
//! Check if uncertain straight line 'ul' is incident.
bool uPoint::isIncidentWith( const uStraightLine & ul,
const double T) const
{
double d = m_val.dot(ul.v()); // d = x'*l
double var_d = ul.v().dot( m_cov*ul.v())
+m_val.dot( ul.Cov()*m_val); // uncorrelated
Q_ASSERT( var_d>0. );
double T_in = (d*d)/var_d;
return (T_in < T);
}
//! Get algebraic distance of 'this' and straight line of 'ul'
uDistance uPoint::distanceAlgebraicTo( const uStraightLine & ul ) const
{
double d = sign( m_val(2) )*m_val.dot( ul.v() );
Vector3d JJx = ul.v().adjoint();
Vector3d JJl = sign(m_val(2))*m_val.adjoint();
// JJ = [l', sign(x(3))*x'];
double var_d = JJx.dot(m_cov*JJx) +JJl.dot( ul.Cov()*JJl ); // uncorrelated
return {d, var_d};
}
//! Get uncertain point in homogeneous coordinates, spherically normalized
uPoint uPoint::sphericalNormalized() const
{
uPoint ux( *this );
ux.normalizeSpherical();
return ux; // Compiler invokes the copy constructor.
}
} // namespace Uncertain