29 for (i = 0, j = points.size() - 1; i < points.size(); j = i++)
31 if (((points[i].y>testy) != (points[j].y>testy)) &&
32 (testx < (points[j].x - points[i].x) * (testy - points[i].y) / (points[j].y - points[i].y) + points[i].x))
49 for (
auto it = area_points.begin(); it != area_points.end(); it++)
52 yAssert(it->map_id == map_name);
54 if (it->map_id != map_name)
58 yError() <<
"all area_points must belong to the same map:" << map_name;
86 this->map_id.resize(string_size);
87 connection.
expectBlock(
const_cast<char*
>(this->map_id.data()), string_size);
94 for (
size_t i = 0; i < siz; i++)
110 size_t siz = this->points.size();
121 for (
size_t i = 0; i < siz; i++)
135 std::ostringstream stringStream;
136 stringStream.precision(-1);
137 stringStream.width(-1);
138 stringStream << std::string(
"map_id:") << map_id <<
" ";
139 for (
size_t i = 0; i<points.size(); i++)
141 stringStream <<
" point " << i <<
"(" << points[i].x <<
"," << points[i].y <<
")";
143 return stringStream.str();
148 if (loc.
map_id != this->map_id) {
151 if (points.size() < 3) {
154 if (
pnpoly(points, loc.
x, loc.
y) > 0) {
186 if (points.size() < 3) {
198 lt.
x = lt.
y = std::numeric_limits<double>::max();
199 rb.
x = rb.
y = std::numeric_limits<double>::min();
203 for (
auto it = points.begin(); it != points.end(); it++)
205 if (it->x > rb.
x) { rb.
x = it->x; }
206 if (it->y > rb.
y) { rb.
y = it->y; }
207 if (it->x < lt.
x) { lt.
x = it->x; }
208 if (it->y < lt.
y) { lt.
y = it->y; }
217 if (findAreaBounds(lt, rb) ==
false) {
221 std::random_device rd;
222 std::mt19937 gen(rd());
223 std::uniform_real_distribution<double> dis_x(lt.
x, rb.
x);
224 std::uniform_real_distribution<double> dis_y(lt.
y, rb.
y);
226 size_t count_trials = 0;
229 double rnd_x = dis_x(gen);
230 double rnd_y = dis_y(gen);
232 loc.
map_id = this->map_id;
237 if (this->checkLocationInsideArea(loc)) {
240 }
while (count_trials < 20);
242 if (count_trials >= 20)
244 yError() <<
"Problem found in Map2DArea::getRandomLocation()";
254 this->points.clear();
261 return points.at(index);
#define BOTTLE_TAG_FLOAT64
#define BOTTLE_TAG_STRING
int pnpoly(std::vector< yarp::math::Vec2D< double >> points, double testx, double testy)
contains the definition of a Map2DArea type
void clear()
Remove all elements from the path.
std::string toString() const
Returns text representation of the area.
std::vector< yarp::math::Vec2D< double > > points
bool operator==(const Map2DArea &r) const
Compares two Map2DArea.
bool operator!=(const Map2DArea &r) const
Compares two Map2DAreas.
Map2DArea()
Default constructor: the map name is empty, coordinates are set to zero.
bool write(yarp::os::ConnectionWriter &connection) const override
Write a map2DArea to a connection.
bool getRandomLocation(yarp::dev::Nav2D::Map2DLocation &loc)
get a random Map2DLocation inside the Map2DArea @loc the computed Map2DLocation
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 @...
bool checkLocationInsideArea(yarp::dev::Nav2D::Map2DLocation loc)
Check if a Map2DLocation is inside a Map2DArea.
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.
bool isValid() const
Checks if the Map2DArea is valid return true if the Map2DArea is valid.
An interface for reading from a network connection.
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
virtual bool isError() const =0
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
An interface for writing to a network connection.
virtual bool isError() const =0
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.
virtual void appendString(const char *str, const char terminate='\n') final
Send a character sequence to the network connection.
An interface for the device drivers.
bool isValid()
Check if time is valid (non-zero).
An interface to the operating system, including Port based communication.