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
00026
00027
00028
00029
00030
00031
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
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