network_of_poses.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+
9  */
10 
12 #include "mrpt_bridge/pose.h"
13 
14 #include <geometry_msgs/Pose.h>
15 #include <geometry_msgs/PoseWithCovariance.h>
16 #include <mrpt_msgs/NodeIDWithPose.h>
17 
18 #include <iostream> // for debugging reasons
19 
20 #include <mrpt/version.h>
21 #if MRPT_VERSION<0x199
22 using namespace mrpt::utils;
23 #else
24 #include <mrpt/graphs/TNodeID.h>
25 using mrpt::graphs::TNodeID;
26 #endif
27 
28 
29 namespace mrpt_bridge
30 {
32 // MRPT => ROS
34 
35 void convert(
36  const mrpt::graphs::CNetworkOfPoses2DInf& mrpt_graph,
37  mrpt_msgs::NetworkOfPoses& ros_graph)
38 {
39  MRPT_START;
40  using namespace geometry_msgs;
41  using namespace mrpt::math;
42  using namespace mrpt::graphs;
43  using namespace mrpt::poses;
44  using namespace std;
45 
46  typedef typename mrpt::graphs::CNetworkOfPoses2DInf::global_poses_t::
47  const_iterator poses_cit_t;
48 
49  const CNetworkOfPoses2DInf::BASE::edges_map_t& constraints =
50  mrpt_graph.BASE::edges;
51 
52  // fill root node
53  ros_graph.root = mrpt_graph.root;
54 
55  // fill nodeIDs, positions
56  for (poses_cit_t poses_cit = mrpt_graph.nodes.begin();
57  poses_cit != mrpt_graph.nodes.end(); ++poses_cit)
58  {
59  mrpt_msgs::NodeIDWithPose ros_node;
60 
61  // nodeID
62  ros_node.nodeID = poses_cit->first;
63  // pose
64  convert(poses_cit->second, ros_node.pose);
65 
66  // zero the optional fields
67  ros_node.str_ID.data = "";
68  ros_node.nodeID_loc = 0;
69 
70  ros_graph.nodes.vec.push_back(ros_node);
71  }
72 
73  // fill the constraints
74  for (CNetworkOfPoses2DInf::const_iterator constr_it = constraints.begin();
75  constr_it != constraints.end(); ++constr_it)
76  {
77  mrpt_msgs::GraphConstraint ros_constr;
78 
79  // constraint ends
80  ros_constr.nodeID_from = constr_it->first.first;
81  ros_constr.nodeID_to = constr_it->first.second;
82 
83  // constraint mean and covariance
84  if (mrpt_graph.edges_store_inverse_poses)
85  {
86  CPosePDFGaussianInf constr_inv;
87  constr_it->second.inverse(constr_inv);
88  convert(constr_inv, ros_constr.constraint);
89  }
90  else
91  {
92  convert(constr_it->second, ros_constr.constraint);
93  }
94 
95  ros_graph.constraints.push_back(ros_constr);
96  }
97 
98  MRPT_END;
99 }
100 
101 void convert(
102  const mrpt::graphs::CNetworkOfPoses3DInf& mrpt_graph,
103  mrpt_msgs::NetworkOfPoses& ros_graph)
104 {
105  THROW_EXCEPTION("Conversion not implemented yet");
106  MRPT_TODO(
107  "Implement CNetworkOfPoses3DInf => mrpt_msgs::NetworkOfPoses "
108  "conversion.");
109 }
110 
111 void convert(
112  const mrpt::graphs::CNetworkOfPoses2DInf_NA& mrpt_graph,
113  mrpt_msgs::NetworkOfPoses& ros_graph)
114 {
115  MRPT_START;
116 
117  using namespace geometry_msgs;
118  using namespace mrpt::math;
119  using namespace mrpt::graphs;
120  using namespace mrpt::poses;
121  using namespace std;
122 
123  typedef typename mrpt::graphs::CNetworkOfPoses2DInf_NA::global_poses_t::
124  const_iterator poses_cit_t;
125 
127  // for (poses_cit_t it = mrpt_graph.nodes.begin();
128  // it != mrpt_graph.nodes.end();
129  //++it) {
130  // cout << it->first << " | " << it->second << endl;
131  //}
132 
133  const CNetworkOfPoses2DInf_NA::BASE::edges_map_t& constraints =
134  mrpt_graph.BASE::edges;
135 
136  // fill root node
137  ros_graph.root = mrpt_graph.root;
138 
139  // fill nodeIDs, positions
140  for (poses_cit_t poses_cit = mrpt_graph.nodes.begin();
141  poses_cit != mrpt_graph.nodes.end(); ++poses_cit)
142  {
143  mrpt_msgs::NodeIDWithPose ros_node;
144 
145  // nodeID
146  ros_node.nodeID = poses_cit->first;
147  // pose
148  convert(poses_cit->second, ros_node.pose);
149 
150  // optional fields for the MR-SLAM case
151  ros_node.str_ID.data = poses_cit->second.agent_ID_str;
152  ros_node.nodeID_loc = poses_cit->second.nodeID_loc;
153 
154  ros_graph.nodes.vec.push_back(ros_node);
155  }
156 
157  // fill the constraints -- same as in the conversion from
158  // CNetworkOfPoses2DInf
159  for (CNetworkOfPoses2DInf::const_iterator constr_it = constraints.begin();
160  constr_it != constraints.end(); ++constr_it)
161  {
162  mrpt_msgs::GraphConstraint ros_constr;
163 
164  // constraint ends
165  ros_constr.nodeID_from = constr_it->first.first;
166  ros_constr.nodeID_to = constr_it->first.second;
167 
168  // constraint mean and covariance
169  if (mrpt_graph.edges_store_inverse_poses)
170  {
171  CPosePDFGaussianInf constr_inv;
172  constr_it->second.inverse(constr_inv);
173  convert(constr_inv, ros_constr.constraint);
174  }
175  else
176  {
177  convert(constr_it->second, ros_constr.constraint);
178  }
179 
180  ros_graph.constraints.push_back(ros_constr);
181  }
182 
183  MRPT_END;
184 }
185 
186 void convert(
187  const mrpt::graphs::CNetworkOfPoses3DInf_NA& mrpt_graph,
188  mrpt_msgs::NetworkOfPoses& ros_graph)
189 {
190  THROW_EXCEPTION("Conversion not implemented yet");
191 }
192 
194 // ROS => MRPT
196 
197 void convert(
198  const mrpt_msgs::NetworkOfPoses& ros_graph,
199  mrpt::graphs::CNetworkOfPoses2DInf& mrpt_graph)
200 {
201  MRPT_START;
202  using namespace mrpt::poses;
203  using namespace mrpt_msgs;
204  using namespace std;
205 
206  typedef NetworkOfPoses::_nodes_type::_vec_type::const_iterator nodes_cit_t;
207  typedef NetworkOfPoses::_constraints_type::const_iterator constraints_cit_t;
208 
209  // fill root node
210  mrpt_graph.root = ros_graph.root;
211 
212  // fill nodeIDs, positions
213  for (nodes_cit_t nodes_cit = ros_graph.nodes.vec.begin();
214  nodes_cit != ros_graph.nodes.vec.end(); ++nodes_cit)
215  {
216  // get the pose
217  CPose2D mrpt_pose;
218  convert(nodes_cit->pose, mrpt_pose);
219 
220  mrpt_graph.nodes.insert(
221  make_pair(static_cast<TNodeID>(nodes_cit->nodeID), mrpt_pose));
222  }
223 
224  // fill the constraints
225  for (constraints_cit_t constr_cit = ros_graph.constraints.begin();
226  constr_cit != ros_graph.constraints.end(); ++constr_cit)
227  {
228  // constraint ends
229  auto constr_ends(
230  make_pair(
231  static_cast<TNodeID>(constr_cit->nodeID_from),
232  static_cast<TNodeID>(constr_cit->nodeID_to)));
233 
234  // constraint value
235  mrpt::poses::CPosePDFGaussianInf mrpt_constr;
236  convert(constr_cit->constraint, mrpt_constr);
237 
238  mrpt_graph.edges.insert(make_pair(constr_ends, mrpt_constr));
239  }
240 
241  mrpt_graph.edges_store_inverse_poses = false;
242 
243  MRPT_END;
244 }
245 
246 void convert(
247  const mrpt_msgs::NetworkOfPoses& ros_graph,
248  mrpt::graphs::CNetworkOfPoses3DInf& mrpt_graph)
249 {
250  THROW_EXCEPTION("Conversion not implemented yet");
251  MRPT_TODO(
252  "Implement mrpt_msgs::NetworkOfPoses => CNetworkOfPoses3DInf "
253  "conversion.");
254 }
255 
256 void convert(
257  const mrpt_msgs::NetworkOfPoses& ros_graph,
258  mrpt::graphs::CNetworkOfPoses2DInf_NA& mrpt_graph)
259 {
260  MRPT_START;
261  using namespace mrpt::poses;
262  using namespace mrpt_msgs;
263  using namespace std;
264 
265  typedef NetworkOfPoses::_nodes_type::_vec_type::const_iterator nodes_cit_t;
266  typedef NetworkOfPoses::_constraints_type::const_iterator constraints_cit_t;
267 
268  typedef mrpt::graphs::CNetworkOfPoses2DInf_NA::global_pose_t
269  mrpt_graph_pose_t;
270 
271  // fill root node
272  mrpt_graph.root = ros_graph.root;
273 
274  // fill nodeIDs, positions
275  for (nodes_cit_t nodes_cit = ros_graph.nodes.vec.begin();
276  nodes_cit != ros_graph.nodes.vec.end(); ++nodes_cit)
277  {
278  mrpt_graph_pose_t mrpt_node;
279 
280  // set the nodeID/pose
281  convert(nodes_cit->pose, mrpt_node);
282 
283  // set the MR-SLAM fields
284  mrpt_node.agent_ID_str = nodes_cit->str_ID.data;
285  mrpt_node.nodeID_loc = nodes_cit->nodeID_loc;
286 
287  mrpt_graph.nodes.insert(
288  make_pair(static_cast<TNodeID>(nodes_cit->nodeID), mrpt_node));
289  }
290 
291  // fill the constraints
292  for (constraints_cit_t constr_cit = ros_graph.constraints.begin();
293  constr_cit != ros_graph.constraints.end(); ++constr_cit)
294  {
295  // constraint ends
296  auto constr_ends(
297  make_pair(
298  static_cast<TNodeID>(constr_cit->nodeID_from),
299  static_cast<TNodeID>(constr_cit->nodeID_to)));
300 
301  // constraint value
302  mrpt::poses::CPosePDFGaussianInf mrpt_constr;
303  convert(constr_cit->constraint, mrpt_constr);
304 
305  mrpt_graph.edges.insert(make_pair(constr_ends, mrpt_constr));
306  }
307 
308  mrpt_graph.edges_store_inverse_poses = false;
309 
310  MRPT_END;
311 }
312 
313 void convert(
314  mrpt_msgs::NetworkOfPoses& ros_graph,
315  const mrpt::graphs::CNetworkOfPoses3DInf_NA& mrpt_graph)
316 {
317  THROW_EXCEPTION("Conversion not implemented yet");
318 }
319 
320 } // end of namespace
void convert(mrpt_msgs::NetworkOfPoses &ros_graph, const mrpt::graphs::CNetworkOfPoses3DInf_NA &mrpt_graph)
File includes methods for converting CNetworkOfPoses*DInf <=> NetworkOfPoses message types...


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Sat Apr 28 2018 02:49:17