TableObjectDescriptors.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Ulrich Klank
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 /************************************************************************
00031 TableObjectDescriptors.cpp
00032 **************************************************************************/
00033 
00034 #include "ElemTypes.h"
00035 #include "NamedDescriptor.h"
00036 #include "RemoteAttention.h"
00037 #include "XMLTag.h"
00038 #include <pluginlib/class_list_macros.h>
00039 #include <ias_table_msgs/TableObject.h>
00040 #include <std_msgs/String.h>
00041 
00042 namespace cop
00043 {
00044    CREATE_NAMED_DESCRIPTOR(TableObjectDescriptor, "TableObjectDescriptor", "DefaultTableObject", DESCRIPTOR_TABLEOBJ, ias_table_msgs::TableObject)
00045    CREATE_NAMED_DESCRIPTOR(ShapeTypeDescriptor, "ShapeType", "DefaultShapeType", DESCRIPTOR_SHAPETYPE, std_msgs::String)
00046 
00047    class  TableObjectAttention : public RemoteAttention< ias_table_msgs::TableObject >
00048    {
00049      public:
00050         TableObjectAttention(){SetObjectType(DESCRIPTOR_TABLEOBJ);}
00051       virtual std::vector<Signature*> MessageToSignature(boost::shared_ptr< ias_table_msgs::TableObject const> msg)
00052       {
00053         std::vector<Signature*> results;
00054         printf("TableObjectAttention::MessageToSignature\n");
00055         Signature* obj = new Signature();
00056         obj->m_ID = msg->object_cop_id;
00057         TableObjectDescriptor* descr = new TableObjectDescriptor();
00058         ShapeTypeDescriptor* descr2 = new ShapeTypeDescriptor();
00059         descr2->SetClass(msg->object_geometric_type);
00060         descr->SetClass(msg->object_type);
00062        //  descr->SetClass();
00063         descr->SetContent(*msg);
00064         obj->SetElem(descr);
00065         obj->SetElem(descr2);
00066         try
00067         {
00068           RelPose* pose = RelPoseFactory::FRelPose(msg->lo_id);
00069           if(pose != NULL)
00070            obj->SetPose(pose);
00071         }
00072         catch(...)
00073         {
00074           printf("no pose here\n");
00075         }
00076         results.push_back(obj);
00077         printf("Returning object with id %ld\n", obj->m_ID);
00078         return results;
00079       }
00080       virtual std::string GetName(){return "TableObjectAttention";}
00081    };
00082    class TableObjectRedetector : public LocateAlgorithm
00083    {
00084     public:
00085       TableObjectRedetector()
00086       {
00087       }
00088 
00089       void SetData(XMLTag* tag)
00090       {
00091         printf("Loading Algorithm %s \n", GetName().c_str());
00092         if(tag != NULL && tag->CountChildren() > 0)
00093         {
00094           m_firstAlg = LocateAlgorithm::LocAlgFactory(tag->GetChild(0));
00095         }
00096         else
00097            throw "Error loading TwoInOneAlg";
00098       }
00099 
00100 
00101       ~TableObjectRedetector(void)
00102       {
00103         delete m_firstAlg;
00104       }
00105 
00106 
00107         XMLTag* Save()
00108         {
00109         XMLTag* tag = new XMLTag(GetName());
00110         tag->AddChild(m_firstAlg->Save());
00111         return tag;
00112         }
00113 
00114         double RelateMatrices(const Matrix& m, const Matrix& m2)
00115         {
00116           double val = 0.0;
00117           double sumM1 = m.element(0,3)*m.element(0,3) + m.element(1,3)*m.element(1,3) + m.element(2,3)*m.element(2,3);
00118           double sumM2 = m2.element(0,3)*m2.element(0,3) + m2.element(1,3)*m2.element(1,3) + m2.element(2,3)*m2.element(2,3);
00119           val =  (sumM2 - sumM1)  / sumM2;
00120           return val < 0 ? 0.0 : val;
00121         }
00122         std::vector<RelPose*> Perform(std::vector<Sensor*> cam, RelPose* posein, Signature& object, int &numOfObjects, double& qualityMeasure)
00123         {
00124           int numOfObjects_first = numOfObjects;
00125           double qualityMeasure_first = qualityMeasure;
00126           std::vector<RelPose*> result_first = m_firstAlg->Perform(cam, posein, object, numOfObjects_first, qualityMeasure_first);
00127           std::vector<RelPose*> results;
00128           if(numOfObjects_first > 0)
00129           {
00130             for(unsigned int i = 0; i < result_first.size(); i++)
00131             {
00132               RelPose* pose = result_first[i];
00133               Matrix m = posein->GetMatrix(pose->m_uniqueID);
00134               Matrix m2 = pose->GetMatrix(pose->m_parentID);
00135               double val = RelateMatrices(m, m2);
00136 
00137               pose->m_qualityMeasure = val;
00138               ROS_WARN("TableObjectRedetector Debug out: Score is scaled by val: %f (which represents the distance) and is now %f\n", val, pose->m_qualityMeasure);
00139               results.push_back(pose);
00140               if(i == 0)
00141               {
00142                  qualityMeasure = result_first[i]->m_qualityMeasure * val;
00143                  numOfObjects = 1;
00144               }
00145               else
00146                 numOfObjects++;
00147             }
00148           }
00149           return results;
00150         }
00151 
00152         double CheckSignature(const Signature& object, const std::vector<Sensor*> &sensors)
00153         {
00154           double val1 = m_firstAlg->CheckSignature(object, sensors);
00155           if(val1 > 0.0)
00156           {
00157             if(object.GetElement(0,DESCRIPTOR_TABLEOBJ))
00158               return 1.0;
00159           }
00160           return  0.0;
00161         }
00162 
00163       virtual std::string GetName(){return "TableObjectRedetector";}
00164     private:
00165       LocateAlgorithm* m_firstAlg;
00166    };
00167 
00168 }
00169 
00170 using namespace cop;
00171 
00172 PLUGINLIB_REGISTER_CLASS(TableObjectDescriptor, cop::TableObjectDescriptor, Descriptor);
00173 PLUGINLIB_REGISTER_CLASS(ShapeTypeDescriptor, cop::ShapeTypeDescriptor, Descriptor);
00174 PLUGINLIB_REGISTER_CLASS(TableObjectAttention, cop::TableObjectAttention, AttentionAlgorithm);
00175 PLUGINLIB_REGISTER_CLASS(TableObjectRedetector, cop::TableObjectRedetector, LocateAlgorithm);
00176 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


cop_ros_plugins
Author(s): U. Klank, Dejan Pangercic
autogenerated on Thu May 23 2013 12:29:47