TrackerROI.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2010, LABUST, UNIZG-FER
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the LABUST nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
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   //Punch the stuff into the querier
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         //Initialize the image and decode the information.
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   //Initialize the XMLWriter.
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 }


target_detector
Author(s): Gyula Nagy
autogenerated on Fri Feb 7 2014 11:36:05