From 6c3647410df616f66096ccce6949ef3b1edc2f24 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Tue, 3 May 2011 15:16:03 +0200 Subject: [PATCH] [Positioning] Result: compute error if possible If the real coordinates are passed to the constructor, the distance error is computed. One can also use Result::compute_error() on a constructed object. --- owlps-positioning/src/result.cc | 28 +++++++++++++++++++++++++++- owlps-positioning/src/result.hh | 23 +++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/owlps-positioning/src/result.cc b/owlps-positioning/src/result.cc index 1173b0c..7645b3e 100644 --- a/owlps-positioning/src/result.cc +++ b/owlps-positioning/src/result.cc @@ -7,6 +7,28 @@ using namespace std ; +/* *** Constructors *** */ + + +Result::Result(const Point3D &_position, const std::string &_algorithm, + const Point3D &real_position): + position(_position), algorithm(_algorithm) +{ + compute_error(real_position) ; +} + + + +/* *** Write accessors *** */ + + +void Result::compute_error(const Point3D &real_position) +{ + error = position.distance(real_position) ; +} + + + /* *** Operators *** */ @@ -42,7 +64,9 @@ const string Result::to_csv() const << algorithm << ';' << position.get_x() << ';' << position.get_y() - << ';' << position.get_z() ; + << ';' << position.get_z() + << ';' << "Error" + << ';' << error ; return csv_line.str() ; } @@ -54,5 +78,7 @@ std::ostream& operator<<(ostream &os, const Result &r) os << "The result of the algorithm " << r.algorithm << " is: " << r.position ; + if (r.error >= 0) + os << ", error = " << r.error << " m" ; return os ; } diff --git a/owlps-positioning/src/result.hh b/owlps-positioning/src/result.hh index ac7f223..5861633 100644 --- a/owlps-positioning/src/result.hh +++ b/owlps-positioning/src/result.hh @@ -9,20 +9,33 @@ class Result { protected: + /// Computed coordinates of the mobile Point3D position ; + /// Algorithm used to compute the position std::string algorithm ; + /// Distance error between the real coordinates and the computed point + /** The error is set to -1 if the real coordinates are unknown. */ + float error ; public: Result(const std::string &_algorithm = "UnknownAlgorithm"): - algorithm(_algorithm) {} + algorithm(_algorithm), error(-1) {} Result(const Point3D &_position, const std::string &_algorithm): - position(_position), algorithm(_algorithm) {} + position(_position), algorithm(_algorithm), error(-1) {} + Result(const Point3D &_position, const std::string &_algorithm, + const Point3D &real_position) ; ~Result(void) {} /** @name Read accessors */ //@{ const std::string& get_algorithm(void) const ; const Point3D& get_position(void) const ; + float get_error(void) const ; + //@} + + /** @name Write accessors */ + //@{ + void compute_error(const Point3D &real_position) ; //@} /** @name Operators */ @@ -59,6 +72,12 @@ inline const Point3D& Result::get_position() const } +inline float Result::get_error() const +{ + return error ; +} + + /* *** Operators *** */