Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIDottedGeometry.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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/****************************************************************************/
18// File for dotted geometry classes and functions
19/****************************************************************************/
24
25#include "GUIDottedGeometry.h"
26#include "GUIGeometry.h"
27
28
29#define MAXIMUM_DOTTEDGEOMETRYLENGTH 500.0
30
31// ===========================================================================
32// method definitions
33// ===========================================================================
34
35// ---------------------------------------------------------------------------
36// GUIDottedGeometry::DottedGeometryColor - methods
37// ---------------------------------------------------------------------------
38
41
42
43const RGBColor
45 switch (type) {
47 if (myColorFlag) {
48 myColorFlag = false;
50 } else {
51 myColorFlag = true;
53 }
55 if (myColorFlag) {
56 myColorFlag = false;
58 } else {
59 myColorFlag = true;
61 }
63 if (myColorFlag) {
64 myColorFlag = false;
65 return RGBColor::GREEN;
66 } else {
67 myColorFlag = true;
69 }
71 if (myColorFlag) {
72 myColorFlag = false;
73 return RGBColor::MAGENTA;
74 } else {
75 myColorFlag = true;
77 }
79 if (myColorFlag) {
80 myColorFlag = false;
81 return RGBColor(229, 233, 255);
82 } else {
83 myColorFlag = true;
84 return RGBColor(255, 109, 196);
85 }
87 if (myColorFlag) {
88 myColorFlag = false;
89 return RGBColor::BLUE;
90 } else {
91 myColorFlag = true;
93 }
95 if (myColorFlag) {
96 myColorFlag = false;
97 return RGBColor(220, 0, 0);
98 } else {
99 myColorFlag = true;
100 return RGBColor(220, 0, 0).changedBrightness(-30);
101 }
103 if (myColorFlag) {
104 myColorFlag = false;
105 return RGBColor::ORANGE;
106 } else {
107 myColorFlag = true;
109 }
111 if (myColorFlag) {
112 myColorFlag = false;
113 return RGBColor::CYAN;
114 } else {
115 myColorFlag = true;
117 }
118 default:
119 return RGBColor::BLACK;
120 }
121}
122
123
124void
126 if (myColorFlag) {
127 myColorFlag = false;
128 } else {
129 myColorFlag = true;
130 }
131}
132
133
134void
136 myColorFlag = true;
137}
138
139// ---------------------------------------------------------------------------
140// GUIDottedGeometry::Segment - methods
141// ---------------------------------------------------------------------------
142
144
145
147 shape(newShape) {
148}
149
150// ---------------------------------------------------------------------------
151// GUIDottedGeometry - methods
152// ---------------------------------------------------------------------------
153
155
156
158 PositionVector shape, const bool closeShape) {
159 // set shape as unresampled shape
160 myUnresampledShape = shape;
161 // check if shape has to be closed
162 if (closeShape && (myUnresampledShape.size() > 2)) {
164 }
165 if (myUnresampledShape.size() > 1) {
166 // get shape
167 for (int i = 1; i < (int)myUnresampledShape.size(); i++) {
169 }
170 // check if resample
172 // calculate segment length
173 double segmentLength = s.dottedContourSettings.segmentLength;
175 segmentLength = myUnresampledShape.length2D() / (MAXIMUM_DOTTEDGEOMETRYLENGTH * 0.5);
176 }
177 // resample all dotted geometries
178 for (auto& segment : myDottedGeometrySegments) {
179 segment.shape = segment.shape.resample(segmentLength, true);
180 }
181 }
182 // calculate shape rotations and lengths
184 }
185}
186
187
188void
190 const PositionVector& laneShape) {
191 // set shape as unresampled shape
192 myUnresampledShape = laneShape;
193 // reset segments
195 // get shape
196 for (int i = 1; i < (int)myUnresampledShape.size(); i++) {
198 }
199 // check if resample
201 for (auto& segment : myDottedGeometrySegments) {
202 segment.shape = segment.shape.resample(s.dottedContourSettings.segmentLength, true);
203 }
204 }
205 // calculate shape rotations and lengths
207}
208
209
210void
212 PositionVector shape, const bool closeShape) {
213 // set shape as unresampled shape
214 myUnresampledShape = shape;
215 // reset segments
217 // check if shape has to be closed
218 if (closeShape && (myUnresampledShape.size() > 2)) {
220 }
221 if (myUnresampledShape.size() > 1) {
222 // get shape
223 for (int i = 1; i < (int)myUnresampledShape.size(); i++) {
225 }
226 // check if resample
228 for (auto& segment : myDottedGeometrySegments) {
229 segment.shape = segment.shape.resample(s.dottedContourSettings.segmentLength, true);
230 }
231 }
232 // calculate shape rotations and lengths
234 }
235}
236
237
238void
240 DottedGeometryColor& dottedGeometryColor, const double lineWidth, const bool addOffset) const {
241 // iterate over all segments
242 for (auto& segment : myDottedGeometrySegments) {
243 // iterate over shape
244 for (int i = 0; i < ((int)segment.shape.size() - 1); i++) {
245 // set color
246 GLHelper::setColor(dottedGeometryColor.getColor(s, type));
247 // draw box line depending of addOffset
248 if (addOffset) {
249 GLHelper::drawBoxLine(segment.shape[i], segment.rotations.at(i), segment.lengths.at(i), lineWidth, -lineWidth);
250 } else {
251 GLHelper::drawBoxLine(segment.shape[i], segment.rotations.at(i), segment.lengths.at(i), lineWidth);
252 }
253 }
254 }
255}
256
257
258void
259GUIDottedGeometry::drawInnenGeometry(const double lineWidth) const {
260 // iterate over all segments
261 for (auto& segment : myDottedGeometrySegments) {
262 // iterate over shape
263 for (int i = 0; i < ((int)segment.shape.size() - 1); i++) {
264 GLHelper::drawBoxLine(segment.shape[i], segment.rotations.at(i), segment.lengths.at(i), lineWidth, lineWidth);
265 }
266 }
267}
268
269
270void
272 // move to side all dotted geometry segments
273 for (auto& segment : myDottedGeometrySegments) {
274 segment.shape.move2side(value);
275 }
276 // also unresampled shape
278}
279
280
283 if (myUnresampledShape.size() > 0) {
284 return myUnresampledShape.front();
285 } else {
286 return Position::INVALID;
287 }
288}
289
290
293 if (myUnresampledShape.size() > 0) {
294 return myUnresampledShape.back();
295 } else {
296 return Position::INVALID;
297 }
298}
299
300
301const PositionVector&
305
306
307void
312
313
314void
316 // iterate over all segments
317 for (auto& segment : myDottedGeometrySegments) {
318 // Get number of parts of the shape
319 int numberOfSegments = (int)segment.shape.size() - 1;
320 // If number of segments is more than 0
321 if (numberOfSegments >= 0) {
322 // Reserve memory (To improve efficiency)
323 segment.rotations.reserve(numberOfSegments);
324 segment.lengths.reserve(numberOfSegments);
325 // Calculate lengths and rotations for every shape
326 for (int i = 0; i < numberOfSegments; i++) {
327 segment.rotations.push_back(GUIGeometry::calculateRotation(segment.shape[i], segment.shape[i + 1]));
328 segment.lengths.push_back(GUIGeometry::calculateLength(segment.shape[i], segment.shape[i + 1]));
329 }
330 }
331 }
332}
333
334/****************************************************************************/
#define MAXIMUM_DOTTEDGEOMETRYLENGTH
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:654
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:295
class for pack all variables related with GUIDottedGeometry color
const RGBColor getColor(const GUIVisualizationSettings &settings, DottedContourType type)
get inspected color (and change flag)
void reset()
rest Dotted Geometry Color
void drawDottedGeometry(const GUIVisualizationSettings &s, GUIDottedGeometry::DottedContourType type, DottedGeometryColor &dottedGeometryColor, const double lineWidth, const bool addOffset) const
draw dotted geometry
std::vector< GUIDottedGeometry::Segment > myDottedGeometrySegments
dotted element shape (note: It's centered in 0,0 due scaling)
Position getFrontPosition() const
get front position
const PositionVector & getUnresampledShape() const
get simple shape (the shape without resampling)
void drawInnenGeometry(const double lineWidth) const
draw innen geometry
PositionVector myUnresampledShape
shape without resampling
void moveShapeToSide(const double value)
move shape to side
void calculateShapeRotationsAndLengths()
calculate shape rotations and lengths
void clearDottedGeometry()
clear dotted geometry
void updateDottedGeometry(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const PositionVector &laneShape)
update GUIDottedGeometry (using lane shape)
GUIDottedGeometry()
constructor
Position getBackPosition() const
get back position
static double calculateRotation(const Position &first, const Position &second)
return angle between two points (used in geometric calculations)
static double calculateLength(const Position &first, const Position &second)
return length between two points (used in geometric calculations)
Stores the information about how to visualize structures.
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static const Position INVALID
used to indicate that a position is valid
Definition Position.h:322
A list of positions.
double length2D() const
Returns the length.
PositionVector resample(double maxLength, const bool adjustEnd) const
resample shape (i.e. transform to segments, equal spacing)
void closePolygon()
ensures that the last position equals the first
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
static const RGBColor BLUE
Definition RGBColor.h:187
static const RGBColor ORANGE
Definition RGBColor.h:191
static const RGBColor CYAN
Definition RGBColor.h:189
static const RGBColor GREEN
Definition RGBColor.h:186
static const RGBColor BLACK
Definition RGBColor.h:193
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:200
static const RGBColor MAGENTA
Definition RGBColor.h:190
dotted geometry segment
static const RGBColor firstFrontColor
first color of dotted front contour
static const RGBColor firstInspectedColor
first color of dotted inspected contour
static const RGBColor secondFrontColor
second color of dotted front contour
static const RGBColor secondInspectedColor
second color of dotted inspectedcontour
static const double segmentLength
length of dotted contour segments