network_of_poses.cpp
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002          |                     Mobile Robot Programming Toolkit (MRPT) |
00003          |                          http://www.mrpt.org/ |
00004          | |
00005          | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
00006          | See: http://www.mrpt.org/Authors - All rights reserved. |
00007          | Released under BSD License. See details in http://www.mrpt.org/License |
00008          +---------------------------------------------------------------------------+
00009    */
00010 
00011 #include "mrpt_bridge/network_of_poses.h"
00012 #include "mrpt_bridge/pose.h"
00013 
00014 #include <geometry_msgs/Pose.h>
00015 #include <geometry_msgs/PoseWithCovariance.h>
00016 #include <mrpt_msgs/NodeIDWithPose.h>
00017 
00018 #include <iostream>  // for debugging reasons
00019 
00020 #include <mrpt/version.h>
00021 #if MRPT_VERSION<0x199
00022 using namespace mrpt::utils;
00023 #else
00024 #include <mrpt/graphs/TNodeID.h>
00025 using mrpt::graphs::TNodeID;
00026 #endif
00027 
00028 
00029 namespace mrpt_bridge
00030 {
00032 // MRPT => ROS
00034 
00035 void convert(
00036         const mrpt::graphs::CNetworkOfPoses2DInf& mrpt_graph,
00037         mrpt_msgs::NetworkOfPoses& ros_graph)
00038 {
00039         MRPT_START;
00040         using namespace geometry_msgs;
00041         using namespace mrpt::math;
00042         using namespace mrpt::graphs;
00043         using namespace mrpt::poses;
00044         using namespace std;
00045 
00046         typedef typename mrpt::graphs::CNetworkOfPoses2DInf::global_poses_t::
00047                 const_iterator poses_cit_t;
00048 
00049         const CNetworkOfPoses2DInf::BASE::edges_map_t& constraints =
00050                 mrpt_graph.BASE::edges;
00051 
00052         // fill root node
00053         ros_graph.root = mrpt_graph.root;
00054 
00055         // fill nodeIDs, positions
00056         for (poses_cit_t poses_cit = mrpt_graph.nodes.begin();
00057                  poses_cit != mrpt_graph.nodes.end(); ++poses_cit)
00058         {
00059                 mrpt_msgs::NodeIDWithPose ros_node;
00060 
00061                 // nodeID
00062                 ros_node.nodeID = poses_cit->first;
00063                 // pose
00064                 convert(poses_cit->second, ros_node.pose);
00065 
00066                 // zero the optional fields
00067                 ros_node.str_ID.data = "";
00068                 ros_node.nodeID_loc = 0;
00069 
00070                 ros_graph.nodes.vec.push_back(ros_node);
00071         }
00072 
00073         // fill the constraints
00074         for (CNetworkOfPoses2DInf::const_iterator constr_it = constraints.begin();
00075                  constr_it != constraints.end(); ++constr_it)
00076         {
00077                 mrpt_msgs::GraphConstraint ros_constr;
00078 
00079                 // constraint ends
00080                 ros_constr.nodeID_from = constr_it->first.first;
00081                 ros_constr.nodeID_to = constr_it->first.second;
00082 
00083                 // constraint mean and covariance
00084                 if (mrpt_graph.edges_store_inverse_poses)
00085                 {
00086                         CPosePDFGaussianInf constr_inv;
00087                         constr_it->second.inverse(constr_inv);
00088                         convert(constr_inv, ros_constr.constraint);
00089                 }
00090                 else
00091                 {
00092                         convert(constr_it->second, ros_constr.constraint);
00093                 }
00094 
00095                 ros_graph.constraints.push_back(ros_constr);
00096         }
00097 
00098         MRPT_END;
00099 }
00100 
00101 void convert(
00102         const mrpt::graphs::CNetworkOfPoses3DInf& mrpt_graph,
00103         mrpt_msgs::NetworkOfPoses& ros_graph)
00104 {
00105         THROW_EXCEPTION("Conversion not implemented yet");
00106         MRPT_TODO(
00107                 "Implement CNetworkOfPoses3DInf => mrpt_msgs::NetworkOfPoses "
00108                 "conversion.");
00109 }
00110 
00111 void convert(
00112         const mrpt::graphs::CNetworkOfPoses2DInf_NA& mrpt_graph,
00113         mrpt_msgs::NetworkOfPoses& ros_graph)
00114 {
00115         MRPT_START;
00116 
00117         using namespace geometry_msgs;
00118         using namespace mrpt::math;
00119         using namespace mrpt::graphs;
00120         using namespace mrpt::poses;
00121         using namespace std;
00122 
00123         typedef typename mrpt::graphs::CNetworkOfPoses2DInf_NA::global_poses_t::
00124                 const_iterator poses_cit_t;
00125 
00127         // for (poses_cit_t it = mrpt_graph.nodes.begin();
00128         // it != mrpt_graph.nodes.end();
00129         //++it) {
00130         // cout << it->first << " | " << it->second << endl;
00131         //}
00132 
00133         const CNetworkOfPoses2DInf_NA::BASE::edges_map_t& constraints =
00134                 mrpt_graph.BASE::edges;
00135 
00136         // fill root node
00137         ros_graph.root = mrpt_graph.root;
00138 
00139         // fill nodeIDs, positions
00140         for (poses_cit_t poses_cit = mrpt_graph.nodes.begin();
00141                  poses_cit != mrpt_graph.nodes.end(); ++poses_cit)
00142         {
00143                 mrpt_msgs::NodeIDWithPose ros_node;
00144 
00145                 // nodeID
00146                 ros_node.nodeID = poses_cit->first;
00147                 // pose
00148                 convert(poses_cit->second, ros_node.pose);
00149 
00150                 // optional fields for the MR-SLAM case
00151                 ros_node.str_ID.data = poses_cit->second.agent_ID_str;
00152                 ros_node.nodeID_loc = poses_cit->second.nodeID_loc;
00153 
00154                 ros_graph.nodes.vec.push_back(ros_node);
00155         }
00156 
00157         // fill the constraints -- same as in the conversion from
00158         // CNetworkOfPoses2DInf
00159         for (CNetworkOfPoses2DInf::const_iterator constr_it = constraints.begin();
00160                  constr_it != constraints.end(); ++constr_it)
00161         {
00162                 mrpt_msgs::GraphConstraint ros_constr;
00163 
00164                 // constraint ends
00165                 ros_constr.nodeID_from = constr_it->first.first;
00166                 ros_constr.nodeID_to = constr_it->first.second;
00167 
00168                 // constraint mean and covariance
00169                 if (mrpt_graph.edges_store_inverse_poses)
00170                 {
00171                         CPosePDFGaussianInf constr_inv;
00172                         constr_it->second.inverse(constr_inv);
00173                         convert(constr_inv, ros_constr.constraint);
00174                 }
00175                 else
00176                 {
00177                         convert(constr_it->second, ros_constr.constraint);
00178                 }
00179 
00180                 ros_graph.constraints.push_back(ros_constr);
00181         }
00182 
00183         MRPT_END;
00184 }
00185 
00186 void convert(
00187         const mrpt::graphs::CNetworkOfPoses3DInf_NA& mrpt_graph,
00188         mrpt_msgs::NetworkOfPoses& ros_graph)
00189 {
00190         THROW_EXCEPTION("Conversion not implemented yet");
00191 }
00192 
00194 // ROS => MRPT
00196 
00197 void convert(
00198         const mrpt_msgs::NetworkOfPoses& ros_graph,
00199         mrpt::graphs::CNetworkOfPoses2DInf& mrpt_graph)
00200 {
00201         MRPT_START;
00202         using namespace mrpt::poses;
00203         using namespace mrpt_msgs;
00204         using namespace std;
00205 
00206         typedef NetworkOfPoses::_nodes_type::_vec_type::const_iterator nodes_cit_t;
00207         typedef NetworkOfPoses::_constraints_type::const_iterator constraints_cit_t;
00208 
00209         // fill root node
00210         mrpt_graph.root = ros_graph.root;
00211 
00212         // fill nodeIDs, positions
00213         for (nodes_cit_t nodes_cit = ros_graph.nodes.vec.begin();
00214                  nodes_cit != ros_graph.nodes.vec.end(); ++nodes_cit)
00215         {
00216                 // get the pose
00217                 CPose2D mrpt_pose;
00218                 convert(nodes_cit->pose, mrpt_pose);
00219 
00220                 mrpt_graph.nodes.insert(
00221                         make_pair(static_cast<TNodeID>(nodes_cit->nodeID), mrpt_pose));
00222         }
00223 
00224         // fill the constraints
00225         for (constraints_cit_t constr_cit = ros_graph.constraints.begin();
00226                  constr_cit != ros_graph.constraints.end(); ++constr_cit)
00227         {
00228                 // constraint ends
00229                 auto constr_ends(
00230                         make_pair(
00231                                 static_cast<TNodeID>(constr_cit->nodeID_from),
00232                                 static_cast<TNodeID>(constr_cit->nodeID_to)));
00233 
00234                 // constraint value
00235                 mrpt::poses::CPosePDFGaussianInf mrpt_constr;
00236                 convert(constr_cit->constraint, mrpt_constr);
00237 
00238                 mrpt_graph.edges.insert(make_pair(constr_ends, mrpt_constr));
00239         }
00240 
00241         mrpt_graph.edges_store_inverse_poses = false;
00242 
00243         MRPT_END;
00244 }
00245 
00246 void convert(
00247         const mrpt_msgs::NetworkOfPoses& ros_graph,
00248         mrpt::graphs::CNetworkOfPoses3DInf& mrpt_graph)
00249 {
00250         THROW_EXCEPTION("Conversion not implemented yet");
00251         MRPT_TODO(
00252                 "Implement mrpt_msgs::NetworkOfPoses => CNetworkOfPoses3DInf "
00253                 "conversion.");
00254 }
00255 
00256 void convert(
00257         const mrpt_msgs::NetworkOfPoses& ros_graph,
00258         mrpt::graphs::CNetworkOfPoses2DInf_NA& mrpt_graph)
00259 {
00260         MRPT_START;
00261         using namespace mrpt::poses;
00262         using namespace mrpt_msgs;
00263         using namespace std;
00264 
00265         typedef NetworkOfPoses::_nodes_type::_vec_type::const_iterator nodes_cit_t;
00266         typedef NetworkOfPoses::_constraints_type::const_iterator constraints_cit_t;
00267 
00268         typedef mrpt::graphs::CNetworkOfPoses2DInf_NA::global_pose_t
00269                 mrpt_graph_pose_t;
00270 
00271         // fill root node
00272         mrpt_graph.root = ros_graph.root;
00273 
00274         // fill nodeIDs, positions
00275         for (nodes_cit_t nodes_cit = ros_graph.nodes.vec.begin();
00276                  nodes_cit != ros_graph.nodes.vec.end(); ++nodes_cit)
00277         {
00278                 mrpt_graph_pose_t mrpt_node;
00279 
00280                 // set the nodeID/pose
00281                 convert(nodes_cit->pose, mrpt_node);
00282 
00283                 // set the MR-SLAM fields
00284                 mrpt_node.agent_ID_str = nodes_cit->str_ID.data;
00285                 mrpt_node.nodeID_loc = nodes_cit->nodeID_loc;
00286 
00287                 mrpt_graph.nodes.insert(
00288                         make_pair(static_cast<TNodeID>(nodes_cit->nodeID), mrpt_node));
00289         }
00290 
00291         // fill the constraints
00292         for (constraints_cit_t constr_cit = ros_graph.constraints.begin();
00293                  constr_cit != ros_graph.constraints.end(); ++constr_cit)
00294         {
00295                 // constraint ends
00296                 auto constr_ends(
00297                         make_pair(
00298                                 static_cast<TNodeID>(constr_cit->nodeID_from),
00299                                 static_cast<TNodeID>(constr_cit->nodeID_to)));
00300 
00301                 // constraint value
00302                 mrpt::poses::CPosePDFGaussianInf mrpt_constr;
00303                 convert(constr_cit->constraint, mrpt_constr);
00304 
00305                 mrpt_graph.edges.insert(make_pair(constr_ends, mrpt_constr));
00306         }
00307 
00308         mrpt_graph.edges_store_inverse_poses = false;
00309 
00310         MRPT_END;
00311 }
00312 
00313 void convert(
00314         mrpt_msgs::NetworkOfPoses& ros_graph,
00315         const mrpt::graphs::CNetworkOfPoses3DInf_NA& mrpt_graph)
00316 {
00317         THROW_EXCEPTION("Conversion not implemented yet");
00318 }
00319 
00320 }  // end of namespace


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Fri Apr 27 2018 05:10:54