Eclipse SUMO - Simulation of Urban MObility
NGNode.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-2024 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 /****************************************************************************/
21 // A netgen-representation of a node
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include <algorithm>
26 #include <netbuild/NBNode.h>
27 #include <netbuild/NBNodeCont.h>
28 #include <netbuild/NBEdge.h>
29 #include <netbuild/NBOwnTLDef.h>
30 #include <netbuild/NBTypeCont.h>
32 #include <netbuild/NBNetBuilder.h>
34 #include <utils/common/ToString.h>
37 #include <utils/options/Option.h>
38 #include "NGNode.h"
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
44 NGNode::NGNode(const std::string& id)
45  : Named(id), myXID(-1), myYID(-1), myAmCenter(false), myAmFringe(false) {}
46 
47 
48 NGNode::NGNode(const std::string& id, int xIDa, int yIDa)
49  : Named(id), myXID(xIDa), myYID(yIDa), myAmCenter(false), myAmFringe(false) {}
50 
51 
52 NGNode::NGNode(const std::string& id, int xIDa, int yIDa, bool amCenter)
53  : Named(id), myXID(xIDa), myYID(yIDa), myAmCenter(amCenter), myAmFringe(false) {}
54 
55 
57  NGEdgeList::iterator li;
58  while (myLinkList.size() != 0) {
59  li = myLinkList.begin();
60  delete (*li);
61  }
62 }
63 
64 
65 NBNode*
66 NGNode::buildNBNode(NBNetBuilder& nb, const Position& perturb) const {
67  Position pos(myPosition + perturb);
69  // the center will have no logic!
70  if (myAmCenter) {
71  return new NBNode(myID, pos, SumoXMLNodeType::NOJUNCTION);
72  }
73  NBNode* node = nullptr;
74  std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ?
75  OptionsCont::getOptions().getString("default-junction-type") : "";
76 
77  if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
79  node = new NBNode(myID, pos, type);
80 
81  // check whether it is a traffic light junction
82  if (NBNode::isTrafficLight(type)) {
84  OptionsCont::getOptions().getString("tls.default-type"));
85  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node, 0, tlType);
86  if (!nb.getTLLogicCont().insert(tlDef)) {
87  // actually, nothing should fail here
88  delete tlDef;
89  throw ProcessError();
90  }
91  }
92  } else {
93  // otherwise netbuild may guess SumoXMLNodeType::TRAFFIC_LIGHT without actually building one
94  node = new NBNode(myID, pos, SumoXMLNodeType::PRIORITY);
95  }
96  if (myAmFringe) {
98  }
99 
100  return node;
101 }
102 
103 
104 void
106  myLinkList.push_back(link);
107 }
108 
109 
110 void
112  myLinkList.remove(link);
113 }
114 
115 
116 bool
117 NGNode::connected(const NGNode* const node, const bool withDir) const {
118  for (NGEdge* ngEdge : myLinkList) {
119  if (ngEdge->getStartNode() == this && ngEdge->getEndNode() == node) {
120  return true;
121  }
122  if (!withDir && ngEdge->getEndNode() == this && ngEdge->getStartNode() == node) {
123  return true;
124  }
125  }
126  return false;
127 }
128 
129 
130 /****************************************************************************/
TrafficLightType
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:84
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
Instance responsible for building networks.
Definition: NBNetBuilder.h:107
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:154
Represents a single node (junction) during network building.
Definition: NBNode.h:66
bool isTrafficLight() const
Definition: NBNode.h:822
void setFringeType(FringeType fringeType)
set method for computing right-of-way
Definition: NBNode.h:574
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:44
The base class for traffic light logic definitions.
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
A netgen-representation of an edge.
Definition: NGEdge.h:52
A netgen-representation of a node.
Definition: NGNode.h:48
bool connected(const NGNode *const node, const bool withDir=false) const
Returns whether the other node is connected.
Definition: NGNode.cpp:117
NGEdgeList myLinkList
List of connected links.
Definition: NGNode.h:193
~NGNode()
Destructor.
Definition: NGNode.cpp:56
NGNode(const std::string &id)
Constructor.
Definition: NGNode.cpp:44
NBNode * buildNBNode(NBNetBuilder &nb, const Position &perturb) const
Builds and returns this node's netbuild-representation.
Definition: NGNode.cpp:66
bool myAmCenter
Information whether this is the center of a cpider-net.
Definition: NGNode.h:202
Position myPosition
The position of the node.
Definition: NGNode.h:196
bool myAmFringe
Information whether this is the center of a cpider-net.
Definition: NGNode.h:205
void addLink(NGEdge *link)
Adds the given link to the internal list.
Definition: NGNode.cpp:105
void removeLink(NGEdge *link)
Removes the given link.
Definition: NGNode.cpp:111
Base class for objects which have an id.
Definition: Named.h:54
std::string myID
The name of the object.
Definition: Named.h:125
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
static StringBijection< SumoXMLNodeType > NodeTypes
node types
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(const std::string &str) const