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-2023 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 // translate to front
325 glTranslated(0, 0, GLO_DOTTEDCONTOUR_INSPECTED);
326 // draw dotted geometry
327 dottedGeometry.drawDottedGeometry(s, type, dottedGeometryColor, customWidth);
328 // pop matrix
330 }
331}
332
333
334void
336 const PositionVector& shape, const double width, const double exaggeration, const bool drawFirstExtrem,
337 const bool drawLastExtrem) {
338 if (s.drawDottedContour(exaggeration)) {
339 // declare DottedGeometryColor
340 DottedGeometryColor dottedGeometryColor(s);
341 // calculate center dotted geometry
342 GUIDottedGeometry dottedGeometry(s, shape, false);
343 // make a copy of dotted geometry
344 GUIDottedGeometry topDottedGeometry = dottedGeometry;
345 GUIDottedGeometry botDottedGeometry = dottedGeometry;
346 // move geometries top and bot
347 topDottedGeometry.moveShapeToSide(width * exaggeration);
348 botDottedGeometry.moveShapeToSide(width * exaggeration * -1);
349 // invert offset of top dotted geometry
350 topDottedGeometry.invertOffset();
351 // calculate extremes
352 GUIDottedGeometry extremes(s, topDottedGeometry, drawFirstExtrem, botDottedGeometry, drawLastExtrem);
353 // Push draw matrix
355 // translate to front
356 glTranslated(0, 0, GLO_DOTTEDCONTOUR_INSPECTED);
357 // draw top dotted geometry
358 topDottedGeometry.drawDottedGeometry(s, type, dottedGeometryColor);
359 // reset color
360 dottedGeometryColor.reset();
361 // draw top dotted geometry
362 botDottedGeometry.drawDottedGeometry(s, type, dottedGeometryColor);
363 // change color
364 dottedGeometryColor.changeColor();
365 // draw extrem dotted geometry
366 extremes.drawDottedGeometry(s, type, dottedGeometryColor);
367 // pop matrix
369 }
370}
371
372
373void
375 const double radius, const double exaggeration) {
376 // continue depending of exaggeratedRadio
377 if ((radius * exaggeration) < 2) {
378 drawDottedContourClosedShape(s, type, GUIGeometry::getVertexCircleAroundPosition(pos, radius, 8), exaggeration);
379 } else {
380 drawDottedContourClosedShape(s, type, GUIGeometry::getVertexCircleAroundPosition(pos, radius, 16), exaggeration);
381 }
382}
383
384
385void
387 const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration) {
388 if (s.drawDottedContour(exaggeration)) {
389 // create shape
390 PositionVector shape;
391 // make rectangle
392 shape.push_back(Position(0 + width, 0 + height));
393 shape.push_back(Position(0 + width, 0 - height));
394 shape.push_back(Position(0 - width, 0 - height));
395 shape.push_back(Position(0 - width, 0 + height));
396 // move shape
397 shape.add(offsetX, offsetY, 0);
398 // rotate shape
399 shape.rotate2D(DEG2RAD((rot * -1) + 90));
400 // move to position
401 shape.add(pos);
402 // draw using drawDottedContourClosedShape
403 drawDottedContourClosedShape(s, type, shape, exaggeration);
404 }
405}
406
407
408void
410 // iterate over all segments
411 for (auto& segment : myDottedGeometrySegments) {
412 // Get number of parts of the shape
413 int numberOfSegments = (int)segment.shape.size() - 1;
414 // If number of segments is more than 0
415 if (numberOfSegments >= 0) {
416 // Reserve memory (To improve efficiency)
417 segment.rotations.reserve(numberOfSegments);
418 segment.lengths.reserve(numberOfSegments);
419 // Calculate lengths and rotations for every shape
420 for (int i = 0; i < numberOfSegments; i++) {
421 segment.rotations.push_back(GUIGeometry::calculateRotation(segment.shape[i], segment.shape[i + 1]));
422 segment.lengths.push_back(GUIGeometry::calculateLength(segment.shape[i], segment.shape[i + 1]));
423 }
424 }
425 }
426}
427
428/****************************************************************************/
#define MAXIMUM_DOTTEDGEOMETRYLENGTH
@ GLO_DOTTEDCONTOUR_INSPECTED
dotted contour inspected 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
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