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-2020 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 #include "Shape.h"
33 
34 
35 // ===========================================================================
36 // class definitions
37 // ===========================================================================
42 class PointOfInterest : public Shape, public Position, public Parameterised {
43 public:
60  PointOfInterest(const std::string& id, const std::string& type,
61  const RGBColor& color, const Position& pos, bool geo,
62  const std::string& lane, double posOverLane, double posLat,
63  double layer = DEFAULT_LAYER,
64  double angle = DEFAULT_ANGLE,
65  const std::string& imgFile = DEFAULT_IMG_FILE,
66  bool relativePath = DEFAULT_RELATIVEPATH,
67  double width = DEFAULT_IMG_WIDTH,
68  double height = DEFAULT_IMG_HEIGHT) :
69  Shape(id, type, color, layer, angle, imgFile, relativePath),
70  Position(pos),
71  myGeo(geo),
72  myLane(lane),
73  myPosOverLane(posOverLane),
74  myPosLat(posLat),
75  myHalfImgWidth(width / 2.0),
76  myHalfImgHeight(height / 2.0) {
77  }
78 
79 
81  virtual ~PointOfInterest() { }
82 
83 
86 
88  inline double getWidth() const {
89  return myHalfImgWidth * 2.0;
90  }
91 
93  inline double getHeight() const {
94  return myHalfImgHeight * 2.0;
95  }
96 
98  Position getCenter() const {
99  return {x() + myHalfImgWidth, y() + myHalfImgHeight};
100  }
102 
103 
106 
108  inline void setWidth(double width) {
109  myHalfImgWidth = width / 2.0;
110  }
111 
113  inline void setHeight(double height) {
114  myHalfImgHeight = height / 2.0;
115  }
117 
118 
119  /* @brief POI definition to the given device
120  * @param[in] geo Whether to write the output in geo-coordinates
121  */
122  void writeXML(OutputDevice& out, const bool geo = false, const double zOffset = 0., const std::string laneID = "", const double pos = 0., const double posLat = 0.) {
123  out.openTag(SUMO_TAG_POI);
125  if (getShapeType().size() > 0) {
127  }
129  out.writeAttr(SUMO_ATTR_LAYER, getShapeLayer() + zOffset);
130  if (laneID != "") {
131  out.writeAttr(SUMO_ATTR_LANE, laneID);
132  out.writeAttr(SUMO_ATTR_POSITION, pos);
133  if (posLat != 0) {
134  out.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
135  }
136  } else {
137  if (geo) {
138  Position POICartesianPos(*this);
139  GeoConvHelper::getFinal().cartesian2geo(POICartesianPos);
141  out.writeAttr(SUMO_ATTR_LON, POICartesianPos.x());
142  out.writeAttr(SUMO_ATTR_LAT, POICartesianPos.y());
143  out.setPrecision();
144  } else {
145  out.writeAttr(SUMO_ATTR_X, x());
146  out.writeAttr(SUMO_ATTR_Y, y());
147  }
148  }
151  }
153  if (getShapeRelativePath()) {
154  // write only the file name, without file path
155  std::string file = getShapeImgFile();
156  file.erase(0, FileHelpers::getFilePath(getShapeImgFile()).size());
157  out.writeAttr(SUMO_ATTR_IMGFILE, file);
158  } else {
160  }
161  }
164  }
167  }
168  writeParams(out);
169  out.closeTag();
170  }
171 
172 
173 protected:
175  bool myGeo;
176 
178  std::string myLane;
179 
182 
184  double myPosLat;
185 
188 
191 
192 };
@ 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_LAYER
A layer number.
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_HEIGHT
@ 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:75
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:73
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
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:239
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
An upper class for objects with additional parameters.
Definition: Parameterised.h:39
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
A point-of-interest.
void writeXML(OutputDevice &out, const bool geo=false, const double zOffset=0., const std::string laneID="", const double pos=0., const double posLat=0.)
bool myGeo
flag to check if POI was loaded as GEO Position (main used by netedit)
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.
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.
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)
double getWidth() const
Returns the image width of the POI.
PointOfInterest(const std::string &id, const std::string &type, const RGBColor &color, const Position &pos, bool geo, const std::string &lane, double posOverLane, 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)
Constructor.
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:36
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
A 2D- or 3D-Shape.
Definition: Shape.h:36
static const bool DEFAULT_RELATIVEPATH
Definition: Shape.h:46
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition: Shape.h:80
static const double DEFAULT_LAYER
Definition: Shape.h:41
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition: Shape.h:101
static const double DEFAULT_IMG_WIDTH
Definition: Shape.h:47
bool getShapeRelativePath() const
Returns the relativePath of the Shape.
Definition: Shape.h:108
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:45
static const double DEFAULT_ANGLE
Definition: Shape.h:44
static const double DEFAULT_IMG_HEIGHT
Definition: Shape.h:48
double getShapeLayer() const
Returns the layer of the Shape.
Definition: Shape.h:87
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:94
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:73
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.