Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

VisionObjectEvent.cc

Go to the documentation of this file.
00001 #include "VisionObjectEvent.h"
00002 #include <sstream>
00003 #include <libxml/tree.h>
00004 
00005 // Changed 'getDescription' to show BB and area info in EventLogger. Change functions to add new parameters (BB and area) to buffer
00006 
00007 std::string
00008 VisionObjectEvent::getDescription(bool showTypeSpecific/*=true*/, unsigned int verbosity/*=0*/) const {
00009   if(!showTypeSpecific)
00010     return EventBase::getDescription(showTypeSpecific,verbosity);
00011   std::ostringstream logdata;
00012   logdata << EventBase::getDescription(showTypeSpecific,verbosity) << '\t' << _x1 <<  '\t' <<_x2 <<'\t' <<_y1 <<'\t' <<_y2<<'\t'<<_frame ;
00013   return logdata.str();
00014 }
00015 
00016 unsigned int
00017 VisionObjectEvent::getBinSize() const {
00018   unsigned int used=EventBase::getBinSize();
00019   if(saveFormat==XML)
00020     return used; //if using XML, the XMLLoadSave::getBinSize (called by EventBase::getBinSize) is all we need
00021   //otherwise need to add our own fields
00022   used+=creatorSize("EventBase::VisionObjectEvent");
00023   used+=sizeof(_x1);
00024   used+=sizeof(_x2);
00025   used+=sizeof(_y1);
00026   used+=sizeof(_y2);
00027   return used;
00028 }
00029 
00030 unsigned int
00031 VisionObjectEvent::LoadBinaryBuffer(const char buf[], unsigned int len) {
00032   unsigned int origlen=len;
00033   unsigned int used;
00034   if(0==(used=EventBase::LoadBinaryBuffer(buf,len))) return 0;
00035   len-=used; buf+=used;
00036   if(0==(used=checkCreator("EventBase::VisionObjectEvent",buf,len,true))) return 0;
00037   len-=used; buf+=used;
00038   if(0==(used=decode(_x1,buf,len))) return 0;
00039   len-=used; buf+=used; 
00040   if(0==(used=decode(_x2,buf,len))) return 0;
00041   len-=used; buf+=used; 
00042   if(0==(used=decode(_y1,buf,len))) return 0;
00043   len-=used; buf+=used; 
00044   if(0==(used=decode(_y2,buf,len))) return 0;
00045   len-=used; buf+=used; 
00046   return origlen-len; 
00047 }
00048 
00049 unsigned int
00050 VisionObjectEvent::SaveBinaryBuffer(char buf[], unsigned int len) const {
00051   unsigned int origlen=len;
00052   unsigned int used;
00053   if(0==(used=EventBase::SaveBinaryBuffer(buf,len))) return 0;
00054   len-=used; buf+=used;
00055   if(0==(used=saveCreator("EventBase::VisionObjectEvent",buf,len))) return 0;
00056   len-=used; buf+=used;
00057   if(0==(used=encode(_x1,buf,len))) return 0;
00058   len-=used; buf+=used; 
00059   if(0==(used=encode(_x2,buf,len))) return 0;
00060   len-=used; buf+=used; 
00061   if(0==(used=encode(_y1,buf,len))) return 0;
00062   len-=used; buf+=used; 
00063   if(0==(used=encode(_y2,buf,len))) return 0;
00064   len-=used; buf+=used; 
00065   return origlen-len;
00066 }
00067 
00068 void VisionObjectEvent::LoadXML(xmlNode* node) {
00069   if(node==NULL)
00070     return;
00071   
00072   EventBase::LoadXML(node);
00073 
00074   for(xmlNode* cur = skipToElement(node->children); cur!=NULL; cur = skipToElement(cur->next)) {
00075     if(xmlStrcmp(cur->name, (const xmlChar *)"param"))
00076       continue;
00077 
00078     xmlChar * name = xmlGetProp(cur,(const xmlChar*)"name");
00079     if(name==NULL)
00080       throw bad_format(cur,"property missing name");
00081 
00082     xmlChar * val = xmlGetProp(cur,(const xmlChar*)"value");
00083     if(val==NULL)
00084       throw bad_format(cur,"property missing value");
00085 
00086     if(xmlStrcmp(name, (const xmlChar *)"x1")==0)
00087       _x1=atof((const char*)val);
00088     else if(xmlStrcmp(name, (const xmlChar *)"x2")==0)
00089       _x2=atof((const char*)val);
00090     else if(xmlStrcmp(name, (const xmlChar *)"y1")==0)
00091       _y1=atof((const char*)val);
00092     else if(xmlStrcmp(name, (const xmlChar *)"y2")==0)
00093       _y2=atof((const char*)val);
00094     else if(xmlStrcmp(name, (const xmlChar *)"clipLeft")==0)
00095       _clipLeft=atoi((const char*)val);
00096     else if(xmlStrcmp(name, (const xmlChar *)"clipRight")==0)
00097       _clipRight=atoi((const char*)val);
00098     else if(xmlStrcmp(name, (const xmlChar *)"clipTop")==0)
00099       _clipTop=atoi((const char*)val);
00100     else if(xmlStrcmp(name, (const xmlChar *)"clipBottom")==0)
00101       _clipBottom=atoi((const char*)val);
00102     
00103     xmlFree(val);
00104     xmlFree(name);
00105   }
00106 }
00107 
00108 //! a little local macro to make saving fields easier
00109 #define SAVE_PARAM(strname,varname,format) {\
00110 xmlNode* cur=xmlNewChild(node,NULL,(const xmlChar*)"param",NULL); \
00111 if(cur==NULL) \
00112 throw bad_format(node,"Error: VisionObjectEvent xml error on saving param"); \
00113 xmlSetProp(cur,(const xmlChar*)"name",(const xmlChar*)strname); \
00114 char valbuf[20]; \
00115 snprintf(valbuf,20,format,varname); \
00116 xmlSetProp(cur,(const xmlChar*)"value",(const xmlChar*)valbuf); }
00117 
00118 void VisionObjectEvent::SaveXML(xmlNode * node) const {
00119   if(node==NULL)
00120     return;
00121   EventBase::SaveXML(node);
00122   
00123   //clear old params first
00124   for(xmlNode* cur = skipToElement(node->children); cur!=NULL; ) {
00125     if(xmlStrcmp(cur->name, (const xmlChar *)"param")==0) {
00126       xmlUnlinkNode(cur);
00127       xmlFreeNode(cur);
00128       cur = skipToElement(node->children); //restart the search (boo)
00129     } else
00130       cur = skipToElement(cur->next);
00131   }
00132   
00133   SAVE_PARAM("x1",_x1,"%g");
00134   SAVE_PARAM("y1",_y1,"%g");
00135   SAVE_PARAM("x2",_x2,"%g");
00136   SAVE_PARAM("y2",_y2,"%g");
00137   SAVE_PARAM("clipLeft",_clipLeft,"%d");
00138   SAVE_PARAM("clipRight",_clipRight,"%d");
00139   SAVE_PARAM("clipTop",_clipTop,"%d");
00140   SAVE_PARAM("clipBottom",_clipBottom,"%d");
00141 }
00142 
00143 /*! @file
00144  * @brief Implements VisionObjectEvent, which provides information about objects recognized in the camera image
00145  * @author alokl (Creator)
00146  * @author Ignacio Herrero Reder &lt; nhr at dte uma es &gt; (VisionObjectInfo Boundary Box - bug 74)
00147  *
00148  * $Author: ejt $
00149  * $Name: tekkotsu-2_4_1 $
00150  * $Revision: 1.9 $
00151  * $State: Exp $
00152  * $Date: 2005/08/07 04:11:03 $
00153  */

Tekkotsu v2.4.1
Generated Tue Aug 16 16:32:49 2005 by Doxygen 1.4.4