Reading.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                         Reading.cpp - Copyright klank
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   //handle the class failing to load
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   //handle the class failing to load
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 }


cognitive_perception
Author(s): Ulrich F Klank
autogenerated on Mon Oct 6 2014 10:48:45