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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // A point-of-interest (2D)
19 /****************************************************************************/
20 #ifndef PointOfInterest_h
21 #define PointOfInterest_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
32 #include <utils/geom/Position.h>
34 #include "Shape.h"
35 
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
44 class PointOfInterest : public Shape, public Position, public Parameterised {
45 public:
62  PointOfInterest(const std::string& id, const std::string& type,
63  const RGBColor& color, const Position& pos, bool geo,
64  const std::string& lane, double posOverLane, double posLat,
65  double layer = DEFAULT_LAYER,
66  double angle = DEFAULT_ANGLE,
67  const std::string& imgFile = DEFAULT_IMG_FILE,
68  bool relativePath = DEFAULT_RELATIVEPATH,
69  double width = DEFAULT_IMG_WIDTH,
70  double height = DEFAULT_IMG_HEIGHT) :
71  Shape(id, type, color, layer, angle, imgFile, relativePath),
72  Position(pos),
73  myGeo(geo),
74  myLane(lane),
75  myPosOverLane(posOverLane),
76  myPosLat(posLat),
77  myHalfImgWidth(width / 2.0),
78  myHalfImgHeight(height / 2.0) {
79  }
80 
81 
83  virtual ~PointOfInterest() { }
84 
85 
88 
90  inline double getWidth() const {
91  return myHalfImgWidth * 2.0;
92  }
93 
95  inline double getHeight() const {
96  return myHalfImgHeight * 2.0;
97  }
98 
100  Position getCenter() const {
101  return {x() + myHalfImgWidth, y() + myHalfImgHeight};
102  }
104 
105 
108 
110  inline void setWidth(double width) {
111  myHalfImgWidth = width / 2.0;
112  }
113 
115  inline void setHeight(double height) {
116  myHalfImgHeight = height / 2.0;
117  }
119 
120 
121  /* @brief POI definition to the given device
122  * @param[in] geo Whether to write the output in geo-coordinates
123  */
124  void writeXML(OutputDevice& out, const bool geo = false, const double zOffset = 0., const std::string laneID = "", const double pos = 0., const double posLat = 0.) {
125  out.openTag(SUMO_TAG_POI);
127  if (getShapeType().size() > 0) {
129  }
131  out.writeAttr(SUMO_ATTR_LAYER, getShapeLayer() + zOffset);
132  if (laneID != "") {
133  out.writeAttr(SUMO_ATTR_LANE, laneID);
134  out.writeAttr(SUMO_ATTR_POSITION, pos);
135  if (posLat != 0) {
136  out.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
137  }
138  } else {
139  if (geo) {
140  Position POICartesianPos(*this);
141  GeoConvHelper::getFinal().cartesian2geo(POICartesianPos);
143  out.writeAttr(SUMO_ATTR_LON, POICartesianPos.x());
144  out.writeAttr(SUMO_ATTR_LAT, POICartesianPos.y());
145  out.setPrecision();
146  } else {
147  out.writeAttr(SUMO_ATTR_X, x());
148  out.writeAttr(SUMO_ATTR_Y, y());
149  }
150  }
153  }
155  if (getShapeRelativePath()) {
156  // write only the file name, without file path
157  std::string file = getShapeImgFile();
158  file.erase(0, FileHelpers::getFilePath(getShapeImgFile()).size());
159  out.writeAttr(SUMO_ATTR_IMGFILE, file);
160  } else {
162  }
163  }
166  }
169  }
170  writeParams(out);
171  out.closeTag();
172  }
173 
174 
175 protected:
177  bool myGeo;
178 
180  std::string myLane;
181 
184 
186  double myPosLat;
187 
190 
193 
194 };
195 
196 
197 #endif
198 
199 /****************************************************************************/
200 
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:48
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition: Shape.h:104
A layer number.
double myPosOverLane
position over lane in which this POI is placed (main used by netedit)
double y() const
Returns the y-position.
Definition: Position.h:62
static const double DEFAULT_IMG_HEIGHT
Definition: Shape.h:51
double x() const
Returns the x-position.
Definition: Position.h:57
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
begin/end of the description of a Point of interest
const std::string & getID() const
Returns the id.
Definition: Named.h:77
double getHeight() const
Returns the image height of the POI.
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:76
double myPosLat
latereal position over lane in which this POI is placed (main used by netedit)
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
void writeXML(OutputDevice &out, const bool geo=false, const double zOffset=0., const std::string laneID="", const double pos=0., const double posLat=0.)
double myHalfImgHeight
The half height of the image when rendering this POI.
std::string myLane
ID of lane in which this POI is placed (main used by netedit)
bool getShapeRelativePath() const
Returns the relativePath of the Shape.
Definition: Shape.h:111
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
int gPrecisionGeo
Definition: StdDefs.cpp:28
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition: Shape.h:83
static const bool DEFAULT_RELATIVEPATH
Definition: Shape.h:49
A 2D- or 3D-Shape.
Definition: Shape.h:39
double myHalfImgWidth
The half width of the image when rendering this POI.
An upper class for objects with additional parameters.
Definition: Parameterised.h:43
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
double getShapeLayer() const
Returns the layer of the Shape.
Definition: Shape.h:90
double getWidth() const
Returns the image width of the POI.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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.
void setHeight(double height)
set the image height of the POI
void setWidth(double width)
set the image width of the POI
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
Position getCenter() const
Returns the image center of the POI.
static const double DEFAULT_IMG_WIDTH
Definition: Shape.h:50
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A point-of-interest.
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
Definition: FileHelpers.cpp:67
bool myGeo
flag to check if POI was loaded as GEO Position (main used by netedit)
A color information.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:97
static const double DEFAULT_ANGLE
Definition: Shape.h:47
static const double DEFAULT_LAYER
Definition: Shape.h:44
virtual ~PointOfInterest()
Destructor.