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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // File for geometry classes and functions
15 /****************************************************************************/
16 #ifndef GNEGeometry_h
17 #define GNEGeometry_h
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
27 #include <utils/common/ToString.h>
34 
35 #include "GNEReferenceCounter.h"
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
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  struct Geometry {
58  Geometry();
59 
67  void updateGeometryShape(const PositionVector& shape, double startPos = -1, double endPos = -1,
68  const Position& extraFirstPosition = Position::INVALID,
69  const Position& extraLastPosition = Position::INVALID);
70 
72  void updateGeometryPosition(const GNELane* lane, const double posOverLane);
73 
75  void updateGeometry(const GNEAdditional* additional);
76 
78  const Position& getPosition() const;
79 
81  double getRotation() const;
82 
84  const PositionVector& getShape() const;
85 
87  const std::vector<double>& getShapeRotations() const;
88 
90  const std::vector<double>& getShapeLengths() const;
91 
92  private:
95 
98 
100  double myRotation;
101 
104 
106  std::vector<double> myShapeRotations;
107 
109  std::vector<double> myShapeLengths;
110 
112  Geometry& operator=(const Geometry& other) = delete;
113  };
114 
117 
119  struct Segment {
121  Segment(const GNEAttributeCarrier* _AC, const GNELane* _lane, const bool _valid);
122 
124  Segment(const GNEAttributeCarrier* _AC, const GNELane* _lane,
125  const PositionVector& shape, const std::vector<double>& shapeRotations, const std::vector<double>& shapeLengths, const bool _valid);
126 
128  Segment(const GNEAttributeCarrier* _AC, const GNELane* currentLane, const GNELane* nextLane, const bool _valid);
129 
131  void update(const PositionVector& shape, const std::vector<double>& shapeRotations, const std::vector<double>& shapeLengths);
132 
134  const PositionVector& getShape() const;
135 
137  const std::vector<double>& getShapeRotations() const;
138 
140  const std::vector<double>& getShapeLengths() const;
141 
144 
146  const GNEEdge* edge;
147 
149  const GNELane* lane;
150 
153 
155  const bool valid;
156 
157  private:
160 
163 
166 
168  std::vector<double> mySegmentRotations;
169 
171  std::vector<double> mySegmentLengths;
172 
174  Segment& operator=(const Segment& other) = delete;
175  };
176 
179 
181  SegmentToUpdate(const int _index, const GNELane* _lane, const GNELane* _nextLane);
182 
184  const int index;
185 
186  // @brief lane segment
187  const GNELane* lane;
188 
191 
192  private:
194  SegmentToUpdate& operator=(const SegmentToUpdate& other) = delete;
195  };
196 
198  SegmentGeometry();
199 
201  void insertLaneSegment(const GNEAttributeCarrier* AC, const GNELane* lane, const bool valid);
202 
204  void insertCustomSegment(const GNEAttributeCarrier* AC, const GNELane* lane,
205  const PositionVector& laneShape, const std::vector<double>& laneShapeRotations, const std::vector<double>& laneShapeLengths, const bool valid);
206 
208  void insertLane2LaneSegment(const GNEAttributeCarrier* AC, const GNELane* currentLane, const GNELane* nextLane, const bool valid);
209 
211  void updateCustomSegment(const int segmentIndex, const PositionVector& newLaneShape, const std::vector<double>& newLaneShapeRotations, const std::vector<double>& newLaneShapeLengths);
212 
214  void updateLane2LaneSegment(const int segmentIndex, const GNELane* lane, const GNELane* nextLane);
215 
217  void clearSegmentGeometry();
218 
220  const Position& getFirstPosition() const;
221 
223  const Position& getLastPosition() const;
224 
226  double getFirstRotation() const;
227 
229  Boundary getBoxBoundary() const;
230 
232  std::vector<Segment>::const_iterator begin() const;
233 
235  std::vector<Segment>::const_iterator end() const;
236 
238  const Segment& front() const;
239 
241  const Segment& back() const;
242 
244  int size() const;
245 
246  private:
248  std::vector<Segment> myShapeSegments;
249 
251  SegmentGeometry& operator=(const SegmentGeometry& other) = delete;
252  };
253 
256 
258  Lane2laneConnection(const GNELane* originLane);
259 
262 
264  std::map<const GNELane*, Geometry> connectionsMap;
265 
266  private:
268  const GNELane* myOriginLane = nullptr;
269 
271  Lane2laneConnection& operator=(const Lane2laneConnection& other) = delete;
272  };
273 
277  ParentConnections(GNEHierarchicalParentElements* hierarchicalElement);
278 
280  void update();
281 
283  void draw(const GUIVisualizationSettings& s, const GUIGlObjectType parentType) const;
284 
286  std::vector<std::pair<Position, double> > symbolsPositionAndRotation;
287 
289  std::vector<PositionVector> connectionPositions;
290 
291  private:
294  };
295 
297  static double calculateRotation(const Position& first, const Position& second);
298 
300  static double calculateLength(const Position& first, const Position& second);
301 
303  static void adjustStartPosGeometricPath(double& startPos, const GNELane* startLane, double& endPos, const GNELane* endLane);
304 
315  static void calculateEdgeGeometricPath(const GNEAttributeCarrier* AC, GNEGeometry::SegmentGeometry& segmentGeometry, const std::vector<GNEEdge*>& edges,
316  const SUMOVehicleClass vClass, GNELane* fromLane, GNELane* toLane, double startPos = -1, double endPos = -1,
317  const Position& extraFirstPosition = Position::INVALID, const Position& extraLastPosition = Position::INVALID);
318 
328  static void calculateLaneGeometricPath(const GNEAttributeCarrier* AC, GNEGeometry::SegmentGeometry& segmentGeometry, const std::vector<GNELane*>& lanes,
329  double startPos = -1, double endPos = -1, const Position& extraFirstPosition = Position::INVALID,
330  const Position& extraLastPosition = Position::INVALID);
331 
340  static void updateGeometricPath(GNEGeometry::SegmentGeometry& segmentGeometry, const GNEEdge* edge, double startPos = -1, double endPos = -1,
341  const Position& extraFirstPosition = Position::INVALID, const Position& extraLastPosition = Position::INVALID);
342 
344  static void drawLaneGeometry(const GNEViewNet* viewNet, const PositionVector& shape, const std::vector<double>& rotations,
345  const std::vector<double>& lengths, const std::vector<RGBColor>& colors, double width);
346 
348  static void drawGeometry(const GNEViewNet* viewNet, const Geometry& geometry, const double width);
349 
351  static void drawSegmentGeometry(const GNEViewNet* viewNet, const SegmentGeometry::Segment& segment, const double width);
352 };
353 
354 #endif
355 
356 /****************************************************************************/
357 
GNEGeometry::calculateLength
static double calculateLength(const Position &first, const Position &second)
return length between two points (used in geometric calculations)
Definition: GNEGeometry.cpp:555
SUMOVehicleClass
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
Definition: SUMOVehicleClass.h:133
GNEGeometry::Lane2laneConnection::Lane2laneConnection
Lane2laneConnection(const GNELane *originLane)
constructor
Definition: GNEGeometry.cpp:395
ToString.h
GNEDemandElement
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEDemandElement.h:55
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
GNEGeometry::calculateEdgeGeometricPath
static void calculateEdgeGeometricPath(const GNEAttributeCarrier *AC, GNEGeometry::SegmentGeometry &segmentGeometry, const std::vector< GNEEdge * > &edges, const SUMOVehicleClass vClass, GNELane *fromLane, GNELane *toLane, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
calculate route between edges
Definition: GNEGeometry.cpp:591
GNEGeometry::Lane2laneConnection
lane2lane struct
Definition: GNEGeometry.h:255
GNEGeometry::SegmentGeometry::myShapeSegments
std::vector< Segment > myShapeSegments
vector of segments that constitutes the shape
Definition: GNEGeometry.h:248
GNEGeometry::Geometry::updateGeometryShape
void updateGeometryShape(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:48
GNEGeometry::ParentConnections::myHierarchicalElement
GNEHierarchicalParentElements * myHierarchicalElement
pointer to hierarchical element parent
Definition: GNEGeometry.h:293
GNEGeometry::drawSegmentGeometry
static void drawSegmentGeometry(const GNEViewNet *viewNet, const SegmentGeometry::Segment &segment, const double width)
draw geometry segment
Definition: GNEGeometry.cpp:850
GNEGeometry::ParentConnections
struct for pack all variables and functions relative to connections between hierarchical element and ...
Definition: GNEGeometry.h:275
Position::INVALID
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:284
GNEGeometry::Geometry::getShapeLengths
const std::vector< double > & getShapeLengths() const
The lengths of the single shape parts.
Definition: GNEGeometry.cpp:159
GNEGeometry::ParentConnections::ParentConnections
ParentConnections(GNEHierarchicalParentElements *hierarchicalElement)
constructor
Definition: GNEGeometry.cpp:434
GNEGeometry::SegmentGeometry::Segment::AC
const GNEAttributeCarrier * AC
element
Definition: GNEGeometry.h:143
GNEGeometry::SegmentGeometry::insertLaneSegment
void insertLaneSegment(const GNEAttributeCarrier *AC, const GNELane *lane, const bool valid)
insert entire lane segment (used to avoid unnecessary calculation in calculatePartialShapeRotationsAn...
Definition: GNEGeometry.cpp:280
GNEGeometry::SegmentGeometry::SegmentToUpdate::operator=
SegmentToUpdate & operator=(const SegmentToUpdate &other)=delete
Invalidated assignment operator.
GNEGeometry::SegmentGeometry::getFirstRotation
double getFirstRotation() const
get first rotation (or Invalid position if segments are empty)
Definition: GNEGeometry.cpp:343
MsgHandler.h
GNEGeometry::Geometry::updateGeometryPosition
void updateGeometryPosition(const GNELane *lane, const double posOverLane)
update position and rotation
Definition: GNEGeometry.cpp:100
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)
draw lane geometry (use their own function due colors)
Definition: GNEGeometry.cpp:820
GNEGeometry::SegmentGeometry::clearSegmentGeometry
void clearSegmentGeometry()
clear element geometry
Definition: GNEGeometry.cpp:317
GNEGeometry::Geometry::calculateShapeRotationsAndLengths
void calculateShapeRotationsAndLengths()
calculate shape rotations and lengths
Definition: GNEGeometry.cpp:165
GNEGeometry::SegmentGeometry::insertLane2LaneSegment
void insertLane2LaneSegment(const GNEAttributeCarrier *AC, const GNELane *currentLane, const GNELane *nextLane, const bool valid)
insert entire lane2lane segment (used to avoid unnecessary calculation in calculatePartialShapeRotati...
Definition: GNEGeometry.cpp:295
GNEGeometry::SegmentGeometry::getLastPosition
const Position & getLastPosition() const
get first position (or Invalid position if segments are empty)
Definition: GNEGeometry.cpp:333
GNEViewNet
Definition: GNEViewNet.h:42
GNEGeometry::Geometry::operator=
Geometry & operator=(const Geometry &other)=delete
Invalidated assignment operator.
GUIVisualizationSettings.h
GNEGeometry::Geometry::myPosition
Position myPosition
get single position
Definition: GNEGeometry.h:97
GNEGeometry
Definition: GNEGeometry.h:53
GNEGeometry::SegmentGeometry::Segment::Segment
Segment(const GNEAttributeCarrier *_AC, const GNELane *_lane, const bool _valid)
parameter constructor for lanes (geometry will be taked from lane)
Definition: GNEGeometry.cpp:188
GNEGeometry::SegmentGeometry::updateLane2LaneSegment
void updateLane2LaneSegment(const int segmentIndex, const GNELane *lane, const GNELane *nextLane)
update lane2Lane segment (used to avoid unnecessary calculation in calculatePartialShapeRotationsAndL...
Definition: GNEGeometry.cpp:308
PositionVector
A list of positions.
Definition: PositionVector.h:45
GNEGeometry::Geometry::Geometry
Geometry()
constructor
Definition: GNEGeometry.cpp:41
GNEGeometry::SegmentGeometry::SegmentToUpdate::lane
const GNELane * lane
Definition: GNEGeometry.h:187
GNEGeometry::SegmentGeometry::Segment::edge
const GNEEdge * edge
edge
Definition: GNEGeometry.h:146
GNEGeometry::SegmentGeometry::insertCustomSegment
void insertCustomSegment(const GNEAttributeCarrier *AC, const GNELane *lane, const PositionVector &laneShape, const std::vector< double > &laneShapeRotations, const std::vector< double > &laneShapeLengths, const bool valid)
insert custom segment
Definition: GNEGeometry.cpp:287
GUIGlObjectType
GUIGlObjectType
Definition: GUIGlObjectTypes.h:39
GNEEdge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:51
GNEGeometry::SegmentGeometry::Segment::getShapeLengths
const std::vector< double > & getShapeLengths() const
get lane/lane2lane shape lengths
Definition: GNEGeometry.cpp:264
GNEGeometry::SegmentGeometry::Segment::mySegmentShape
PositionVector mySegmentShape
segment shape
Definition: GNEGeometry.h:165
GNEGeometry::SegmentGeometry::operator=
SegmentGeometry & operator=(const SegmentGeometry &other)=delete
Invalidated assignment operator.
GNEGeometry::SegmentGeometry::SegmentToUpdate::SegmentToUpdate
SegmentToUpdate(const int _index, const GNELane *_lane, const GNELane *_nextLane)
constructor
Definition: GNEGeometry.cpp:236
GNEGeometry::SegmentGeometry
struct for pack all variables related with geometry of elemements divided in segments
Definition: GNEGeometry.h:116
GNEGeometry::Geometry::myShapeRotations
std::vector< double > myShapeRotations
The rotations of the shape (note: Always size = myShape.size()-1)
Definition: GNEGeometry.h:106
GNEGeometry::Geometry::getShape
const PositionVector & getShape() const
The shape of the additional element.
Definition: GNEGeometry.cpp:147
GNEGeometry::SegmentGeometry::Segment::update
void update(const PositionVector &shape, const std::vector< double > &shapeRotations, const std::vector< double > &shapeLengths)
update segment
Definition: GNEGeometry.cpp:229
Parameterised.h
GNEGeometry::SegmentGeometry::Segment::myUseLane2LaneShape
bool myUseLane2LaneShape
flag to use lane2lane connection
Definition: GNEGeometry.h:162
GNEGeometry::ParentConnections::symbolsPositionAndRotation
std::vector< std::pair< Position, double > > symbolsPositionAndRotation
position and rotation of every symbol over lane
Definition: GNEGeometry.h:286
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
GNEGeometry::Lane2laneConnection::updateLane2laneConnection
void updateLane2laneConnection()
update
Definition: GNEGeometry.cpp:401
GNEGeometry::Geometry::getRotation
double getRotation() const
get rotation
Definition: GNEGeometry.cpp:137
GNEGeometry::drawGeometry
static void drawGeometry(const GNEViewNet *viewNet, const Geometry &geometry, const double width)
draw geometry
Definition: GNEGeometry.cpp:795
GNEGeometry::ParentConnections::update
void update()
update Connection's geometry
Definition: GNEGeometry.cpp:439
GNEGeometry::SegmentGeometry::begin
std::vector< Segment >::const_iterator begin() const
begin iterator
Definition: GNEGeometry.cpp:363
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
GNEGeometry::SegmentGeometry::updateCustomSegment
void updateCustomSegment(const int segmentIndex, const PositionVector &newLaneShape, const std::vector< double > &newLaneShapeRotations, const std::vector< double > &newLaneShapeLengths)
update custom segment
Definition: GNEGeometry.cpp:302
GUIIcons.h
GNEGeometry::updateGeometricPath
static void updateGeometricPath(GNEGeometry::SegmentGeometry &segmentGeometry, const GNEEdge *edge, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
calculate route between edges
Definition: GNEGeometry.cpp:719
UtilExceptions.h
GNEGeometry::SegmentGeometry::Segment::mySegmentRotations
std::vector< double > mySegmentRotations
segment rotation
Definition: GNEGeometry.h:168
GNEGeometry::Geometry
struct for pack all variables related with geometry of stop
Definition: GNEGeometry.h:56
GNEGeometry::SegmentGeometry::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing all segments.
Definition: GNEGeometry.cpp:353
GNEGeometry::SegmentGeometry::getFirstPosition
const Position & getFirstPosition() const
get first position (or Invalid position if segments are empty)
Definition: GNEGeometry.cpp:324
GNEGeometry::Geometry::getPosition
const Position & getPosition() const
get Position
Definition: GNEGeometry.cpp:127
GNEGeometry::SegmentGeometry::Segment::myUseLaneShape
bool myUseLaneShape
flag to use lane shape
Definition: GNEGeometry.h:159
GNEGeometry::SegmentGeometry::Segment::getShapeRotations
const std::vector< double > & getShapeRotations() const
get lane/lane2lane shape rotations
Definition: GNEGeometry.cpp:254
GNEGeometry::SegmentGeometry::Segment
struct used for represent segments of element geometry
Definition: GNEGeometry.h:119
GNEGeometry::SegmentGeometry::SegmentGeometry
SegmentGeometry()
constructor
Definition: GNEGeometry.cpp:276
SUMOSAXAttributes.h
GNEHierarchicalParentElements
An special type of Attribute carrier that owns hierarchical elements.
Definition: GNEHierarchicalParentElements.h:49
GNEGeometry::calculateLaneGeometricPath
static void calculateLaneGeometricPath(const GNEAttributeCarrier *AC, GNEGeometry::SegmentGeometry &segmentGeometry, const std::vector< GNELane * > &lanes, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
calculate route between lanes
Definition: GNEGeometry.cpp:640
GNEGeometry::Geometry::myShapeLengths
std::vector< double > myShapeLengths
The lengths of the shape (note: Always size = myShape.size()-1)
Definition: GNEGeometry.h:109
GNEGeometry::SegmentGeometry::front
const Segment & front() const
front segment
Definition: GNEGeometry.cpp:375
GNEGeometry::SegmentGeometry::Segment::lane
const GNELane * lane
lane
Definition: GNEGeometry.h:149
GNEGeometry::Geometry::myRotation
double myRotation
get single rotation
Definition: GNEGeometry.h:100
config.h
GNEGeometry::SegmentGeometry::Segment::operator=
Segment & operator=(const Segment &other)=delete
Invalidated assignment operator.
GNEGeometry::SegmentGeometry::Segment::mySegmentLengths
std::vector< double > mySegmentLengths
segment lengths
Definition: GNEGeometry.h:171
GNEGeometry::ParentConnections::connectionPositions
std::vector< PositionVector > connectionPositions
Matrix with the Vertex's positions of connections between parents an their children.
Definition: GNEGeometry.h:289
GNEGeometry::SegmentGeometry::size
int size() const
number of segments
Definition: GNEGeometry.cpp:387
GNEGeometry::Geometry::getShapeRotations
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
Definition: GNEGeometry.cpp:153
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:562
GNEGeometry::calculateRotation
static double calculateRotation(const Position &first, const Position &second)
return angle between two points (used in geometric calculations)
Definition: GNEGeometry.cpp:548
GNEGeometry::SegmentGeometry::SegmentToUpdate::index
const int index
segment index
Definition: GNEGeometry.h:184
GNEGeometry::SegmentGeometry::SegmentToUpdate::nextLane
const GNELane * nextLane
lane segment (used for updating lane2lane segments)
Definition: GNEGeometry.h:190
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
GNEGeometry::Geometry::myShape
PositionVector myShape
element shape
Definition: GNEGeometry.h:103
GNEJunction
Definition: GNEJunction.h:47
GNEGeometry::SegmentGeometry::Segment::junction
const GNEJunction * junction
junction
Definition: GNEGeometry.h:152
GNEReferenceCounter.h
GNEGeometry::SegmentGeometry::Segment::getShape
const PositionVector & getShape() const
get lane/lane2lane shape
Definition: GNEGeometry.cpp:244
PositionVector.h
GNELane
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:45
GNEGeometry::SegmentGeometry::SegmentToUpdate
struct used for represent segments that must be updated
Definition: GNEGeometry.h:178
GNEGeometry::Lane2laneConnection::connectionsMap
std::map< const GNELane *, Geometry > connectionsMap
connection shape
Definition: GNEGeometry.h:264
GNEAttributeCarrier
Definition: GNEAttributeCarrier.h:54
SUMOXMLDefinitions.h
GNEGeometry::SegmentGeometry::end
std::vector< Segment >::const_iterator end() const
end iterator
Definition: GNEGeometry.cpp:369
GNEGeometry::SegmentGeometry::Segment::valid
const bool valid
valid
Definition: GNEGeometry.h:155
GNEGeometry::SegmentGeometry::back
const Segment & back() const
back segment
Definition: GNEGeometry.cpp:381
GNEGeometry::Geometry::updateGeometry
void updateGeometry(const GNEAdditional *additional)
update geometry (using geometry of another additional)
Definition: GNEGeometry.cpp:118
GNEGeometry::Lane2laneConnection::operator=
Lane2laneConnection & operator=(const Lane2laneConnection &other)=delete
Invalidated assignment operator.
GNEGeometry::Lane2laneConnection::myOriginLane
const GNELane * myOriginLane
origin lane
Definition: GNEGeometry.h:268
GNEGeometry::ParentConnections::draw
void draw(const GUIVisualizationSettings &s, const GUIGlObjectType parentType) const
draw connections between Parent and childrens
Definition: GNEGeometry.cpp:524