Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <labust/blueview/TrackerROI.hpp>
00035 #include <labust/xml/XMLReader.hpp>
00036 #include <labust/xml/XMLWriter.hpp>
00037
00038 #include <modp_b85.h>
00039
00040 #include <sstream>
00041
00042 using namespace labust::blueview;
00043
00044 TrackerROI::TrackerROI(){};
00045
00046 TrackerROI::TrackerROI(const std::string& str)
00047 {
00048 this->deserialize(str,this);
00049 }
00050
00051 TrackerROI::~TrackerROI(){};
00052
00053 bool TrackerROI::deserialize(const std::string& str, TrackerROI* const object)
00054 try
00055 {
00056
00057 labust::xml::Reader reader(str);
00058
00059 reader.useNode(reader.value<_xmlNode*>("/tracker-roi"));
00060
00061 reader.value("width",&object->size.width);
00062 reader.value("height",&object->size.height);
00063 reader.value("meters-per-pixel",&object->headData.resolution);
00064
00065
00066 object->roi = cv::Mat(object->size, CV_16U);
00067 std::string pixels;
00068 reader.value("pixels",&pixels);
00069 modp_b85_decode(reinterpret_cast<char*>(object->roi.data), str.c_str(), str.length());
00070
00071 reader.useNode(reader.value<_xmlNode*>("sonar-head"));
00072 reader.value("latitude",&object->headData.latlon.x);
00073 reader.value("longitude",&object->headData.latlon.y);
00074 reader.value("heading",&object->headData.heading);
00075 reader.value("pan-angle",&object->headData.panAngle);
00076 reader.value("tilt-angle",&object->headData.tiltAngle);
00077 reader.value("origin-x",&object->origin.x);
00078 reader.value("origin-y",&object->origin.y);
00079
00080 return true;
00081 }
00082 catch (labust::xml::XMLException& e)
00083 {
00084 std::cerr<<"Failed to deserialize:"<<e.what()<<std::endl;
00085 return false;
00086 }
00087
00088 bool TrackerROI::serialize(const TrackerROI& object, std::string* str)
00089 try
00090 {
00091
00092 labust::xml::Writer writer;
00093 writer.startElement("tracker-roi");
00094 writer.addElement("width",object.size.width);
00095 writer.addElement("height",object.size.height);
00096 writer.addElement("meters-per-pixel",object.headData.resolution);
00097 writer.startElement("sonar-head");
00098 writer.addElement("latitude",object.headData.latlon.x);
00099 writer.addElement("longitude",object.headData.latlon.y);
00100 writer.addElement("heading",object.headData.heading);
00101 writer.addElement("pan-angle",object.headData.panAngle);
00102 writer.addElement("tilt-angle",object.headData.tiltAngle);
00103 writer.addElement("origin-x",object.origin.x);
00104 writer.addElement("origin-y",object.origin.y);
00105 writer.endElement();
00106
00107 boost::shared_ptr<char> buffer(new char[modp_b85_encode_strlen(object.roi.rows*object.roi.step)]);
00108 modp_b85_encode(buffer.get(),reinterpret_cast<const char*>(object.roi.data),object.roi.rows*object.roi.step);
00109 writer.addElement("pixels",buffer.get());
00110 writer.endDocument();
00111
00112 (*str) = writer.toString();
00113
00114 return true;
00115 }
00116 catch (labust::xml::XMLException& e)
00117 {
00118 std::cerr<<"Failed to serialize:"<<e.what()<<std::endl;
00119 return false;
00120 }