YARP
Yet Another Robot Platform
Map2DPath.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 
7 #include <yarp/dev/Map2DPath.h>
10 #include <yarp/os/Log.h>
11 #include <yarp/os/LogStream.h>
12 #include <cassert>
13 #include <functional>
14 #include <math.h>
15 
16 using namespace yarp::dev;
17 using namespace yarp::dev::Nav2D;
18 using namespace yarp::sig;
19 using namespace yarp::os;
20 using namespace yarp::math;
21 
22 bool Map2DPath::operator!=(const Map2DPath& r) const
23 {
24  for (size_t i = 0; i < waypoints.size(); i++) {
25  if (this->waypoints[i].map_id == r.waypoints[i].map_id || this->waypoints[i].x == r.waypoints[i].x || this->waypoints[i].y == r.waypoints[i].y || this->waypoints[i].theta == r.waypoints[i].theta) {
26  return false;
27  }
28  }
29  return true;
30 }
31 
32 bool Map2DPath::operator==(const Map2DPath& r) const
33 {
34  for (size_t i = 0; i < waypoints.size(); i++) {
35  if (this->waypoints[i].map_id != r.waypoints[i].map_id || this->waypoints[i].x != r.waypoints[i].x || this->waypoints[i].y != r.waypoints[i].y || this->waypoints[i].theta != r.waypoints[i].theta) {
36  return false;
37  }
38  }
39  return true;
40 }
41 
42 std::string Map2DPath::toString() const
43 {
44  std::ostringstream stringStream;
45  stringStream.precision(2);
46  //stringStream.width(0);
47  for (size_t i = 0; i < waypoints.size(); i++)
48  {
49  stringStream << " waypoint " << i << "(" << waypoints[i].map_id << " " << waypoints[i].x << "," << waypoints[i].y << "," << waypoints[i].theta << ")";
50  }
51  return stringStream.str();
52 }
53 
55 {
56  this->waypoints.clear();
57 }
58 
59 Map2DPath::Map2DPath(const std::vector<Map2DLocation> map_waypoints)
60 {
61  for (const auto& map_waypoint : map_waypoints)
62  {
63  waypoints.push_back(map_waypoint);
64  }
65 }
66 
68 {
69 }
70 
72 {
73  return waypoints[index];
74 }
75 
76 size_t Map2DPath::size() const
77 {
78  return this->waypoints.size();
79 }
80 
81 double Map2DPath::getLength() const
82 {
83  double ll = 0;
84  for (auto it = waypoints.begin(); it != waypoints.end(); it++)
85  {
86  ll += sqrt(pow(it->x,2)+ pow(it->y,2));
87  }
88  return ll;
89 }
90 
92 {
93  if (waypoints.size() == 0) {
94  return true;
95  }
96  std::string mapname = waypoints[0].map_id;
97  for (auto it = waypoints.begin(); it != waypoints.end(); it++)
98  {
99  if (it->map_id != mapname) {
100  return false;
101  }
102  }
103  return true;
104 }
105 
107 {
108  return waypoints.begin();
109 }
110 
111 
113 {
114  return waypoints.end();
115 }
116 
118 {
119  return waypoints.cbegin();
120 }
121 
123 {
124  return waypoints.cend();
125 }
126 
128 {
129  waypoints.push_back(loc);
130 }
contains the definition of a Map2DPath type
std::vector< yarp::dev::Nav2D::Map2DLocation > waypoints
Definition: Map2DPathData.h:28
void push_back(yarp::dev::Nav2D::Map2DLocation loc)
Inserts a new location into the path @loc the location to be inserted.
Definition: Map2DPath.cpp:127
std::vector< Map2DLocation >::const_iterator const_iterator
Definition: Map2DPath.h:93
void clear()
Remove all elements from the path.
Definition: Map2DPath.cpp:54
const_iterator cbegin() const noexcept
Returns a const iterator to the begin of the Path.
Definition: Map2DPath.cpp:117
const_iterator cend() const noexcept
Returns a const iterator to the end of the Path.
Definition: Map2DPath.cpp:122
std::string toString() const
Returns text representation of the path.
Definition: Map2DPath.cpp:42
yarp::dev::Nav2D::Map2DLocation & operator[](size_t index)
Returns a waypoint in the path.
Definition: Map2DPath.cpp:71
iterator begin() noexcept
Returns an iterator to the begin of the Path.
Definition: Map2DPath.cpp:106
size_t size() const
Returns the size of the path.
Definition: Map2DPath.cpp:76
bool operator==(const Map2DPath &r) const
Compares two Map2DArea.
Definition: Map2DPath.cpp:32
bool isOnSingleMap() const
Checks if all the waypoints of the path belong to the same map return true if the test is successful.
Definition: Map2DPath.cpp:91
bool operator!=(const Map2DPath &r) const
Compares two Map2DPath.
Definition: Map2DPath.cpp:22
std::vector< Map2DLocation >::iterator iterator
Definition: Map2DPath.h:92
double getLength() const
Returns the length of the path.
Definition: Map2DPath.cpp:81
Map2DPath()
Default constructor: the map name is empty, coordinates are set to zero.
Definition: Map2DPath.cpp:67
iterator end() noexcept
Returns an iterator to the end of the Path.
Definition: Map2DPath.cpp:112
An interface for the device drivers.
An interface to the operating system, including Port based communication.
Signal processing.
Definition: Image.h:22