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 /****************************************************************************/
17 // A point-of-interest (2D)
18 /****************************************************************************/
19 #ifndef PointOfInterest_h
20 #define PointOfInterest_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
31 #include <utils/geom/Position.h>
33 #include "Shape.h"
34 
35 
36 // ===========================================================================
37 // class definitions
38 // ===========================================================================
43 class PointOfInterest : public Shape, public Position, public Parameterised {
44 public:
61  PointOfInterest(const std::string& id, const std::string& type,
62  const RGBColor& color, const Position& pos, bool geo,
63  const std::string& lane, double posOverLane, double posLat,
64  double layer = DEFAULT_LAYER,
65  double angle = DEFAULT_ANGLE,
66  const std::string& imgFile = DEFAULT_IMG_FILE,
67  bool relativePath = DEFAULT_RELATIVEPATH,
68  double width = DEFAULT_IMG_WIDTH,
69  double height = DEFAULT_IMG_HEIGHT) :
70  Shape(id, type, color, layer, angle, imgFile, relativePath),
71  Position(pos),
72  myGeo(geo),
73  myLane(lane),
74  myPosOverLane(posOverLane),
75  myPosLat(posLat),
76  myHalfImgWidth(width / 2.0),
77  myHalfImgHeight(height / 2.0) {
78  }
79 
80 
82  virtual ~PointOfInterest() { }
83 
84 
87 
89  inline double getWidth() const {
90  return myHalfImgWidth * 2.0;
91  }
92 
94  inline double getHeight() const {
95  return myHalfImgHeight * 2.0;
96  }
97 
99  Position getCenter() const {
100  return {x() + myHalfImgWidth, y() + myHalfImgHeight};
101  }
103 
104 
107 
109  inline void setWidth(double width) {
110  myHalfImgWidth = width / 2.0;
111  }
112 
114  inline void setHeight(double height) {
115  myHalfImgHeight = height / 2.0;
116  }
118 
119 
120  /* @brief POI definition to the given device
121  * @param[in] geo Whether to write the output in geo-coordinates
122  */
123  void writeXML(OutputDevice& out, const bool geo = false, const double zOffset = 0., const std::string laneID = "", const double pos = 0., const double posLat = 0.) {
124  out.openTag(SUMO_TAG_POI);
126  if (getShapeType().size() > 0) {
128  }
130  out.writeAttr(SUMO_ATTR_LAYER, getShapeLayer() + zOffset);
131  if (laneID != "") {
132  out.writeAttr(SUMO_ATTR_LANE, laneID);
133  out.writeAttr(SUMO_ATTR_POSITION, pos);
134  if (posLat != 0) {
135  out.writeAttr(SUMO_ATTR_POSITION_LAT, posLat);
136  }
137  } else {
138  if (geo) {
139  Position POICartesianPos(*this);
140  GeoConvHelper::getFinal().cartesian2geo(POICartesianPos);
142  out.writeAttr(SUMO_ATTR_LON, POICartesianPos.x());
143  out.writeAttr(SUMO_ATTR_LAT, POICartesianPos.y());
144  out.setPrecision();
145  } else {
146  out.writeAttr(SUMO_ATTR_X, x());
147  out.writeAttr(SUMO_ATTR_Y, y());
148  }
149  }
152  }
154  if (getShapeRelativePath()) {
155  // write only the file name, without file path
156  std::string file = getShapeImgFile();
157  file.erase(0, FileHelpers::getFilePath(getShapeImgFile()).size());
158  out.writeAttr(SUMO_ATTR_IMGFILE, file);
159  } else {
161  }
162  }
165  }
168  }
169  writeParams(out);
170  out.closeTag();
171  }
172 
173 
174 protected:
176  bool myGeo;
177 
179  std::string myLane;
180 
183 
185  double myPosLat;
186 
189 
192 
193 };
194 
195 
196 #endif
197 
198 /****************************************************************************/
199 
SUMO_ATTR_TYPE
@ SUMO_ATTR_TYPE
Definition: SUMOXMLDefinitions.h:381
SUMO_ATTR_ANGLE
@ SUMO_ATTR_ANGLE
Definition: SUMOXMLDefinitions.h:794
SUMO_ATTR_IMGFILE
@ SUMO_ATTR_IMGFILE
Definition: SUMOXMLDefinitions.h:792
Parameterised
An upper class for objects with additional parameters.
Definition: Parameterised.h:42
PointOfInterest::~PointOfInterest
virtual ~PointOfInterest()
Destructor.
Definition: PointOfInterest.h:82
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
Shape::getShapeNaviDegree
double getShapeNaviDegree() const
Returns the angle of the Shape in navigational degrees.
Definition: Shape.h:96
PointOfInterest::myGeo
bool myGeo
flag to check if POI was loaded as GEO Position (main used by netedit)
Definition: PointOfInterest.h:176
PointOfInterest::getHeight
double getHeight() const
Returns the image height of the POI.
Definition: PointOfInterest.h:94
PointOfInterest::writeXML
void writeXML(OutputDevice &out, const bool geo=false, const double zOffset=0., const std::string laneID="", const double pos=0., const double posLat=0.)
Definition: PointOfInterest.h:123
Shape::DEFAULT_LAYER
static const double DEFAULT_LAYER
Definition: Shape.h:43
OutputDevice::setPrecision
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Definition: OutputDevice.cpp:221
GeoConvHelper.h
SUMO_ATTR_COLOR
@ SUMO_ATTR_COLOR
A color information.
Definition: SUMOXMLDefinitions.h:704
SUMO_TAG_POI
@ SUMO_TAG_POI
begin/end of the description of a Point of interest
Definition: SUMOXMLDefinitions.h:53
Shape::getShapeImgFile
const std::string & getShapeImgFile() const
Returns the imgFile of the Shape.
Definition: Shape.h:103
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
SUMO_ATTR_LANE
@ SUMO_ATTR_LANE
Definition: SUMOXMLDefinitions.h:637
PointOfInterest::myPosOverLane
double myPosOverLane
position over lane in which this POI is placed (main used by netedit)
Definition: PointOfInterest.h:182
Shape::getShapeColor
const RGBColor & getShapeColor() const
Returns the color of the Shape.
Definition: Shape.h:82
gPrecisionGeo
int gPrecisionGeo
Definition: StdDefs.cpp:27
Parameterised::writeParams
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
Definition: Parameterised.cpp:154
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
FileHelpers::getFilePath
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
Definition: FileHelpers.cpp:76
Shape::DEFAULT_IMG_HEIGHT
static const double DEFAULT_IMG_HEIGHT
Definition: Shape.h:50
Shape::DEFAULT_RELATIVEPATH
static const bool DEFAULT_RELATIVEPATH
Definition: Shape.h:48
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
RGBColor
Definition: RGBColor.h:39
Shape.h
PointOfInterest::myHalfImgWidth
double myHalfImgWidth
The half width of the image when rendering this POI.
Definition: PointOfInterest.h:188
Shape::getShapeLayer
double getShapeLayer() const
Returns the layer of the Shape.
Definition: Shape.h:89
GeoConvHelper::getFinal
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
Definition: GeoConvHelper.h:105
Parameterised.h
SUMO_ATTR_WIDTH
@ SUMO_ATTR_WIDTH
Definition: SUMOXMLDefinitions.h:386
StringUtils::escapeXML
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
Definition: StringUtils.cpp:190
PointOfInterest::setWidth
void setWidth(double width)
set the image width of the POI
Definition: PointOfInterest.h:109
SUMO_ATTR_LAYER
@ SUMO_ATTR_LAYER
A layer number.
Definition: SUMOXMLDefinitions.h:712
OutputDevice.h
PointOfInterest::myHalfImgHeight
double myHalfImgHeight
The half height of the image when rendering this POI.
Definition: PointOfInterest.h:191
GeoConvHelper::cartesian2geo
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
Definition: GeoConvHelper.cpp:293
PointOfInterest::setHeight
void setHeight(double height)
set the image height of the POI
Definition: PointOfInterest.h:114
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
Position::x
double x() const
Returns the x-position.
Definition: Position.h:56
SUMO_ATTR_Y
@ SUMO_ATTR_Y
Definition: SUMOXMLDefinitions.h:399
Shape::getShapeType
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:75
PointOfInterest::getCenter
Position getCenter() const
Returns the image center of the POI.
Definition: PointOfInterest.h:99
Shape
A 2D- or 3D-Shape.
Definition: Shape.h:38
PointOfInterest::myLane
std::string myLane
ID of lane in which this POI is placed (main used by netedit)
Definition: PointOfInterest.h:179
Shape::getShapeRelativePath
bool getShapeRelativePath() const
Returns the relativePath of the Shape.
Definition: Shape.h:110
SUMO_ATTR_POSITION
@ SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:660
PointOfInterest::myPosLat
double myPosLat
latereal position over lane in which this POI is placed (main used by netedit)
Definition: PointOfInterest.h:185
SUMO_ATTR_HEIGHT
@ SUMO_ATTR_HEIGHT
Definition: SUMOXMLDefinitions.h:789
Position.h
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
StringUtils.h
Position::y
double y() const
Returns the y-position.
Definition: Position.h:61
SUMO_ATTR_LAT
@ SUMO_ATTR_LAT
Definition: SUMOXMLDefinitions.h:815
SUMO_ATTR_POSITION_LAT
@ SUMO_ATTR_POSITION_LAT
Definition: SUMOXMLDefinitions.h:661
PointOfInterest::getWidth
double getWidth() const
Returns the image width of the POI.
Definition: PointOfInterest.h:89
Shape::DEFAULT_ANGLE
static const double DEFAULT_ANGLE
Definition: Shape.h:46
config.h
PointOfInterest
A point-of-interest.
Definition: PointOfInterest.h:43
Shape::DEFAULT_IMG_FILE
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:47
SUMO_ATTR_LON
@ SUMO_ATTR_LON
Definition: SUMOXMLDefinitions.h:814
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
SUMO_ATTR_X
@ SUMO_ATTR_X
Definition: SUMOXMLDefinitions.h:398
PointOfInterest::PointOfInterest
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.
Definition: PointOfInterest.h:61
Shape::DEFAULT_IMG_WIDTH
static const double DEFAULT_IMG_WIDTH
Definition: Shape.h:49