$search
00001 #include "Object.h" 00002 #include <boost/lexical_cast.hpp> 00003 00004 namespace object_tracker { 00005 00006 std::map<std::string,unsigned int> Object::object_count; 00007 std::string Object::object_namespace; 00008 00009 Object::Object(const std::string class_id, const std::string object_id) 00010 { 00011 if (!class_id.empty()) { 00012 object.info.class_id = class_id; 00013 } else { 00014 object.info.class_id = "object"; 00015 } 00016 00017 if (!object_id.empty()) { 00018 object.info.object_id = object_id; 00019 } else { 00020 object.info.object_id = object.info.class_id + "_" + boost::lexical_cast<std::string>(object_count[object.info.class_id]++); 00021 } 00022 00023 // if (object.info.object_id[0] != '/') object.info.object_id = object_namespace + "/" + object.info.object_id; 00024 } 00025 00026 Object::~Object() 00027 {} 00028 00029 void Object::reset() { 00030 object_count.clear(); 00031 } 00032 00033 const Eigen::Vector3f& Object::getPosition() const { 00034 return position; 00035 } 00036 00037 void Object::setPosition(const Eigen::Vector3f& position) { 00038 this->position = position; 00039 00040 object.pose.pose.position.x = position.x(); 00041 object.pose.pose.position.y = position.y(); 00042 object.pose.pose.position.z = position.z(); 00043 object.pose.pose.orientation.w = 1.0; 00044 } 00045 00046 const Eigen::Matrix3f& Object::getCovariance() const { 00047 return covariance; 00048 } 00049 00050 void Object::setCovariance(const Eigen::Matrix3f& covariance) { 00051 this->covariance = covariance; 00052 00053 object.pose.covariance[0] = covariance(0,0); 00054 object.pose.covariance[1] = covariance(0,1); 00055 object.pose.covariance[2] = covariance(0,2); 00056 object.pose.covariance[6] = covariance(1,0); 00057 object.pose.covariance[7] = covariance(1,1); 00058 object.pose.covariance[8] = covariance(1,2); 00059 object.pose.covariance[12] = covariance(2,0); 00060 object.pose.covariance[13] = covariance(2,1); 00061 object.pose.covariance[14] = covariance(2,2); 00062 } 00063 00064 void Object::intersect(const Eigen::Vector3f& positionB, const Eigen::Matrix3f& covarianceB, float support) { 00065 // old cov/covariance is A , new cov/covIn is B 00066 float omega = 0.5f; 00067 00068 Eigen::Matrix3f A(covariance.inverse() * omega); 00069 Eigen::Matrix3f B(covarianceB.inverse() * (1.0f - omega)); 00070 00071 covariance = (A + B).inverse(); 00072 position = covariance * (A * position + B * positionB); 00073 00074 setPosition(position); 00075 setCovariance(covariance); 00076 addSupport(support); 00077 } 00078 00079 void Object::update(const Eigen::Vector3f& positionB, const Eigen::Matrix3f& covarianceB, float support) { 00080 Eigen::Matrix3f A(covariance.inverse()); 00081 Eigen::Matrix3f B(covarianceB.inverse()); 00082 00083 covariance = (A + B).inverse(); 00084 position = covariance * (A * position + B * positionB); 00085 00086 setPosition(position); 00087 setCovariance(covariance); 00088 addSupport(support); 00089 } 00090 00091 void Object::getVisualization(visualization_msgs::MarkerArray &markers) const { 00092 visualization_msgs::Marker marker; 00093 std::string postfix; 00094 00095 // default color 00096 marker.color.r = 0.8; 00097 marker.color.g = 0.0; 00098 marker.color.b = 0.0; 00099 marker.color.a = 1.0; 00100 00101 switch(object.state.state) { 00102 case worldmodel_msgs::ObjectState::CONFIRMED: 00103 marker.color.r = 0.0; 00104 marker.color.g = 0.8; 00105 marker.color.b = 0.0; 00106 postfix = " (CONFIRMED)"; 00107 break; 00108 case worldmodel_msgs::ObjectState::DISCARDED: 00109 marker.color.a = 0.5; 00110 postfix = " (DISCARDED)"; 00111 break; 00112 default: 00113 break; 00114 } 00115 00116 marker.header = object.header; 00117 marker.action = visualization_msgs::Marker::ADD; 00118 marker.pose = object.pose.pose; 00119 marker.ns = "worldmodel"; 00120 00121 marker.type = visualization_msgs::Marker::ARROW; 00122 marker.scale.x = 1.0; 00123 marker.scale.y = 1.0; 00124 marker.scale.z = 1.0; 00125 // markers.markers.push_back(marker); 00126 00127 marker.type = visualization_msgs::Marker::SPHERE; 00128 marker.scale.x = 0.1; 00129 marker.scale.y = 0.1; 00130 marker.scale.z = 0.1; 00131 markers.markers.push_back(marker); 00132 00133 marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING; 00134 marker.text = (!object.info.name.empty() ? object.info.name : object.info.object_id) + postfix; 00135 marker.scale.x = 0.0; 00136 marker.scale.y = 0.0; 00137 marker.scale.z = 0.1; 00138 marker.pose.position.z += 1.5 * marker.scale.z; 00139 markers.markers.push_back(marker); 00140 } 00141 00142 void Object::setNamespace(const std::string &ns) { 00143 object_namespace = ns; 00144 } 00145 00146 } // namespace object_tracker