-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusegment.h
More file actions
143 lines (111 loc) · 4.84 KB
/
usegment.h
File metadata and controls
143 lines (111 loc) · 4.84 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
143
/*
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
* Copyright (c) 2022-2025 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/>.
*/
#ifndef USEGMENT_H
#define USEGMENT_H
#include "aabb.h"
#include <QDataStream> // Qt
#include <Eigen/Core>
#include <Eigen/Dense> // Eigen
#include <cmath>
#include <memory> // C++
namespace Uncertain {
class uPoint;
class uStraightLine;
using Eigen::Matrix;
using Eigen::VectorXd;
using Eigen::MatrixXd;
using Eigen::Matrix3d;
using Eigen::Vector2d;
using Eigen::Vector3d;
//! Uncertain straight line segment
class uStraightLineSegment
{
private:
using Vector9d = Matrix<double,9,1>; // type alias (typedef)
using Matrix9d = Matrix<double,9,9>; // type alias (typedef)
uStraightLineSegment() = default;
public:
uStraightLineSegment( const uPoint & ux,
const uPoint & uy);
// deserialization with protected constructor
static std::shared_ptr<uStraightLineSegment> create();
void serialize( QDataStream & out) const;
bool deserialize( QDataStream & in);
// relations ....................................................
[[nodiscard]] bool intersects( const uStraightLineSegment & ut_) const;
[[nodiscard]] bool touches( const uStraightLineSegment & other,
double T_dist,
double T_in) const;
[[nodiscard]] bool touchedBy( const uPoint &,
double T_dist,
double T_in) const;
// unary
[[nodiscard]] bool isVertical ( double T) const;
[[nodiscard]] bool isHorizontal( double T) const;
[[nodiscard]] bool isDiagonal ( double T) const;
// binary
[[nodiscard]] bool isOrthogonalTo( const uStraightLine & um, double T) const;
[[nodiscard]] bool isParallelTo( const uStraightLine & um, double T) const;
[[nodiscard]] bool straightLineIsIdenticalTo( const uStraightLine & um, double T) const;
// ternary
[[nodiscard]] bool isCopunctualWith( const uStraightLine & um,
const uStraightLine & un,
double T) const;
[[nodiscard]] uPoint ux() const;
[[nodiscard]] uPoint uy() const;
[[nodiscard]] uStraightLine ul() const;
[[nodiscard]] uStraightLine um() const;
[[nodiscard]] uStraightLine un() const;
[[nodiscard]] Vector3d hx() const;
[[nodiscard]] Vector3d hy() const;
//! Get the endpoints connecting straight line l = S(x)*y
[[nodiscard]] Vector3d hl() const { return m_t.head(3); }
//! Get delimiting straight line m in homogeneous coordinates
[[nodiscard]] Vector3d hm() const { return m_t.segment(3,3); }
//! Get delimiting straight line n in homogeneous coordinates
[[nodiscard]] Vector3d hn() const { return m_t.tail(3); }
//! Get the 9-vector t = [l',m',n']'
[[nodiscard]] VectorXd t() const { return m_t;}
//! Get 9x9 covariance matrix of vector t
[[nodiscard]] MatrixXd Cov_tt() const { return m_Cov_tt; }
//! Get endpoint x in Euclidean coordinates
[[nodiscard]] Vector2d x() const { return hx().head(2)/hx()(2); }
//! Get endpoint y in Euclidean coordinates
[[nodiscard]] Vector2d y() const { return hy().head(2)/hy()(2); }
//! Get angle between straight line l and x-axis in degree
[[nodiscard]] double phi_deg() const {
constexpr double rho = 180./3.14159;
return rho*atan2( m_t(1),m_t(0) );
}
//! Get axis-aligned bounding box
[[nodiscard]] Aabb bounding_box() const { return m_bounding_box; }
[[nodiscard]] bool move_x_to( const Vector3d & m );
[[nodiscard]] bool move_y_to( const Vector3d & n );
void transform( const Matrix9d & TT );
private:
Vector9d m_t; // 9-vector t=[l',m',n']'
Matrix9d m_Cov_tt;
Aabb m_bounding_box; // not constant, due to merge operation, .united(...)
static Matrix3d CC(); // Diag([1,1,0])
template <typename T>
int sign(T val) { return (T(0) <= val) - (val < T(0)); } // sign(0):=+1
template <typename T>
bool sameSign( T a, T b ) const { return a*b >= 0.; } // for debugging and assertion
};
} // namespace Uncertain
#endif // USEGMENT_H