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-2021 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 
34 #include "GNEReferenceCounter.h"
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
41 class GNELane;
42 class GNEEdge;
43 class GNEAdditional;
44 class GNEDemandElement;
45 class GNEJunction;
46 class GNEViewNet;
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
52 
53 struct GNEGeometry {
54 
56  class Geometry {
57 
58  public:
60  Geometry();
61 
63  Geometry(const PositionVector& shape);
64 
66  Geometry(const PositionVector& shape, const std::vector<double>& shapeRotations, const std::vector<double>& shapeLengths);
67 
69  void updateGeometry(const PositionVector& shape);
70 
72  void updateGeometry(const PositionVector& shape, const double posOverShape, const double lateralOffset);
73 
75  void updateGeometry(const PositionVector& shape, double starPosOverShape, double endPosOverShape, const double lateralOffset);
76 
80  void updateGeometry(const PositionVector& shape, double beginTrimPosition, double endTrimPosition,
81  const Position& extraFirstPosition, const Position& extraLastPosition);
82 
84  void updateSinglePosGeometry(const Position& position, const double rotation);
85 
87  void scaleGeometry(const double scale);
88 
90  const PositionVector& getShape() const;
91 
93  const std::vector<double>& getShapeRotations() const;
94 
96  const std::vector<double>& getShapeLengths() const;
97 
98  protected:
100  void clearGeometry();
101 
104 
107 
109  std::vector<double> myShapeRotations;
110 
112  std::vector<double> myShapeLengths;
113  };
114 
116  enum class DottedContourType {
117  INSPECT,
118  FRONT,
119  MOVE,
120  GREEN,
121  MAGENTA
122  };
123 
126 
127  public:
130 
132  const RGBColor getColor(DottedContourType type);
133 
135  void changeColor();
136 
138  void reset();
139 
140  private:
143 
146 
148  DottedGeometryColor& operator=(const DottedGeometryColor& other) = delete;
149  };
150 
153 
154  public:
156  struct Segment {
158  Segment();
159 
161  Segment(PositionVector newShape);
162 
165 
167  std::vector<double> rotations;
168 
170  std::vector<double> lengths;
171 
173  double offset;
174  };
175 
177  DottedGeometry();
178 
180  DottedGeometry(const GUIVisualizationSettings& s, PositionVector shape, const bool closeShape);
181 
184  const DottedGeometry& topDottedGeometry, const bool drawFirstExtrem,
185  const DottedGeometry& botDottedGeometry, const bool drawLastExtrem);
186 
188  void updateDottedGeometry(const GUIVisualizationSettings& s, const GNELane* lane);
189 
191  void updateDottedGeometry(const GUIVisualizationSettings& s, PositionVector shape, const bool closeShape);
192 
194  void drawDottedGeometry(DottedGeometryColor& dottedGeometryColor, GNEGeometry::DottedContourType type, const double customWidth = -1) const;
195 
197  void moveShapeToSide(const double value);
198 
200  double getWidth() const;
201 
203  void setWidth(const double width);
204 
206  void invertOffset();
207 
208  private:
211 
213  double myWidth;
214 
216  std::vector<DottedGeometry::Segment> myDottedGeometrySegments;
217 
219  DottedGeometry& operator=(const DottedGeometry& other) = delete;
220  };
221 
224 
225  public:
227  Lane2laneConnection(const GNELane* fromLane);
228 
231 
233  bool exist(const GNELane* toLane) const;
234 
236  const GNEGeometry::Geometry& getLane2laneGeometry(const GNELane* toLane) const;
237 
238  protected:
241 
243  std::map<const GNELane*, GNEGeometry::Geometry> myConnectionsMap;
244 
245  private:
248 
250  Lane2laneConnection& operator=(const Lane2laneConnection& other) = delete;
251  };
252 
254  static double calculateRotation(const Position& first, const Position& second);
255 
257  static double calculateLength(const Position& first, const Position& second);
258 
260  static void adjustStartPosGeometricPath(double& startPos, const GNELane* startLane, double& endPos, const GNELane* endLane);
261 
263  static void drawLaneGeometry(const GNEViewNet* viewNet, const PositionVector& shape, const std::vector<double>& rotations,
264  const std::vector<double>& lengths, const std::vector<RGBColor>& colors, double width, const bool onlyContour = false);
265 
267  static void drawGeometry(const GNEViewNet* viewNet, const Geometry& geometry, const double width);
268 
270  static void drawContourGeometry(const Geometry& geometry, const double width, const bool drawExtremes = false);
271 
273  static void drawGeometryPoints(const GUIVisualizationSettings& s, const GNEViewNet* viewNet, const PositionVector& shape,
274  const RGBColor& geometryPointColor, const RGBColor& textColor, const double radius, const double exaggeration);
275 
277  static void drawMovingHint(const GUIVisualizationSettings& s, const GNEViewNet* viewNet, const PositionVector& shape,
278  const RGBColor& hintColor, const double radius, const double exaggeration);
279 
281  static void drawDottedContourEdge(const DottedContourType type, const GUIVisualizationSettings& s, const GNEEdge* edge,
282  const bool drawFrontExtreme, const bool drawBackExtreme);
283 
285  static void drawDottedContourClosedShape(const DottedContourType type, const GUIVisualizationSettings& s, const PositionVector& shape,
286  const double exaggeration, const double lineWidth = -1);
287 
289  static void drawDottedContourShape(const DottedContourType type, const GUIVisualizationSettings& s, const PositionVector& shape,
290  const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem,
291  const double lineWidth = -1);
292 
294  static void drawDottedContourCircle(const DottedContourType type, const GUIVisualizationSettings& s, const Position& pos,
295  const double radius, const double exaggeration);
296 
298  static void drawDottedSquaredShape(const DottedContourType type, const GUIVisualizationSettings& s, const Position& pos,
299  const double width, const double height, const double offsetX, const double offsetY,
300  const double rot, const double exaggeration);
301 
303  static void drawParentLine(const GUIVisualizationSettings& s, const Position &parent, const Position& child, const RGBColor &color, const bool drawEntire);
304 
306  static void drawChildLine(const GUIVisualizationSettings& s, const Position &child, const Position& parent, const RGBColor &color, const bool drawEntire);
307 
309  static PositionVector getVertexCircleAroundPosition(const Position& pos, const double width, const int steps = 8);
310 
312  static void rotateOverLane(const double rot);
313 
314 private:
317 
319  static int angleLookup(const double angleDeg);
320 };
GNEGeometry::Geometry::myShapeRotations
std::vector< double > myShapeRotations
The rotations of the shape (note: Always size = myShape.size()-1)
Definition: GNEGeometry.h:109
GNEGeometry::calculateLength
static double calculateLength(const Position &first, const Position &second)
return length between two points (used in geometric calculations)
Definition: GNEGeometry.cpp:574
ToString.h
GNEGeometry::drawDottedContourShape
static void drawDottedContourShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem, const double lineWidth=-1)
draw dotted contour for the given shape (used by additionals)
Definition: GNEGeometry.cpp:891
GNEDemandElement
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEDemandElement.h:52
GUIGlObjectTypes.h
GNEGeometry::Lane2laneConnection::myFromLane
const GNELane * myFromLane
from lane
Definition: GNEGeometry.h:240
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
GNEGeometry::getVertexCircleAroundPosition
static PositionVector getVertexCircleAroundPosition(const Position &pos, const double width, const int steps=8)
get a circle around the given position
Definition: GNEGeometry.cpp:1087
GNEGeometry::DottedGeometry::moveShapeToSide
void moveShapeToSide(const double value)
move shape to side
Definition: GNEGeometry.cpp:453
GNEGeometry::angleLookup
static int angleLookup(const double angleDeg)
normalize angle for lookup in myCircleCoords
Definition: GNEGeometry.cpp:1117
GNEGeometry::DottedGeometry::calculateShapeRotationsAndLengths
void calculateShapeRotationsAndLengths()
calculate shape rotations and lengths
Definition: GNEGeometry.cpp:483
GNEGeometry::drawParentLine
static void drawParentLine(const GUIVisualizationSettings &s, const Position &parent, const Position &child, const RGBColor &color, const bool drawEntire)
draw line between parent and children (used in NETEDIT)
Definition: GNEGeometry.cpp:966
GNEGeometry::DottedGeometryColor::myColorFlag
bool myColorFlag
flag to get color
Definition: GNEGeometry.h:145
GNEGeometry::Geometry::getShapeRotations
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
Definition: GNEGeometry.cpp:205
GNEGeometry::Lane2laneConnection
class lane2lane connection geometry
Definition: GNEGeometry.h:223
GNEGeometry::DottedGeometry::Segment::Segment
Segment()
default constructor
Definition: GNEGeometry.cpp:313
GNEGeometry::Lane2laneConnection::updateLane2laneConnection
void updateLane2laneConnection()
update
Definition: GNEGeometry.cpp:512
GNEGeometry::DottedGeometryColor
class for pack all variables related with DottedGeometry color
Definition: GNEGeometry.h:125
MsgHandler.h
GNEGeometry::drawDottedContourEdge
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)
Definition: GNEGeometry.cpp:809
GNEGeometry::Geometry::myShapeLengths
std::vector< double > myShapeLengths
The lengths of the shape (note: Always size = myShape.size()-1)
Definition: GNEGeometry.h:112
GNEViewNet
Definition: GNEViewNet.h:41
GNEGeometry::DottedGeometryColor::changeColor
void changeColor()
change color
Definition: GNEGeometry.cpp:294
GNEGeometry::drawGeometryPoints
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
Definition: GNEGeometry.cpp:665
GUIVisualizationSettings.h
GNEGeometry::DottedGeometryColor::getColor
const RGBColor getColor(DottedContourType type)
get inspected color (and change flag)
Definition: GNEGeometry.cpp:254
GNEGeometry
Definition: GNEGeometry.h:53
GNEGeometry::DottedGeometryColor::DottedGeometryColor
DottedGeometryColor(const GUIVisualizationSettings &settings)
constructor
Definition: GNEGeometry.cpp:248
PositionVector
A list of positions.
Definition: PositionVector.h:43
GNEGeometry::DottedGeometry::invertOffset
void invertOffset()
invert offset of all segments
Definition: GNEGeometry.cpp:474
GNEGeometry::Geometry::updateGeometry
void updateGeometry(const PositionVector &shape)
update entire geometry
Definition: GNEGeometry.cpp:64
GNEGeometry::DottedGeometry::Segment::rotations
std::vector< double > rotations
rotations
Definition: GNEGeometry.h:167
GNEGeometry::Geometry
class for NETEDIT geometries over lanes
Definition: GNEGeometry.h:56
GNEEdge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
RGBColor
Definition: RGBColor.h:38
GNEGeometry::DottedContourType::FRONT
@ FRONT
GNEGeometry::drawLaneGeometry
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, const bool onlyContour=false)
draw lane geometry (use their own function due colors)
Definition: GNEGeometry.cpp:764
GNEGeometry::DottedContourType::MAGENTA
@ MAGENTA
Parameterised.h
GNEGeometry::DottedContourType
DottedContourType
Definition: GNEGeometry.h:116
GNEGeometry::DottedGeometry
class for pack all variables related with DottedGeometry
Definition: GNEGeometry.h:152
GNEGeometry::drawGeometry
static void drawGeometry(const GNEViewNet *viewNet, const Geometry &geometry, const double width)
draw geometry
Definition: GNEGeometry.cpp:610
GNEGeometry::DottedGeometry::Segment::shape
PositionVector shape
shape
Definition: GNEGeometry.h:164
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
GUIIcons.h
UtilExceptions.h
GNEGeometry::rotateOverLane
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
Definition: GNEGeometry.cpp:1110
GNEGeometry::DottedGeometry::setWidth
void setWidth(const double width)
change default width
Definition: GNEGeometry.cpp:468
GNEGeometry::Geometry::scaleGeometry
void scaleGeometry(const double scale)
scale geometry
Definition: GNEGeometry.cpp:188
GNEGeometry::Lane2laneConnection::exist
bool exist(const GNELane *toLane) const
check if exist a lane2lane geometry for the given tolane
Definition: GNEGeometry.cpp:547
GNEGeometry::DottedGeometry::operator=
DottedGeometry & operator=(const DottedGeometry &other)=delete
Invalidated assignment operator.
GNEGeometry::Geometry::clearGeometry
void clearGeometry()
clear geometry
Definition: GNEGeometry.cpp:216
GNEGeometry::Geometry::getShapeLengths
const std::vector< double > & getShapeLengths() const
The lengths of the single shape parts.
Definition: GNEGeometry.cpp:211
GNEGeometry::drawChildLine
static void drawChildLine(const GUIVisualizationSettings &s, const Position &child, const Position &parent, const RGBColor &color, const bool drawEntire)
draw line between child and parent (used in NETEDIT)
Definition: GNEGeometry.cpp:1025
GNEGeometry::Lane2laneConnection::operator=
Lane2laneConnection & operator=(const Lane2laneConnection &other)=delete
Invalidated assignment operator.
GNEGeometry::DottedContourType::GREEN
@ GREEN
GNEGeometry::DottedGeometry::updateDottedGeometry
void updateDottedGeometry(const GUIVisualizationSettings &s, const GNELane *lane)
update DottedGeometry (using lane shape)
Definition: GNEGeometry.cpp:392
GNEGeometry::DottedGeometry::myWidth
double myWidth
geometry width
Definition: GNEGeometry.h:213
GNEGeometry::DottedContourType::INSPECT
@ INSPECT
GNEGeometry::Lane2laneConnection::getLane2laneGeometry
const GNEGeometry::Geometry & getLane2laneGeometry(const GNELane *toLane) const
get lane2lane geometry
Definition: GNEGeometry.cpp:553
GNEGeometry::drawMovingHint
static void drawMovingHint(const GUIVisualizationSettings &s, const GNEViewNet *viewNet, const PositionVector &shape, const RGBColor &hintColor, const double radius, const double exaggeration)
draw moving hint
Definition: GNEGeometry.cpp:721
GNEGeometry::DottedGeometry::Segment::lengths
std::vector< double > lengths
lengths
Definition: GNEGeometry.h:170
GNEGeometry::DottedGeometry::drawDottedGeometry
void drawDottedGeometry(DottedGeometryColor &dottedGeometryColor, GNEGeometry::DottedContourType type, const double customWidth=-1) const
draw inspected dottedShape
Definition: GNEGeometry.cpp:436
GNEGeometry::drawDottedContourClosedShape
static void drawDottedContourClosedShape(const DottedContourType type, const GUIVisualizationSettings &s, const PositionVector &shape, const double exaggeration, const double lineWidth=-1)
draw dotted contour for the given closed shape (used by Juctions, shapes and TAZs)
Definition: GNEGeometry.cpp:861
GNEGeometry::DottedGeometryColor::mySettings
const GUIVisualizationSettings & mySettings
pointer to GUIVisualizationSettings
Definition: GNEGeometry.h:142
SUMOSAXAttributes.h
GNEGeometry::DottedGeometry::getWidth
double getWidth() const
get width
Definition: GNEGeometry.cpp:462
GNEGeometry::Geometry::myShape
PositionVector myShape
element shape
Definition: GNEGeometry.h:106
GNEGeometry::DottedGeometry::Segment
dotted geometry segment
Definition: GNEGeometry.h:156
GNEGeometry::Geometry::Geometry
Geometry()
default constructor
Definition: GNEGeometry.cpp:45
GNEHierarchicalElement
Definition: GNEHierarchicalElement.h:37
config.h
GNEGeometry::myCircleCoords
static PositionVector myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
Definition: GNEGeometry.h:316
GNEGeometry::DottedGeometry::DottedGeometry
DottedGeometry()
constructor
Definition: GNEGeometry.cpp:324
GNEGeometry::DottedGeometryColor::reset
void reset()
rest Dotted Geometry Color
Definition: GNEGeometry.cpp:304
GNEGeometry::drawContourGeometry
static void drawContourGeometry(const Geometry &geometry, const double width, const bool drawExtremes=false)
draw contour geometry
Definition: GNEGeometry.cpp:638
GNEGeometry::adjustStartPosGeometricPath
static void adjustStartPosGeometricPath(double &startPos, const GNELane *startLane, double &endPos, const GNELane *endLane)
adjust start and end positions in geometric path
Definition: GNEGeometry.cpp:581
GNEGeometry::DottedGeometry::myDottedGeometrySegments
std::vector< DottedGeometry::Segment > myDottedGeometrySegments
dotted element shape (note: It's centered in 0,0 due scaling)
Definition: GNEGeometry.h:216
GNEGeometry::calculateRotation
static double calculateRotation(const Position &first, const Position &second)
return angle between two points (used in geometric calculations)
Definition: GNEGeometry.cpp:567
GNEGeometry::Lane2laneConnection::Lane2laneConnection
Lane2laneConnection()
constructor
Definition: GNEGeometry.cpp:558
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:546
GNEJunction
Definition: GNEJunction.h:46
GNEReferenceCounter.h
GNEGeometry::DottedGeometry::Segment::offset
double offset
drawing offset (-1 or 1 only)
Definition: GNEGeometry.h:173
GNEGeometry::Lane2laneConnection::myConnectionsMap
std::map< const GNELane *, GNEGeometry::Geometry > myConnectionsMap
connection shape
Definition: GNEGeometry.h:243
GNEGeometry::drawDottedSquaredShape
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)
Definition: GNEGeometry.cpp:945
GNEGeometry::DottedGeometryColor::operator=
DottedGeometryColor & operator=(const DottedGeometryColor &other)=delete
Invalidated assignment operator.
PositionVector.h
GNEGeometry::Geometry::updateSinglePosGeometry
void updateSinglePosGeometry(const Position &position, const double rotation)
update position and rotation
Definition: GNEGeometry.cpp:178
GNELane
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:45
GNEGeometry::Geometry::getShape
const PositionVector & getShape() const
The shape of the additional element.
Definition: GNEGeometry.cpp:199
GNEAttributeCarrier
Definition: GNEAttributeCarrier.h:48
SUMOXMLDefinitions.h
GNEGeometry::drawDottedContourCircle
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)
Definition: GNEGeometry.cpp:934
GNEGeometry::Geometry::calculateShapeRotationsAndLengths
void calculateShapeRotationsAndLengths()
calculate shape rotations and lengths
Definition: GNEGeometry.cpp:225
GNEGeometry::DottedContourType::MOVE
@ MOVE