SUMO - Simulation of Urban MObility
NGNode.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A netgen-representation of a node
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <algorithm>
35 #include <netbuild/NBNode.h>
36 #include <netbuild/NBNodeCont.h>
37 #include <netbuild/NBEdge.h>
38 #include <netbuild/NBOwnTLDef.h>
39 #include <netbuild/NBTypeCont.h>
41 #include <netbuild/NBNetBuilder.h>
43 #include <utils/common/ToString.h>
46 #include <utils/options/Option.h>
47 #include "NGNode.h"
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
53 NGNode::NGNode(const std::string& id)
54  : Named(id), xID(-1), yID(-1), myAmCenter(false) {}
55 
56 
57 NGNode::NGNode(const std::string& id, int xIDa, int yIDa)
58  : Named(id), xID(xIDa), yID(yIDa), myAmCenter(false) {}
59 
60 
61 NGNode::NGNode(const std::string& id, int xIDa, int yIDa, bool amCenter)
62  : Named(id), xID(xIDa), yID(yIDa), myAmCenter(amCenter) {}
63 
64 
66  NGEdgeList::iterator li;
67  while (LinkList.size() != 0) {
68  li = LinkList.begin();
69  delete(*li);
70  }
71 }
72 
73 
74 NBNode*
76  Position pos(myPosition);
78  // the center will have no logic!
79  if (myAmCenter) {
80  return new NBNode(myID, pos, NODETYPE_NOJUNCTION);
81  }
82  NBNode* node = 0;
83  std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ?
84  OptionsCont::getOptions().getString("default-junction-type") : "";
85 
86  if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
88  node = new NBNode(myID, pos, type);
89 
90  // check whether it is a traffic light junction
91  if (NBNode::isTrafficLight(type)) {
93  OptionsCont::getOptions().getString("tls.default-type"));
94  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node, 0, type);
95  if (!nb.getTLLogicCont().insert(tlDef)) {
96  // actually, nothing should fail here
97  delete tlDef;
98  throw ProcessError();
99  }
100  }
101  } else {
102  // otherwise netbuild may guess NODETYPE_TRAFFIC_LIGHT without actually building one
103  node = new NBNode(myID, pos, NODETYPE_PRIORITY);
104  }
105 
106  return node;
107 }
108 
109 
110 void
112  LinkList.push_back(link);
113 }
114 
115 
116 void
118  LinkList.remove(link);
119 }
120 
121 
122 bool
123 NGNode::connected(NGNode* node) const {
124  for (NGEdgeList::const_iterator i = LinkList.begin(); i != LinkList.end(); ++i) {
125  if (find(node->LinkList.begin(), node->LinkList.end(), *i) != node->LinkList.end()) {
126  return true;
127  }
128  }
129  return false;
130 }
131 
132 
133 /****************************************************************************/
134 
static StringBijection< SumoXMLNodeType > NodeTypes
node types
A netgen-representation of an edge.
Definition: NGEdge.h:62
int xID
Integer x-position (x-id)
Definition: NGNode.h:192
bool myAmCenter
Information whether this is the center of a cpider-net.
Definition: NGNode.h:207
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:98
bool x2cartesian(Position &from, bool includeInBoundary=true)
int yID
Integer y-position (y-id)
Definition: NGNode.h:195
The base class for traffic light logic definitions.
void removeLink(NGEdge *link)
Removes the given link.
Definition: NGNode.cpp:117
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
~NGNode()
Destructor.
Definition: NGNode.cpp:65
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
bool connected(NGNode *node) const
Returns whether the other node is connected.
Definition: NGNode.cpp:123
T get(const std::string &str) const
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Base class for objects which have an id.
Definition: Named.h:46
Position myPosition
The position of the node.
Definition: NGNode.h:201
std::string myID
The name of the object.
Definition: Named.h:136
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
Instance responsible for building networks.
Definition: NBNetBuilder.h:114
NGNode(const std::string &id)
Constructor.
Definition: NGNode.cpp:53
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:170
Represents a single node (junction) during network building.
Definition: NBNode.h:75
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
A netgen-representation of a node.
Definition: NGNode.h:58
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:54
NGEdgeList LinkList
List of connected links.
Definition: NGNode.h:198
void addLink(NGEdge *link)
Adds the given link to the internal list.
Definition: NGNode.cpp:111
static bool isTrafficLight(SumoXMLNodeType type)
return whether the given type is a traffic light
Definition: NBNode.cpp:2698
NBNode * buildNBNode(NBNetBuilder &nb) const
Builds and returns this node&#39;s netbuild-representation.
Definition: NGNode.cpp:75
TrafficLightType