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 #include "Descriptor.h"
00026 #include "XMLTag.h"
00027
00028 #define XML_ATTRIBUTE_QUALITY "DescriptorQuality"
00029
00030 using namespace cop;
00031
00032
00033
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);
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
00101 delete m_poseLastMatchReading;
00102 }
00103 }
00104
00105
00106
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