Descriptor.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 by Ulrich Friedrich Klank <klank@in.tum.de>
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 
00019 /************************************************************************
00020                         Descriptor.cpp - Copyright klank
00021 
00022 
00023 **************************************************************************/
00024 
00025 #include "Descriptor.h"
00026 #include "XMLTag.h"
00027 
00028 #define XML_ATTRIBUTE_QUALITY "DescriptorQuality"
00029 
00030 using namespace cop;
00031 
00032 
00033 // Constructors/Destructors
00034 //
00035 Descriptor::Descriptor (Class *classref ) :
00036   Elem(),
00037         m_class(classref),
00038         m_imgLastMatchReading(NULL),
00039         m_poseLastMatchReading(NULL),
00040         m_qualityMeasure(1.0)
00041 {
00042 }
00043 
00044 Descriptor::Descriptor():
00045         m_class(NULL),
00046         m_imgLastMatchReading(NULL),
00047         m_poseLastMatchReading(NULL),
00048         m_qualityMeasure(1.0)
00049 {
00050 }
00051 
00052 void Descriptor::SetData ( XMLTag* tag)
00053 {
00054   Elem::SetData(tag);
00055   ElemWriteLock lk(m_mutexElems);
00056   m_imgLastMatchReading = (NULL);
00057   m_poseLastMatchReading = (NULL);
00058   m_class = (Class*)Elem::ElemFactory(tag->GetChild(0));
00059   m_qualityMeasure = tag->GetPropertyDouble(XML_ATTRIBUTE_QUALITY, 1.0);
00060   
00061   try
00062   {
00063     XMLTag* img = tag->GetChild(XML_NODE_IMAGEFILE);
00064     if(img != NULL)
00065     {
00066       try
00067       {
00068         m_imgLastMatchReading = Reading::ReadingFactory(img); /*TODO: implement factory for Readings*/
00069       }
00070       catch(...)
00071       {
00072         printf("Error reading XML: Last matched image of a descriptor could not be found\n");
00073       }
00074     }
00075     XMLTag* tagPose = tag->GetChild(XML_NODE_RELPOSE);
00076     if(tagPose != NULL)
00077       m_poseLastMatchReading = RelPoseFactory::FRelPose(tagPose);
00078 
00079   }
00080   catch(char const* ch)
00081   {
00082     delete m_imgLastMatchReading;
00083     m_imgLastMatchReading = NULL;
00084     ROS_WARN("Error reading XML: %s\n", ch);
00085   }
00086 }
00087 
00088 Class* Descriptor::GetClass()
00089 {
00090         return m_class;
00091 }
00092 
00093 Descriptor::~Descriptor ( )
00094 {
00095         if(m_imgLastMatchReading != NULL)
00096         {
00097                 m_imgLastMatchReading->Free();
00098                 if(m_imgLastMatchReading->m_usageCount < 0)
00099                         delete m_imgLastMatchReading;
00100                 //RelPoseFactory::FreeRelPose(m_poseLastMatchImage);
00101     delete m_poseLastMatchReading;
00102         }
00103 }
00104 
00105 //
00106 // Methods
00107 //
00108 void Descriptor::SaveTo(XMLTag* tag)
00109 {
00110         tag->AddProperty(XML_ATTRIBUTE_QUALITY, m_qualityMeasure);
00111         if(m_imgLastMatchReading != NULL)
00112           tag->AddChild(m_imgLastMatchReading->Save());
00113         if(m_poseLastMatchReading != NULL)           
00114           tag->AddChild(m_poseLastMatchReading->Save());
00115 
00116         if(m_class != NULL)
00117                 tag->AddChild(m_class->Save(), 0);
00118         else
00119                 ROS_WARN("Trying to save a broken Descriptor\n");
00120 }
00121 
00122 void Descriptor::SetLastMatchedImage(Reading* img, RelPose* pose)
00123 {
00124   ElemWriteLock lk(m_mutexElems);
00125   if(img != NULL)
00126   {
00127     if( m_imgLastMatchReading != NULL)
00128     {
00129       m_imgLastMatchReading->Free();
00130       RelPoseFactory::FreeRelPose(&m_poseLastMatchReading);
00131     }
00132      m_imgLastMatchReading = img->Clone();
00133   }
00134   try
00135   {
00136            m_poseLastMatchReading = RelPoseFactory::CloneRelPose(pose);
00137   }
00138   catch(...)
00139   {
00140     ROS_WARN("Tying to copy a singular position\n");
00141     m_poseLastMatchReading = RelPoseFactory::FRelPoseWorld();
00142   }
00143   this->Touch();
00144 }
00145 
00146 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


cognitive_perception
Author(s): Ulrich F Klank
autogenerated on Thu May 23 2013 07:38:34