|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
33 for (i = 0, j = points.size() - 1; i < points.size(); j = i++)
35 if (((points[i].y>testy) != (points[j].y>testy)) &&
36 (testx < (points[j].x - points[i].x) * (testy - points[i].y) / (points[j].y - points[i].y) + points[i].x))
53 for (
auto it = area_points.begin(); it != area_points.end(); it++)
56 yAssert(it->map_id == map_name);
58 if (it->map_id != map_name)
62 yError() <<
"all area_points must belong to the same map:" << map_name;
90 this->map_id.resize(string_size);
91 connection.
expectBlock(
const_cast<char*
>(this->map_id.data()), string_size);
98 for (
size_t i = 0; i < siz; i++)
114 size_t siz = this->points.size();
125 for (
size_t i = 0; i < siz; i++)
139 std::ostringstream stringStream;
140 stringStream.precision(-1);
141 stringStream.width(-1);
142 stringStream << std::string(
"map_id:") << map_id <<
" ";
143 for (
size_t i = 0; i<points.size(); i++)
145 stringStream <<
" point " << i <<
"(" << points[i].x <<
"," << points[i].y <<
")";
147 return stringStream.str();
152 if (loc.
map_id != this->map_id)
return false;
153 if (points.size() < 3)
return false;
154 if (
pnpoly(points, loc.
x, loc.
y) > 0)
return true;
184 if (points.size() < 3)
return false;
185 if (map_id ==
"")
return false;
192 lt.
x = lt.
y = std::numeric_limits<double>::max();
193 rb.
x = rb.
y = std::numeric_limits<double>::min();
194 if (
isValid() ==
false)
return false;
195 for (
auto it = points.begin(); it != points.end(); it++)
197 if (it->x > rb.
x) { rb.
x = it->x; }
198 if (it->y > rb.
y) { rb.
y = it->y; }
199 if (it->x < lt.
x) { lt.
x = it->x; }
200 if (it->y < lt.
y) { lt.
y = it->y; }
209 if (findAreaBounds(lt, rb) ==
false)
212 std::random_device rd;
213 std::mt19937 gen(rd());
214 std::uniform_real_distribution<double> dis_x(lt.
x, rb.
x);
215 std::uniform_real_distribution<double> dis_y(lt.
y, rb.
y);
217 size_t count_trials = 0;
220 double rnd_x = dis_x(gen);
221 double rnd_y = dis_y(gen);
223 loc.
map_id = this->map_id;
228 if (this->checkLocationInsideArea(loc))
break;
229 }
while (count_trials < 20);
231 if (count_trials >= 20)
233 yError() <<
"Problem found in Map2DArea::getRandomLocation()";
243 this->points.clear();
250 return points.at(index);
contains the definition of a Map2DArea type
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.
bool isValid()
Check if time is valid (non-zero).
#define BOTTLE_TAG_STRING
bool getRandomLocation(yarp::dev::Nav2D::Map2DLocation &loc)
get a random Map2DLocation inside the Map2DArea @loc the computed Map2DLocation
Map2DArea()
Default constructor: the map name is empty, coordinates are set to zero.
bool operator==(const Map2DArea &r) const
Compares two Map2DArea.
int pnpoly(std::vector< yarp::math::Vec2D< double >> points, double testx, double testy)
std::string toString() const
Returns text representation of the area.
bool findAreaBounds(yarp::dev::Nav2D::Map2DLocation <, yarp::dev::Nav2D::Map2DLocation &rb)
retrieves two Map2DLocations representing the bounding box of the Map2DArea @lt the left-top vertex @...
An interface for the device drivers.
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
virtual bool isError() const =0
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
An interface for writing to a network connection.
std::vector< yarp::math::Vec2D< double > > points
virtual bool isError() const =0
void clear()
Remove all elements from the path.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
bool operator!=(const Map2DArea &r) const
Compares two Map2DAreas.
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
An interface for reading from a network connection.
#define BOTTLE_TAG_FLOAT64
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
yarp::math::Vec2D< double > & operator[](size_t index)
Returns a vertex of the area.
An interface to the operating system, including Port based communication.
bool isValid() const
Checks if the Map2DArea is valid return true if the Map2DArea is valid.
virtual void appendString(const char *str, const char terminate='\n') final
Send a character sequence to the network connection.
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write a map2DArea to a connection.
bool checkLocationInsideArea(yarp::dev::Nav2D::Map2DLocation loc)
Check if a Map2DLocation is inside a Map2DArea.