58 uchar* palette_ptr = palette.data();
60 for(
int i = 0; i <= 100; i++ )
62 uchar v = 255 - (255 * i) / 100;
69 for(
int i = 101; i <= 127; i++ )
77 for(
int i = 128; i <= 254; i++ )
80 *palette_ptr++ = (255*(i-128))/(254-128);
85 *palette_ptr++ = 0x70;
86 *palette_ptr++ = 0x89;
87 *palette_ptr++ = 0x86;
96 uchar* palette_ptr = palette.data();
105 for(
int i = 1; i <= 98; i++ )
107 uchar v = (255 * i) / 100;
110 *palette_ptr++ = 255 - v;
111 *palette_ptr++ = 255;
115 *palette_ptr++ = 255;
116 *palette_ptr++ = 255;
117 *palette_ptr++ = 255;
119 *palette_ptr++ = 255;
121 *palette_ptr++ = 255;
122 *palette_ptr++ = 255;
124 for(
int i = 101; i <= 127; i++ )
127 *palette_ptr++ = 255;
129 *palette_ptr++ = 255;
132 for(
int i = 128; i <= 254; i++ )
134 *palette_ptr++ = 255;
135 *palette_ptr++ = (255*(i-128))/(254-128);
137 *palette_ptr++ = 255;
140 *palette_ptr++ = 0x70;
141 *palette_ptr++ = 0x89;
142 *palette_ptr++ = 0x86;
143 *palette_ptr++ = 160;
150 OccupancyGridPlugin::OccupancyGridPlugin() :
151 config_widget_(new QWidget()),
161 p.setColor(QPalette::Background, Qt::white);
165 QPalette p3(
ui_.status->palette());
166 p3.setColor(QPalette::Text, Qt::red);
167 ui_.status->setPalette(p3);
171 QObject::connect(
ui_.topic_grid, SIGNAL(textEdited(
const QString&)),
this, SLOT(
TopicGridEdited()));
177 QObject::connect(
ui_.color_scheme, SIGNAL(currentTextChanged(
const QString &)),
this, SLOT(
colorSchemeUpdated(
const QString &)));
195 QPixmap icon(16, 16);
196 icon.fill(Qt::transparent);
198 QPainter painter(&icon);
199 painter.setRenderHint(QPainter::Antialiasing,
true);
204 pen.setCapStyle(Qt::SquareCap);
207 painter.drawLine(2, 2, 14, 2);
208 painter.drawLine(2, 2, 2, 14);
209 painter.drawLine(14, 2, 14, 14);
210 painter.drawLine(2, 14, 14, 14);
211 painter.drawLine(8, 2, 8, 14);
212 painter.drawLine(2, 8, 14, 8);
226 if (!topic.
name.empty())
228 QString str = QString::fromStdString(topic.
name);
229 ui_.topic_grid->setText( str);
237 const std::string topic =
ui_.topic_grid->text().trimmed().toStdString();
249 if(
ui_.checkbox_update)
253 ROS_INFO(
"Subscribing to %s", topic.c_str());
259 const std::string topic =
ui_.topic_grid->text().trimmed().toStdString();
262 if(
ui_.checkbox_update)
273 const size_t width =
grid_->info.width;
274 const size_t height =
grid_->info.height;
277 for (
size_t row = 0; row < height; row++)
279 for (
size_t col = 0; col < width; col++)
283 memcpy( &
color_buffer_[index*CHANNELS], &palette[color*CHANNELS], CHANNELS);
331 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
333 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
334 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
336 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
337 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
339 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
352 glBindTexture(GL_TEXTURE_2D, 0);
353 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
361 const int width =
grid_->info.width;
362 const int height =
grid_->info.height;
371 int32_t max_dimension = std::max(height, width);
381 color_buffer_.resize(texture_size_*texture_size_*CHANNELS, 0);
383 for (
size_t row = 0; row < height; row++)
385 for (
size_t col = 0; col < width; col++)
387 size_t index_src = (col + row*width);
389 uchar color =
static_cast<uchar
>(
grid_->data[ index_src ] );
391 memcpy( &
color_buffer_[index_dst*CHANNELS], &palette[color*CHANNELS], CHANNELS);
395 texture_x_ =
static_cast<float>(width) / static_cast<float>(texture_size_);
396 texture_y_ =
static_cast<float>(height) / static_cast<float>(texture_size_);
410 for (
size_t row = 0; row < msg->height; row++)
412 for (
size_t col = 0; col < msg->width; col++)
414 size_t index_src = (col + row * msg->width);
415 size_t index_dst = ( (col + msg->x) + (row + msg->y)*
texture_size_);
416 uchar color =
static_cast<uchar
>( msg->data[ index_src ] );
418 memcpy( &
color_buffer_[index_dst*CHANNELS], &palette[color*CHANNELS], CHANNELS);
431 double resolution =
grid_->info.resolution;
436 const double RAD_TO_DEG = 180.0 / M_PI;
442 glRotatef(pitch * RAD_TO_DEG, 0, 1, 0);
443 glRotatef(roll * RAD_TO_DEG, 1, 0, 0);
444 glRotatef(yaw * RAD_TO_DEG, 0, 0, 1);
446 glTranslatef(
grid_->info.origin.position.x,
447 grid_->info.origin.position.y,
450 glScalef( resolution, resolution, 1.0);
452 float width =
static_cast<float>(
grid_->info.width);
453 float height =
static_cast<float>(
grid_->info.height);
455 glEnable(GL_TEXTURE_2D);
457 glBegin(GL_TRIANGLES);
459 glColor4f(1.0
f, 1.0
f, 1.0
f,
ui_.alpha->value() );
464 glVertex2d(width, 0);
466 glVertex2d(width, height);
471 glVertex2d(width, height);
473 glVertex2d(0, height);
477 glBindTexture(GL_TEXTURE_2D, 0);
478 glDisable(GL_TEXTURE_2D);
506 node[
"topic"] >> topic;
507 ui_.topic_grid->setText(QString::fromStdString(topic));
513 node[
"update"] >> checked;
514 ui_.checkbox_update->setChecked( checked );
520 node[
"alpha"] >> alpha;
521 ui_.alpha->setValue(alpha);
527 node[
"scheme"] >> scheme;
528 int index =
ui_.color_scheme->findText(QString::fromStdString(scheme), Qt::MatchExactly);
531 ui_.color_scheme->setCurrentIndex(index);
541 emitter << YAML::Key <<
"alpha" << YAML::Value <<
ui_.alpha->value();
542 emitter << YAML::Key <<
"topic" << YAML::Value <<
ui_.topic_grid->text().toStdString();
543 emitter << YAML::Key <<
"update" << YAML::Value <<
ui_.checkbox_update->isChecked();
544 emitter << YAML::Key <<
"scheme" << YAML::Value <<
ui_.color_scheme->currentText().toStdString();
bool GetTransform(const ros::Time &stamp, swri_transform_util::Transform &transform, bool use_latest_transforms=true)
void PrintWarning(const std::string &message)
static ros::master::TopicInfo selectTopic(const std::string &datatype, QWidget *parent=0)
void upgradeCheckBoxToggled(bool)
virtual ~OccupancyGridPlugin()
Ui::occupancy_grid_config ui_
Palette makeCostmapPalette()
void transform(Route &route, const swri_transform_util::Transform &transform, const std::string &target_frame)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void getEulerYPR(tfScalar &yaw, tfScalar &pitch, tfScalar &roll, unsigned int solution_number=1) const
void FrameChanged(std::string)
std::vector< uchar > color_buffer_
static void PrintWarningHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
static void PrintErrorHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
nav_msgs::OccupancyGridConstPtr grid_
TFSIMD_FORCE_INLINE const tfScalar & getY() const
std::string target_frame_
void PrintError(const std::string &message)
static void PrintInfoHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
std::string source_frame_
swri_transform_util::Transform transform_
std::array< uchar, 256 *4 > Palette
void colorSchemeUpdated(const QString &)
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
void LoadConfig(const YAML::Node &node, const std::string &path)
void Callback(const nav_msgs::OccupancyGridConstPtr &msg)
void PrintInfo(const std::string &message)
void TargetFrameChanged(const std::string &target_frame)
ros::Subscriber grid_sub_
QWidget * GetConfigWidget(QWidget *parent)
bool Initialize(QGLWidget *canvas)
void Draw(double x, double y, double scale)
std::vector< uchar > raw_buffer_
ros::Subscriber update_sub_
TFSIMD_FORCE_INLINE const tfScalar & getX() const
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void CallbackUpdate(const map_msgs::OccupancyGridUpdateConstPtr &msg)