2012-02-06 16:44:09 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Owl Positioning System (OwlPS).
|
|
|
|
* OwlPS is a project of the University of Franche-Comté
|
|
|
|
* (Université de Franche-Comté), France.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-03-03 16:06:41 +01:00
|
|
|
#include "result.hh"
|
2010-03-03 17:57:32 +01:00
|
|
|
#include "request.hh"
|
2011-07-29 00:05:52 +02:00
|
|
|
#include "area.hh"
|
|
|
|
#include "stock.hh"
|
2012-08-24 16:39:00 +02:00
|
|
|
#include "configuration.hh"
|
2010-03-03 16:06:41 +01:00
|
|
|
|
2011-04-05 14:45:27 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
using namespace std ;
|
|
|
|
|
2010-03-03 16:06:41 +01:00
|
|
|
|
|
|
|
|
2011-05-03 15:16:03 +02:00
|
|
|
/* *** Constructors *** */
|
|
|
|
|
|
|
|
|
2011-07-24 12:32:07 +02:00
|
|
|
Result::Result(const Request *_request,
|
|
|
|
const std::string &_algorithm,
|
|
|
|
const Point3D &_position,
|
2011-05-03 15:16:03 +02:00
|
|
|
const Point3D &real_position):
|
2011-07-24 12:32:07 +02:00
|
|
|
request(_request), algorithm(_algorithm), position(_position)
|
2011-05-03 15:16:03 +02:00
|
|
|
{
|
|
|
|
compute_error(real_position) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-07-29 00:05:52 +02:00
|
|
|
/* *** Read accessors *** */
|
|
|
|
|
|
|
|
|
|
|
|
string Result::in_which_area() const
|
|
|
|
{
|
|
|
|
const Area *area = Stock::in_which_area_is(position) ;
|
|
|
|
if (area == NULL)
|
|
|
|
return "" ;
|
|
|
|
|
|
|
|
return area->get_name() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-03 15:16:03 +02:00
|
|
|
/* *** Write accessors *** */
|
|
|
|
|
|
|
|
|
|
|
|
void Result::compute_error(const Point3D &real_position)
|
|
|
|
{
|
2012-08-24 16:39:00 +02:00
|
|
|
if (Configuration::bool_value("output.2d-error"))
|
|
|
|
error = position.distance_2d(real_position) ;
|
|
|
|
else
|
|
|
|
error = position.distance(real_position) ;
|
2011-05-03 15:16:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-03-03 16:06:41 +01:00
|
|
|
/* *** Operators *** */
|
|
|
|
|
|
|
|
|
2011-07-30 20:38:42 +02:00
|
|
|
Result& Result::operator=(const Result &source)
|
2010-03-03 16:06:41 +01:00
|
|
|
{
|
|
|
|
if (this == &source)
|
|
|
|
return *this ;
|
|
|
|
|
2011-07-24 12:32:07 +02:00
|
|
|
request = source.request ;
|
2011-03-31 19:42:35 +02:00
|
|
|
algorithm = source.algorithm ;
|
2010-03-03 16:06:41 +01:00
|
|
|
position = source.position ;
|
2011-05-11 09:44:49 +02:00
|
|
|
error = source.error ;
|
2010-03-03 16:06:41 +01:00
|
|
|
|
|
|
|
return *this ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-08 14:37:49 +02:00
|
|
|
bool Result::operator==(const Result &source) const
|
2010-03-03 16:06:41 +01:00
|
|
|
{
|
|
|
|
return
|
2011-07-24 12:32:07 +02:00
|
|
|
request == source.request &&
|
2011-03-31 19:42:35 +02:00
|
|
|
algorithm == source.algorithm &&
|
2011-05-11 09:44:49 +02:00
|
|
|
position == source.position &&
|
|
|
|
error == source.error ;
|
2010-03-03 16:06:41 +01:00
|
|
|
}
|
2010-03-03 17:57:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-06 14:10:51 +02:00
|
|
|
/**
|
2011-08-18 11:27:38 +02:00
|
|
|
* This function creates a CSV string from the Result's data.
|
|
|
|
*
|
|
|
|
* The format used is the following:
|
|
|
|
* Algorithm_name;X;Y;Z;Error;Area_name
|
|
|
|
*
|
|
|
|
* @return The result as a CSV string, \em without a trailing '\\n'.
|
2011-04-06 14:10:51 +02:00
|
|
|
*/
|
2011-04-05 14:45:27 +02:00
|
|
|
const string Result::to_csv() const
|
|
|
|
{
|
|
|
|
ostringstream csv_line ;
|
|
|
|
|
|
|
|
csv_line
|
|
|
|
<< algorithm
|
|
|
|
<< ';' << position.get_x()
|
|
|
|
<< ';' << position.get_y()
|
2011-05-03 15:16:03 +02:00
|
|
|
<< ';' << position.get_z()
|
2011-07-30 19:35:47 +02:00
|
|
|
<< ';' << error
|
|
|
|
<< ';' ;
|
|
|
|
|
|
|
|
const Area *const area = Stock::in_which_area_is(position) ;
|
|
|
|
if (area != NULL)
|
|
|
|
csv_line << area->get_name() ;
|
2011-04-05 14:45:27 +02:00
|
|
|
|
|
|
|
return csv_line.str() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::ostream& operator<<(ostream &os, const Result &r)
|
2010-03-03 17:57:32 +01:00
|
|
|
{
|
2011-03-31 19:42:35 +02:00
|
|
|
os
|
2011-04-05 11:52:06 +02:00
|
|
|
<< "The result of the algorithm " << r.algorithm
|
2011-07-29 00:06:40 +02:00
|
|
|
<< " is: " << r.position
|
2012-01-24 18:43:00 +01:00
|
|
|
<< " (area: \"" << r.in_which_area() << "\")" ;
|
2011-05-03 15:16:03 +02:00
|
|
|
if (r.error >= 0)
|
|
|
|
os << ", error = " << r.error << " m" ;
|
2010-03-03 17:57:32 +01:00
|
|
|
return os ;
|
|
|
|
}
|