YARP
Yet Another Robot Platform
Map2DLocation.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_DEV_MAP2DLOCATION_H
10 #define YARP_DEV_MAP2DLOCATION_H
11 
12 #include <sstream>
13 #include <string>
14 
15 //#include <yarp/math/Vec2D.h>
16 #include <yarp/dev/api.h>
17 #include <yarp/dev/NavTypes.h>
19 
23 namespace yarp
24 {
25  namespace dev
26  {
27  namespace Nav2D
28  {
30  {
38  Map2DLocation(const std::string& map_name, const double& inX, const double& inY, const double& inT)
39  {
40  map_id = map_name;
41  x = inX;
42  y = inY;
43  theta = inT;
44  }
45 
54  Map2DLocation(const std::string& map_name, yarp::dev::Nav2D::XYWorld location)
55  {
56  map_id = map_name;
57  x = location.x;
58  y = location.y;
59  theta = 0;
60  }
61 
66  {
67  map_id = "";
68  x = 0;
69  y = 0;
70  theta = 0;
71  }
72 
77  std::string toString() const
78  {
79  std::ostringstream stringStream;
80  stringStream.precision(-1);
81  stringStream.width(-1);
82  stringStream << std::string("map_id:") << map_id << std::string(" x:") << x << std::string(" y:") << y << std::string(" theta:") << theta;
83  return stringStream.str();
84  }
85 
90  inline bool operator!=(const Map2DLocation& r) const
91  {
92  if (
93  map_id != r.map_id ||
94  x != r.x ||
95  y != r.y ||
96  theta != r.theta
97  )
98  {
99  return true;
100  }
101  return false;
102  }
103 
108  inline bool operator==(const Map2DLocation& r) const
109  {
110  if (
111  map_id == r.map_id &&
112  x == r.x &&
113  y == r.y &&
114  theta == r.theta
115  )
116  {
117  return true;
118  }
119  return false;
120  }
121 
126  bool is_near_to(const Map2DLocation& other_loc, double linear_tolerance, double angular_tolerance) const;
127 
131  bool read(yarp::os::idl::WireReader& reader) override { return Map2DLocationData::read(reader); }
132  bool write(const yarp::os::idl::WireWriter& writer) const override { return Map2DLocationData::write(writer); }
133  bool read(yarp::os::ConnectionReader& reader) override { return Map2DLocationData::read(reader); }
134  bool write(yarp::os::ConnectionWriter& writer) const override { return Map2DLocationData::write(writer); }
135  };
136  }
137  }
138 }
139 
140 #endif // YARP_DEV_MAP2DLOCATION_H
yarp::dev::Nav2D::Map2DLocation::write
bool write(yarp::os::ConnectionWriter &writer) const override
Write this object to a network connection.
Definition: Map2DLocation.h:134
Map2DLocationData.h
yarp::dev::Map2DLocationData::read
bool read(yarp::os::idl::WireReader &reader) override
Definition: Map2DLocationData.cpp:43
yarp::dev::Map2DLocationData::y
double y
Definition: Map2DLocationData.h:32
yarp::dev::Nav2D::Map2DLocation::Map2DLocation
Map2DLocation(const std::string &map_name, yarp::dev::Nav2D::XYWorld location)
A constructor which accepts a yarp::math::Vec2D, defining the location by its x,y coordinates.
Definition: Map2DLocation.h:54
yarp::math::Vec2D::x
T x
Definition: Vec2D.h:27
yarp::dev::Nav2D::Map2DLocation::operator!=
bool operator!=(const Map2DLocation &r) const
Compares two Map2DLocations.
Definition: Map2DLocation.h:90
yarp::dev::Nav2D::Map2DLocation::write
bool write(const yarp::os::idl::WireWriter &writer) const override
Definition: Map2DLocation.h:132
yarp::dev::Nav2D::Map2DLocation::toString
std::string toString() const
Returns text representation of the location.
Definition: Map2DLocation.h:77
yarp::dev::Map2DLocationData::write
bool write(const yarp::os::idl::WireWriter &writer) const override
Definition: Map2DLocationData.cpp:71
yarp::dev::Nav2D::Map2DLocation::read
bool read(yarp::os::idl::WireReader &reader) override
Serialization methods.
Definition: Map2DLocation.h:131
yarp::dev::Map2DLocationData::theta
double theta
Definition: Map2DLocationData.h:33
yarp::math::Vec2D< double >
yarp::os::idl::WireWriter
IDL-friendly connection writer.
Definition: WireWriter.h:33
NavTypes.h
contains definitions for common types used in navigation interfaces
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::dev::Map2DLocationData
Definition: Map2DLocationData.h:27
YARP_dev_API
#define YARP_dev_API
Definition: api.h:19
yarp::dev::Nav2D::Map2DLocation::Map2DLocation
Map2DLocation(const std::string &map_name, const double &inX, const double &inY, const double &inT)
Constructor.
Definition: Map2DLocation.h:38
yarp::dev::Nav2D::Map2DLocation
Definition: Map2DLocation.h:30
yarp::os::idl::WireReader
IDL-friendly connection reader.
Definition: WireReader.h:33
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::dev::Nav2D::Map2DLocation::operator==
bool operator==(const Map2DLocation &r) const
Compares two Map2DLocations.
Definition: Map2DLocation.h:108
yarp::dev::Nav2D::Map2DLocation::Map2DLocation
Map2DLocation()
Default constructor: the map name is empty, coordinates are set to zero.
Definition: Map2DLocation.h:65
yarp::dev::Map2DLocationData::x
double x
Definition: Map2DLocationData.h:31
yarp::dev::Nav2D::Map2DLocation::read
bool read(yarp::os::ConnectionReader &reader) override
Read this object from a network connection.
Definition: Map2DLocation.h:133
yarp::dev::Map2DLocationData::map_id
std::string map_id
Definition: Map2DLocationData.h:30
api.h
yarp::math::Vec2D::y
T y
Definition: Vec2D.h:31