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> 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,
90 if (coloring_method_ ==
"auto") {
92 return QColor(ros_color.r * 255.0,
97 else if (coloring_method_ ==
"flat") {
100 else if (coloring_method_ ==
"label") {
102 return QColor(ros_color.r * 255.0,
105 ros_color.a * 255.0);
107 else if (coloring_method_ ==
"value") {
108 if (min_value != max_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()) {
137 if (num > shapes_.size()) {
138 for (
size_t i = shapes_.size(); i < num; i++) {
142 shapes_.push_back(shape);
145 else if (num < shapes_.size())
153 if (num > edges_.size()) {
154 for (
size_t i = edges_.size(); i < num; i++) {
157 edges_.push_back(line);
160 else if (num < edges_.size())
168 if (num > coords_objects_.size()) {
169 for (
size_t i = coords_objects_.size(); i < num; i++) {
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);
176 coords_nodes_.push_back(scene_node);
177 coords_objects_.push_back(coord);
180 else if (num < coords_objects_.size()) {
181 for (
size_t i = num; i < coords_objects_.size(); i++) {
186 coords_nodes_[i]->setVisible(
false);
188 coords_objects_.resize(num);
189 coords_nodes_.resize(num);
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];
216 ShapePtr shape = shapes_[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;
278 BillboardLinePtr edge = edges_[i];
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);
298 edge->setLineWidth(line_width_);
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];
365 std::vector<ArrowPtr> coord = coords_objects_[i];
367 Ogre::SceneNode* scene_node = coords_nodes_[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];
420 ArrowPtr arrow = coords_objects_[i][j];
421 arrow->setPosition(pos);
422 arrow->setDirection(direction);
423 arrow->setScale(scale);
424 arrow->setColor(rgba);
431 for (
size_t i = 0; i < coords_nodes_.size(); i++) {
432 coords_nodes_[i]->setVisible(
false);
440 #endif // JSK_RVIZ_PLUGINS_BOUDNING_BOX_DISPLAY_COMMON_H_ void allocateShapes(int num)
boost::shared_ptr< rviz::Shape > ShapePtr
void allocateBillboardLines(int num)
bool isValidBoundingBox(const jsk_recognition_msgs::BoundingBox box_msg)
void allocateCoords(int num)
DisplayContext * context_
std::string coloring_method_
QColor getColor(size_t index, const jsk_recognition_msgs::BoundingBox &box, double min_value, double max_value)
Ogre::SceneNode * scene_node_
boost::shared_ptr< rviz::BillboardLine > BillboardLinePtr
std::vector< ShapePtr > shapes_
#define ROS_WARN_THROTTLE(period,...)
bool transform(const Header &header, const geometry_msgs::Pose &pose, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
virtual FrameManager * getFrameManager() const=0
Ogre::SceneManager * scene_manager_
std::vector< BillboardLinePtr > edges_
virtual Ogre::SceneManager * getSceneManager() const=0
void showCoords(const jsk_recognition_msgs::BoundingBoxArray::ConstPtr &msg)
void showBoxes(const jsk_recognition_msgs::BoundingBoxArray::ConstPtr &msg)
~BoundingBoxDisplayCommon()
void showEdges(const jsk_recognition_msgs::BoundingBoxArray::ConstPtr &msg)
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
#define ROS_ERROR_STREAM(args)
BoundingBoxDisplayCommon()
boost::shared_ptr< rviz::Arrow > ArrowPtr
std::vector< Ogre::SceneNode * > coords_nodes_
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
std::vector< std::vector< ArrowPtr > > coords_objects_