stdr_laser_visualization.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  STDR Simulator - Simple Two DImensional Robot Simulator
3  Copyright (C) 2013 STDR Simulator
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 3 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 
16  Authors :
17  * Manos Tsardoulias, etsardou@gmail.com
18  * Aris Thallas, aris.thallas@gmail.com
19  * Chris Zalidis, zalidis@gmail.com
20 ******************************************************************************/
21 
23 
24 namespace stdr_gui
25 {
26 
33  CLaserVisualisation::CLaserVisualisation(QString name,float resolution):
34  name_(name),
35  resolution_(resolution)
36  {
37  setupUi(this);
38  setWindowTitle(name_);
39  active_ = true;
40 
42 
44  name_.toStdString().c_str(),
45  1,
47  this);
48 
49  void_image_ = QImage(
50  laserImage->width(),
51  laserImage->height(),
52  QImage::Format_RGB32);
53 
54  void_image_.fill(QColor(255,255,255,255));
55  }
56 
62  {
63 
64  }
65 
71  {
72  active_ = false;
74  hide();
75  delete laserMean;
76  delete laserMax;
77  delete laserMin;
78  delete laserImage;
79  }
80 
86  void CLaserVisualisation::closeEvent(QCloseEvent *event)
87  {
88  destruct();
89  active_ = false;
91  }
92 
98  {
99  return active_;
100  }
101 
107  void CLaserVisualisation::setLaser(stdr_msgs::LaserSensorMsg msg)
108  {
109  msg_ = msg;
110  laserMax->setText(QString().setNum(msg.maxRange) + QString(" m"));
111  laserMin->setText(QString().setNum(msg.minRange) + QString(" m"));
112  }
113 
119  void CLaserVisualisation::callback(const sensor_msgs::LaserScan& msg)
120  {
121  scan_ = msg;
122  }
123 
129  {
131  QPainter painter(&internal_image_);
132  float mean = 0;
133  for(unsigned int i = 0 ; i < scan_.ranges.size() ; i++)
134  {
135 
136  float real_dist = scan_.ranges[i];
137  if(real_dist > msg_.maxRange)
138  {
139  real_dist = msg_.maxRange;
140  painter.setPen(QColor(255,0,0,100));
141  }
142  else if(real_dist < msg_.minRange)
143  {
144  real_dist = msg_.minRange;
145  painter.setPen(QColor(100,100,100,100));
146  }
147  else
148  {
149  painter.setPen(QColor(255,0,0,100));
150  }
151 
152  mean += real_dist;
153  painter.drawLine(
154  internal_image_.width() / 2,
155  internal_image_.height() / 2,
156  internal_image_.width() / 2 + real_dist / msg_.maxRange *
157  cos(scan_.angle_min + ((float)i) * scan_.angle_increment) *
158  internal_image_.width() / 2,
159  internal_image_.height() / 2 + real_dist / msg_.maxRange *
160  sin(scan_.angle_min + ((float)i) * scan_.angle_increment) *
161  internal_image_.width() / 2
162  );
163  }
164  laserMean->setText(
165  QString().setNum(mean/scan_.ranges.size()) + QString(" m"));
166  laserImage->setPixmap(
167  QPixmap().fromImage(internal_image_.mirrored(false,true)));
168  }
169 }
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
sensor_msgs::LaserScan scan_
Subscriber for getting the laser scans.
stdr_msgs::LaserSensorMsg msg_
The image to draw into.
void destruct(void)
Destroys the visualizer.
ros::Subscriber subscriber_
Description of the laser sensor.
bool active_
< True if the visualizer is active
CLaserVisualisation(QString name, float resolution)
Default contructor.
void setLaser(stdr_msgs::LaserSensorMsg msg)
Sets the laser description message.
void paint(void)
Paints the visualizer.
The main namespace for STDR GUI.
void closeEvent(QCloseEvent *event)
Called when the close event is triggered.
QImage void_image_
The laser frame id.
bool getActive(void)
Returns true if the visualizer is active.
~CLaserVisualisation(void)
Default destructor.
void callback(const sensor_msgs::LaserScan &msg)
Called when new laser data are available.


stdr_gui
Author(s): Manos Tsardoulias
autogenerated on Mon Jun 10 2019 15:15:16