Eclipse SUMO - Simulation of Urban MObility
GNEGeometry.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 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 geometry classes and functions
19 /****************************************************************************/
20 #pragma once
21 #include <config.h>
22 
25 #include <utils/common/ToString.h>
33 
35 
36 #include "GNEReferenceCounter.h"
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
43 class GNELane;
44 class GNEEdge;
45 class GNEAdditional;
46 class GNEDemandElement;
47 class GNEJunction;
48 class GNEViewNet;
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
54 
55 struct GNEGeometry {
56 
58  struct ExtremeGeometry {
61 
64 
67 
70 
73  };
74 
76  class Geometry {
77 
78  public:
80  Geometry();
81 
83  Geometry(const PositionVector& shape);
84 
86  Geometry(const PositionVector& shape, const std::vector<double>& shapeRotations, const std::vector<double>& shapeLengths);
87 
92  void updateGeometry(const PositionVector& shape, double startPos = -1, double endPos = -1,
93  const Position& extraFirstPosition = Position::INVALID,
94  const Position& extraLastPosition = Position::INVALID);
95 
97  void updateGeometry(const Position& position, const double rotation);
98 
100  void updateGeometry(const GNELane* lane, const double posOverLane);
101 
103  void updateGeometry(const GNELane* lane);
104 
106  void updateGeometry(const GNEAdditional* additional);
107 
109  void updateGeometry(const Geometry& geometry);
110 
112  void scaleGeometry(const double scale);
113 
115  const PositionVector& getShape() const;
116 
118  const std::vector<double>& getShapeRotations() const;
119 
121  const std::vector<double>& getShapeLengths() const;
122 
123  private:
125  void clearGeometry();
126 
129 
132 
134  std::vector<double> myShapeRotations;
135 
137  std::vector<double> myShapeLengths;
138 
140  const GNELane* myLane;
141 
144 
146  Geometry& operator=(const Geometry& other) = delete;
147  };
148 
150  enum class DottedContourType {
151  INSPECT,
152  FRONT,
153  MOVE
154  };
155 
158 
159  public:
162 
164  const RGBColor& getInspectedColor();
165 
167  const RGBColor& getFrontColor();
168 
170  void changeColor();
171 
173  void reset();
174 
175  private:
178 
181 
184  };
185 
188 
189  public:
191  struct Segment {
193  Segment();
194 
196  Segment(PositionVector newShape);
197 
200 
202  std::vector<double> rotations;
203 
205  std::vector<double> lengths;
206 
208  double offset;
209  };
210 
212  DottedGeometry();
213 
215  DottedGeometry(const GUIVisualizationSettings& s, PositionVector shape, const bool closeShape);
216 
219  const DottedGeometry& topDottedGeometry, const bool drawFirstExtrem,
220  const DottedGeometry& botDottedGeometry, const bool drawLastExtrem);
221 
223  void updateDottedGeometry(const GUIVisualizationSettings& s, const GNELane* lane);
224 
226  void updateDottedGeometry(const GUIVisualizationSettings& s, PositionVector shape, const bool closeShape);
227 
229  void drawInspectedDottedGeometry(DottedGeometryColor& dottedGeometryColor) const;
230 
232  void drawFrontDottedGeometry(DottedGeometryColor& dottedGeometryColor) const;
233 
235  void moveShapeToSide(const double value);
236 
238  double getWidth() const;
239 
241  void setWidth(const double width);
242 
244  void invertOffset();
245 
246  private:
249 
251  double myWidth;
252 
254  std::vector<DottedGeometry::Segment> myDottedGeometrySegments;
255 
257  DottedGeometry& operator=(const DottedGeometry& other) = delete;
258  };
259 
262 
264  class Segment {
265 
266  public:
268  Segment(const GNELane* lane, const bool valid);
269 
271  Segment(const GNELane* lane, const Geometry& geometry, const bool valid);
272 
274  Segment(const GNELane* lane, const GNELane* nextLane, const bool valid);
275 
277  void update(const Geometry& geometry);
278 
280  void update(const GNELane* lane);
281 
283  const PositionVector& getShape() const;
284 
286  const std::vector<double>& getShapeRotations() const;
287 
289  const std::vector<double>& getShapeLengths() const;
290 
292  const GNELane* getLane() const;
293 
295  const GNEJunction* getJunction() const;
296 
298  bool getValid() const;
299 
301  bool isLaneSegment() const;
302 
303  protected:
305  const GNELane* myLane;
306 
309 
311  const bool myValid;
312 
315 
316  private:
319 
321  Segment& operator=(const Segment& other) = delete;
322  };
323 
326 
327  public:
329  SegmentToUpdate(const int segmentIndex, const GNELane* lane, const GNELane* nextLane);
330 
332  int getSegmentIndex() const;
333 
334  // @brief get lane segment
335  const GNELane* getLane() const;
336 
338  const GNELane* getNextLane() const;
339 
340  private:
342  const int mySegmentIndex;
343 
344  // @brief lane segment
345  const GNELane* myLane;
346 
349 
350  private:
352  SegmentToUpdate& operator=(const SegmentToUpdate& other) = delete;
353  };
354 
356  SegmentGeometry();
357 
359  void insertLaneSegment(const GNELane* lane, const bool valid);
360 
362  void insertCustomSegment(const GNELane* lane, const Geometry& geometry, const bool valid);
363 
365  void insertLane2LaneSegment(const GNELane* currentLane, const GNELane* nextLane, const bool valid);
366 
368  void updateCustomSegment(const int segmentIndex, const Geometry& geometry);
369 
371  void updateLane2LaneSegment(const int segmentIndex, const GNELane* lane, const GNELane* nextLane);
372 
374  void clearSegmentGeometry();
375 
377  const Position& getFirstPosition() const;
378 
380  const Position& getLastPosition() const;
381 
383  double getFirstRotation() const;
384 
386  Boundary getBoxBoundary() const;
387 
389  std::vector<Segment>::const_iterator begin() const;
390 
392  std::vector<Segment>::const_iterator end() const;
393 
395  const Segment& front() const;
396 
398  const Segment& back() const;
399 
401  int size() const;
402 
403  private:
405  std::vector<Segment> myShapeSegments;
406 
408  SegmentGeometry& operator=(const SegmentGeometry& other) = delete;
409  };
410 
413 
414  public:
416  Lane2laneConnection(const GNELane* fromLane);
417 
420 
422  bool exist(const GNELane* toLane) const;
423 
425  const GNEGeometry::Geometry& getLane2laneGeometry(const GNELane* toLane) const;
426 
429 
430  protected:
433 
435  std::map<const GNELane*, std::pair<GNEGeometry::Geometry, GNEGeometry::DottedGeometry> > myConnectionsMap;
436 
437  private:
440 
443  };
444 
447 
448  private:
451 
452  public:
455 
457  const GNELane* getLane() const;
458 
460  const Position& getPosition() const;
461 
463  double getRotation() const;
464 
465  private:
468 
471 
473  double myRotation;
474 
477  };
478 
479  public:
481  HierarchicalConnections(GNEHierarchicalElement* hierarchicalElement);
482 
484  void update();
485 
487  void drawConnection(const GUIVisualizationSettings& s, const GNEAttributeCarrier* AC, const double exaggeration) const;
488 
490  void drawDottedConnection(const DottedContourType type, const GUIVisualizationSettings& s, const double exaggeration) const;
491 
493  std::vector<ConnectionGeometry> symbolsPositionAndRotation;
494 
496  std::vector<GNEGeometry::Geometry> connectionsGeometries;
497 
498  private:
501  };
502 
504  static double calculateRotation(const Position& first, const Position& second);
505 
507  static double calculateLength(const Position& first, const Position& second);
508 
510  static void adjustStartPosGeometricPath(double& startPos, const GNELane* startLane, double& endPos, const GNELane* endLane);
511 
517  static void calculateLaneGeometricPath(GNEGeometry::SegmentGeometry& segmentGeometry,
518  const std::vector<GNEPathElements::PathElement>& path,
519  GNEGeometry::ExtremeGeometry& extremeGeometry);
520 
526  static void updateGeometricPath(GNEGeometry::SegmentGeometry& segmentGeometry, const GNELane* lane,
527  GNEGeometry::ExtremeGeometry& extremeGeometry);
528 
530  static void drawLaneGeometry(const GNEViewNet* viewNet, const PositionVector& shape, const std::vector<double>& rotations,
531  const std::vector<double>& lengths, const std::vector<RGBColor>& colors, double width);
532 
534  static void drawGeometry(const GNEViewNet* viewNet, const Geometry& geometry, const double width);
535 
537  static void drawGeometryPoints(const GUIVisualizationSettings& s, const GNEViewNet* viewNet, const PositionVector& shape,
538  const RGBColor& geometryPointColor, const RGBColor& textColor, const double radius, const double exaggeration);
539 
541  static void drawMovingHint(const GUIVisualizationSettings& s, const GNEViewNet* viewNet, const PositionVector& shape,
542  const RGBColor& hintColor, const double radius, const double exaggeration);
543 
545  static void drawSegmentGeometry(const GNEViewNet* viewNet, const SegmentGeometry::Segment& segment, const double width);
546 
548  static void drawDottedContourLane(const DottedContourType type, const GUIVisualizationSettings& s, const DottedGeometry& dottedGeometry, const double width, const bool drawFirstExtrem, const bool drawLastExtrem);
549 
551  static void drawDottedContourEdge(const DottedContourType type, const GUIVisualizationSettings& s, const GNEEdge* edge, const bool drawFrontExtreme, const bool drawBackExtreme);
552 
554  static void drawDottedContourClosedShape(const DottedContourType type, const GUIVisualizationSettings& s, const PositionVector& shape, const double exaggeration);
555 
557  static void drawDottedContourShape(const DottedContourType type, const GUIVisualizationSettings& s, const PositionVector& shape, const double width, const double exaggeration);
558 
560  static void drawDottedContourCircle(const DottedContourType type, const GUIVisualizationSettings& s, const Position& pos, const double radius, const double exaggeration);
561 
563  static void drawDottedSquaredShape(const DottedContourType type, const GUIVisualizationSettings& s, const Position& pos,
564  const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration);
565 
567  static PositionVector getVertexCircleAroundPosition(const Position& pos, const double width, const int steps = 8);
568 
570  static void rotateOverLane(const double rot);
571 
572 private:
575 
577  static int angleLookup(const double angleDeg);
578 };
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
An Element which don't belongs to GNENet but has influency in the simulation.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:49
class for pack all variables related with DottedGeometry color
Definition: GNEGeometry.h:157
DottedGeometryColor(const GUIVisualizationSettings &settings)
constructor
const GUIVisualizationSettings & mySettings
pointer to GUIVisualizationSettings
Definition: GNEGeometry.h:177
void reset()
rest Dotted Geometry Color
const RGBColor & getFrontColor()
get front color (and change flag)
bool myColorFlag
flag to get color
Definition: GNEGeometry.h:180
const RGBColor & getInspectedColor()
get inspected color (and change flag)
DottedGeometryColor & operator=(const DottedGeometryColor &other)=delete
Invalidated assignment operator.
class for pack all variables related with DottedGeometry
Definition: GNEGeometry.h:187
void moveShapeToSide(const double value)
move shape to side
double getWidth() const
get width
double myWidth
geometry width
Definition: GNEGeometry.h:251
void updateDottedGeometry(const GUIVisualizationSettings &s, const GNELane *lane)
update DottedGeometry (using lane shape)
void drawFrontDottedGeometry(DottedGeometryColor &dottedGeometryColor) const
draw front inspected dottedShape
void drawInspectedDottedGeometry(DottedGeometryColor &dottedGeometryColor) const
draw inspected dottedShape
DottedGeometry & operator=(const DottedGeometry &other)=delete
Invalidated assignment operator.
void calculateShapeRotationsAndLengths()
calculate shape rotations and lengths
std::vector< DottedGeometry::Segment > myDottedGeometrySegments
dotted element shape (note: It's centered in 0,0 due scaling)
Definition: GNEGeometry.h:254
void setWidth(const double width)
change default width
void invertOffset()
invert offset of all segments
class for NETEDIT geometries over lanes
Definition: GNEGeometry.h:76
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
Geometry()
constructor
Definition: GNEGeometry.cpp:56
Geometry & operator=(const Geometry &other)=delete
Invalidated assignment operator.
void scaleGeometry(const double scale)
scale geometry
std::vector< double > myShapeLengths
The lengths of the shape (note: Always size = myShape.size()-1)
Definition: GNEGeometry.h:137
const GNELane * myLane
lane (to use lane geometry)
Definition: GNEGeometry.h:140
std::vector< double > myShapeRotations
The rotations of the shape (note: Always size = myShape.size()-1)
Definition: GNEGeometry.h:134
PositionVector myShape
element shape
Definition: GNEGeometry.h:131
void calculateShapeRotationsAndLengths()
calculate shape rotations and lengths
const PositionVector & getShape() const
The shape of the additional element.
const GNEAdditional * myAdditional
additional (to use additional geometry)
Definition: GNEGeometry.h:143
void clearGeometry()
clear geometry
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
const std::vector< double > & getShapeLengths() const
The lengths of the single shape parts.
const Position & getPosition() const
get position
class to pack all variables and functions relative to connections between hierarchical element and th...
Definition: GNEGeometry.h:446
void drawConnection(const GUIVisualizationSettings &s, const GNEAttributeCarrier *AC, const double exaggeration) const
draw connections between Parent and childrens
void update()
update Connection's geometry
GNEHierarchicalElement * myHierarchicalElement
pointer to hierarchical element parent
Definition: GNEGeometry.h:500
std::vector< ConnectionGeometry > symbolsPositionAndRotation
position and rotation of every symbol over lane
Definition: GNEGeometry.h:493
HierarchicalConnections(GNEHierarchicalElement *hierarchicalElement)
constructor
std::vector< GNEGeometry::Geometry > connectionsGeometries
geometry connections between parents an their children
Definition: GNEGeometry.h:496
void drawDottedConnection(const DottedContourType type, const GUIVisualizationSettings &s, const double exaggeration) const
draw dotted connections between Parent and childrens
class lane2lane connection geometry
Definition: GNEGeometry.h:412
bool exist(const GNELane *toLane) const
check if exist a lane2lane geometry for the given tolane
Lane2laneConnection & operator=(const Lane2laneConnection &other)=delete
Invalidated assignment operator.
const GNEGeometry::Geometry & getLane2laneGeometry(const GNELane *toLane) const
get lane2lane geometry
const GNEGeometry::DottedGeometry & getLane2laneDottedGeometry(const GNELane *toLane) const
get lane2lane dotted geometry
std::map< const GNELane *, std::pair< GNEGeometry::Geometry, GNEGeometry::DottedGeometry > > myConnectionsMap
connection shape
Definition: GNEGeometry.h:435
const GNELane * myFromLane
from lane
Definition: GNEGeometry.h:432
struct used for represent segments of element geometry
Definition: GNEGeometry.h:264
Segment(const GNELane *lane, const bool valid)
parameter constructor for lanes (geometry will be taked from lane)
const std::vector< double > & getShapeRotations() const
get lane/lane2lane shape rotations
Segment & operator=(const Segment &other)=delete
Invalidated assignment operator.
bool myUseLaneShape
flag to use lane shape
Definition: GNEGeometry.h:314
const PositionVector & getShape() const
get lane/lane2lane shape
bool isLaneSegment() const
return true if this is a lane segment (i.e. myNextLane is nullptr)
const GNELane * getLane() const
lane (only for lane segments)
Geometry mySegmentGeometry
geometry used in segment
Definition: GNEGeometry.h:318
const std::vector< double > & getShapeLengths() const
get lane/lane2lane shape lengths
const GNEJunction * getJunction() const
junction
void update(const Geometry &geometry)
update segment using geometry
const GNELane * myNextLane
nextLane
Definition: GNEGeometry.h:308
struct used for represent segments that must be updated
Definition: GNEGeometry.h:325
int getSegmentIndex() const
get segment index
SegmentToUpdate & operator=(const SegmentToUpdate &other)=delete
Invalidated assignment operator.
const GNELane * myNextLane
lane segment (used for updating lane2lane segments)
Definition: GNEGeometry.h:348
SegmentToUpdate(const int segmentIndex, const GNELane *lane, const GNELane *nextLane)
constructor
const GNELane * getNextLane() const
get lane segment (used for updating lane2lane segments)
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:45
Stores the information about how to visualize structures.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:282
A list of positions.
double offset
drawing offset (-1 or 1 only)
Definition: GNEGeometry.h:208
std::vector< double > lengths
lengths
Definition: GNEGeometry.h:205
std::vector< double > rotations
rotations
Definition: GNEGeometry.h:202
struct for variables used in Geometry extremes
Definition: GNEGeometry.h:58
double laneEndPosition
arrival position over lane
Definition: GNEGeometry.h:66
Position viewEndPos
end position over view
Definition: GNEGeometry.h:72
double laneStartPosition
depart position over lane
Definition: GNEGeometry.h:63
Position viewStartPos
start position over view
Definition: GNEGeometry.h:69
struct for pack all variables related with geometry of elemements divided in segments
Definition: GNEGeometry.h:261
SegmentGeometry & operator=(const SegmentGeometry &other)=delete
Invalidated assignment operator.
void insertCustomSegment(const GNELane *lane, const Geometry &geometry, const bool valid)
insert custom segment
int size() const
number of segments
void updateCustomSegment(const int segmentIndex, const Geometry &geometry)
update custom segment
const Segment & back() const
back segment
std::vector< Segment >::const_iterator end() const
end iterator
const Position & getFirstPosition() const
get first position (or Invalid position if segments are empty)
const Position & getLastPosition() const
get first position (or Invalid position if segments are empty)
void updateLane2LaneSegment(const int segmentIndex, const GNELane *lane, const GNELane *nextLane)
update lane2Lane segment (used to avoid unnecessary calculation in calculatePartialShapeRotationsAndL...
void insertLaneSegment(const GNELane *lane, const bool valid)
insert entire lane segment (used to avoid unnecessary calculation in calculatePartialShapeRotationsAn...
std::vector< Segment > myShapeSegments
vector of segments that constitutes the shape
Definition: GNEGeometry.h:405
std::vector< Segment >::const_iterator begin() const
begin iterator
double getFirstRotation() const
get first rotation (or Invalid position if segments are empty)
const Segment & front() const
front segment
void clearSegmentGeometry()
clear element geometry
void insertLane2LaneSegment(const GNELane *currentLane, const GNELane *nextLane, const bool valid)
insert entire lane2lane segment (used to avoid unnecessary calculation in calculatePartialShapeRotati...
Boundary getBoxBoundary() const
Returns a boundary enclosing all segments.
static void drawDottedContourClosedShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double exaggeration)
draw dotted contour for the given closed shape (used by Juctions, shapes and TAZs)
static void drawGeometryPoints(const GUIVisualizationSettings &s, const GNEViewNet *viewNet, const PositionVector &shape, const RGBColor &geometryPointColor, const RGBColor &textColor, const double radius, const double exaggeration)
draw geometry points
static void drawDottedContourLane(const DottedContourType type, const GUIVisualizationSettings &s, const DottedGeometry &dottedGeometry, const double width, const bool drawFirstExtrem, const bool drawLastExtrem)
draw dotted contour for the given dottedGeometry (used by lanes, routes, etc.)
static double calculateRotation(const Position &first, const Position &second)
return angle between two points (used in geometric calculations)
static void adjustStartPosGeometricPath(double &startPos, const GNELane *startLane, double &endPos, const GNELane *endLane)
adjust start and end positions in geometric path
static void drawDottedContourShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration)
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 void calculateLaneGeometricPath(GNEGeometry::SegmentGeometry &segmentGeometry, const std::vector< GNEPathElements::PathElement > &path, GNEGeometry::ExtremeGeometry &extremeGeometry)
calculate route between lanes
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
static PositionVector myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
Definition: GNEGeometry.h:574
static void updateGeometricPath(GNEGeometry::SegmentGeometry &segmentGeometry, const GNELane *lane, GNEGeometry::ExtremeGeometry &extremeGeometry)
calculate route between edges
static void drawDottedContourEdge(const DottedContourType type, const GUIVisualizationSettings &s, const GNEEdge *edge, const bool drawFrontExtreme, const bool drawBackExtreme)
draw dotted contour for the given dottedGeometries (used by edges)
static void drawSegmentGeometry(const GNEViewNet *viewNet, const SegmentGeometry::Segment &segment, const double width)
draw geometry segment
static void drawGeometry(const GNEViewNet *viewNet, const Geometry &geometry, const double width)
draw geometry
static void drawMovingHint(const GUIVisualizationSettings &s, const GNEViewNet *viewNet, const PositionVector &shape, const RGBColor &hintColor, const double radius, const double exaggeration)
draw moving hint
static void drawDottedContourCircle(const DottedContourType type, const GUIVisualizationSettings &s, const Position &pos, const double radius, const double exaggeration)
draw dotted contour for the given Position and radius (used by Juctions and POIs)
static void drawDottedSquaredShape(const DottedContourType type, const GUIVisualizationSettings &s, 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 int angleLookup(const double angleDeg)
normalize angle for lookup in myCircleCoords
static double calculateLength(const Position &first, const Position &second)
return length between two points (used in geometric calculations)
static void drawLaneGeometry(const GNEViewNet *viewNet, const PositionVector &shape, const std::vector< double > &rotations, const std::vector< double > &lengths, const std::vector< RGBColor > &colors, double width)
draw lane geometry (use their own function due colors)