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 }
119 return settings.junctionColorer.getScheme().getColor(6);
120 default:
121 return RGBColor::BLACK;
122 }
123}
124
125
126void
128 if (myColorFlag) {
129 myColorFlag = false;
130 } else {
131 myColorFlag = true;
132 }
133}
134
135
136void
138 myColorFlag = true;
139}
140
141// ---------------------------------------------------------------------------
142// GUIDottedGeometry::Segment - methods
143// ---------------------------------------------------------------------------
144
146
147
149 shape(newShape) {
150}
151
152// ---------------------------------------------------------------------------
153// GUIDottedGeometry - methods
154// ---------------------------------------------------------------------------
155
157
158
160 PositionVector shape, const bool closeShape) {
161 // set shape as unresampled shape
162 myUnresampledShape = shape;
163 // check if shape has to be closed
164 if (closeShape && (myUnresampledShape.size() > 2)) {
166 }
167 if (myUnresampledShape.size() > 1) {
168 // get shape
169 for (int i = 1; i < (int)myUnresampledShape.size(); i++) {
171 }
172 // check if resample
174 // calculate segment length
175 double segmentLength = s.dottedContourSettings.segmentLength;
177 segmentLength = myUnresampledShape.length2D() / (MAXIMUM_DOTTEDGEOMETRYLENGTH * 0.5);
178 }
179 // resample all dotted geometries
180 for (auto& segment : myDottedGeometrySegments) {
181 segment.shape = segment.shape.resample(segmentLength, true);
182 }
183 }
184 // calculate shape rotations and lengths
186 }
187}
188
189
190void
192 const PositionVector& laneShape) {
193 // set shape as unresampled shape
194 myUnresampledShape = laneShape;
195 // reset segments
197 // get shape
198 for (int i = 1; i < (int)myUnresampledShape.size(); i++) {
200 }
201 // check if resample
203 for (auto& segment : myDottedGeometrySegments) {
204 segment.shape = segment.shape.resample(s.dottedContourSettings.segmentLength, true);
205 }
206 }
207 // calculate shape rotations and lengths
209}
210
211
212void
214 PositionVector shape, const bool closeShape) {
215 // set shape as unresampled shape
216 myUnresampledShape = shape;
217 // reset segments
219 // check if shape has to be closed
220 if (closeShape && (myUnresampledShape.size() > 2)) {
222 }
223 if (myUnresampledShape.size() > 1) {
224 // get shape
225 for (int i = 1; i < (int)myUnresampledShape.size(); i++) {
227 }
228 // check if resample
230 for (auto& segment : myDottedGeometrySegments) {
231 segment.shape = segment.shape.resample(s.dottedContourSettings.segmentLength, true);
232 }
233 }
234 // calculate shape rotations and lengths
236 }
237}
238
239
240void
242 DottedGeometryColor& dottedGeometryColor, const double lineWidth, const bool addOffset) const {
243 // iterate over all segments
244 for (auto& segment : myDottedGeometrySegments) {
245 // iterate over shape
246 for (int i = 0; i < ((int)segment.shape.size() - 1); i++) {
247 // set color
248 GLHelper::setColor(dottedGeometryColor.getColor(s, type));
249 // draw box line depending of addOffset
250 if (addOffset) {
251 GLHelper::drawBoxLine(segment.shape[i], segment.rotations.at(i), segment.lengths.at(i), lineWidth, -lineWidth);
252 } else {
253 GLHelper::drawBoxLine(segment.shape[i], segment.rotations.at(i), segment.lengths.at(i), lineWidth);
254 }
255 }
256 }
257}
258
259
260void
261GUIDottedGeometry::drawInnenGeometry(const double lineWidth) const {
262 // iterate over all segments
263 for (auto& segment : myDottedGeometrySegments) {
264 // iterate over shape
265 for (int i = 0; i < ((int)segment.shape.size() - 1); i++) {
266 GLHelper::drawBoxLine(segment.shape[i], segment.rotations.at(i), segment.lengths.at(i), lineWidth, lineWidth);
267 }
268 }
269}
270
271
272void
274 // move to side all dotted geometry segments
275 for (auto& segment : myDottedGeometrySegments) {
276 segment.shape.move2side(value);
277 }
278 // also unresampled shape
280}
281
282
285 if (myUnresampledShape.size() > 0) {
286 return myUnresampledShape.front();
287 } else {
288 return Position::INVALID;
289 }
290}
291
292
295 if (myUnresampledShape.size() > 0) {
296 return myUnresampledShape.back();
297 } else {
298 return Position::INVALID;
299 }
300}
301
302
303const PositionVector&
307
308
309void
314
315
316void
318 // iterate over all segments
319 for (auto& segment : myDottedGeometrySegments) {
320 // Get number of parts of the shape
321 int numberOfSegments = (int)segment.shape.size() - 1;
322 // If number of segments is more than 0
323 if (numberOfSegments >= 0) {
324 // Reserve memory (To improve efficiency)
325 segment.rotations.reserve(numberOfSegments);
326 segment.lengths.reserve(numberOfSegments);
327 // Calculate lengths and rotations for every shape
328 for (int i = 0; i < numberOfSegments; i++) {
329 segment.rotations.push_back(GUIGeometry::calculateRotation(segment.shape[i], segment.shape[i + 1]));
330 segment.lengths.push_back(GUIGeometry::calculateLength(segment.shape[i], segment.shape[i + 1]));
331 }
332 }
333 }
334}
335
336/****************************************************************************/
#define MAXIMUM_DOTTEDGEOMETRYLENGTH
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:296
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)
T getColor(const double value) const
Stores the information about how to visualize structures.
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
GUIColorer junctionColorer
The junction colorer.
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