KinematicChainVisualizer.cpp
Go to the documentation of this file.
1 
19 
20 namespace Visualization {
21 
24  {
25  }
26 
28  {
29  }
30 
32  unsigned int& pMarkerId,
33  const boost::shared_ptr<ISM::Pose> pPose,
34  double pQualityOfMatch)
35  {
36  // Check, if publisher is available.
37  if(!pPublisher)
38  throw std::invalid_argument("Empty ros::publisher cannot be used to publish marker messages.");
39 
40  visualization_msgs::MarkerArray array;
41 
42  // Generate the arrow message that symbolizes the link.
43  array.markers.push_back(generatePerpendicularArrowMessage(pMarkerId, pPose, pQualityOfMatch, 0.2));
44 
45  // Publish the markers.
46  pPublisher->publish(array);
47  }
48 
50  unsigned int& pMarkerId,
51  const boost::shared_ptr<ISM::Pose> pPose)
52  {
53  // Check, if publisher is available.
54  if(!pPublisher)
55  throw std::invalid_argument("Empty ros::publisher cannot be used to publish marker messages.");
56 
57  visualization_msgs::MarkerArray array;
58 
59  // Generate the point message that symbolizes the object position.
60  array.markers.push_back(generatePointMessage(pMarkerId, pPose->point->getEigen()));
61 
62  // Publish the markers.
63  pPublisher->publish(array);
64  }
65 
67  unsigned int& pMarkerId,
68  const boost::shared_ptr<ISM::Pose> pPose,
69  std::vector<double> pScores,
70  double pQualityOfMatch)
71  {
72  // Check, if publisher is available.
73  if(!pPublisher)
74  throw std::invalid_argument("Empty ros::publisher cannot be used to publish marker messages.");
75 
76  visualization_msgs::MarkerArray array;
77 
78  double arrowLength = 0.2;
79 
80  // Generate the arrow message that points perpendicular to the object position.
81  array.markers.push_back(generatePerpendicularArrowMessage(pMarkerId, pPose, pQualityOfMatch, arrowLength));
82 
83  // Generate the term markers.
84  for(unsigned int i = 0; i < pScores.size(); i++)
85  array.markers.push_back(generateTermIndicatorMessage(pMarkerId, pPose, i * (arrowLength / (pScores.size() * 2.0)), pScores[i]));
86 
87  // Generate the point message that symbolizes the object position.
88  array.markers.push_back(generatePointMessage(pMarkerId, pPose->point->getEigen()));
89 
90  // Publish the markers.
91  pPublisher->publish(array);
92  }
93 
95  unsigned int& pMarkerId,
96  const Eigen::Vector3d pFrom,
97  const Eigen::Vector3d pTo,
98  double pQualityOfMatch)
99  {
100  // Check, if publisher is available.
101  if(!pPublisher)
102  throw std::invalid_argument("Empty ros::publisher cannot be used to publish marker messages.");
103 
104  visualization_msgs::MarkerArray array;
105 
106  // Generate the arrow message that symbolizes the link.
107  array.markers.push_back(generateArrowMessage(pMarkerId, pFrom, pTo, pQualityOfMatch, 0.04, 0.1, 0.10));
108 
109  // Publish the markers.
110  pPublisher->publish(array);
111  }
112 
114  {
115  mBestStatus = pStatus;
116  }
117 
118  visualization_msgs::Marker KinematicChainVisualizer::generatePointMessage(unsigned int& pMarkerId,
119  const Eigen::Vector3d pPosition)
120  {
121  visualization_msgs::Marker msg;
122 
123  // Set time and frame id.
124  msg.header.stamp = ros::Time::now();
125  msg.header.frame_id = getFrameId();
126 
127  // Namespace will represent the nature of the message.
128  msg.ns = getNamespace();
129 
130  // Every sample has its own id.
131  msg.id = pMarkerId++;
132 
133  // Point is represented by a sphere.
134  msg.type = visualization_msgs::Marker::SPHERE;
135 
136  // We always want to show a marker by publishing ros messages here.
137  msg.action = visualization_msgs::Marker::ADD;
138 
139  // Draw the sphere at the given position.
140  msg.pose.position.x = pPosition[0] * getScaleFactor();
141  msg.pose.position.y = pPosition[1] * getScaleFactor();
142  msg.pose.position.z = pPosition[2] * getScaleFactor();
143 
144  // orientation is irrelevant.getScaleFactor
145  msg.pose.orientation.w = 1;
146  msg.pose.orientation.x = 0;
147  msg.pose.orientation.y = 0;
148  msg.pose.orientation.z = 0;
149 
150  // Spheres shall be very small, but must be scaled, too.
151  msg.scale.x = msg.scale.y = msg.scale.z = 0.05 * getScaleFactor();
152 
153  // Make it gray like the ISM visualization.
154  msg.color.r = 0.5;
155  msg.color.g = 0.5;
156  msg.color.b = 0.5;
157  msg.color.a = 0.7;
158 
159  // Return the point message.
160  return msg;
161  }
162 
163  visualization_msgs::Marker KinematicChainVisualizer::generateArrowMessage(unsigned int& pMarkerId,
164  const Eigen::Vector3d pFrom,
165  const Eigen::Vector3d pTo,
166  double pQualityOfMatch,
167  double pScalePeak,
168  double pScaleShaft,
169  double pPeakLength)
170  {
171  visualization_msgs::Marker msg;
172 
173  // Set time and frame id.
174  msg.header.stamp = ros::Time::now();
175  msg.header.frame_id = getFrameId();
176 
177  // Scale it to be very small and long.
178  msg.scale.x = pScalePeak;
179  msg.scale.y = pScaleShaft;
180  msg.scale.z = pPeakLength;
181 
182  // This should be an arrow.
183  msg.type = visualization_msgs::Marker::ARROW;
184 
185  // Namespace will represent the nature of the message.
186  // Yeah, it's really hard to find comments for every line...
187  msg.ns = getNamespace();
188 
189  // Markers with different namespaces but same id represent same object location distribution with different shapes.
190  msg.id = pMarkerId++;
191 
192  // We always want to show a marker by publishing ros messages here.
193  msg.action = visualization_msgs::Marker::ADD;
194 
195  // Create the starting point.
196  geometry_msgs::Point start;
197  start.x = pFrom[0] * getScaleFactor();
198  start.y = pFrom[1] * getScaleFactor();
199  start.z = pFrom[2] * getScaleFactor();
200  msg.points.push_back(start);
201 
202  // Create the end point.
203  geometry_msgs::Point stop;
204  stop.x = pTo[0] * getScaleFactor();
205  stop.y = pTo[1] * getScaleFactor();
206  stop.z = pTo[2] * getScaleFactor();
207  msg.points.push_back(stop);
208 
209  // The color depends on the certainty with that the object was detected.
210  // High certainty is green, high uncertainty is red!
211  msg.color.r = 1.0 - pQualityOfMatch;
212  msg.color.g = pQualityOfMatch;
213  msg.color.b = 0.0;
214  msg.color.a = 1.0;
215 
216  // Return the link message message.
217  return msg;
218  }
219 
220  visualization_msgs::Marker KinematicChainVisualizer::generatePerpendicularArrowMessage(unsigned int& pMarkerId,
221  const boost::shared_ptr<ISM::Pose> pPose,
222  double pQualityOfMatch,
223  double pLength)
224  {
225  // This is the point where the arrow starts.
226  Eigen::Vector3d from = pPose->point->getEigen();
227  Eigen::Vector3d to = pPose->point->getEigen();
228 
229  // The arrow should point along the z-axis.
230  from[2] -= 0.1 + pLength;
231  to[2] -= 0.1;
232 
233  // Generate the arrow message that symbolizes the link.
234  visualization_msgs::Marker msg = generateArrowMessage(pMarkerId, from, to, pQualityOfMatch, 0.055, 0.12, 0.05);
235 
236  // If it's not the the marker for the best scene object, make it gray.
237  if(!mBestStatus)
238  {
239  msg.color.r = msg.color.g = msg.color.b = 0.7;
240  msg.color.a = 0.0;
241  }
242  return msg;
243  }
244 
245  visualization_msgs::Marker KinematicChainVisualizer::generateTermIndicatorMessage(unsigned int& pMarkerId,
246  const boost::shared_ptr<ISM::Pose> pPose,
247  double pOffset,
248  double pScore)
249  {
250  visualization_msgs::Marker msg;
251 
252  // Set time and frame id.
253  msg.header.stamp = ros::Time::now();
254  msg.header.frame_id = getFrameId();
255 
256  // Namespace will represent the nature of the message.
257  msg.ns = getNamespace();
258 
259  // Every sample has its own id.
260  msg.id = pMarkerId++;
261 
262  // Point is represented by a sphere.
263  msg.type = visualization_msgs::Marker::SPHERE;
264 
265  // We always want to show a marker by publishing ros messages here.
266  msg.action = visualization_msgs::Marker::ADD;
267 
268  // Draw the sphere at the given position.
269  msg.pose.position.x = pPose->point->getEigen()[0] * getScaleFactor();
270  msg.pose.position.y = pPose->point->getEigen()[1] * getScaleFactor();
271  msg.pose.position.z = pPose->point->getEigen()[2] * getScaleFactor() - (0.2 + pOffset);
272 
273  // orientation is irrelevant.getScaleFactor
274  msg.pose.orientation.w = 1;
275  msg.pose.orientation.x = 0;
276  msg.pose.orientation.y = 0;
277  msg.pose.orientation.z = 0;
278 
279  // Spheres shall be very small, but must be scaled, too.
280  msg.scale.x = msg.scale.y = 0.05 * getScaleFactor();
281  msg.scale.z = 0.001 * getScaleFactor();
282 
283  // If it's not the the marker for the best scene object, make it gray.
284  if(mBestStatus)
285  {
286  msg.color.r = 1.0 - pScore;
287  msg.color.g = pScore;
288  msg.color.b = 0.0;
289  msg.color.a = 1.0;
290  } else {
291  msg.color.r = msg.color.g = msg.color.b = 0.7;
292  msg.color.a = 0.0;
293  }
294 
295  // Return the point message.
296  return msg;
297  }
298 
299 }
void publishObjectPositionAsPoint(boost::shared_ptr< ros::Publisher > pPublisher, unsigned int &pMarkerId, const boost::shared_ptr< ISM::Pose > pPose)
visualization_msgs::Marker generateArrowMessage(unsigned int &pMarkerId, const Eigen::Vector3d pFrom, const Eigen::Vector3d pTo, double pQualityOfMatch, double pScalePeak, double pScaleShaft, double pPeakLength)
void publishLink(boost::shared_ptr< ros::Publisher > pPublisher, unsigned int &pMarkerId, const Eigen::Vector3d pFrom, const Eigen::Vector3d pTo, double pQualityOfMatch)
visualization_msgs::Marker generateTermIndicatorMessage(unsigned int &pMarkerId, const boost::shared_ptr< ISM::Pose > pPose, double pOffset, double pScore)
void publishObjectPositionAsPointWithScore(boost::shared_ptr< ros::Publisher > pPublisher, unsigned int &pMarkerId, const boost::shared_ptr< ISM::Pose > pPose, std::vector< double > pScores, double pQualityOfMatch)
visualization_msgs::Marker generatePointMessage(unsigned int &pMarkerId, const Eigen::Vector3d pPosition)
visualization_msgs::Marker generatePerpendicularArrowMessage(unsigned int &pMarkerId, const boost::shared_ptr< ISM::Pose > pPose, double pQualityOfMatch, double pLength)
static Time now()
void publishObjectPositionAsArrow(boost::shared_ptr< ros::Publisher > pPublisher, unsigned int &pMarkerId, const boost::shared_ptr< ISM::Pose > pPose, double pQualityOfMatch)


asr_psm_visualizations
Author(s): Gehrung Joachim, Meißner Pascal
autogenerated on Sat Nov 9 2019 03:49:13