Eclipse SUMO - Simulation of Urban MObility
GUIDottedGeometry.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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
40 mySettings(settings),
41 myColorFlag(true) {}
42
43
44const RGBColor
46 switch (type) {
49 if (myColorFlag) {
50 myColorFlag = false;
51 return mySettings.dottedContourSettings.firstInspectedColor;
52 } else {
53 myColorFlag = true;
54 return mySettings.dottedContourSettings.secondInspectedColor;
55 }
58 if (myColorFlag) {
59 myColorFlag = false;
60 return mySettings.dottedContourSettings.firstFrontColor;
61 } else {
62 myColorFlag = true;
63 return mySettings.dottedContourSettings.secondFrontColor;
64 }
67 if (myColorFlag) {
68 myColorFlag = false;
69 return RGBColor::GREEN;
70 } else {
71 myColorFlag = true;
73 }
76 if (myColorFlag) {
77 myColorFlag = false;
78 return RGBColor::MAGENTA;
79 } else {
80 myColorFlag = true;
82 }
84 if (myColorFlag) {
85 myColorFlag = false;
86 return RGBColor(229, 233, 255);
87 } else {
88 myColorFlag = true;
89 return RGBColor(255, 109, 196);
90 }
92 if (myColorFlag) {
93 myColorFlag = false;
94 return RGBColor::BLUE;
95 } else {
96 myColorFlag = true;
98 }
100 if (myColorFlag) {
101 myColorFlag = false;
102 return RGBColor::ORANGE;
103 } else {
104 myColorFlag = true;
106 }
108 if (myColorFlag) {
109 myColorFlag = false;
110 return RGBColor::YELLOW;
111 } else {
112 myColorFlag = true;
114 }
115 default:
116 return RGBColor::BLACK;
117 }
118}
119
120
121void
123 if (myColorFlag) {
124 myColorFlag = false;
125 } else {
126 myColorFlag = true;
127 }
128}
129
130
131void
133 myColorFlag = true;
134}
135
136// ---------------------------------------------------------------------------
137// GUIDottedGeometry::Segment - methods
138// ---------------------------------------------------------------------------
139
141 offset(-1) {
142}
143
144
146 shape(newShape),
147 offset(-1) {
148}
149
150// ---------------------------------------------------------------------------
151// GUIDottedGeometry - methods
152// ---------------------------------------------------------------------------
153
155
156
158 // check if shape has to be closed
159 if (closeShape && (shape.size() > 2)) {
160 shape.closePolygon();
161 }
162 if (shape.size() > 1) {
163 // get shape
164 for (int i = 1; i < (int)shape.size(); i++) {
165 myDottedGeometrySegments.push_back(Segment({shape[i - 1], shape[i]}));
166 }
167 // calculate segment length
168 double segmentLength = s.dottedContourSettings.segmentLength;
170 segmentLength = shape.length2D() / (MAXIMUM_DOTTEDGEOMETRYLENGTH * 0.5);
171 }
172 // resample
173 for (auto& segment : myDottedGeometrySegments) {
174 segment.shape = segment.shape.resample(segmentLength, true);
175 }
176 // calculate shape rotations and lengths
178 }
179}
180
181
183 const GUIDottedGeometry& topDottedGeometry, const bool drawFirstExtrem,
184 const GUIDottedGeometry& botDottedGeometry, const bool drawLastExtrem) {
185 // check size of both geometries
186 if ((topDottedGeometry.myDottedGeometrySegments.size() > 0) &&
187 (botDottedGeometry.myDottedGeometrySegments.size() > 0)) {
188 // add extremes
189 if (drawFirstExtrem &&
190 (topDottedGeometry.myDottedGeometrySegments.front().shape.size() > 0) &&
191 (botDottedGeometry.myDottedGeometrySegments.front().shape.size() > 0)) {
192 // add first extreme
194 topDottedGeometry.myDottedGeometrySegments.front().shape.front(),
195 botDottedGeometry.myDottedGeometrySegments.front().shape.front()}));
196 }
197 if (drawLastExtrem &&
198 (topDottedGeometry.myDottedGeometrySegments.back().shape.size() > 0) &&
199 (botDottedGeometry.myDottedGeometrySegments.back().shape.size() > 0)) {
200 // add last extreme
202 topDottedGeometry.myDottedGeometrySegments.back().shape.back(),
203 botDottedGeometry.myDottedGeometrySegments.back().shape.back()}));
204 // invert offset of second dotted geometry
205 myDottedGeometrySegments.back().offset *= -1;
206 }
207 }
208 // resample
209 for (auto& segment : myDottedGeometrySegments) {
210 segment.shape = segment.shape.resample(s.dottedContourSettings.segmentLength, true);
211 }
212 // calculate shape rotations and lengths
214}
215
216
217void
219 // reset segments
221 // get shape
222 for (int i = 1; i < (int)laneShape.size(); i++) {
223 myDottedGeometrySegments.push_back(Segment({laneShape[i - 1], laneShape[i]}));
224 }
225 // resample
226 for (auto& segment : myDottedGeometrySegments) {
227 segment.shape = segment.shape.resample(s.dottedContourSettings.segmentLength, true);
228 }
229 // calculate shape rotations and lengths
231}
232
233
234void
236 // reset segments
238 // check if shape has to be closed
239 if (closeShape && (shape.size() > 2)) {
240 shape.closePolygon();
241 }
242 if (shape.size() > 1) {
243 // get shape
244 for (int i = 1; i < (int)shape.size(); i++) {
245 myDottedGeometrySegments.push_back(Segment({shape[i - 1], shape[i]}));
246 }
247 // resample
248 for (auto& segment : myDottedGeometrySegments) {
249 segment.shape = segment.shape.resample(s.dottedContourSettings.segmentLength, true);
250 }
251 // calculate shape rotations and lengths
253 }
254}
255
256
257void
259 DottedGeometryColor& dottedGeometryColor, const double customWidth) const {
260 // set segment width
262 switch (type) {
267 // use segment width small
269 break;
272 // use custom width
273 width = customWidth;
274 break;
275 default:
276 // use segment width large
277 break;
278 }
279 // iterate over all segments
280 for (auto& segment : myDottedGeometrySegments) {
281 // iterate over shape
282 for (int i = 0; i < ((int)segment.shape.size() - 1); i++) {
283 // set color
284 GLHelper::setColor(dottedGeometryColor.getColor(type));
285 // draw box line
286 GLHelper::drawBoxLine(segment.shape[i], segment.rotations.at(i), segment.lengths.at(i), width, 0);
287 }
288 }
289}
290
291
292void
294 // move 2 side
295 for (auto& segment : myDottedGeometrySegments) {
296 segment.shape.move2side(value);
297 }
298}
299
300
301void
303 // iterate over all segments
304 for (auto& segment : myDottedGeometrySegments) {
305 segment.offset *= -1;
306 }
307}
308
309
310void
312 const PositionVector& shape, const double exaggeration, const double customWidth) {
313 if (s.drawDottedContour(exaggeration)) {
314 // declare DottedGeometryColor
315 DottedGeometryColor dottedGeometryColor(s);
316 // scale shape using exaggeration and default dotted geometry width
317 PositionVector scaledShape = shape;
318 // scale exaggeration
319 scaledShape.scaleRelative(exaggeration);
320 // calculate dotted geometry
321 GUIDottedGeometry dottedGeometry(s, scaledShape, true);
322 // Push draw matrix
324 // draw inspect or front dotted contour
325 if (type == DottedContourType::FRONT) {
326 // translate to front
327 glTranslated(0, 0, GLO_DOTTEDCONTOUR_INSPECTED);
328 } else {
329 // translate to front
330 glTranslated(0, 0, GLO_DOTTEDCONTOUR_INSPECTED);
331 }
332 // draw dotted geometry
333 dottedGeometry.drawDottedGeometry(s, type, dottedGeometryColor, customWidth);
334 // pop matrix
336 }
337}
338
339
340void
342 const PositionVector& shape, const double width, const double exaggeration, const bool drawFirstExtrem,
343 const bool drawLastExtrem) {
344 if (s.drawDottedContour(exaggeration)) {
345 // declare DottedGeometryColor
346 DottedGeometryColor dottedGeometryColor(s);
347 // calculate center dotted geometry
348 GUIDottedGeometry dottedGeometry(s, shape, false);
349 // make a copy of dotted geometry
350 GUIDottedGeometry topDottedGeometry = dottedGeometry;
351 GUIDottedGeometry botDottedGeometry = dottedGeometry;
352 // move geometries top and bot
353 topDottedGeometry.moveShapeToSide(width * exaggeration);
354 botDottedGeometry.moveShapeToSide(width * exaggeration * -1);
355 // invert offset of top dotted geometry
356 topDottedGeometry.invertOffset();
357 // calculate extremes
358 GUIDottedGeometry extremes(s, topDottedGeometry, drawFirstExtrem, botDottedGeometry, drawLastExtrem);
359 // Push draw matrix
361 // translate to front
362 if (type == DottedContourType::FRONT) {
363 // translate to front
364 glTranslated(0, 0, GLO_DOTTEDCONTOUR_FRONT);
365 } else {
366 // translate to front
367 glTranslated(0, 0, GLO_DOTTEDCONTOUR_INSPECTED);
368 }
369 // draw top dotted geometry
370 topDottedGeometry.drawDottedGeometry(s, type, dottedGeometryColor);
371 // reset color
372 dottedGeometryColor.reset();
373 // draw top dotted geometry
374 botDottedGeometry.drawDottedGeometry(s, type, dottedGeometryColor);
375 // change color
376 dottedGeometryColor.changeColor();
377 // draw extrem dotted geometry
378 extremes.drawDottedGeometry(s, type, dottedGeometryColor);
379 // pop matrix
381 }
382}
383
384
385void
387 const double radius, const double exaggeration) {
388 // continue depending of exaggeratedRadio
389 if ((radius * exaggeration) < 2) {
390 drawDottedContourClosedShape(s, type, GUIGeometry::getVertexCircleAroundPosition(pos, radius, 8), exaggeration);
391 } else {
392 drawDottedContourClosedShape(s, type, GUIGeometry::getVertexCircleAroundPosition(pos, radius, 16), exaggeration);
393 }
394}
395
396
397void
399 const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration) {
400 if (s.drawDottedContour(exaggeration)) {
401 // create shape
402 PositionVector shape;
403 // make rectangle
404 shape.push_back(Position(0 + width, 0 + height));
405 shape.push_back(Position(0 + width, 0 - height));
406 shape.push_back(Position(0 - width, 0 - height));
407 shape.push_back(Position(0 - width, 0 + height));
408 // move shape
409 shape.add(offsetX, offsetY, 0);
410 // rotate shape
411 shape.rotate2D(DEG2RAD((rot * -1) + 90));
412 // move to position
413 shape.add(pos);
414 // draw using drawDottedContourClosedShape
415 drawDottedContourClosedShape(s, type, shape, exaggeration);
416 }
417}
418
419
420void
422 // iterate over all segments
423 for (auto& segment : myDottedGeometrySegments) {
424 // Get number of parts of the shape
425 int numberOfSegments = (int)segment.shape.size() - 1;
426 // If number of segments is more than 0
427 if (numberOfSegments >= 0) {
428 // Reserve memory (To improve efficiency)
429 segment.rotations.reserve(numberOfSegments);
430 segment.lengths.reserve(numberOfSegments);
431 // Calculate lengths and rotations for every shape
432 for (int i = 0; i < numberOfSegments; i++) {
433 segment.rotations.push_back(GUIGeometry::calculateRotation(segment.shape[i], segment.shape[i + 1]));
434 segment.lengths.push_back(GUIGeometry::calculateLength(segment.shape[i], segment.shape[i + 1]));
435 }
436 }
437 }
438}
439
440/****************************************************************************/
#define MAXIMUM_DOTTEDGEOMETRYLENGTH
@ GLO_DOTTEDCONTOUR_INSPECTED
dotted contour inspected element (used in NETEDIT)
@ GLO_DOTTEDCONTOUR_FRONT
dotted contour front element (used in NETEDIT)
#define DEG2RAD(x)
Definition: GeomHelper.h:35
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:583
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:277
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
class for pack all variables related with GUIDottedGeometry color
const RGBColor getColor(DottedContourType type)
get inspected color (and change flag)
void reset()
rest Dotted Geometry Color
DottedGeometryColor(const GUIVisualizationSettings &settings)
constructor
std::vector< GUIDottedGeometry::Segment > myDottedGeometrySegments
dotted element shape (note: It's centered in 0,0 due scaling)
void drawDottedGeometry(const GUIVisualizationSettings &s, GUIDottedGeometry::DottedContourType type, DottedGeometryColor &dottedGeometryColor, const double customWidth=1) const
draw inspected dottedShape
void moveShapeToSide(const double value)
move shape to side
void calculateShapeRotationsAndLengths()
calculate shape rotations and lengths
static void drawDottedContourClosedShape(const GUIVisualizationSettings &s, const DottedContourType type, const PositionVector &shape, const double exaggeration, const double customWidth=1)
draw dotted contour for the given closed shape (used by Juctions, shapes and TAZs)
void updateDottedGeometry(const GUIVisualizationSettings &s, const PositionVector &laneShape)
update GUIDottedGeometry (using lane shape)
void invertOffset()
invert offset of all segments
static void drawDottedSquaredShape(const GUIVisualizationSettings &s, const DottedContourType type, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
static void drawDottedContourCircle(const GUIVisualizationSettings &s, const DottedContourType type, const Position &pos, const double radius, const double exaggeration)
draw dotted contour for the given Position and radius (used by Juctions and POIs)
GUIDottedGeometry()
constructor
static void drawDottedContourShape(const GUIVisualizationSettings &s, const DottedContourType type, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem)
draw dotted contour for the given shape (used by additionals)
static PositionVector getVertexCircleAroundPosition(const Position &pos, const double width, const int steps=8)
get a circle around the given 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.
bool drawDottedContour(const double exaggeration) const
check if dotted contour can be drawn
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.
double length2D() const
Returns the length.
void rotate2D(double angle)
void add(double xoff, double yoff, double zoff)
void closePolygon()
ensures that the last position equals the first
void scaleRelative(double factor)
enlarges/shrinks the polygon by a factor based at the centroid
static const RGBColor BLUE
Definition: RGBColor.h:187
static const RGBColor YELLOW
Definition: RGBColor.h:188
static const RGBColor ORANGE
Definition: RGBColor.h:191
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
Segment()
default constructor
static const double segmentWidthSmall
width of dotted contour segments
static const double segmentLength
length of dotted contour segments
static const double segmentWidthLarge
width of dotted contour segments