YARP
Yet Another Robot Platform
Map2DPath.cpp
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 
10 #include <yarp/dev/Map2DPath.h>
13 #include <yarp/os/Log.h>
14 #include <yarp/os/LogStream.h>
15 #include <cassert>
16 #include <functional>
17 #include <math.h>
18 
19 using namespace yarp::dev;
20 using namespace yarp::dev::Nav2D;
21 using namespace yarp::sig;
22 using namespace yarp::os;
23 using namespace yarp::math;
24 using namespace std;
25 
26 bool Map2DPath::operator!=(const Map2DPath& r) const
27 {
28  for (size_t i = 0; i < waypoints.size(); i++)
29  if (this->waypoints[i].map_id == r.waypoints[i].map_id ||
30  this->waypoints[i].x == r.waypoints[i].x ||
31  this->waypoints[i].y == r.waypoints[i].y ||
32  this->waypoints[i].theta == r.waypoints[i].theta) return false;
33  return true;
34 }
35 
36 bool Map2DPath::operator==(const Map2DPath& r) const
37 {
38  for (size_t i = 0; i < waypoints.size(); i++)
39  if (this->waypoints[i].map_id != r.waypoints[i].map_id ||
40  this->waypoints[i].x != r.waypoints[i].x ||
41  this->waypoints[i].y != r.waypoints[i].y ||
42  this->waypoints[i].theta != r.waypoints[i].theta) return false;
43  return true;
44 }
45 
46 std::string Map2DPath::toString() const
47 {
48  std::ostringstream stringStream;
49  stringStream.precision(2);
50  //stringStream.width(0);
51  for (size_t i = 0; i < waypoints.size(); i++)
52  {
53  stringStream << " waypoint " << i << "(" << waypoints[i].map_id << " " << waypoints[i].x << "," << waypoints[i].y << "," << waypoints[i].theta << ")";
54  }
55  return stringStream.str();
56 }
57 
59 {
60  this->waypoints.clear();
61 }
62 
63 Map2DPath::Map2DPath(const std::vector<Map2DLocation> map_waypoints)
64 {
65  for (const auto& map_waypoint : map_waypoints)
66  {
67  waypoints.push_back(map_waypoint);
68  }
69 }
70 
72 {
73 }
74 
76 {
77  return waypoints[index];
78 }
79 
80 size_t Map2DPath::size() const
81 {
82  return this->waypoints.size();
83 }
84 
85 double Map2DPath::getLength() const
86 {
87  double ll = 0;
88  for (auto it = waypoints.begin(); it != waypoints.end(); it++)
89  {
90  ll += sqrt(pow(it->x,2)+ pow(it->y,2));
91  }
92  return ll;
93 }
94 
96 {
97  if (waypoints.size() == 0) return true;
98  string mapname = waypoints[0].map_id;
99  for (auto it = waypoints.begin(); it != waypoints.end(); it++)
100  {
101  if (it->map_id != mapname) return false;
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 }
LogStream.h
yarp::sig
Signal processing.
Definition: Image.h:25
ConnectionWriter.h
yarp::dev::Nav2D::Map2DPath::cend
const_iterator cend() const noexcept
Returns a const iterator to the end of the Path.
Definition: Map2DPath.cpp:122
yarp::dev::Nav2D::Map2DPath::const_iterator
std::vector< Map2DLocation >::const_iterator const_iterator
Definition: Map2DPath.h:96
yarp::math
Definition: FrameTransform.h:18
yarp::dev::Nav2D::Map2DPath::begin
iterator begin() noexcept
Returns an iterator to the begin of the Path.
Definition: Map2DPath.cpp:106
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::dev::Nav2D::Map2DPath::operator[]
yarp::dev::Nav2D::Map2DLocation & operator[](size_t index)
Returns a waypoint in the path.
Definition: Map2DPath.cpp:75
yarp::dev::Nav2D::Map2DPath::getLength
double getLength() const
Returns the length of the path.
Definition: Map2DPath.cpp:85
yarp::dev::Map2DPathData::waypoints
std::vector< yarp::dev::Nav2D::Map2DLocation > waypoints
Definition: Map2DPathData.h:31
Log.h
yarp::dev::Nav2D::Map2DPath::iterator
std::vector< Map2DLocation >::iterator iterator
Definition: Map2DPath.h:95
yarp::dev::Nav2D::Map2DPath::operator!=
bool operator!=(const Map2DPath &r) const
Compares two Map2DPath.
Definition: Map2DPath.cpp:26
yarp::dev::Nav2D::Map2DPath::push_back
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
yarp::dev::Nav2D::Map2DPath::cbegin
const_iterator cbegin() const noexcept
Returns a const iterator to the begin of the Path.
Definition: Map2DPath.cpp:117
yarp::dev::Nav2D::Map2DPath::Map2DPath
Map2DPath()
Default constructor: the map name is empty, coordinates are set to zero.
Definition: Map2DPath.cpp:71
yarp::dev::Nav2D::Map2DPath::clear
void clear()
Remove all elements from the path.
Definition: Map2DPath.cpp:58
yarp::dev::Nav2D::Map2DPath::size
size_t size() const
Returns the size of the path.
Definition: Map2DPath.cpp:80
yarp::dev::Nav2D::Map2DPath
Definition: Map2DPath.h:27
yarp::dev::Nav2D
Definition: ILocalization2D.h:21
yarp::dev::Nav2D::Map2DPath::operator==
bool operator==(const Map2DPath &r) const
Compares two Map2DArea.
Definition: Map2DPath.cpp:36
yarp::dev::Nav2D::Map2DLocation
Definition: Map2DLocation.h:30
Map2DPath.h
contains the definition of a Map2DPath type
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
yarp::dev::Nav2D::Map2DPath::isOnSingleMap
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:95
yarp::dev::Nav2D::Map2DPath::end
iterator end() noexcept
Returns an iterator to the end of the Path.
Definition: Map2DPath.cpp:112
yarp::dev::Nav2D::Map2DPath::toString
std::string toString() const
Returns text representation of the path.
Definition: Map2DPath.cpp:46
ConnectionReader.h