39 #include <boost/algorithm/string.hpp> 42 #include <QColorDialog> 47 #include "ui_topic_select.h" 62 LaserScanPlugin::LaserScanPlugin() :
63 config_widget_(new QWidget()),
77 p.setColor(QPalette::Background, Qt::white);
81 QPalette p3(
ui_.status->palette());
82 p3.setColor(QPalette::Text, Qt::red);
83 ui_.status->setPalette(p3);
86 ui_.min_color->setColor(Qt::white);
87 ui_.max_color->setColor(Qt::black);
90 ui_.color_transformer->addItem(QString(
"Flat Color"), QVariant(0));
91 ui_.color_transformer->addItem(QString(
"Intensity"), QVariant(1));
92 ui_.color_transformer->addItem(QString(
"Range"), QVariant(2));
93 ui_.color_transformer->addItem(QString(
"X Axis"), QVariant(3));
94 ui_.color_transformer->addItem(QString(
"Y Axis"), QVariant(4));
95 ui_.color_transformer->addItem(QString(
"Z Axis"), QVariant(5));
97 QObject::connect(
ui_.selecttopic,
101 QObject::connect(
ui_.topic,
102 SIGNAL(editingFinished()),
105 QObject::connect(
ui_.alpha,
106 SIGNAL(valueChanged(
double)),
109 QObject::connect(
ui_.color_transformer,
110 SIGNAL(currentIndexChanged(
int)),
113 QObject::connect(
ui_.max_color,
114 SIGNAL(colorEdited(
const QColor &)),
117 QObject::connect(
ui_.min_color,
118 SIGNAL(colorEdited(
const QColor &)),
121 QObject::connect(
ui_.minValue,
122 SIGNAL(valueChanged(
double)),
125 QObject::connect(
ui_.maxValue,
126 SIGNAL(valueChanged(
double)),
129 QObject::connect(
ui_.bufferSize,
130 SIGNAL(valueChanged(
int)),
133 QObject::connect(
ui_.pointSize,
134 SIGNAL(valueChanged(
int)),
137 QObject::connect(
ui_.use_rainbow,
138 SIGNAL(stateChanged(
int)),
142 QObject::connect(
ui_.max_color,
143 SIGNAL(colorEdited(
const QColor &)),
146 QObject::connect(
ui_.min_color,
147 SIGNAL(colorEdited(
const QColor &)),
150 QObject::connect(
this,
155 PrintInfo(
"Constructed LaserScanPlugin");
172 QPixmap icon(16, 16);
173 icon.fill(Qt::transparent);
175 QPainter painter(&icon);
176 painter.setRenderHint(QPainter::Antialiasing,
true);
180 pen.setCapStyle(Qt::RoundCap);
182 pen.setColor(
ui_.min_color->color());
184 painter.drawPoint(2, 13);
186 pen.setColor(
ui_.min_color->color());
188 painter.drawPoint(4, 6);
190 pen.setColor(
ui_.max_color->color());
192 painter.drawPoint(12, 9);
194 pen.setColor(
ui_.max_color->color());
196 painter.drawPoint(13, 2);
206 scan.transformed =
false;
214 int color_transformer =
ui_.color_transformer->currentIndex();
223 else if (color_transformer ==
COLOR_X)
227 else if (color_transformer ==
COLOR_Y)
231 else if (color_transformer ==
COLOR_Z)
237 return ui_.min_color->color();
241 val = std::max(0.0, std::min(val, 1.0));
242 if (
ui_.use_rainbow->isChecked())
245 int hue =
static_cast<int>(val * 255);
246 return QColor::fromHsl(hue, 255, 127, 255);
250 const QColor min_color =
ui_.min_color->color();
251 const QColor max_color =
ui_.max_color->color();
253 int red, green, blue;
254 red =
static_cast<int>(val * max_color.red() + ((1.0 - val) * min_color.red()));
255 green =
static_cast<int>(val * max_color.green() + ((1.0 - val) * min_color.green()));
256 blue =
static_cast<int>(val * max_color.blue() + ((1.0 - val) * min_color.blue()));
257 return QColor(red, green, blue, 255);
263 std::deque<Scan>::iterator scan_it =
scans_.begin();
264 for (; scan_it !=
scans_.end(); ++scan_it)
266 std::vector<StampedPoint>::iterator point_it = scan_it->points.begin();
267 for (; point_it != scan_it->points.end(); point_it++)
269 point_it->color =
CalculateColor(*point_it, scan_it->has_intensity);
277 "sensor_msgs/LaserScan");
279 if (!topic.
name.empty())
281 ui_.topic->setText(QString::fromStdString(topic.
name));
288 std::string topic =
ui_.topic->text().trimmed().toStdString();
354 for (
size_t i = 0; i < msg->ranges.size(); i++)
356 double angle = msg->angle_min + msg->angle_increment * i;
369 if( !has_tranform && was_using_latest_transforms)
394 scan.
stamp = msg->header.stamp;
395 scan.
color = QColor::fromRgbF(1.0
f, 0.0
f, 0.0
f, 1.0
f);
398 scan.
points.reserve( msg->ranges.size() );
406 for (
size_t i = 0; i < msg->ranges.size(); i++)
409 if (msg->ranges[i] > msg->range_max || msg->ranges[i] < msg->range_min)
417 point.
range = msg->ranges[i];
418 if (i < msg->intensities.size())
426 scan.
points.push_back(point);
476 std::deque<Scan>::const_iterator scan_it =
scans_.begin();
477 while (scan_it !=
scans_.end())
479 if (scan_it->transformed)
481 std::vector<StampedPoint>::const_iterator point_it = scan_it->points.begin();
482 for (; point_it != scan_it->points.end(); ++point_it)
485 point_it->color.redF(),
486 point_it->color.greenF(),
487 point_it->color.blueF(),
490 point_it->transformed_point.getX(),
491 point_it->transformed_point.getY());
504 if (check_state == Qt::Checked)
506 ui_.max_color->setVisible(
false);
507 ui_.min_color->setVisible(
false);
508 ui_.maxColorLabel->setVisible(
false);
509 ui_.minColorLabel->setVisible(
false);
513 ui_.max_color->setVisible(
true);
514 ui_.min_color->setVisible(
true);
515 ui_.maxColorLabel->setVisible(
true);
516 ui_.minColorLabel->setVisible(
true);
523 std::deque<Scan>::iterator scan_it =
scans_.begin();
524 for (; scan_it !=
scans_.end(); ++scan_it)
526 Scan& scan = *scan_it;
535 std::vector<StampedPoint>::iterator point_it = scan.
points.begin();
536 for (; point_it != scan.
points.end(); ++point_it)
538 point_it->transformed_point = transform * point_it->point;
548 if (
ui_.color_transformer->currentIndex() ==
COLOR_Z)
555 const std::string& path)
560 node[
"topic"] >> topic;
561 ui_.topic->setText(boost::trim_copy(topic).c_str());
568 ui_.pointSize->setValue(static_cast<int>(point_size_));
571 if (node[
"buffer_size"])
574 ui_.bufferSize->setValue(static_cast<int>(buffer_size_));
577 if (node[
"color_transformer"])
579 std::string color_transformer;
580 node[
"color_transformer"] >> color_transformer;
581 if (color_transformer ==
"Intensity")
583 else if (color_transformer ==
"Range")
585 else if (color_transformer ==
"X Axis")
586 ui_.color_transformer->setCurrentIndex(
COLOR_X);
587 else if (color_transformer ==
"Y Axis")
588 ui_.color_transformer->setCurrentIndex(
COLOR_Y);
589 else if (color_transformer ==
"Z Axis")
590 ui_.color_transformer->setCurrentIndex(
COLOR_Z);
595 if (node[
"min_color"])
597 std::string min_color_str;
598 node[
"min_color"] >> min_color_str;
599 ui_.min_color->setColor(QColor(min_color_str.c_str()));
602 if (node[
"max_color"])
604 std::string max_color_str;
605 node[
"max_color"] >> max_color_str;
606 ui_.max_color->setColor(QColor(max_color_str.c_str()));
609 if (node[
"value_min"])
612 ui_.minValue->setValue(min_value_);
615 if (node[
"max_value"])
618 ui_.maxValue->setValue(max_value_);
624 ui_.alpha->setValue(alpha_);
627 if (node[
"use_rainbow"])
630 node[
"use_rainbow"] >> use_rainbow;
631 ui_.use_rainbow->setChecked(use_rainbow);
642 ROS_DEBUG(
"Color transformer changed to %d", index);
646 ui_.min_color->setVisible(
true);
647 ui_.max_color->setVisible(
false);
648 ui_.maxColorLabel->setVisible(
false);
649 ui_.minColorLabel->setVisible(
false);
650 ui_.minValueLabel->setVisible(
false);
651 ui_.maxValueLabel->setVisible(
false);
652 ui_.minValue->setVisible(
false);
653 ui_.maxValue->setVisible(
false);
654 ui_.use_rainbow->setVisible(
false);
662 ui_.min_color->setVisible(!
ui_.use_rainbow->isChecked());
663 ui_.max_color->setVisible(!
ui_.use_rainbow->isChecked());
664 ui_.maxColorLabel->setVisible(!
ui_.use_rainbow->isChecked());
665 ui_.minColorLabel->setVisible(!
ui_.use_rainbow->isChecked());
666 ui_.minValueLabel->setVisible(
true);
667 ui_.maxValueLabel->setVisible(
true);
668 ui_.minValue->setVisible(
true);
669 ui_.maxValue->setVisible(
true);
670 ui_.use_rainbow->setVisible(
true);
681 alpha_ = std::max(0.0
f, std::min((
float)val, 1.0
f));
685 const std::string& path)
687 emitter << YAML::Key <<
"topic" <<
688 YAML::Value << boost::trim_copy(
ui_.topic->text().toStdString());
689 emitter << YAML::Key <<
"size" <<
690 YAML::Value <<
ui_.pointSize->value();
691 emitter << YAML::Key <<
"buffer_size" <<
692 YAML::Value <<
ui_.bufferSize->value();
693 emitter << YAML::Key <<
"alpha" <<
695 emitter << YAML::Key <<
"color_transformer" <<
696 YAML::Value <<
ui_.color_transformer->currentText().toStdString();
697 emitter << YAML::Key <<
"min_color" <<
698 YAML::Value <<
ui_.min_color->color().name().toStdString();
699 emitter << YAML::Key <<
"max_color" <<
700 YAML::Value <<
ui_.max_color->color().name().toStdString();
701 emitter << YAML::Key <<
"value_min" <<
702 YAML::Value <<
ui_.minValue->text().toDouble();
703 emitter << YAML::Key <<
"value_max" <<
704 YAML::Value <<
ui_.maxValue->text().toDouble();
705 emitter << YAML::Key <<
"use_rainbow" <<
706 YAML::Value <<
ui_.use_rainbow->isChecked();
virtual ~LaserScanPlugin()
bool GetTransform(const ros::Time &stamp, swri_transform_util::Transform &transform, bool use_latest_transforms=true)
static ros::master::TopicInfo selectTopic(const std::string &datatype, QWidget *parent=0)
void PointSizeChanged(int value)
void laserScanCallback(const sensor_msgs::LaserScanConstPtr &scan)
std::vector< StampedPoint > points
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())
static void PrintWarningHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
std::string source_frame_
static void PrintErrorHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
void PrintWarning(const std::string &message)
std::string target_frame_
TFSIMD_FORCE_INLINE const tfScalar & y() const
void ResetTransformedScans()
static void PrintInfoHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
QWidget * GetConfigWidget(QWidget *parent)
std::vector< double > precomputed_cos_
void Draw(double x, double y, double scale)
TFSIMD_FORCE_INLINE const tfScalar & x() const
void MinValueChanged(double value)
TFSIMD_FORCE_INLINE const tfScalar & z() const
std::deque< Scan > scans_
std::vector< double > precomputed_sin_
void TargetFrameChanged(const std::string &target_frame)
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE const tfScalar & x() const
void MaxValueChanged(double value)
void LoadConfig(const YAML::Node &node, const std::string &path)
ros::Subscriber laserscan_sub_
QColor CalculateColor(const StampedPoint &point, bool has_intensity)
void ColorTransformerChanged(int index)
void PrintInfo(const std::string &message)
void PrintError(const std::string &message)
bool Initialize(QGLWidget *canvas)
tf::Point transformed_point
void AlphaEdited(double val)
void updatePreComputedTriginometic(const sensor_msgs::LaserScanConstPtr &msg)
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
void BufferSizeChanged(int value)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void UseRainbowChanged(int check_state)
bool use_latest_transforms_
bool GetScanTransform(const Scan &scan, swri_transform_util::Transform &transform)