YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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
10#include <yarp/os/Log.h>
11#include <yarp/os/LogStream.h>
12#include <cassert>
13#include <functional>
14#include <math.h>
15
16using namespace yarp::dev;
17using namespace yarp::dev::Nav2D;
18using namespace yarp::sig;
19using namespace yarp::os;
20using namespace yarp::math;
21
22bool 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
32bool 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
42std::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 stringStream << " desc: " << description;
52 return stringStream.str();
53}
54
56{
57 this->waypoints.clear();
58 description = "";
59}
60
61Map2DPath::Map2DPath(const std::vector<Map2DLocation>& map_waypoints, const std::string& desc)
62{
63 description = desc;
64 for (const auto& map_waypoint : map_waypoints)
65 {
66 waypoints.push_back(map_waypoint);
67 }
68}
69
73
75{
76 return waypoints[index];
77}
78
79size_t Map2DPath::size() const
80{
81 return this->waypoints.size();
82}
83
85{
86 double ll = 0;
87 for (auto it = waypoints.begin(); it != waypoints.end(); it++)
88 {
89 ll += sqrt(pow(it->x,2)+ pow(it->y,2));
90 }
91 return ll;
92}
93
95{
96 if (waypoints.size() == 0) {
97 return true;
98 }
99 std::string mapname = waypoints[0].map_id;
100 for (auto it = waypoints.begin(); it != waypoints.end(); it++)
101 {
102 if (it->map_id != mapname) {
103 return false;
104 }
105 }
106 return true;
107}
108
113
114
119
124
129
131{
132 waypoints.push_back(loc);
133}
contains the definition of a Map2DPath type
std::vector< yarp::dev::Nav2D::Map2DLocation > waypoints
list of waypoints which define the path
std::string description
user defined string
void push_back(yarp::dev::Nav2D::Map2DLocation loc)
Inserts a new location into the path @loc the location to be inserted.
std::vector< Map2DLocation >::const_iterator const_iterator
Definition Map2DPath.h:100
void clear()
Remove all elements from the path.
Definition Map2DPath.cpp:55
const_iterator cbegin() const noexcept
Returns a const iterator to the begin of the Path.
const_iterator cend() const noexcept
Returns a const iterator to the end of the Path.
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:74
iterator begin() noexcept
Returns an iterator to the begin of the Path.
size_t size() const
Returns the size of the path.
Definition Map2DPath.cpp:79
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:94
bool operator!=(const Map2DPath &r) const
Compares two Map2DPath.
Definition Map2DPath.cpp:22
std::vector< Map2DLocation >::iterator iterator
Definition Map2DPath.h:99
double getLength() const
Returns the length of the path.
Definition Map2DPath.cpp:84
Map2DPath()
Default constructor: the map name is empty, coordinates are set to zero.
Definition Map2DPath.cpp:70
iterator end() noexcept
Returns an iterator to the end of the Path.
A mini-server for performing network communication in the background.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.