-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqsegment.h
More file actions
166 lines (128 loc) · 5.94 KB
/
qsegment.h
File metadata and controls
166 lines (128 loc) · 5.94 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* 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/>.
*/
#ifndef QSEGMENT_H
#define QSEGMENT_H
#include <Eigen/Dense>
#include <QDebug>
#include <QGraphicsItem>
#include <QPen>
namespace Uncertain {
class uPoint;
}
//! Graphics: Strokes and straight line segments
namespace QEntity {
using Uncertain::uPoint;
//! Graphics: Base class for straight line segments
class QSegment : public QGraphicsItem
{
public:
QSegment( const uPoint & ux,
const uPoint & uy); //!< Value constructor (two uncorrelated uncertain points)
QSegment( const QSegment & other) = delete; //!< Copy constructor
QSegment & operator= ( const QSegment & other ) = delete; //!< Copy assignment constructor
enum {Type = UserType +164}; //!< Definition graphics type (id)
int type() const override { return Type; } //!< Get graphics type (id)
QPen pen() const { return pen_;} //!< Get pen
void setPen( const QPen & p) { pen_ = p;} //!< Set pen
void setColor( const QColor & c) { pen_.setColor(c); } //!< Set color
void setLineWidth( const int w) { pen_.setWidth(w); } //!< Set line width
void setLineStyle( const int s) { pen_.setStyle( Qt::PenStyle(s)); } //!< Set line style
virtual void serialize( QDataStream & out ) const; //!< Serialization
bool deserialize( QDataStream &in ); //!< Deserialization
//! Toggle visibility confidence regions
static void toggleShowUncertainty() { s_showUncertainty = !s_showUncertainty; }
//! Get status visibility confidence regions
static bool showUncertainty() { return s_showUncertainty; }
static void setPenSelected( const QPen & p) { s_penSelected = p;}
protected:
//! Standard constructor
QSegment( QGraphicsItem *parent= nullptr );
~QSegment() override = default;
QPainterPath shape() const override; //!< Get bounding shape
void mousePressEvent( QGraphicsSceneMouseEvent * /* event */) override; //!< Handle mouse press event
QRectF boundingRect() const override; //!< Get axis-aligned bounding box
//! Plot uncertain straight line segment (base class)
void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget) override;
private:
void createSelectionPolygon( qreal halfWidth );
void setShape( const uPoint &ux,
const uPoint &uy ); // with new or adjusted endpoints.
double getSelectionOffset( const uPoint &,
const uPoint &) const;
QLineF line() const { return line_;}
QPolygonF toPoly( std::pair<Eigen::VectorXd, Eigen::VectorXd> p);
QLineF line_; // straight line segment
std::pair<QPolygonF, QPolygonF> branch_; // hyperbola branches
std::pair<QPolygonF, QPolygonF> ellipse_; // ellipses of end-points
QPen pen_;
QPolygonF minBBox; // used in shape() und paint()
static bool s_showUncertainty;
static QPen s_penSelected;
};
//! Graphics: Constrained straight line segment
class QConstrained : public QSegment
{
public:
QConstrained();
QConstrained( const uPoint & ux,
const uPoint & uy); //!< Value constructor
// using QSegment::operator=;
void setAltColor( const QColor &); //!< Set color for automatic colorization (subtasks)
static bool show() { return s_show; } //!< Get status of visibility
static void toggleShow() { s_show = !s_show; } //!< Toggle visibility
static bool showColor() { return s_showColor; } //!< Get status colorization
static void toogleShowColor() { s_showColor = !s_showColor;} //!< Toggle colorization / no colorization
static void setPenDefault( const QPen & p) { s_defaultPen = p; } //!< Set default pen
static QPen defaultPen() { return s_defaultPen; } //!< Get current default pen
protected:
//! Plot uncertain constrained straight line segment
void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget) override;
private:
QColor altColor;
static bool s_show;
static bool s_showColor;
static QPen s_defaultPen;
};
//! Graphics: Unconstrained straight line segment
class QUnconstrained : public QSegment
{
public:
QUnconstrained( QGraphicsItem *parent=nullptr); //!< Standard Constructor
QUnconstrained( const uPoint & ux,
const uPoint & uy); //!< Value constructor (two uncorrelated uncertain points)
// using QSegment::operator=;
static void toggleShow() { s_show = !s_show; } //!< Toggle visibility
static bool show() { return s_show; } //!< Get status visibility
static void setPenDefault( const QPen &p) { s_defaultPen = p; } //!< Set default pen
static QPen defaultPen() { return s_defaultPen; } //!< Get current default pen
protected:
// QRectF boundingRect() const override { return QSegment::boundingRect(); }
//! Plot unconstrained uncertain straight line segment
void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget) override;
private:
static bool s_show;
static QPen s_defaultPen;
};
} // namespace QEntity
#endif // QSEGMENT_H