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 #include "Reading.h"
00025 #include "XMLTag.h"
00026 #include <sstream>
00027
00028 #include <pluginlib/class_loader.h>
00029
00030 using namespace cop;
00031
00032
00033 Reading::~Reading()
00034 {
00035 try
00036 {
00037 RelPoseFactory::FreeRelPose(&m_relPose);
00038 }
00039 catch(const char* text)
00040 {
00041 printf("Error while freeing pose of an image: %s\n", text);
00042 }
00043 }
00044
00045 pluginlib::ClassLoader<Reading> s_reading_loader("cognitive_perception", "Reading");
00046
00047 Reading* Reading::ReadingFactory( XMLTag* tag)
00048 {
00049 std::string name = tag->GetName();
00050 Reading* reading = NULL;
00051
00052 try
00053 {
00054 reading = s_reading_loader.createClassInstance(name);
00055 reading->SetData(tag);
00056 }
00057 catch(pluginlib::PluginlibException& ex)
00058 {
00059
00060 printf("The plugin failed to load for some reason. Error: %s\n", ex.what());
00061 printf("Tag failed: %s\n", tag->GetName().c_str());
00062
00063 }
00064 return reading;
00065 }
00066
00067 void Reading::SetPose(RelPose* parent)
00068 {
00069 if(m_relPose != NULL)
00070 {
00071 try
00072 {
00073 RelPoseFactory::FreeRelPose(&m_relPose);
00074 }
00075 catch(const char* text)
00076 {
00077 printf("Error while freeing pose of an image: %s\n", text);
00078 }
00079 }
00080 m_relPose = RelPoseFactory::FRelPoseIdentityChild(parent);
00081 }
00082
00083 std::map<std::pair<ReadingType_t, ReadingType_t> , ReadingConverter*> Reading::s_conv;
00084
00085 Reading* Reading::ConvertTo(ReadingType_t type)
00086 {
00087 std::pair<ReadingType_t, ReadingType_t> prr(GetType(), type);
00088 printf("Searching for a converter from %d to %d\n", GetType(), type);
00089 if(s_conv.find(prr) != s_conv.end())
00090 {
00091 return s_conv[prr]->Convert(this);
00092 }
00093 throw "No conversion Available for the requested reading types";
00094 }
00095
00096
00097 pluginlib::ClassLoader<ReadingConverter> s_reading_conv_loader("cognitive_perception", "ReadingConverter");
00098
00099 ReadingConverter* ReadingConverter::ReadingConverterFactory(std::string name)
00100 {
00101 ReadingConverter* reading = NULL;
00102 try
00103 {
00104 reading = s_reading_conv_loader.createClassInstance(name);
00105 }
00106 catch(pluginlib::PluginlibException& ex)
00107 {
00108
00109 printf("The plugin failed to load for some reason. Error: %s\n", ex.what());
00110 printf("Tag failed: %s\n", name.c_str());
00111 }
00112 return reading;
00113 }