Eclipse SUMO - Simulation of Urban MObility
PointOfInterest.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2005-2022 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 point-of-interest (2D)
22 /****************************************************************************/
23 #pragma once
24 #include <config.h>
25 
30 #include <utils/geom/Position.h>
32 
33 #include "Shape.h"
34 
35 
36 // ===========================================================================
37 // class definitions
38 // ===========================================================================
43 class PointOfInterest : public Shape, public Position, public Parameterised {
44 public:
64  PointOfInterest(const std::string& id, const std::string& type,
65  const RGBColor& color, const Position& pos, bool geo,
66  const std::string& lane, double posOverLane,
67  bool friendlyPos, double posLat,
68  double layer = DEFAULT_LAYER,
69  double angle = DEFAULT_ANGLE,
70  const std::string& imgFile = DEFAULT_IMG_FILE,
71  bool relativePath = DEFAULT_RELATIVEPATH,
72  double width = DEFAULT_IMG_WIDTH,
73  double height = DEFAULT_IMG_HEIGHT,
74  const std::string& name = DEFAULT_NAME,
75  const std::map<std::string, std::string>& parameters = DEFAULT_PARAMETERS) :
76  Shape(id, type, color, layer, angle, imgFile, name, relativePath),
77  Position(pos),
78  Parameterised(parameters),
79  myGeo(geo),
80  myLane(lane),
81  myPosOverLane(posOverLane),
82  myFriendlyPos(friendlyPos),
83  myPosLat(posLat),
84  myHalfImgWidth(width / 2.0),
85  myHalfImgHeight(height / 2.0) {
86  }
87 
89  virtual ~PointOfInterest() { }
90 
93 
95  inline double getWidth() const {
96  return myHalfImgWidth * 2.0;
97  }
98 
100  inline double getHeight() const {
101  return myHalfImgHeight * 2.0;
102  }
103 
105  Position getCenter() const {
106  return {x() + myHalfImgWidth, y() + myHalfImgHeight};
107  }
108 
110  bool getFriendlyPos() const {
111  return myFriendlyPos;
112  }
114 
115 
118 
120  inline void setWidth(double width) {
121  myHalfImgWidth = width / 2.0;
122  }
123 
125  inline void setHeight(double height) {
126  myHalfImgHeight = height / 2.0;
127  }
128 
130  inline void setFriendlyPos(const bool friendlyPos) {
131  myFriendlyPos = friendlyPos;
132  }
134 
135  /* @brief POI definition to the given device
136  * @param[in] geo Whether to write the output in geo-coordinates
137  */
138  void writeXML(OutputDevice& out, const bool geo = false, const double zOffset = 0., const std::string laneID = "", const double pos = 0., const bool friendlyPos = false, const double posLat = 0.) {
139  out.openTag(SUMO_TAG_POI);
141  if (getShapeType().size() > 0) {
143  }
145  out.writeAttr(SUMO_ATTR_LAYER, getShapeLayer() + zOffset);
146  if (!getShapeName().empty()) {
148  }
149  if (laneID != "") {
150  out.writeAttr(SUMO_ATTR_LANE, laneID);
151  out.writeAttr(SUMO_ATTR_POSITION, pos);
152  if (posLat != 0) {
153  out.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
154  }
155  if (friendlyPos) {
156  out.writeAttr(SUMO_ATTR_FRIENDLY_POS, friendlyPos);
157  }
158  } else {
159  if (geo) {
160  Position POICartesianPos(*this);
161  GeoConvHelper::getFinal().cartesian2geo(POICartesianPos);
163  out.writeAttr(SUMO_ATTR_LON, POICartesianPos.x());
164  out.writeAttr(SUMO_ATTR_LAT, POICartesianPos.y());
165  out.setPrecision();
166  } else {
167  out.writeAttr(SUMO_ATTR_X, x());
168  out.writeAttr(SUMO_ATTR_Y, y());
169  }
170  }
173  }
175  if (getShapeRelativePath()) {
176  // write only the file name, without file path
177  std::string file = getShapeImgFile();
178  file.erase(0, FileHelpers::getFilePath(getShapeImgFile()).size());
179  out.writeAttr(SUMO_ATTR_IMGFILE, file);
180  } else {
182  }
183  }
186  }
189  }
190  writeParams(out);
191  out.closeTag();
192  }
193 
194 protected:
196  bool myGeo;
197 
199  std::string myLane;
200 
203 
206 
208  double myPosLat;
209 
212 
215 };
@ SUMO_TAG_POI
begin/end of the description of a Point of interest
@ SUMO_ATTR_LANE
@ SUMO_ATTR_LON
@ SUMO_ATTR_Y
@ SUMO_ATTR_X
@ SUMO_ATTR_POSITION_LAT
@ SUMO_ATTR_NAME
@ SUMO_ATTR_LAYER
A layer number.
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_HEIGHT
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_LAT
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_IMGFILE
@ SUMO_ATTR_WIDTH
@ SUMO_ATTR_POSITION
int gPrecisionGeo
Definition: StdDefs.cpp:26
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
Definition: FileHelpers.cpp:81
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
const std::string & getID() const
Returns the id.
Definition: Named.h:74
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
A point-of-interest.
bool myGeo
flag to check if POI was loaded as GEO Position (main used by netedit)
PointOfInterest(const std::string &id, const std::string &type, const RGBColor &color, const Position &pos, bool geo, const std::string &lane, double posOverLane, bool friendlyPos, double posLat, double layer=DEFAULT_LAYER, double angle=DEFAULT_ANGLE, const std::string &imgFile=DEFAULT_IMG_FILE, bool relativePath=DEFAULT_RELATIVEPATH, double width=DEFAULT_IMG_WIDTH, double height=DEFAULT_IMG_HEIGHT, const std::string &name=DEFAULT_NAME, const std::map< std::string, std::string > &parameters=DEFAULT_PARAMETERS)
Constructor.
bool getFriendlyPos() const
returns friendly position
void setHeight(double height)
set the image height of the POI
virtual ~PointOfInterest()
Destructor.
double myHalfImgHeight
The half height of the image when rendering this POI.
void setFriendlyPos(const bool friendlyPos)
set friendly position
double myPosLat
latereal position over lane in which this POI is placed (main used by netedit)
Position getCenter() const
Returns the image center of the POI.
void setWidth(double width)
set the image width of the POI
double getHeight() const
Returns the image height of the POI.
bool myFriendlyPos
friendlyPos enable or disable friendly position for position over lane
std::string myLane
ID of lane in which this POI is placed (main used by netedit)
double myPosOverLane
position over lane in which this POI is placed (main used by netedit)
void writeXML(OutputDevice &out, const bool geo=false, const double zOffset=0., const std::string laneID="", const double pos=0., const bool friendlyPos=false, const double posLat=0.)
double getWidth() const
Returns the image width of the POI.
double myHalfImgWidth
The half width of the image when rendering this POI.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double x() const
Returns the x-position.
Definition: Position.h:55
double y() const
Returns the y-position.
Definition: Position.h:60
A 2D- or 3D-Shape.
Definition: Shape.h:37
const std::string getShapeName() const
Returns the name of the Shape.
Definition: Shape.h:109
static const bool DEFAULT_RELATIVEPATH
Definition: Shape.h:47
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition: Shape.h:83
static const std::map< std::string, std::string > DEFAULT_PARAMETERS
Definition: Shape.h:51
static const double DEFAULT_LAYER
Definition: Shape.h:42
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition: Shape.h:104
static const double DEFAULT_IMG_WIDTH
Definition: Shape.h:48
bool getShapeRelativePath() const
Returns the relativePath of the Shape.
Definition: Shape.h:116
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:46
static const double DEFAULT_ANGLE
Definition: Shape.h:45
static const std::string DEFAULT_NAME
Definition: Shape.h:50
static const double DEFAULT_IMG_HEIGHT
Definition: Shape.h:49
double getShapeLayer() const
Returns the layer of the Shape.
Definition: Shape.h:90
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:97
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:76
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.