[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.
This commit is contained in:
Matteo Cypriani 2011-05-03 15:16:03 +02:00
parent 2d2b49947a
commit 6c3647410d
2 changed files with 48 additions and 3 deletions

View File

@ -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 ;
}

View File

@ -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 *** */