41 #include <QFileDialog> 56 config_widget_(new QWidget()),
62 texture_loaded_(false),
69 p.setColor(QPalette::Background, Qt::white);
73 QPalette p3(
ui_.status->palette());
74 p3.setColor(QPalette::Text, Qt::red);
75 ui_.status->setPalette(p3);
79 QObject::connect(
ui_.browse, SIGNAL(clicked()),
this, SLOT(
SelectFile()));
80 QObject::connect(
ui_.selectframe, SIGNAL(clicked()),
this, SLOT(
SelectFrame()));
81 QObject::connect(
ui_.frame, SIGNAL(editingFinished()),
this, SLOT(
FrameEdited()));
82 QObject::connect(
ui_.image, SIGNAL(editingFinished()),
this, SLOT(
ImageEdited()));
83 QObject::connect(
ui_.width, SIGNAL(valueChanged(
double)),
this, SLOT(
WidthChanged(
double)));
84 QObject::connect(
ui_.height, SIGNAL(valueChanged(
double)),
this, SLOT(
HeightChanged(
double)));
85 QObject::connect(
ui_.offset_x, SIGNAL(valueChanged(
double)),
this, SLOT(
OffsetXChanged(
double)));
86 QObject::connect(
ui_.offset_y, SIGNAL(valueChanged(
double)),
this, SLOT(
OffsetYChanged(
double)));
87 ui_.offset_x->setMinimum(-99.99);
88 ui_.offset_y->setMinimum(-99.99);
101 dialog.setFileMode(QFileDialog::ExistingFile);
102 dialog.setNameFilter(tr(
"PNG Image Files (*.png)"));
106 if (dialog.result() == QDialog::Accepted && dialog.selectedFiles().count() == 1)
108 ui_.image->setText(dialog.selectedFiles().first());
109 filename_ = dialog.selectedFiles().first().toStdString();
119 ui_.frame->setText(QString::fromStdString(frame));
145 if(
ui_.ratio_equal->isChecked()){
148 else if(
ui_.ratio_original->isChecked()){
177 ui_.height->setEnabled(
false);
186 ui_.height->setEnabled(
true);
196 ui_.height->setEnabled(
false);
244 glColor3f(1.0
f, 1.0
f, 1.0
f);
245 glEnable(GL_TEXTURE_2D);
246 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(
texture_id_));
257 glDisable(GL_TEXTURE_2D);
294 glDeleteTextures(1, &ids[0]);
298 const std::string prefix =
"$(find ";
299 std::string real_filename;
301 bool has_close = spos != -1 ?
filename_.find(
')', spos) != -1:
false;
302 if (spos != -1 && spos + prefix.length() <
filename_.size() && has_close)
304 std::string
package = filename_.substr(spos + prefix.length());
305 package = package.substr(0, package.find(")"));
315 if (
image_.load(real_filename.c_str()))
317 int width =
image_.width();
318 int height =
image_.height();
321 float max_dim = std::max(width, height);
322 dimension_ =
static_cast<int>(std::pow(2, std::ceil(std::log(max_dim) / std::log(2.0
f))));
332 glGenTextures(1, &ids[0]);
335 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(
texture_id_));
338 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
339 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
341 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
342 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
345 if(
ui_.ratio_original->isChecked() )
355 catch (
const std::exception& e)
357 PrintError(
"Failed to load image. Exception occured.");
366 ui_.frame->setText(source_frame_.c_str());
368 if (node[
"offset_x"])
371 ui_.offset_x->setValue(offset_x_);
374 if (node[
"offset_y"])
377 ui_.offset_y->setValue(offset_y_);
383 ui_.image->setText(filename_.c_str());
389 ui_.width->setValue(width_);
395 ui_.height->setValue(height_);
401 node[
"ratio"] >> value;
404 ui_.ratio_equal->setChecked(
true);
406 else if(value ==
"custom")
408 ui_.ratio_custom->setChecked(
true);
410 else if(value ==
"original")
412 ui_.ratio_original->setChecked(
true);
423 emitter << YAML::Key <<
"frame" << YAML::Value <<
ui_.frame->text().toStdString();
424 emitter << YAML::Key <<
"image" << YAML::Value <<
ui_.image->text().toStdString();
425 emitter << YAML::Key <<
"width" << YAML::Value <<
width_;
426 emitter << YAML::Key <<
"height" << YAML::Value <<
height_;
427 emitter << YAML::Key <<
"offset_x" << YAML::Value <<
offset_x_;
428 emitter << YAML::Key <<
"offset_y" << YAML::Value <<
offset_y_;
429 if(
ui_.ratio_custom->isChecked())
431 emitter << YAML::Key <<
"ratio" << YAML::Value <<
"custom";
433 else if(
ui_.ratio_equal->isChecked())
435 emitter << YAML::Key <<
"ratio" << YAML::Value <<
"equal";
437 else if(
ui_.ratio_original->isChecked())
439 emitter << YAML::Key <<
"ratio" << YAML::Value <<
"original";
bool GetTransform(const ros::Time &stamp, swri_transform_util::Transform &transform, bool use_latest_transforms=true)
void PrintWarning(const std::string &message)
void PrintError(const std::string &message)
void RatioOriginalToggled(bool toggled)
void HeightChanged(double value)
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
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)
QWidget * GetConfigWidget(QWidget *parent)
std::string target_frame_
void PrintInfo(const std::string &message)
tf::Point bottom_left_transformed_
static void PrintInfoHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
void Draw(double x, double y, double scale)
virtual ~RobotImagePlugin()
std::string source_frame_
tf::Point top_left_transformed_
void RatioEqualToggled(bool toggled)
void OffsetYChanged(double value)
void RatioCustomToggled(bool toggled)
tf::Point bottom_right_transformed_
bool Initialize(QGLWidget *canvas)
tf::Point top_right_transformed_
ROSLIB_DECL std::string getPath(const std::string &package_name)
void transform(marti_nav_msgs::Path &path, const swri_transform_util::Transform &transform, const std::string &target_frame)
boost::shared_ptr< tf::TransformListener > tf_
void LoadConfig(const YAML::Node &node, const std::string &path)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
Ui::robot_image_config ui_
void OffsetXChanged(double value)
void WidthChanged(double value)