From 85cca4debda043fe46c74bc29a3cdbc71f6b119b Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 7 Dec 2009 16:03:53 +0100 Subject: [PATCH] [Positioning] Rewriting begins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /!\ This branch does not compile! (But some single files can.) /!\ All the following commits are broken code. (Hopefully it will work /!\ in a few days.) Backup commit. Beginning of the rewriting work on OWLPS Positioning, following the new class diagram. --- owlps-positioning/Makefile | 2 +- owlps-positioning/area.cc | 185 ++++++++++++++++++----- owlps-positioning/area.hh | 112 +++++--------- owlps-positioning/building.cc | 135 +++++++++++++++++ owlps-positioning/building.hh | 40 +++++ owlps-positioning/point.cc | 43 ------ owlps-positioning/point.hh | 105 ------------- owlps-positioning/point3d.cc | 215 ++++++++++++++++++++++++++ owlps-positioning/point3d.hh | 52 +++++++ owlps-positioning/referencepoint.cc | 225 ++++++++++++++-------------- owlps-positioning/referencepoint.hh | 72 +++------ owlps-positioning/waypoint.cc | 103 +++++++++++++ owlps-positioning/waypoint.hh | 36 +++++ 13 files changed, 905 insertions(+), 420 deletions(-) create mode 100644 owlps-positioning/building.cc create mode 100644 owlps-positioning/building.hh delete mode 100644 owlps-positioning/point.cc delete mode 100644 owlps-positioning/point.hh create mode 100644 owlps-positioning/point3d.cc create mode 100644 owlps-positioning/point3d.hh create mode 100644 owlps-positioning/waypoint.cc create mode 100644 owlps-positioning/waypoint.hh diff --git a/owlps-positioning/Makefile b/owlps-positioning/Makefile index 22e0e99..3075f7e 100644 --- a/owlps-positioning/Makefile +++ b/owlps-positioning/Makefile @@ -42,7 +42,7 @@ owlps-positioning.o : server.hh ${TARGET} : point.o measurement.o accesspoint.o referencepoint.o positioning.o server.o area.o treatment.o libowlps-positioning.o owlps-positioning.o clean: - @rm -fv *~ *.o *.orig + @rm -fv *~ *.o *.gch *.orig purge : clean @rm -f $(TARGET) diff --git a/owlps-positioning/area.cc b/owlps-positioning/area.cc index 19c6867..350604d 100644 --- a/owlps-positioning/area.cc +++ b/owlps-positioning/area.cc @@ -2,36 +2,48 @@ -Area::Area(const string &_name, const float &_x1, const float &_x2, const float &_y1, const float &_y2, const float &_z1, const float &_z2) -{ - area_name = _name ; +/*** Constructeurs ***/ - if (_x1 < _x2 && _y1 > _y2) // Le premier point de la pièce est en haut à gauche + +Area::Area(const Building &_building, const string &_name, + const float &_x1, const float &_y1, const float &_z1, + const float &_x2, const float &_y2, const float &_z2) +{ + building = (Building *) &_building ; + name = _name ; + + float x_min, x_max, y_min, y_max, z_min, z_max ; + + if (_x1 < _x2 && _y1 > _y2) // Le premier point de la pièce { + // est en haut à gauche x_min = _x1 ; x_max = _x2 ; y_min = _y2 ; // on inverse les Y y_max = _y1 ; } - else if (_x1 > _x2 && _y1 < _y2) // Le premier point de la pièce est en bas à droite + else if (_x1 > _x2 && _y1 < _y2) // Le premier point de la pièce { + // est en bas à droite x_min = _x2 ; // on inverse les X x_max = _x1 ; y_min = _y1 ; y_max = _y2 ; } - else if (_x1 > _x2 && _z1 > _z2) // Le premier point de la pièce est en haut à droite + else if (_x1 > _x2 && _z1 > _z2) // Le premier point de la pièce { + // est en haut à droite x_min = _x2 ; // on inverse les X x_max = _x1 ; z_min = _z2 ; // on inverse les Y z_max = _z1 ; } - else // Le premier point de la pièce est en bas à gauche ou autres cas (par ex. coordonnées nulles) + else // Le premier point de la pièce est en bas à gauche { + // ou autres cas (par ex. coordonnées nulles) x_min = _x1 ; x_max = _x2 ; y_min = _y1 ; @@ -49,61 +61,158 @@ Area::Area(const string &_name, const float &_x1, const float &_x2, const float z_max = _z1 ; } + p_min = Point3D(x_min, y_min, z_min) ; + p_max = Point3D(x_max, y_max, z_max) ; + #ifdef DEBUG_2 - cout << "Area créée ("<< area_name << ',' << x_min << ',' << y_min << ',' << x_max << ',' << y_max << ',' << z_min << ',' << z_max << ")" << endl ; + cout << "Area created : "<< area_name << p_min << "," << p_max << endl ; #endif // DEBUG_2 } - Area::Area(const Area &a) { - area_name = a.area_name; - x_min = a.x_min; - x_max = a.x_max; - y_min = a.y_min; - y_max = a.y_max; - z_min = a.z_min; - z_max = a.z_max; + building = a.building ; + name = a.name ; + p_min = a.p_min ; + p_max = a.p_max ; } -bool Area::containsPoint(const Point &p)const -{ - if (p.getX() >= x_min && - p.getX() <= x_max && - p.getY() >= y_min && - p.getY() <= y_max && - p.getZ() >= z_min && - p.getZ() <= z_max - ) - return true; +/*** Accesseurs lecture ***/ - return false; + +Building* Area::get_building(void) const +{ + return building ; +} + + +string Area::get_name() const +{ + return name ; +} + + +Point3D Area::get_p_min() const +{ + return p_min ; +} + + +Point3D Area::get_p_max() const +{ + return p_max ; } -bool Area::operator==(const Area &a)const +/*** Accesseurs écriture ***/ + + +void Area::set_building(const Building &_building) { - if (area_name == a.area_name && - x_min == a.x_min && - x_max == a.x_max && - y_min == a.y_min && - y_max == a.y_max && - z_min == a.z_min && - z_max == a.z_max - ) + building = (Building *) &_building ; +} + + +void Area::set_name(const string &_name) +{ + name = _name ; +} + + +void Area::set_x_min(const float &v) +{ + p_min.set_x(v) ; +} + + +void Area::set_y_min(const float &v) +{ + p_min.set_y(v) ; +} + + +void Area::set_z_min(const float &v) +{ + p_min.set_z(v) ; +} + + +void Area::set_x_max(const float &v) +{ + p_max.set_x(v) ; +} + + +void Area::set_y_max(const float &v) +{ + p_max.set_y(v) ; +} + + +void Area::set_z_max(const float &v) +{ + p_max.set_z(v) ; +} + + +void Area::set_p_min(const Point3D &p) +{ + p_min = p ; +} + + +void Area::set_p_max(const Point3D &p) +{ + p_max = p ; +} + + + +bool Area::contains_point(const Point3D &p) const +{ + return + p.get_x() >= p_min.get_x() && + p.get_x() <= p_max.get_x() && + p.get_y() >= p_min.get_y() && + p.get_y() <= p_max.get_y() && + p.get_z() >= p_min.get_z() && + p.get_z() <= p_max.get_z() ; +} + + + +bool Area::operator==(const Area &a) const +{ + if (this == &a) return true ; - return false ; + return + building == a.building && + name == a.name && + p_min == a.p_min && + p_max == a.p_max ; +} + + +bool Area::operator!=(const Area &a) const +{ + return !(*this == a) ; } ostream &operator<<(ostream &os, const Area &a) { - os << a.area_name << ';' << a.x_min << ';' << a.x_max << ';' << a.y_min << ';' << a.y_max << ';' << a.z_min << ';' << a.z_max ; + os << a.name << ';' + << a.p_min.get_x() << ';' + << a.p_max.get_x() << ';' + << a.p_min.get_y() << ';' + << a.p_max.get_y() << ';' + << a.p_min.get_z() << ';' + << a.p_max.get_z() ; return os ; } diff --git a/owlps-positioning/area.hh b/owlps-positioning/area.hh index 571c2c9..7b9e19a 100644 --- a/owlps-positioning/area.hh +++ b/owlps-positioning/area.hh @@ -1,91 +1,55 @@ -#ifndef _AREA_HH_ -#define _AREA_HH_ +#ifndef _OWLPS_POSITIONING_AREA_HH_ +#define _OWLPS_POSITIONING_AREA_HH_ +class Area ; + +#include "building.hh" +#include "point3d.hh" + +#include #include #include -#include "point.hh" -using namespace std; -using std::string; +using namespace std ; class Area { protected: - string area_name; - float x_min; - float x_max; - float y_min; - float y_max; - float z_min; - float z_max; + Building *building ; + string name ; + Point3D p_min ; + Point3D p_max ; public: - Area(const string &_name = "No name", const float &_x1 = 0, const float &_x2 = 0, const float &_y1 = 0, const float &_y2 = 0, const float &_z1 = 0, const float &_z2 = 0) ; + Area(const Building &_building, const string &_name = "Unnamed area", + const float &_x1 = 0, const float &_y1 = 0, const float &_z1 = 0, + const float &_x2 = 0, const float &_y2 = 0, const float &_z2 = 0) ; Area(const Area &a) ; - ~Area() {}; - bool containsPoint(const Point &p)const ; + ~Area() {} ; - string getName()const - { - return area_name ; - } ; - float getXmin()const - { - return x_min; - } ; - float getXmax()const - { - return x_max; - } ; - float getYmin()const - { - return y_min; - } ; - float getYmax()const - { - return y_max; - } ; - float getZmin()const - { - return z_min; - } ; - float getZmax()const - { - return z_max; - } ; + Building* get_building(void) const ; + string get_name(void) const ; + Point3D get_p_min(void) const ; + Point3D get_p_max(void) const ; - void setName(const string &_name) - { - area_name = _name ; - } ; - void setXmin(const float &v) - { - x_min = v; - } ; - void setXmax(const float &v) - { - x_max = v; - } ; - void setYmin(const float &v) - { - y_min = v; - } ; - void setYmax(const float &v) - { - y_max = v; - } ; - void setZmin(const float &v) - { - z_min = v; - } ; - void setZmax(const float &v) - { - z_max = v; - } ; + void set_building(const Building &_building) ; + void set_name(const string &_name) ; + void set_x_min(const float &v) ; + void set_y_min(const float &v) ; + void set_z_min(const float &v) ; + void set_x_max(const float &v) ; + void set_y_max(const float &v) ; + void set_z_max(const float &v) ; + void set_p_min(const Point3D &p) ; + void set_p_max(const Point3D &p) ; + + bool contains_point(const Point3D &p) const ; + + bool operator==(const Area &a) const ; + inline bool operator!=(const Area &a) const ; - bool operator==(const Area &a)const ; friend ostream &operator<<(ostream &os, const Area &a) ; -}; +} ; -#endif // _AREA_HH_ +#endif // _OWLPS_POSITIONING_AREA_HH_ diff --git a/owlps-positioning/building.cc b/owlps-positioning/building.cc new file mode 100644 index 0000000..62d01cb --- /dev/null +++ b/owlps-positioning/building.cc @@ -0,0 +1,135 @@ +#include "building.hh" +#include "waypoint.hh" +#include "area.hh" + + + +/*** Constructeurs ***/ + + +Building::Building(const string &_name) +{ + name = _name ; +} + + + +Building::Building(const Building &b) +{ + name = b.name ; + areas = b.areas ; + waypoints = b.waypoints ; +} + + + +/* + * Destructor + * Note: deletes (unallocates) all elements in areas; deletes elements in + * waypoints that belong only to this Building (waypoints that link) + * several buildings are preserved). + */ +Building::~Building() +{ + cout << "Building "<< name <<" area size : " << areas.size() << endl; + // Empty Area list + for (unsigned int i = 0 ; i < areas.size() ; i++) + delete areas[i] ; + areas.clear() ; + + // Empty Waypoint list + for (unsigned int i = 0 ; i < waypoints.size() ; i++) + { + // Delete current waypoint only if it is not linked to another building + if (waypoints[i]->get_buildings().size() <= 1) + delete waypoints[i] ; + } + waypoints.clear() ; +} + + +/*** Accesseurs lecture ***/ + + +string Building::get_name() const +{ + return name ; +} + + +vector Building::get_areas() const +{ + return areas ; +} + + +vector Building::get_waypoints() const +{ + return waypoints ; +} + + + +/*** Accesseurs écriture ***/ + + +void Building::set_name(const string &_name) +{ + name = _name ; +} + + +void Building::add_area(const Area *a) +{ + areas.push_back((Area *) a) ; +} + + +void Building::add_waypoint(const Waypoint *wp) +{ + waypoints.push_back((Waypoint *) wp) ; +} + + + +/*** Opérateurs ***/ + + +Building Building::operator=(const Building &b) +{ + if (this == &b) + return *this ; + + name = b.name ; + areas = b.areas ; + waypoints = b.waypoints ; + + return *this; +} + + +bool Building::operator==(const Building &b) const +{ + if (this == &b) + return true ; + + return + name == b.name && + areas == b.areas && + waypoints == b.waypoints ; +} + + +bool Building::operator!=(const Building &b) const +{ + return !(*this == b) ; +} + + + +ostream& operator<<(ostream &os, Building &b) +{ + os << b.name ; + + return os ; +} diff --git a/owlps-positioning/building.hh b/owlps-positioning/building.hh new file mode 100644 index 0000000..c987a40 --- /dev/null +++ b/owlps-positioning/building.hh @@ -0,0 +1,40 @@ +#ifndef _OWLPS_POSITIONING_REFERENCEPOINT_HH_ +#define _OWLPS_POSITIONING_REFERENCEPOINT_HH_ + +class Area ; +class Waypoint ; + +#include +#include + +using namespace std ; + +class Building +{ +protected: + string name ; + vector areas ; + vector waypoints ; + +public : + Building(const string &_name = "Unnamed building") ; + Building(const Building &b) ; + + ~Building(void) ; + + string get_name(void) const ; + vector get_areas(void) const ; + vector get_waypoints(void) const ; + + void set_name(const string &_name) ; + void add_area(const Area *a) ; + void add_waypoint(const Waypoint *wp) ; + + Building operator=(const Building &p) ; + bool operator==(const Building &p) const ; + inline bool operator!=(const Building &p) const ; + + friend ostream& operator<<(ostream &os, Building &b) ; +} ; + +#endif // _OWLPS_POSITIONING_REFERENCEPOINT_HH_ diff --git a/owlps-positioning/point.cc b/owlps-positioning/point.cc deleted file mode 100644 index 8cc522a..0000000 --- a/owlps-positioning/point.cc +++ /dev/null @@ -1,43 +0,0 @@ -#include "point.hh" - - - -Point Point::operator=(const Point &p) -{ - if (this == &p) - return *this; - - x = p.x; - y = p.y; - z = p.z; - - return *this; -} - - - -bool Point::operator<(const Point &p) const -{ - if (x < p.x) - return true ; - if (x > p.x) - return false ; - - if (y < p.y) - return true ; - if (y > p.y) - return false ; - - if (z < p.z) - return true ; - - return false ; -} - - - -ostream &operator<<(ostream &os, const Point &p) -{ - os << "(" << p.x << ";" << p.y << ";" << p.z << ")"; - return os; -} diff --git a/owlps-positioning/point.hh b/owlps-positioning/point.hh deleted file mode 100644 index e59657b..0000000 --- a/owlps-positioning/point.hh +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef _POINT_HH_ -#define _POINT_HH_ - -#include -#include - -using namespace std; - -class Point -{ -protected: - float x; - float y; - float z; - -public: - Point(const float &_x = 0, const float &_y = 0, const float &_z = 0) - { - x = _x; - y = _y; - z = _z; - } ; - Point(const Point &p) - { - x = p.x; - y = p.y; - z = p.z; - } ; - Point(const float c[3]) - { - x = c[0] ; - y = c[1] ; - z = c[2] ; - } ; - ~Point() {}; - - float getX()const - { - return x; - }; - float getY()const - { - return y; - }; - float getZ()const - { - return z; - }; - - void setX(const float &_x) - { - x = _x; - }; - void setY(const float &_y) - { - y = _y; - }; - void setZ(const float &_z) - { - z = _z; - }; - - float squareDistance(const Point &p)const - { - return ((x-p.x)*(x-p.x))+((y-p.y)*(y-p.y))+((z-p.z)*(z-p.z)); - }; - float squareDistance(const float &mx, const float &my, const float &mz)const - { - return ((x-mx)*(x-mx))+((y-my)*(y-my))+((z-mz)*(z-mz)); - }; - float distance(const Point &p)const - { - return sqrt(((x-p.x)*(x-p.x))+((y-p.y)*(y-p.y))+((z-p.z)*(z-p.z))); - }; - float distance(const float &mx, const float &my, const float &mz)const - { - return sqrt(((x-mx)*(x-mx))+((y-my)*(y-my))+((z-mz)*(z-mz))); - }; - - Point operator=(const Point &p) ; - bool operator==(const Point &p) const - { - return ((x == p.x) && (y == p.y) && (z == p.z)) ; - } ; - bool operator!=(const Point &p) const - { - return !(*this == p) ; - } ; - bool operator<(const Point &p) const ; - bool operator>(const Point &p) const - { - return (p < *this) ; - } ; - bool operator<=(const Point &p) const - { - return (*this < p || *this == p) ; - } ; - bool operator>=(const Point &p) const - { - return (p <= *this) ; - } ; - friend ostream &operator<<(ostream & os, const Point &p); -}; - -#endif diff --git a/owlps-positioning/point3d.cc b/owlps-positioning/point3d.cc new file mode 100644 index 0000000..0823eff --- /dev/null +++ b/owlps-positioning/point3d.cc @@ -0,0 +1,215 @@ +#include "point3d.hh" + + + +/*** Constructeurs ***/ + + +Point3D::Point3D(const float &_x, const float &_y, const float &_z) +{ + x = _x ; + y = _y ; + z = _z ; +} ; + + +Point3D::Point3D(const Point3D &p) +{ + x = p.x ; + y = p.y ; + z = p.z ; +} + + +Point3D::Point3D(const float c[3]) +{ + x = c[0] ; + y = c[1] ; + z = c[2] ; +} + + + +/*** Accesseurs lecture ***/ + + +float Point3D::get_x() const +{ + return x ; +} + + +float Point3D::get_y() const +{ + return y ; +} + + +float Point3D::get_z() const +{ + return z ; +} + + + +/*** Accesseurs écriture ***/ + + +void Point3D::set_x(const float &_x) +{ + x = _x ; +} + + +void Point3D::set_y(const float &_y) +{ + y = _y ; +} + + +void Point3D::set_z(const float &_z) +{ + z = _z ; +} + + +/* + * Updates x, y, z by passing a Point3D + * This is useful for derivated classes, and different than a direct call to + * operator=(). + */ +void Point3D::set_coordinates(const Point3D &p) +{ + this->operator=(p) ; +} + + + +/*** Calcul de distances ***/ + + +/* + * Distance carrée à un point (Point3D) + */ +float Point3D::square_distance(const Point3D &p) const +{ + return + (x - p.x) * (x - p.x) + + (y - p.y) * (y - p.y) + + (z - p.z) * (z - p.z) ; +} + + +/* + * Distance carrée à un point décrit par ses coordonnées + */ +float Point3D::square_distance(const float &_x, + const float &_y, + const float &_z) const +{ + return + (x - _x) * (x - _x) + + (y - _y) * (y - _y) + + (z - _z) * (z - _z) ; +} + + +/* + * Distance à un point (Point3D) + * Note : pour comparer deux distances, utiliser de préférence + * square_distance, qui fait économiser une racine carrée. + */ +float Point3D::distance(const Point3D &p) const +{ + return sqrt(square_distance(p)) ; +} + + +/* + * Distance à un point décrit par ses coordonnées + * Note : pour comparer deux distances, utiliser de préférence + * square_distance, qui fait économiser une racine carrée. + */ +float Point3D::distance(const float &_x, + const float &_y, + const float &_z) const +{ + return sqrt(square_distance(_x, _y, _z)) ; +} + + + +/*** Opérateurs ***/ + + +Point3D Point3D::operator=(const Point3D &p) +{ + if (this == &p) + return *this ; + + x = p.x ; + y = p.y ; + z = p.z ; + + return *this ; +} + + +bool Point3D::operator==(const Point3D &p) const +{ + return + x == p.x && + y == p.y && + z == p.z ; +} + + +bool Point3D::operator!=(const Point3D &p) const +{ + return !(*this == p) ; +} + + +bool Point3D::operator<(const Point3D &p) const +{ + if (x < p.x) + return true ; + if (x > p.x) + return false ; + + if (y < p.y) + return true ; + if (y > p.y) + return false ; + + if (z < p.z) + return true ; + + return false ; +} + + +bool Point3D::operator>(const Point3D &p) const +{ + return (p < *this) ; +} + + +bool Point3D::operator<=(const Point3D &p) const +{ + return (*this < p || *this == p) ; +} + + +bool Point3D::operator>=(const Point3D &p) const +{ + return (p <= *this) ; +} + + + +ostream& operator<<(ostream &os, const Point3D &p) +{ + os << "(" << p.x << ";" << p.y << ";" << p.z << ")" ; + return os ; +} diff --git a/owlps-positioning/point3d.hh b/owlps-positioning/point3d.hh new file mode 100644 index 0000000..7317d09 --- /dev/null +++ b/owlps-positioning/point3d.hh @@ -0,0 +1,52 @@ +#ifndef _OWLPS_POSITIONING_POINT3D_HH_ +#define _OWLPS_POSITIONING_POINT3D_HH_ + +#include +#include + +using namespace std ; + +class Point3D +{ +protected: + float x ; + float y ; + float z ; + +public: + Point3D(const float &_x = 0, const float &_y = 0, const float &_z = 0) ; + Point3D(const Point3D &p) ; + Point3D(const float c[3]) ; + + ~Point3D() {} ; + + float get_x(void) const ; + float get_y(void) const ; + float get_z(void) const ; + + void set_x(const float &_x) ; + void set_y(const float &_y) ; + void set_z(const float &_z) ; + void set_coordinates(const Point3D &p) ; + + float square_distance(const Point3D &p) const ; + inline float distance(const Point3D &p) const ; + float square_distance(const float &mx, + const float &my, + const float &mz) const ; + inline float distance(const float &mx, + const float &my, + const float &mz) const ; + + Point3D operator=(const Point3D &p) ; + bool operator==(const Point3D &p) const ; + inline bool operator!=(const Point3D &p) const ; + bool operator<(const Point3D &p) const ; + inline bool operator>(const Point3D &p) const ; + bool operator<=(const Point3D &p) const ; + inline bool operator>=(const Point3D &p) const ; + + friend ostream& operator<<(ostream &os, const Point3D &p) ; +} ; + +#endif // _OWLPS_POSITIONING_POINT3D_HH_ diff --git a/owlps-positioning/referencepoint.cc b/owlps-positioning/referencepoint.cc index 90a7609..d50da32 100644 --- a/owlps-positioning/referencepoint.cc +++ b/owlps-positioning/referencepoint.cc @@ -2,123 +2,134 @@ -float ReferencePoint::getSsSquareDistance(const vector &m)const +ReferencePoint::~ReferencePoint() { - unsigned int i, j; - float ret = 0; - bool found; - vector ref_m = measurement_list; - vector test_m = m; - Measurement new_meas; - - new_meas.addSsValue(-95); - - /* Complete measurement vector with unexisting ap (from ref point) */ - for (i = 0 ; i < ref_m.size() ; i++) - { - found = false; - for (j = 0 ; j < test_m.size() && !found ; j++) - if (test_m[j].getMacAddr() == ref_m[i].getMacAddr()) - found = true; - if (!found) - { - new_meas.setMacAddr(measurement_list[i].getMacAddr()); - test_m.push_back(new_meas); - } - } - - /* Now, complete ref. point meas. */ - for (i = 0 ; i < test_m.size() ; i++) - { - found = false; - for (j = 0 ; j < ref_m.size() && !found ; j++) - if (test_m[i].getMacAddr() == ref_m[j].getMacAddr()) - found = true; - if (!found) - { - new_meas.setMacAddr(test_m[i].getMacAddr()); - ref_m.push_back(new_meas); - } - } - - /* Now, compute SS distance */ - for (i = 0 ; i < test_m.size() ; i++) - { - j = 0; - found = false; - while ((j < ref_m.size())&&(found == false)) - { - if (ref_m[j].getMacAddr() == test_m[i].getMacAddr()) - { - found = true; - ret += ref_m[j].getSsSquareDistance(test_m[i].getAverage()); - } - j++; - } - } - - ref_m.clear(); - test_m.clear(); - - return ret; + measurements.clear() ; } -void ReferencePoint::addMeasurement(const string &mac_a, const int &value) +vector ReferencePoint::get_measurements() const { - unsigned int i; - Measurement m; - bool inserted = false; - - for (i = 0 ; i < measurement_list.size() ; i++) - if (measurement_list[i].getMacAddr() == mac_a) - { - measurement_list[i].addSsValue(value); - inserted = true; - break; - } - if (inserted == false) - { - m.setMacAddr(mac_a); - m.addSsValue(value); - measurement_list.push_back(m); - } + return measurements ; } +// float ReferencePoint::getSsSquareDistance(const vector &m) const +// { +// unsigned int i, j; +// float ret = 0; +// bool found; +// vector ref_m = measurements; +// vector test_m = m; +// Measurement new_meas; + +// new_meas.addSsValue(-95); + +// /* Complete measurement vector with unexisting ap (from ref point) */ +// for (i = 0 ; i < ref_m.size() ; i++) +// { +// found = false; +// for (j = 0 ; j < test_m.size() && !found ; j++) +// if (test_m[j].getMacAddr() == ref_m[i].getMacAddr()) +// found = true; +// if (!found) +// { +// new_meas.setMacAddr(measurements[i].getMacAddr()); +// test_m.push_back(new_meas); +// } +// } + +// /* Now, complete ref. point meas. */ +// for (i = 0 ; i < test_m.size() ; i++) +// { +// found = false; +// for (j = 0 ; j < ref_m.size() && !found ; j++) +// if (test_m[i].getMacAddr() == ref_m[j].getMacAddr()) +// found = true; +// if (!found) +// { +// new_meas.setMacAddr(test_m[i].getMacAddr()); +// ref_m.push_back(new_meas); +// } +// } + +// /* Now, compute SS distance */ +// for (i = 0 ; i < test_m.size() ; i++) +// { +// j = 0; +// found = false; +// while ((j < ref_m.size())&&(found == false)) +// { +// if (ref_m[j].getMacAddr() == test_m[i].getMacAddr()) +// { +// found = true; +// ret += ref_m[j].getSsSquareDistance(test_m[i].getAverage()); +// } +// j++; +// } +// } + +// ref_m.clear(); +// test_m.clear(); + +// return ret; +// } -bool ReferencePoint::getPowerForAp(const string &ap_mac, float *p)const -{ - unsigned int i; - string str = ap_mac; - string macLowerCase; +// void ReferencePoint::addMeasurement(const string &mac_a, const int &value) +// { +// unsigned int i; +// Measurement m; +// bool inserted = false; - //Pour convertir les majuscules en miniscules - const int length = str.length(); - for (int j=0; j < length; ++j) - str[j] = tolower(str[j]); +// for (i = 0 ; i < measurements.size() ; i++) +// if (measurements[i].getMacAddr() == mac_a) +// { +// measurements[i].addSsValue(value); +// inserted = true; +// break; +// } +// if (inserted == false) +// { +// m.setMacAddr(mac_a); +// m.addSsValue(value); +// measurements.push_back(m); +// } +// } - for (i = 0 ; i < measurement_list.size() ; i++) - if (measurement_list[i].getMacAddr() == str) - { - *p = measurement_list[i].getAverage(); - return true; - } - return false; -} +// bool ReferencePoint::getPowerForAp(const string &ap_mac, float *p) const +// { +// unsigned int i; +// string str = ap_mac; +// string macLowerCase; + +// //Pour convertir les majuscules en miniscules +// const int length = str.length(); +// for (int j=0; j < length; ++j) +// str[j] = tolower(str[j]); + +// for (i = 0 ; i < measurements.size() ; i++) +// if (measurements[i].getMacAddr() == str) +// { +// *p = measurements[i].getAverage(); +// return true; +// } + +// return false; +// } ReferencePoint ReferencePoint::operator=(const ReferencePoint &rp) { if (this == &rp) - return *this; + return *this ; - coordinates = rp.coordinates; - measurement_list = rp.measurement_list; - return *this; + this->Point3D::operator=(rp) ; + measurements = rp.measurements ; + + return *this ; } @@ -127,20 +138,12 @@ ostream &operator<<(ostream &os, ReferencePoint &rp) { unsigned int i; - os << rp.coordinates << endl; - if (rp.measurement_list.size() == 0) - os << "No measurement" << endl; + os << (Point3D) rp << endl ; + if (rp.measurements.size() == 0) + os << "No measurement." << endl ; else - for (i = 0 ; i < rp.measurement_list.size() ; i++) - os << rp.measurement_list[i] << endl; + for (i = 0 ; i < rp.measurements.size() ; i++) + os << endl << rp.measurements[i] ; - return os; -} - - - -/* Opérateur de cast en Point */ -ReferencePoint::operator Point() const -{ - return coordinates ; + return os ; } diff --git a/owlps-positioning/referencepoint.hh b/owlps-positioning/referencepoint.hh index ddb3f85..8c458ab 100644 --- a/owlps-positioning/referencepoint.hh +++ b/owlps-positioning/referencepoint.hh @@ -1,61 +1,37 @@ -#ifndef _REFERENCEPOINT_HH_ -#define _REFERENCEPOINT_HH_ +#ifndef _OWLPS_POSITIONING_REFERENCEPOINT_HH_ +#define _OWLPS_POSITIONING_REFERENCEPOINT_HH_ + +#include "point3d.hh" +#include "measurement.hh" #include #include -#include "point.hh" -#include "measurement.hh" +using namespace std ; -using namespace std; - -class ReferencePoint +class ReferencePoint: public Point3D { protected: - Point coordinates; - vector measurement_list; + vector measurements ; public: - ReferencePoint(const float &x = 0, const float &y = 0, const float &z = 0) - { - coordinates.setX(x); - coordinates.setY(y); - coordinates.setZ(z); - }; - ReferencePoint(const ReferencePoint &rp) - { - coordinates = rp.coordinates; - measurement_list = rp.measurement_list; - }; - ReferencePoint(const Point &c) - { - coordinates = c; - }; - ~ReferencePoint() - { - measurement_list.clear(); - }; + ReferencePoint(const float &_x = 0, const float &_y = 0, const float &_z = 0 + ): Point3D(_x, _y, _z) {} + ReferencePoint(const Point3D &p): Point3D(p) {} + ReferencePoint(const ReferencePoint &rp): Point3D(rp), + measurements(rp.measurements) {} - float getSsSquareDistance(const vector &m)const; - Point getCoordinates()const - { - return coordinates; - }; - void addMeasurement(const string &mac_a, const int &value); + ~ReferencePoint() ; - void setCoordinates(const Point &p) - { - coordinates = p; - }; - vector getMeasurementList() const - { - return measurement_list; - } ; - bool getPowerForAp(const string &ap_mac, float *p) const ; + vector get_measurements() const ; - ReferencePoint operator=(const ReferencePoint &rp); - operator Point() const ; - friend ostream &operator<<(ostream &os, ReferencePoint &rp); -}; + // float get_ss_square_distance(const vector &m) const ; + // void add_measurement(const string &mac_a, const int &value) ; + // bool get_power_for_ap(const string &ap_mac, float *p) const ; -#endif + ReferencePoint operator=(const ReferencePoint &rp) ; + + friend ostream &operator<<(ostream &os, ReferencePoint &rp) ; +} ; + +#endif // _OWLPS_POSITIONING_REFERENCEPOINT_HH_ diff --git a/owlps-positioning/waypoint.cc b/owlps-positioning/waypoint.cc new file mode 100644 index 0000000..288d7ae --- /dev/null +++ b/owlps-positioning/waypoint.cc @@ -0,0 +1,103 @@ +#include "waypoint.hh" + + + +/*** Constructeurs ***/ + + +Waypoint::Waypoint(const Building &b, const Point3D &p): Point3D(p) +{ + buildings.push_back((Building *) &b) ; +} + + +Waypoint::Waypoint(const Building &b, + const float &_x, const float &_y, const float &_z + ): Point3D(_x, _y, _z) +{ + buildings.push_back((Building *) &b) ; +} + + +Waypoint::~Waypoint() +{ + buildings.clear() ; +} + + + +/*** Accesseurs lecture ***/ + + +Building* Waypoint::get_1st_building() const +{ + if (buildings.size() > 0) + return buildings[0] ; + + return NULL ; +} + + +vector Waypoint::get_buildings() const +{ + return buildings ; +} + + + +/*** Accesseurs écriture ***/ + + +void Waypoint::add_building(const Building &_b) +{ + buildings.push_back((Building *) &_b) ; +} + + + +/*** Opérateurs ***/ + + +Waypoint Waypoint::operator=(const Waypoint &wp) +{ + if (this == &wp) + return *this ; + + this->Point3D::operator=(wp) ; + buildings = wp.buildings ; + + return *this ; +} + + +bool Waypoint::operator==(const Waypoint &wp) const +{ + if (this == &wp) + return true ; + + return + this->Point3D::operator==(wp) && + buildings == wp.buildings ; +} + + +bool Waypoint::operator!=(const Waypoint &wp) const +{ + return !(*this == wp) ; +} + + + +ostream &operator<<(ostream &os, Waypoint &wp) +{ + unsigned int i; + + os << (Point3D) wp ; + if (wp.buildings.size() == 0) + os << endl << "Belongs to no building!" ; + else + for (i = 0 ; i < wp.buildings.size() ; i++) + os << endl << *wp.buildings[i] ; + + return os ; +} diff --git a/owlps-positioning/waypoint.hh b/owlps-positioning/waypoint.hh new file mode 100644 index 0000000..b8c32ba --- /dev/null +++ b/owlps-positioning/waypoint.hh @@ -0,0 +1,36 @@ +#ifndef _OWLPS_POSITIONING_WAYPOINT_HH_ +#define _OWLPS_POSITIONING_WAYPOINT_HH_ + +#include "building.hh" +#include "point3d.hh" + +#include +#include + +class Waypoint: public Point3D +{ +protected: + vector buildings ; + +public: + Waypoint(const Building &b, const Point3D &p) ; + Waypoint(const Building &b, const float &_x = 0, const float &_y = 0, + const float &_z = 0) ; + Waypoint(const Point3D &p): Point3D(p) {} + Waypoint(const Waypoint &wp): Point3D(wp), buildings(wp.buildings) {} + + ~Waypoint(void) ; + + Building* get_1st_building(void) const ; + vector get_buildings(void) const ; + + void add_building(const Building &building) ; + + Waypoint operator=(const Waypoint &wp) ; + bool operator==(const Waypoint &wp) const ; + inline bool operator!=(const Waypoint &wp) const ; + + friend ostream& operator<<(ostream &os, Waypoint &wp) ; +} ; + +#endif // _OWLPS_POSITIONING_WAYPOINT_HH_