Go to the documentation of this file.00001 #include "vws_alg_node.h"
00002
00003 VwsAlgNode::VwsAlgNode(void) :
00004 algorithm_base::IriBaseAlgorithm<VwsAlgorithm>()
00005 {
00006
00007
00008
00009
00010
00011
00012
00013
00014 this->set_centroids_server_ = this->public_node_handle_.advertiseService("set_centroids", &VwsAlgNode::set_centroidsCallback, this);
00015 this->get_vws_server_ = this->public_node_handle_.advertiseService("get_vws", &VwsAlgNode::get_vwsCallback, this);
00016
00017
00018
00019
00020
00021
00022 }
00023
00024 VwsAlgNode::~VwsAlgNode(void)
00025 {
00026
00027 }
00028
00029 void VwsAlgNode::mainNodeThread(void)
00030 {
00031
00032
00033
00034
00035
00036
00037
00038 }
00039
00040
00041
00042
00043 bool VwsAlgNode::set_centroidsCallback(iri_publish_params::classifier_update_service::Request &req, iri_publish_params::classifier_update_service::Response &res)
00044 {
00045 ROS_INFO("VwsAlgNode::set_centroidsCallback: New Request Received!");
00046
00047
00048 this->alg_.lock();
00049
00050
00051
00052 ROS_INFO_STREAM("Size " << req.params.update_params.size() << " y " << req.params.update_params[0].params.size());
00053
00054
00055 this->alg_.centroids_ = cv::Mat::zeros(req.params.update_params.size(), req.params.update_params[0].params.size(), CV_32FC1);
00056 for(size_t i=0; i < req.params.update_params.size(); i++) {
00057 for(size_t j=0; j< req.params.update_params[i].params.size(); j++) {
00058 this->alg_.centroids_.at<float>(i,j) = (float)req.params.update_params[i].params[j];
00059 }
00060 }
00061
00062 this->alg_.centroids_ready_ = true;
00063
00064
00065 this->alg_.unlock();
00066
00067 res.result = true;
00068
00069 return true;
00070 }
00071 bool VwsAlgNode::get_vwsCallback(iri_perception_msgs::DescriptorsToVws::Request &req, iri_perception_msgs::DescriptorsToVws::Response &res)
00072 {
00073 ROS_INFO("VwsAlgNode::get_vwsCallback: New Request Received!");
00074
00075
00076
00077
00078
00079 if (this->alg_.centroids_ready_) {
00080 ROS_DEBUG("Getting geo_vw.");
00081 res.geo_vw_set = this->alg_.get_geo_vw_from_descriptors(req);
00082 return true;
00083 }
00084 else {
00085 ROS_ERROR("iri_vws: Need centroids!");
00086 return false;
00087 }
00088
00089
00090
00091
00092
00093
00094 }
00095
00096
00097
00098
00099
00100 void VwsAlgNode::node_config_update(Config &config, uint32_t level)
00101 {
00102 this->alg_.lock();
00103
00104 this->alg_.unlock();
00105 }
00106
00107 void VwsAlgNode::addNodeDiagnostics(void)
00108 {
00109 }
00110
00111
00112 int main(int argc,char *argv[])
00113 {
00114 return algorithm_base::main<VwsAlgNode>(argc, argv, "vws_alg_node");
00115 }