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)) {
136 if (num > shapes_.size()) {
137 for (
size_t i = shapes_.size(); i < num; i++) {
141 shapes_.push_back(shape);
144 else if (num < shapes_.size())
152 if (num > edges_.size()) {
153 for (
size_t i = edges_.size(); i < num; i++) {
156 edges_.push_back(line);
159 else if (num < edges_.size())
167 if (num > coords_objects_.size()) {
168 for (
size_t i = coords_objects_.size(); i < num; i++) {
169 Ogre::SceneNode* scene_node = this->
scene_node_->createChildSceneNode();
170 std::vector<ArrowPtr> coord;
171 for (
int i = 0; i < 3; i++) {
173 coord.push_back(arrow);
175 coords_nodes_.push_back(scene_node);
176 coords_objects_.push_back(coord);
179 else if (num < coords_objects_.size()) {
180 for (
size_t i = num; i < coords_objects_.size(); i++) {
185 coords_nodes_[i]->setVisible(
false);
187 coords_objects_.resize(num);
188 coords_nodes_.resize(num);
193 const jsk_recognition_msgs::BoundingBoxArray::ConstPtr& msg)
197 float min_value = DBL_MAX;
198 float max_value = -DBL_MAX;
199 for (
size_t i = 0; i < msg->boxes.size(); i++) {
200 min_value = std::min(min_value, msg->boxes[i].value);
201 max_value = std::max(max_value, msg->boxes[i].value);
203 for (
size_t i = 0; i < msg->boxes.size(); i++) {
204 jsk_recognition_msgs::BoundingBox box = msg->boxes[i];
206 ROS_WARN_THROTTLE(10,
"Invalid size of bounding box is included and skipped: [%f, %f, %f]",
207 box.dimensions.x, box.dimensions.y, box.dimensions.z);
211 ShapePtr shape = shapes_[i];
212 Ogre::Vector3 position;
213 Ogre::Quaternion orientation;
215 box.header, box.pose, position, orientation)) {
216 std::ostringstream oss;
217 oss <<
"Error transforming pose";
218 oss <<
" from frame '" << box.header.frame_id <<
"'";
219 oss <<
" to frame '" << qPrintable(this->
fixed_frame_) <<
"'";
232 shape->setPosition(position);
233 shape->setOrientation(orientation);
234 Ogre::Vector3 dimensions;
235 dimensions[0] = box.dimensions.x;
236 dimensions[1] = box.dimensions.y;
237 dimensions[2] = box.dimensions.z;
238 shape->setScale(dimensions);
239 QColor color =
getColor(i, box, min_value, max_value);
240 shape->setColor(color.red() / 255.0,
241 color.green() / 255.0,
242 color.blue() / 255.0,
248 const jsk_recognition_msgs::BoundingBoxArray::ConstPtr& msg)
252 float min_value = DBL_MAX;
253 float max_value = -DBL_MAX;
254 for (
size_t i = 0; i < msg->boxes.size(); i++) {
255 min_value = std::min(min_value, msg->boxes[i].value);
256 max_value = std::max(max_value, msg->boxes[i].value);
259 for (
size_t i = 0; i < msg->boxes.size(); i++) {
260 jsk_recognition_msgs::BoundingBox box = msg->boxes[i];
262 ROS_WARN_THROTTLE(10,
"Invalid size of bounding box is included and skipped: [%f, %f, %f]",
263 box.dimensions.x, box.dimensions.y, box.dimensions.z);
267 geometry_msgs::Vector3 dimensions = box.dimensions;
269 BillboardLinePtr edge = edges_[i];
271 Ogre::Vector3 position;
272 Ogre::Quaternion quaternion;
276 std::ostringstream oss;
277 oss <<
"Error transforming pose";
278 oss <<
" from frame '" << box.header.frame_id <<
"'";
279 oss <<
" to frame '" << qPrintable(this->
fixed_frame_) <<
"'";
284 edge->setPosition(position);
285 edge->setOrientation(quaternion);
287 edge->setMaxPointsPerLine(2);
288 edge->setNumLines(12);
289 edge->setLineWidth(line_width_);
290 QColor color =
getColor(i, box, min_value, max_value);
291 edge->setColor(color.red() / 255.0,
292 color.green() / 255.0,
293 color.blue() / 255.0,
296 Ogre::Vector3
A, B, C, D, E, F, G, H;
297 A[0] = dimensions.x / 2.0;
298 A[1] = dimensions.y / 2.0;
299 A[2] = dimensions.z / 2.0;
300 B[0] = - dimensions.x / 2.0;
301 B[1] = dimensions.y / 2.0;
302 B[2] = dimensions.z / 2.0;
303 C[0] = - dimensions.x / 2.0;
304 C[1] = - dimensions.y / 2.0;
305 C[2] = dimensions.z / 2.0;
306 D[0] = dimensions.x / 2.0;
307 D[1] = - dimensions.y / 2.0;
308 D[2] = dimensions.z / 2.0;
310 E[0] = dimensions.x / 2.0;
311 E[1] = dimensions.y / 2.0;
312 E[2] = - dimensions.z / 2.0;
313 F[0] = - dimensions.x / 2.0;
314 F[1] = dimensions.y / 2.0;
315 F[2] = - dimensions.z / 2.0;
316 G[0] = - dimensions.x / 2.0;
317 G[1] = - dimensions.y / 2.0;
318 G[2] = - dimensions.z / 2.0;
319 H[0] = dimensions.x / 2.0;
320 H[1] = - dimensions.y / 2.0;
321 H[2] = - dimensions.z / 2.0;
323 edge->addPoint(A); edge->addPoint(B); edge->newLine();
324 edge->addPoint(B); edge->addPoint(C); edge->newLine();
325 edge->addPoint(C); edge->addPoint(D); edge->newLine();
326 edge->addPoint(D); edge->addPoint(A); edge->newLine();
327 edge->addPoint(E); edge->addPoint(F); edge->newLine();
328 edge->addPoint(F); edge->addPoint(G); edge->newLine();
329 edge->addPoint(G); edge->addPoint(H); edge->newLine();
330 edge->addPoint(H); edge->addPoint(E); edge->newLine();
331 edge->addPoint(A); edge->addPoint(E); edge->newLine();
332 edge->addPoint(B); edge->addPoint(F); edge->newLine();
333 edge->addPoint(C); edge->addPoint(G); edge->newLine();
334 edge->addPoint(D); edge->addPoint(H);
339 const jsk_recognition_msgs::BoundingBoxArray::ConstPtr& msg)
342 for (
size_t i = 0; i < msg->boxes.size(); i++) {
343 jsk_recognition_msgs::BoundingBox box = msg->boxes[i];
344 std::vector<ArrowPtr> coord = coords_objects_[i];
346 Ogre::SceneNode* scene_node = coords_nodes_[i];
347 scene_node->setVisible(
true);
348 Ogre::Vector3 position;
349 Ogre::Quaternion orientation;
351 box.header, position, orientation)) {
352 ROS_DEBUG(
"Error transforming from frame '%s' to frame '%s'",
353 box.header.frame_id.c_str(), qPrintable(this->
fixed_frame_));
356 scene_node->setPosition(position);
357 scene_node->setOrientation(orientation);
359 float color[3][3] = {{1, 0, 0},
362 for (
int j = 0; j < 3; j++) {
365 if (color[j][0] == 1) {
366 scale = Ogre::Vector3(
368 std::min(box.dimensions.y, box.dimensions.z),
369 std::min(box.dimensions.y, box.dimensions.z));
371 if (color[j][1] == 1) {
372 scale = Ogre::Vector3(
374 std::min(box.dimensions.x, box.dimensions.z),
375 std::min(box.dimensions.x, box.dimensions.z));
377 if (color[j][2] == 1) {
378 scale = Ogre::Vector3(
380 std::min(box.dimensions.x, box.dimensions.y),
381 std::min(box.dimensions.x, box.dimensions.y));
384 Ogre::Vector3 direction(color[j][0], color[j][1], color[j][2]);
385 Ogre::Vector3
pos(box.pose.position.x,
387 box.pose.position.z);
388 Ogre::Quaternion qua(box.pose.orientation.w,
389 box.pose.orientation.x,
390 box.pose.orientation.y,
391 box.pose.orientation.z);
392 direction = qua * direction;
393 Ogre::ColourValue rgba;
395 rgba.r = color[j][0];
396 rgba.g = color[j][1];
397 rgba.b = color[j][2];
399 ArrowPtr arrow = coords_objects_[i][j];
400 arrow->setPosition(pos);
401 arrow->setDirection(direction);
402 arrow->setScale(scale);
403 arrow->setColor(rgba);
410 for (
size_t i = 0; i < coords_nodes_.size(); i++) {
411 coords_nodes_[i]->setVisible(
false);
419 #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)
#define ROS_WARN_THROTTLE(rate,...)
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_
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_