Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/div/GUIGeometry.h
169684 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file GUIGeometry.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Oct 2020
17
///
18
// File for geometry classes and functions
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <utils/geom/PositionVector.h>
24
#include <utils/gui/globjects/GUIGlObject.h>
25
#include <utils/gui/settings/GUIVisualizationSettings.h>
26
27
// ===========================================================================
28
// class definitions
29
// ===========================================================================
30
31
class GUIGeometry {
32
33
public:
34
/// @brief default constructor
35
GUIGeometry();
36
37
/// @brief parameter constructor
38
GUIGeometry(const PositionVector& shape);
39
40
/// @brief parameter constructor
41
GUIGeometry(const PositionVector& shape, const std::vector<double>& shapeRotations,
42
const std::vector<double>& shapeLengths);
43
44
/// @brief update entire geometry
45
void updateGeometry(const PositionVector& shape);
46
47
/// @brief update geometry (using a shape, a position over shape and a lateral offset)
48
void updateGeometry(const PositionVector& shape, const double posOverShape, const double lateralOffset);
49
50
/// @brief update geometry (using a shape, a starPos over shape, a endPos and a lateral offset)
51
void updateGeometry(const PositionVector& shape, double starPosOverShape, double endPosOverShape,
52
const double lateralOffset);
53
54
/// @brief update geometry (using a shape to be trimmed)
55
void updateGeometry(const PositionVector& shape, double beginTrimPosition, const Position& extraFirstPosition,
56
double endTrimPosition, const Position& extraLastPosition);
57
58
/// @brief update position and rotation
59
void updateSinglePosGeometry(const Position& position, const double rotation);
60
61
/// @brief clear geometry
62
void clearGeometry();
63
64
/// @brief move current shape to side
65
void moveGeometryToSide(const double amount);
66
67
/// @brief scale geometry
68
void scaleGeometry(const double scale);
69
70
/// @brief The shape of the additional element
71
const PositionVector& getShape() const;
72
73
/// @brief The rotations of the single shape parts
74
const std::vector<double>& getShapeRotations() const;
75
76
/// @brief The lengths of the single shape parts
77
const std::vector<double>& getShapeLengths() const;
78
79
/// @name calculation functions
80
/// @{
81
82
/// @brief return angle between two points (used in geometric calculations)
83
static double calculateRotation(const Position& first, const Position& second);
84
85
/// @brief return length between two points (used in geometric calculations)
86
static double calculateLength(const Position& first, const Position& second);
87
88
/// @brief adjust start and end positions in geometric path
89
static void adjustStartPosGeometricPath(double& startPos, const PositionVector& startLaneShape, double& endPos,
90
const PositionVector& endLaneShape);
91
92
/// @}
93
94
/// @name draw functions
95
/// @{
96
97
/// @brief draw geometry
98
static void drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeometry& geometry,
99
const double width, double offset = 0);
100
101
/// @brief draw colored geometry
102
static void drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeometry& geometry,
103
const std::vector<RGBColor>& colors, const double width, double offset = 0);
104
105
/// @brief draw contour geometry
106
static void drawContourGeometry(const GUIGeometry& geometry, const double width, const bool drawExtremes = false);
107
108
/// @brief draw geometry points
109
static void drawGeometryPoints(const GUIVisualizationSettings::Detail d, const PositionVector& shape,
110
const RGBColor& color, const double radius, const double exaggeration,
111
const bool editingElevation);
112
113
/// @brief draw line between parent and children (used in netedit)
114
static void drawParentLine(const GUIVisualizationSettings& s, const Position& parent, const Position& child,
115
const RGBColor& color, const bool drawEntire, const double lineWidth);
116
117
/// @brief draw line between child and parent (used in netedit)
118
static void drawChildLine(const GUIVisualizationSettings& s, const Position& child, const Position& parent,
119
const RGBColor& color, const bool drawEntire, const double lineWidth);
120
121
/// @brief get a circle around the given position
122
static PositionVector getVertexCircleAroundPosition(const Position& pos, const double width, const int steps = 8);
123
124
/// @brief rotate over lane (used by Lock icons, detector logos, etc.)
125
static void rotateOverLane(const double rot);
126
127
/// @}
128
129
protected:
130
/// @brief calculate shape rotations and lengths
131
void calculateShapeRotationsAndLengths();
132
133
/// @brief element shape
134
PositionVector myShape;
135
136
/// @brief The rotations of the shape (note: Always size = myShape.size()-1)
137
std::vector<double> myShapeRotations;
138
139
/// @brief The lengths of the shape (note: Always size = myShape.size()-1)
140
std::vector<double> myShapeLengths;
141
142
private:
143
/// @brief Storage for precomputed sin/cos-values describing a circle
144
static PositionVector myCircleCoords;
145
146
/// @brief normalize angle for lookup in myCircleCoords
147
static int angleLookup(const double angleDeg);
148
};
149
150