Hello guys, I'm currently using LIDAR and an aerial vehicle. I'm stucked at this situation where I don't know how am I gonna find out the OccupancyGrid message data and how to use it and copy the map from the message data to mapImage (QImage). I'm a real amateur so... I really need obvious hints/help. Thanks a ton!



Qt Code:
  1. void QNode::parsemap(const nav_msgs::OccupancyGrid::ConstPtr& msg) {
  2. if (mapImage == NULL) {
  3. // copy map from message to mapImage.
  4. mapImage = new QImage(240, 350, QImage::Format_RGB888);
  5. }
  6. ...
  7. }
To copy to clipboard, switch view to plain text mode 


I've asked this on another forum and they gave me this, but I don't know how do I get around with it too...

"If you look at the OccupancyGrid message (i.e., rosmsg show nav_msgs/OccupancyGrid), there are member fields for width, height, and the binary data. There are multiple ways of creating a QImage given that data; I haven't run the following (you may need to futz with the cast of the msg->data), but you can do something like:

Qt Code:
  1. const unsigned char* databeg = &(msg->data.front());
  2. QImage img(databeg, msg->info.width, msg->info.height, QImage::Format_RGB888);
To copy to clipboard, switch view to plain text mode 

Note that there are additional considerations of which you must be aware. For instance, as stated in the QImage documentation, the data buffer must remain valid throughout the life of the QImage. So you might want to store the data, say as a QByteArray:

Qt Code:
  1. QByteArray m_data;
  2. ...
  3. void QNode::parsemap( const nav_msgs::OccupancyGrid::ConstPtr& msg ) {
  4. const unsigned char* databeg = &(msg->data.front());
  5. m_data = QByteArray(databeg, msg->data.size());
  6. QImage img((uchar*)m_data.data(), msg->info.width, msg->info.height, QImage::Format_RGB888);
  7. ...
  8. }
To copy to clipboard, switch view to plain text mode 

"


I've heard I needed to use Scanline to create the QImage, but I'm not sure how to really use it either. I've been trying to read up on QByteArray, QPixmap, Scanline(), and many more but I still don't get a single thing.. I'd really appreciate you guys' help.