GridMapDisplay.cpp
Go to the documentation of this file.
1 /*
2  * GridMapDisplay.cpp
3  *
4  * Created on: Aug 3, 2016
5  * Author: Philipp Krüsi, Péter Fankhauser
6  * Institute: ETH Zurich, ANYbotics
7  */
8 
12 
13 #include <OGRE/OgreSceneNode.h>
14 #include <OGRE/OgreSceneManager.h>
15 
16 #include <tf/transform_listener.h>
17 
25 
26 namespace grid_map_rviz_plugin {
27 
29 {
30  alphaProperty_ = new rviz::FloatProperty("Alpha", 1.0,
31  "0 is fully transparent, 1.0 is fully opaque.", this,
32  SLOT(updateVisualization()));
33 
34  historyLengthProperty_ = new rviz::IntProperty("History Length", 1,
35  "Number of prior grid maps to display.", this,
36  SLOT(updateHistoryLength()));
37 
39  "Show Grid Lines", true, "Whether to show the lines connecting the grid cells.", this,
40  SLOT(updateVisualization()));
41 
42  heightModeProperty_ = new rviz::EnumProperty("Height Transformer", "GridMapLayer",
43  "Select the transformer to use to set the height.",
44  this, SLOT(updateHeightMode()));
45  heightModeProperty_->addOption("Layer", 0);
46  heightModeProperty_->addOption("Flat", 1);
47 
49  "Height Layer", "elevation", "Select the grid map layer to compute the height.", this,
50  SLOT(updateVisualization()));
51 
52  colorModeProperty_ = new rviz::EnumProperty("Color Transformer", "GridMapLayer",
53  "Select the transformer to use to set the color.",
54  this, SLOT(updateColorMode()));
55  colorModeProperty_->addOption("IntensityLayer", 0);
56  colorModeProperty_->addOption("ColorLayer", 1);
57  colorModeProperty_->addOption("FlatColor", 2);
58  colorModeProperty_->addOption("None", 3);
59 
61  "Color Layer", "elevation", "Select the grid map layer to compute the color.", this,
62  SLOT(updateVisualization()));
63 
64  colorProperty_ = new rviz::ColorProperty("Color", QColor(200, 200, 200),
65  "Color to draw the mesh.", this,
66  SLOT(updateVisualization()));
68 
70  "Use Rainbow", true,
71  "Whether to use a rainbow of colors or to interpolate between two colors.", this,
72  SLOT(updateUseRainbow()));
73 
75  "Invert Rainbow", false,
76  "Whether to invert the rainbow colors.", this,
77  SLOT(updateVisualization()));
78 
80  "Min Color", QColor(0, 0, 0), "Color to assign to cells with the minimum intensity. "
81  "Actual color is interpolated between this and Max Color.",
82  this, SLOT(updateVisualization()));
84 
86  "Max Color", QColor(255, 255, 255), "Color to assign to cells with the maximum intensity. "
87  "Actual color is interpolated between Min Color and this.",
88  this, SLOT(updateVisualization()));
90 
92  "Autocompute Intensity Bounds", true,
93  "Whether to automatically compute the intensity min/max values.", this,
95 
97  "Min Intensity", 0.0,
98  "Minimum possible intensity value, used to interpolate from Min Color to Max Color.", this,
99  SLOT(updateVisualization()));
101 
103  "Max Intensity", 10.0,
104  "Maximum possible intensity value, used to interpolate from Min Color to Max Color.", this,
105  SLOT(updateVisualization()));
107 
110 }
111 
113 {
114 }
115 
117 {
118  MFDClass::onInitialize(); // "MFDClass" = typedef of "MessageFilterDisplay<message type>"
120 }
121 
123 {
124  MFDClass::reset();
125  visuals_.clear();
126 }
127 
129 {
130  visuals_.rset_capacity(historyLengthProperty_->getInt());
131 }
132 
134 {
137 }
138 
140 {
142 
143  bool intensityColor = colorModeProperty_->getOptionInt() == 0;
144  bool flatColor = colorModeProperty_->getOptionInt() == 2;
145  bool none = colorModeProperty_->getOptionInt() == 3;
146  colorProperty_->setHidden(!flatColor);
147  colorTransformerProperty_->setHidden(flatColor || none);
148  useRainbowProperty_->setHidden(!intensityColor);
149  invertRainbowProperty_->setHidden(!intensityColor);
151  bool useRainbow = useRainbowProperty_->getBool();
152  minColorProperty_->setHidden(!intensityColor || useRainbow);
153  maxColorProperty_->setHidden(!intensityColor || useRainbow);
154  bool autocomputeIntensity = autocomputeIntensityBoundsProperty_->getBool();
155  minIntensityProperty_->setHidden(!intensityColor || autocomputeIntensity);
156  minIntensityProperty_->setHidden(!intensityColor || autocomputeIntensity);
157 }
158 
160 {
162  bool useRainbow = useRainbowProperty_->getBool();
163  minColorProperty_->setHidden(useRainbow);
164  maxColorProperty_->setHidden(useRainbow);
165  invertRainbowProperty_->setHidden(!useRainbow);
166 }
167 
169 {
173 }
174 
176 {
177  float alpha = alphaProperty_->getFloat();
178  bool showGridLines = showGridLinesProperty_->getBool();
179  bool flatTerrain = heightModeProperty_->getOptionInt() == 1;
180  std::string heightLayer = heightTransformerProperty_->getStdString();
181  bool mapLayerColor = colorModeProperty_->getOptionInt() == 1;
182  bool flatColor = colorModeProperty_->getOptionInt() == 2;
183  bool noColor = colorModeProperty_->getOptionInt() == 3;
184  Ogre::ColourValue meshColor = colorProperty_->getOgreColor();
185  std::string colorLayer = colorTransformerProperty_->getStdString();
186  bool useRainbow = useRainbowProperty_->getBool();
187  bool invertRainbow = invertRainbowProperty_->getBool();
188  Ogre::ColourValue minColor = minColorProperty_->getOgreColor();
189  Ogre::ColourValue maxColor = maxColorProperty_->getOgreColor();
190  bool autocomputeIntensity = autocomputeIntensityBoundsProperty_->getBool();
191  float minIntensity = minIntensityProperty_->getFloat();
192  float maxIntensity = maxIntensityProperty_->getFloat();
193 
194  for (size_t i = 0; i < visuals_.size(); i++) {
195  visuals_[i]->computeVisualization(alpha, showGridLines, flatTerrain, heightLayer, flatColor, noColor, meshColor,
196  mapLayerColor, colorLayer, useRainbow, invertRainbow, minColor, maxColor,
197  autocomputeIntensity, minIntensity, maxIntensity);
198  }
199 }
200 
201 void GridMapDisplay::processMessage(const grid_map_msgs::GridMap::ConstPtr& msg)
202 {
203  // Check if transform between the message's frame and the fixed frame exists.
204  Ogre::Quaternion orientation;
205  Ogre::Vector3 position;
206  if (!context_->getFrameManager()->getTransform(msg->info.header.frame_id, msg->info.header.stamp,
207  position, orientation)) {
208  ROS_DEBUG("Error transforming from frame '%s' to frame '%s'", msg->info.header.frame_id.c_str(),
209  qPrintable(fixed_frame_));
210  return;
211  }
212 
214  if (visuals_.full()) {
215  visual = visuals_.front();
216  } else {
217  visual.reset(new GridMapVisual(context_->getSceneManager(), scene_node_));
218  }
219 
220  visual->setMessage(msg);
221  visual->setFramePosition(position);
222  visual->setFrameOrientation(orientation);
223 
224  visual->computeVisualization(alphaProperty_->getFloat(), showGridLinesProperty_->getBool(),
232 
233  std::vector<std::string> layer_names = visual->getLayerNames();
236  for (size_t i = 0; i < layer_names.size(); i++) {
237  heightTransformerProperty_->addOptionStd(layer_names[i]);
238  colorTransformerProperty_->addOptionStd(layer_names[i]);
239  }
240 
241  visuals_.push_back(visual);
242 }
243 
244 } // end namespace grid_map_rviz_plugin
245 
rviz::BoolProperty * showGridLinesProperty_
rviz::ColorProperty * minColorProperty_
Ogre::ColourValue getOgreColor() const
DisplayContext * context_
virtual void clearOptions()
virtual int getInt() const
rviz::IntProperty * historyLengthProperty_
virtual float getFloat() const
void setMin(int min)
void addOptionStd(const std::string &option)
rviz::BoolProperty * autocomputeIntensityBoundsProperty_
Ogre::SceneNode * scene_node_
std::string getStdString()
void setMax(int max)
virtual bool getBool() const
QString fixed_frame_
rviz::ColorProperty * maxColorProperty_
virtual void addOption(const QString &option, int value=0)
virtual FrameManager * getFrameManager() const =0
rviz::BoolProperty * invertRainbowProperty_
virtual Ogre::SceneManager * getSceneManager() const =0
virtual void setHidden(bool hidden)
rviz::BoolProperty * useRainbowProperty_
rviz::EnumProperty * heightModeProperty_
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
rviz::FloatProperty * minIntensityProperty_
rviz::EditableEnumProperty * colorTransformerProperty_
virtual int getOptionInt()
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
BoolProperty(const QString &name=QString(), bool default_value=false, const QString &description=QString(), Property *parent=0, const char *changed_slot=0, QObject *receiver=0)
void processMessage(const grid_map_msgs::GridMap::ConstPtr &msg)
boost::circular_buffer< boost::shared_ptr< GridMapVisual > > visuals_
rviz::FloatProperty * maxIntensityProperty_
rviz::EditableEnumProperty * heightTransformerProperty_
#define ROS_DEBUG(...)


grid_map_rviz_plugin
Author(s): Philipp Krüsi, Péter Fankhauser
autogenerated on Tue Jun 25 2019 20:02:28