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-2018 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  }
99 
100 
103 
105  inline void setWidth(double width) {
106  myHalfImgWidth = width / 2.0;
107  }
108 
110  inline void setHeight(double height) {
111  myHalfImgHeight = height / 2.0;
112  }
114 
115 
116  /* @brief POI definition to the given device
117  * @param[in] geo Whether to write the output in geo-coordinates
118  */
119  void writeXML(OutputDevice& out, const bool geo = false, const double zOffset = 0., const std::string laneID = "", const double pos = 0., const double posLat = 0.) {
120  out.openTag(SUMO_TAG_POI);
122  if (getShapeType().size() > 0) {
124  }
126  out.writeAttr(SUMO_ATTR_LAYER, getShapeLayer() + zOffset);
127  if (laneID != "") {
128  out.writeAttr(SUMO_ATTR_LANE, laneID);
129  out.writeAttr(SUMO_ATTR_POSITION, pos);
130  if (posLat != 0) {
131  out.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
132  }
133  } else {
134  if (geo) {
135  Position POICartesianPos(*this);
136  GeoConvHelper::getFinal().cartesian2geo(POICartesianPos);
138  out.writeAttr(SUMO_ATTR_LON, POICartesianPos.x());
139  out.writeAttr(SUMO_ATTR_LAT, POICartesianPos.y());
140  out.setPrecision();
141  } else {
142  out.writeAttr(SUMO_ATTR_X, x());
143  out.writeAttr(SUMO_ATTR_Y, y());
144  }
145  }
148  }
150  if (getShapeRelativePath()) {
151  // write only the file name, without file path
152  std::string file = getShapeImgFile();
153  file.erase(0, FileHelpers::getFilePath(getShapeImgFile()).size());
154  out.writeAttr(SUMO_ATTR_IMGFILE, file);
155  } else {
157  }
158  }
161  }
164  }
165  writeParams(out);
166  out.closeTag();
167  }
168 
169 
170 protected:
172  bool myGeo;
173 
175  std::string myLane;
176 
179 
181  double myPosLat;
182 
185 
188 
189 };
190 
191 
192 #endif
193 
194 /****************************************************************************/
195 
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:78
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:44
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...
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:65
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.