Line data Source code
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 : /****************************************************************************/ 14 : /// @file NGNode.h 15 : /// @author Markus Hartinger 16 : /// @author Daniel Krajzewicz 17 : /// @author Michael Behrisch 18 : /// @date Mar, 2003 19 : /// 20 : // A netgen-representation of a node 21 : /****************************************************************************/ 22 : #pragma once 23 : #include <config.h> 24 : 25 : #include <list> 26 : #include <utils/common/Named.h> 27 : #include <utils/geom/Position.h> 28 : #include <utils/geom/GeomHelper.h> 29 : #include <utils/common/UtilExceptions.h> 30 : #include "NGEdge.h" 31 : 32 : 33 : // =========================================================================== 34 : // class declarations 35 : // =========================================================================== 36 : class NBNode; 37 : class NBEdge; 38 : class NBNetBuilder; 39 : 40 : 41 : // =========================================================================== 42 : // class definitions 43 : // =========================================================================== 44 : /** 45 : * @class NGNode 46 : * @brief A netgen-representation of a node 47 : */ 48 : class NGNode : public Named { 49 : public: 50 : /** @brief Constructor 51 : * 52 : * @param[in] id The id of the node 53 : */ 54 : NGNode(const std::string& id); 55 : 56 : 57 : /** @brief Constructor 58 : * 59 : * @param[in] id The id of the node 60 : * @param[in] xPos The x-position of the node 61 : * @param[in] yPos The y-position of the node 62 : */ 63 : NGNode(const std::string& id, int xPos, int yPos); 64 : 65 : 66 : /** @brief Constructor 67 : * 68 : * @param[in] id The id of the node 69 : * @param[in] xPos The x-position of the node 70 : * @param[in] yPos The y-position of the node 71 : * @param[in] amCenter Information whether this is the center-node of a spider-net 72 : */ 73 : NGNode(const std::string& id, int xID, int yID, bool amCenter); 74 : 75 : 76 : /// @brief Destructor 77 : ~NGNode(); 78 : 79 : 80 : /** @brief Returns this node's position 81 : * 82 : * @return The position of the node 83 : */ 84 : const Position& getPosition() const { 85 3738706 : return myPosition; 86 : } 87 : 88 : 89 : /** @brief Returns this node's maximum neighbour number 90 : * 91 : * @return The maximum neighbour number of the node 92 : */ 93 : int getMaxNeighbours() { 94 416933 : return myMaxNeighbours; 95 : } 96 : 97 : 98 : /** @brief Sets this node's maximum neighbour number 99 : * 100 : * @param[in] value The new maximum neighbour number of the node 101 : */ 102 : void setMaxNeighbours(int value) { 103 32881 : myMaxNeighbours = value; 104 : } 105 : 106 : 107 : /** @brief Sets a new value for x-position 108 : * 109 : * @param[in] value The new x-position of this node 110 : */ 111 : void setX(double x) { 112 : myPosition.set(x, myPosition.y()); 113 : } 114 : 115 : 116 : /** @brief Sets a new value for y-position 117 : * 118 : * @param[in] value The new y-position of this node 119 : */ 120 : void setY(double y) { 121 : myPosition.set(myPosition.x(), y); 122 : } 123 : 124 : /// @brief mark node as fringe 125 : void setFringe() { 126 16 : myAmFringe = true; 127 : } 128 : 129 : /** @brief Builds and returns this node's netbuild-representation 130 : * 131 : * The position of the node is transformed to cartesian using GeoConvHelper::x2cartesian, 132 : * first. If this node is the center node of a spider net, a node of the type 133 : * NBNode::SumoXMLNodeType::NOJUNCTION is returned. 134 : * Otherwise, a plain node is built and it is checked whether the options 135 : * indicate building one of the tls node-types. In this case, a logic is built and 136 : * stored. A ProcessError is thrown if this fails (should never happen, in fact). 137 : * 138 : * @param[in] nb The netbuilder to retrieve the tls-container from 139 : * @return The built node 140 : * @exception ProcessError If the built tls logic could not be added (should never happen) 141 : * @todo There is no interaction with explicit node setting options? Where is this done? 142 : * @todo Check whether throwing an exception is really necessary, here 143 : */ 144 : NBNode* buildNBNode(NBNetBuilder& nb, const Position& perturb) const; 145 : 146 : 147 : /** @brief Adds the given link to the internal list 148 : * 149 : * @param[in] link The link to add 150 : */ 151 : void addLink(NGEdge* link); 152 : 153 : 154 : /** @brief Removes the given link 155 : * 156 : * The given pointer is compared to those in the list. A matching 157 : * pointer is removed, not other same connections. 158 : * 159 : * @param[in] link The link to remove 160 : */ 161 : void removeLink(NGEdge* link); 162 : 163 : 164 : const NGEdgeList& getLinks() const { 165 : return myLinkList; 166 : } 167 : 168 : /** @brief Returns whether the other node is connected 169 : * 170 : * @param[in] node The link to check whether it is connected 171 : * @return Whether the given node is connected 172 : */ 173 : bool connected(const NGNode* const node, const bool withDir = false) const; 174 : 175 : 176 : /** @brief Returns whether the node has the given position 177 : * 178 : * @param[in] node The link to check whether it is connected 179 : * @return Whether the given node is connected 180 : */ 181 : bool samePos(int xPos, int yPos) const { 182 166850 : return myXID == xPos && myYID == yPos; 183 : } 184 : 185 : private: 186 : /// @brief Integer x-position (x-id) 187 : int myXID; 188 : 189 : /// @brief Integer y-position (y-id) 190 : int myYID; 191 : 192 : /// @brief List of connected links 193 : NGEdgeList myLinkList; 194 : 195 : /// @brief The position of the node 196 : Position myPosition; 197 : 198 : /// @brief The maximum number of neighbours 199 : int myMaxNeighbours; 200 : 201 : /// @brief Information whether this is the center of a cpider-net 202 : bool myAmCenter; 203 : 204 : /// @brief Information whether this is the center of a cpider-net 205 : bool myAmFringe; 206 : 207 : }; 208 : 209 : /** 210 : * @typedef NGNodeList 211 : * @brief A list of nodes (node pointers) 212 : */ 213 : typedef std::list<NGNode*> NGNodeList;