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;
81 std::vector<BillboardLinePtr>
edges_;
86 const jsk_recognition_msgs::BoundingBox& box,
91 std_msgs::ColorRGBA ros_color = jsk_topic_tools::colorCategory20(index);
92 return QColor(ros_color.r * 255.0,
101 std_msgs::ColorRGBA ros_color = jsk_topic_tools::colorCategory20(box.label);
102 return QColor(ros_color.r * 255.0,
105 ros_color.a * 255.0);
108 if (min_value != max_value) {
109 std_msgs::ColorRGBA ros_color = jsk_topic_tools::heatColor((box.value - min_value) / (max_value - min_value));
110 return QColor(ros_color.r * 255.0,
113 ros_color.a * 255.0);
116 return QColor(255.0, 255.0, 255.0, 255.0);
120 const jsk_recognition_msgs::BoundingBox box_msg)
123 if (box_msg.dimensions.x < 1.0e-9 ||
124 box_msg.dimensions.y < 1.0e-9 ||
125 box_msg.dimensions.z < 1.0e-9 ||
126 std::isnan(box_msg.dimensions.x) ||
127 std::isnan(box_msg.dimensions.y) ||
128 std::isnan(box_msg.dimensions.z) ||
129 box_msg.header.frame_id.empty()) {
138 for (
size_t i =
shapes_.size(); i < num; i++) {
154 for (
size_t i =
edges_.size(); i <
num; i++) {
160 else if (num <
edges_.size())
170 Ogre::SceneNode* scene_node = this->
scene_node_->createChildSceneNode();
171 std::vector<ArrowPtr> coord;
172 for (
int i = 0; i < 3; i++) {
174 coord.push_back(arrow);
194 const jsk_recognition_msgs::BoundingBoxArray::ConstPtr& msg)
197 float min_value = DBL_MAX;
198 float max_value = -DBL_MAX;
199 std::vector<jsk_recognition_msgs::BoundingBox> boxes;
200 for (
size_t i = 0; i <
msg->boxes.size(); i++) {
201 jsk_recognition_msgs::BoundingBox box =
msg->boxes[i];
203 boxes.push_back(box);
204 min_value = std::min(min_value,
msg->boxes[i].value);
205 max_value = std::max(max_value,
msg->boxes[i].value);
209 ROS_WARN_THROTTLE(10,
"Invalid size of bounding box is included and skipped: [%f, %f, %f]",
210 box.dimensions.x, box.dimensions.y, box.dimensions.z);
214 for (
size_t i = 0; i < boxes.size(); i++) {
215 jsk_recognition_msgs::BoundingBox box = boxes[i];
217 Ogre::Vector3 position;
218 Ogre::Quaternion orientation;
220 box.header, box.pose, position, orientation)) {
221 std::ostringstream oss;
222 oss <<
"Error transforming pose";
223 oss <<
" from frame '" << box.header.frame_id <<
"'";
224 oss <<
" to frame '" << qPrintable(this->
fixed_frame_) <<
"'";
237 shape->setPosition(position);
238 shape->setOrientation(orientation);
239 Ogre::Vector3 dimensions;
240 dimensions[0] = box.dimensions.x;
241 dimensions[1] = box.dimensions.y;
242 dimensions[2] = box.dimensions.z;
243 shape->setScale(dimensions);
244 QColor color =
getColor(i, box, min_value, max_value);
245 shape->setColor(color.red() / 255.0,
246 color.green() / 255.0,
247 color.blue() / 255.0,
253 const jsk_recognition_msgs::BoundingBoxArray::ConstPtr& msg)
256 float min_value = DBL_MAX;
257 float max_value = -DBL_MAX;
258 std::vector<jsk_recognition_msgs::BoundingBox> boxes;
259 for (
size_t i = 0; i <
msg->boxes.size(); i++) {
260 jsk_recognition_msgs::BoundingBox box =
msg->boxes[i];
262 boxes.push_back(box);
263 min_value = std::min(min_value,
msg->boxes[i].value);
264 max_value = std::max(max_value,
msg->boxes[i].value);
268 ROS_WARN_THROTTLE(10,
"Invalid size of bounding box is included and skipped: [%f, %f, %f]",
269 box.dimensions.x, box.dimensions.y, box.dimensions.z);
274 for (
size_t i = 0; i < boxes.size(); i++) {
275 jsk_recognition_msgs::BoundingBox box = boxes[i];
276 geometry_msgs::Vector3 dimensions = box.dimensions;
280 Ogre::Vector3 position;
281 Ogre::Quaternion quaternion;
285 std::ostringstream oss;
286 oss <<
"Error transforming pose";
287 oss <<
" from frame '" << box.header.frame_id <<
"'";
288 oss <<
" to frame '" << qPrintable(this->
fixed_frame_) <<
"'";
293 edge->setPosition(position);
294 edge->setOrientation(quaternion);
296 edge->setMaxPointsPerLine(2);
297 edge->setNumLines(12);
299 QColor color =
getColor(i, box, min_value, max_value);
300 edge->setColor(color.red() / 255.0,
301 color.green() / 255.0,
302 color.blue() / 255.0,
305 Ogre::Vector3
A, B, C, D, E, F, G, H;
306 A[0] = dimensions.x / 2.0;
307 A[1] = dimensions.y / 2.0;
308 A[2] = dimensions.z / 2.0;
309 B[0] = - dimensions.x / 2.0;
310 B[1] = dimensions.y / 2.0;
311 B[2] = dimensions.z / 2.0;
312 C[0] = - dimensions.x / 2.0;
313 C[1] = - dimensions.y / 2.0;
314 C[2] = dimensions.z / 2.0;
315 D[0] = dimensions.x / 2.0;
316 D[1] = - dimensions.y / 2.0;
317 D[2] = dimensions.z / 2.0;
319 E[0] = dimensions.x / 2.0;
320 E[1] = dimensions.y / 2.0;
321 E[2] = - dimensions.z / 2.0;
322 F[0] = - dimensions.x / 2.0;
323 F[1] = dimensions.y / 2.0;
324 F[2] = - dimensions.z / 2.0;
325 G[0] = - dimensions.x / 2.0;
326 G[1] = - dimensions.y / 2.0;
327 G[2] = - dimensions.z / 2.0;
328 H[0] = dimensions.x / 2.0;
329 H[1] = - dimensions.y / 2.0;
330 H[2] = - dimensions.z / 2.0;
332 edge->addPoint(
A); edge->addPoint(B); edge->newLine();
333 edge->addPoint(B); edge->addPoint(C); edge->newLine();
334 edge->addPoint(C); edge->addPoint(D); edge->newLine();
335 edge->addPoint(D); edge->addPoint(
A); edge->newLine();
336 edge->addPoint(E); edge->addPoint(F); edge->newLine();
337 edge->addPoint(F); edge->addPoint(G); edge->newLine();
338 edge->addPoint(G); edge->addPoint(H); edge->newLine();
339 edge->addPoint(H); edge->addPoint(E); edge->newLine();
340 edge->addPoint(
A); edge->addPoint(E); edge->newLine();
341 edge->addPoint(B); edge->addPoint(F); edge->newLine();
342 edge->addPoint(C); edge->addPoint(G); edge->newLine();
343 edge->addPoint(D); edge->addPoint(H);
348 const jsk_recognition_msgs::BoundingBoxArray::ConstPtr& msg)
350 std::vector<jsk_recognition_msgs::BoundingBox> boxes;
351 for (
size_t i = 0; i <
msg->boxes.size(); i++) {
352 jsk_recognition_msgs::BoundingBox box =
msg->boxes[i];
354 boxes.push_back(box);
358 ROS_WARN_THROTTLE(10,
"Invalid size of bounding box is included and skipped: [%f, %f, %f]",
359 box.dimensions.x, box.dimensions.y, box.dimensions.z);
363 for (
size_t i = 0; i < boxes.size(); i++) {
364 jsk_recognition_msgs::BoundingBox box = boxes[i];
368 scene_node->setVisible(
true);
369 Ogre::Vector3 position;
370 Ogre::Quaternion orientation;
372 box.header, position, orientation)) {
373 ROS_DEBUG(
"Error transforming from frame '%s' to frame '%s'",
374 box.header.frame_id.c_str(), qPrintable(this->
fixed_frame_));
377 scene_node->setPosition(position);
378 scene_node->setOrientation(orientation);
380 float color[3][3] = {{1, 0, 0},
383 for (
int j = 0; j < 3; j++) {
386 if (color[j][0] == 1) {
387 scale = Ogre::Vector3(
389 std::min(box.dimensions.y, box.dimensions.z),
390 std::min(box.dimensions.y, box.dimensions.z));
392 if (color[j][1] == 1) {
393 scale = Ogre::Vector3(
395 std::min(box.dimensions.x, box.dimensions.z),
396 std::min(box.dimensions.x, box.dimensions.z));
398 if (color[j][2] == 1) {
399 scale = Ogre::Vector3(
401 std::min(box.dimensions.x, box.dimensions.y),
402 std::min(box.dimensions.x, box.dimensions.y));
405 Ogre::Vector3 direction(color[j][0], color[j][1], color[j][2]);
406 Ogre::Vector3
pos(box.pose.position.x,
408 box.pose.position.z);
409 Ogre::Quaternion qua(box.pose.orientation.w,
410 box.pose.orientation.x,
411 box.pose.orientation.y,
412 box.pose.orientation.z);
413 direction = qua * direction;
414 Ogre::ColourValue rgba;
416 rgba.r = color[j][0];
417 rgba.g = color[j][1];
418 rgba.b = color[j][2];
421 arrow->setPosition(
pos);
422 arrow->setDirection(direction);
423 arrow->setScale(
scale);
424 arrow->setColor(rgba);
440 #endif // JSK_RVIZ_PLUGINS_BOUDNING_BOX_DISPLAY_COMMON_H_