35 #ifndef JSK_RVIZ_PLUGINS_BOUDNING_BOX_DISPLAY_COMMON_H_
36 #define JSK_RVIZ_PLUGINS_BOUDNING_BOX_DISPLAY_COMMON_H_
40 #include <jsk_recognition_msgs/BoundingBoxArray.h>
41 #include <jsk_topic_tools/color_utils.h>
50 #include <OGRE/OgreSceneManager.h>
51 #include <OGRE/OgreSceneNode.h>
57 template <
class MessageType>
63 #if ROS_VERSION_MINIMUM(1,12,0)
64 typedef std::shared_ptr<rviz::Shape>
ShapePtr;
66 typedef std::shared_ptr<rviz::Arrow>
ArrowPtr;
85 std::vector<BillboardLinePtr>
edges_;
90 const jsk_recognition_msgs::BoundingBox& box,
95 std_msgs::ColorRGBA ros_color = jsk_topic_tools::colorCategory20(index);
96 return QColor(ros_color.r * 255.0,
105 std_msgs::ColorRGBA ros_color = jsk_topic_tools::colorCategory20(box.label);
106 return QColor(ros_color.r * 255.0,
109 ros_color.a * 255.0);
112 if (min_value != max_value) {
113 std_msgs::ColorRGBA ros_color = jsk_topic_tools::heatColor((box.value - min_value) / (max_value - min_value));
114 return QColor(ros_color.r * 255.0,
117 ros_color.a * 255.0);
120 return QColor(255.0, 255.0, 255.0, 255.0);
123 double getAlpha(
const jsk_recognition_msgs::BoundingBox& box)
137 const jsk_recognition_msgs::BoundingBox box_msg)
140 if (box_msg.dimensions.x < 1.0e-9 ||
141 box_msg.dimensions.y < 1.0e-9 ||
142 box_msg.dimensions.z < 1.0e-9 ||
143 std::isnan(box_msg.dimensions.x) ||
144 std::isnan(box_msg.dimensions.y) ||
145 std::isnan(box_msg.dimensions.z) ||
146 box_msg.header.frame_id.empty()) {
155 for (
size_t i =
shapes_.size(); i <
num; i++) {
170 if (num >
edges_.size()) {
171 for (
size_t i =
edges_.size(); i < num; i++) {
177 else if (num <
edges_.size())
187 Ogre::SceneNode* scene_node = this->
scene_node_->createChildSceneNode();
188 std::vector<ArrowPtr> coord;
189 for (
int i = 0; i < 3; i++) {
191 coord.push_back(arrow);
211 const jsk_recognition_msgs::BoundingBoxArray::ConstPtr& msg)
214 float min_value = DBL_MAX;
215 float max_value = -DBL_MAX;
217 std::vector<int> box_indices;
218 std::vector<jsk_recognition_msgs::BoundingBox> boxes;
219 for (
size_t i = 0; i <
msg->boxes.size(); i++) {
220 jsk_recognition_msgs::BoundingBox box =
msg->boxes[i];
225 boxes.push_back(box);
226 box_indices.push_back(i);
227 min_value = std::min(min_value,
msg->boxes[i].value);
228 max_value = std::max(max_value,
msg->boxes[i].value);
233 box.dimensions.x, box.dimensions.y, box.dimensions.z);
239 for (
size_t i = 0; i < boxes.size(); i++) {
240 jsk_recognition_msgs::BoundingBox box = boxes[i];
242 Ogre::Vector3 position;
243 Ogre::Quaternion orientation;
245 box.header, box.pose, position, orientation)) {
246 std::ostringstream oss;
247 oss <<
"Error transforming pose";
248 oss <<
" from frame '" << box.header.frame_id <<
"'";
249 oss <<
" to frame '" << qPrintable(this->
fixed_frame_) <<
"'";
262 shape->setPosition(position);
263 shape->setOrientation(orientation);
264 Ogre::Vector3 dimensions;
265 dimensions[0] = box.dimensions.x;
266 dimensions[1] = box.dimensions.y;
267 dimensions[2] = box.dimensions.z;
268 shape->setScale(dimensions);
269 QColor color =
getColor(box_indices[i], box, min_value, max_value);
270 shape->setColor(color.red() / 255.0,
271 color.green() / 255.0,
272 color.blue() / 255.0,
278 const jsk_recognition_msgs::BoundingBoxArray::ConstPtr& msg)
281 float min_value = DBL_MAX;
282 float max_value = -DBL_MAX;
284 std::vector<int> box_indices;
285 std::vector<jsk_recognition_msgs::BoundingBox> boxes;
286 for (
size_t i = 0; i <
msg->boxes.size(); i++) {
287 jsk_recognition_msgs::BoundingBox box =
msg->boxes[i];
292 boxes.push_back(box);
293 box_indices.push_back(i);
294 min_value = std::min(min_value,
msg->boxes[i].value);
295 max_value = std::max(max_value,
msg->boxes[i].value);
299 ROS_WARN_THROTTLE(10,
"Invalid size of bounding box is included and skipped: [%f, %f, %f]",
300 box.dimensions.x, box.dimensions.y, box.dimensions.z);
306 for (
size_t i = 0; i < boxes.size(); i++) {
307 jsk_recognition_msgs::BoundingBox box = boxes[i];
308 geometry_msgs::Vector3 dimensions = box.dimensions;
312 Ogre::Vector3 position;
313 Ogre::Quaternion quaternion;
317 std::ostringstream oss;
318 oss <<
"Error transforming pose";
319 oss <<
" from frame '" << box.header.frame_id <<
"'";
320 oss <<
" to frame '" << qPrintable(this->
fixed_frame_) <<
"'";
325 edge->setPosition(position);
326 edge->setOrientation(quaternion);
328 edge->setMaxPointsPerLine(2);
329 edge->setNumLines(12);
331 QColor color =
getColor(box_indices[i], box, min_value, max_value);
332 edge->setColor(color.red() / 255.0,
333 color.green() / 255.0,
334 color.blue() / 255.0,
337 Ogre::Vector3
A, B, C, D, E, F, G, H;
338 A[0] = dimensions.x / 2.0;
339 A[1] = dimensions.y / 2.0;
340 A[2] = dimensions.z / 2.0;
341 B[0] = - dimensions.x / 2.0;
342 B[1] = dimensions.y / 2.0;
343 B[2] = dimensions.z / 2.0;
344 C[0] = - dimensions.x / 2.0;
345 C[1] = - dimensions.y / 2.0;
346 C[2] = dimensions.z / 2.0;
347 D[0] = dimensions.x / 2.0;
348 D[1] = - dimensions.y / 2.0;
349 D[2] = dimensions.z / 2.0;
351 E[0] = dimensions.x / 2.0;
352 E[1] = dimensions.y / 2.0;
353 E[2] = - dimensions.z / 2.0;
354 F[0] = - dimensions.x / 2.0;
355 F[1] = dimensions.y / 2.0;
356 F[2] = - dimensions.z / 2.0;
357 G[0] = - dimensions.x / 2.0;
358 G[1] = - dimensions.y / 2.0;
359 G[2] = - dimensions.z / 2.0;
360 H[0] = dimensions.x / 2.0;
361 H[1] = - dimensions.y / 2.0;
362 H[2] = - dimensions.z / 2.0;
364 edge->addPoint(
A); edge->addPoint(B); edge->newLine();
365 edge->addPoint(B); edge->addPoint(C); edge->newLine();
366 edge->addPoint(C); edge->addPoint(D); edge->newLine();
367 edge->addPoint(D); edge->addPoint(
A); edge->newLine();
368 edge->addPoint(E); edge->addPoint(F); edge->newLine();
369 edge->addPoint(F); edge->addPoint(G); edge->newLine();
370 edge->addPoint(G); edge->addPoint(H); edge->newLine();
371 edge->addPoint(H); edge->addPoint(E); edge->newLine();
372 edge->addPoint(
A); edge->addPoint(E); edge->newLine();
373 edge->addPoint(B); edge->addPoint(F); edge->newLine();
374 edge->addPoint(C); edge->addPoint(G); edge->newLine();
375 edge->addPoint(D); edge->addPoint(H);
380 const jsk_recognition_msgs::BoundingBoxArray::ConstPtr& msg)
382 std::vector<jsk_recognition_msgs::BoundingBox> boxes;
383 for (
size_t i = 0; i <
msg->boxes.size(); i++) {
384 jsk_recognition_msgs::BoundingBox box =
msg->boxes[i];
386 boxes.push_back(box);
390 ROS_WARN_THROTTLE(10,
"Invalid size of bounding box is included and skipped: [%f, %f, %f]",
391 box.dimensions.x, box.dimensions.y, box.dimensions.z);
395 for (
size_t i = 0; i < boxes.size(); i++) {
396 jsk_recognition_msgs::BoundingBox box = boxes[i];
400 scene_node->setVisible(
true);
401 Ogre::Vector3 position;
402 Ogre::Quaternion orientation;
404 box.header, position, orientation)) {
405 ROS_DEBUG(
"Error transforming from frame '%s' to frame '%s'",
406 box.header.frame_id.c_str(), qPrintable(this->
fixed_frame_));
409 scene_node->setPosition(position);
410 scene_node->setOrientation(orientation);
412 float color[3][3] = {{1, 0, 0},
415 for (
int j = 0; j < 3; j++) {
418 if (color[j][0] == 1) {
419 scale = Ogre::Vector3(
421 std::min(box.dimensions.y, box.dimensions.z),
422 std::min(box.dimensions.y, box.dimensions.z));
424 if (color[j][1] == 1) {
425 scale = Ogre::Vector3(
427 std::min(box.dimensions.x, box.dimensions.z),
428 std::min(box.dimensions.x, box.dimensions.z));
430 if (color[j][2] == 1) {
431 scale = Ogre::Vector3(
433 std::min(box.dimensions.x, box.dimensions.y),
434 std::min(box.dimensions.x, box.dimensions.y));
437 Ogre::Vector3 direction(color[j][0], color[j][1], color[j][2]);
438 Ogre::Vector3
pos(box.pose.position.x,
440 box.pose.position.z);
441 Ogre::Quaternion qua(box.pose.orientation.w,
442 box.pose.orientation.x,
443 box.pose.orientation.y,
444 box.pose.orientation.z);
445 direction = qua * direction;
446 Ogre::ColourValue rgba;
448 rgba.r = color[j][0];
449 rgba.g = color[j][1];
450 rgba.b = color[j][2];
453 arrow->setPosition(
pos);
454 arrow->setDirection(direction);
455 arrow->setScale(
scale);
456 arrow->setColor(rgba);
472 #endif // JSK_RVIZ_PLUGINS_BOUDNING_BOX_DISPLAY_COMMON_H_