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 
11 // The following replaces <rviz/frame_manager.h>
13 
14 #include <OGRE/OgreSceneNode.h>
15 #include <OGRE/OgreSceneManager.h>
16 
17 #include <tf/transform_listener.h>
18 
26 
27 namespace grid_map_rviz_plugin {
28 
30 {
31  alphaProperty_ = new rviz::FloatProperty("Alpha", 1.0,
32  "0 is fully transparent, 1.0 is fully opaque.", this,
33  SLOT(updateVisualization()));
34 
35  historyLengthProperty_ = new rviz::IntProperty("History Length", 1,
36  "Number of prior grid maps to display.", this,
37  SLOT(updateHistoryLength()));
38 
40  "Show Grid Lines", true, "Whether to show the lines connecting the grid cells.", this,
41  SLOT(updateVisualization()));
42 
43  heightModeProperty_ = new rviz::EnumProperty("Height Transformer", "GridMapLayer",
44  "Select the transformer to use to set the height.",
45  this, SLOT(updateHeightMode()));
46  heightModeProperty_->addOption("Layer", 0);
47  heightModeProperty_->addOption("Flat", 1);
48 
50  "Height Layer", "elevation", "Select the grid map layer to compute the height.", this,
51  SLOT(updateVisualization()));
52 
53  colorModeProperty_ = new rviz::EnumProperty("Color Transformer", "GridMapLayer",
54  "Select the transformer to use to set the color.",
55  this, SLOT(updateColorMode()));
56  colorModeProperty_->addOption("IntensityLayer", 0);
57  colorModeProperty_->addOption("ColorLayer", 1);
58  colorModeProperty_->addOption("FlatColor", 2);
59  colorModeProperty_->addOption("None", 3);
60 
62  "Color Layer", "elevation", "Select the grid map layer to compute the color.", this,
63  SLOT(updateVisualization()));
64 
65  colorProperty_ = new rviz::ColorProperty("Color", QColor(200, 200, 200),
66  "Color to draw the mesh.", this,
67  SLOT(updateVisualization()));
69 
71  "Use Rainbow", true,
72  "Whether to use a rainbow of colors or to interpolate between two colors.", this,
73  SLOT(updateUseRainbow()));
74 
76  "Invert Rainbow", false,
77  "Whether to invert the rainbow colors.", this,
78  SLOT(updateVisualization()));
79 
81  "Min Color", QColor(0, 0, 0), "Color to assign to cells with the minimum intensity. "
82  "Actual color is interpolated between this and Max Color.",
83  this, SLOT(updateVisualization()));
85 
87  "Max Color", QColor(255, 255, 255), "Color to assign to cells with the maximum intensity. "
88  "Actual color is interpolated between Min Color and this.",
89  this, SLOT(updateVisualization()));
91 
93  "Autocompute Intensity Bounds", true,
94  "Whether to automatically compute the intensity min/max values.", this,
96 
98  "Min Intensity", 0.0,
99  "Minimum possible intensity value, used to interpolate from Min Color to Max Color.", this,
100  SLOT(updateVisualization()));
102 
104  "Max Intensity", 10.0,
105  "Maximum possible intensity value, used to interpolate from Min Color to Max Color.", this,
106  SLOT(updateVisualization()));
108 
111 }
112 
114 {
115 }
116 
118 {
119  MFDClass::onInitialize(); // "MFDClass" = typedef of "MessageFilterDisplay<message type>"
121 }
122 
124 {
125  MFDClass::reset();
126  visuals_.clear();
127 }
128 
130 {
131  visuals_.rset_capacity(historyLengthProperty_->getInt());
132 }
133 
135 {
138 }
139 
141 {
143 
144  bool intensityColor = colorModeProperty_->getOptionInt() == 0;
145  bool flatColor = colorModeProperty_->getOptionInt() == 2;
146  bool none = colorModeProperty_->getOptionInt() == 3;
147  colorProperty_->setHidden(!flatColor);
148  colorTransformerProperty_->setHidden(flatColor || none);
149  useRainbowProperty_->setHidden(!intensityColor);
150  invertRainbowProperty_->setHidden(!intensityColor);
152  bool useRainbow = useRainbowProperty_->getBool();
153  minColorProperty_->setHidden(!intensityColor || useRainbow);
154  maxColorProperty_->setHidden(!intensityColor || useRainbow);
155  bool autocomputeIntensity = autocomputeIntensityBoundsProperty_->getBool();
156  minIntensityProperty_->setHidden(!intensityColor || autocomputeIntensity);
157  minIntensityProperty_->setHidden(!intensityColor || autocomputeIntensity);
158 }
159 
161 {
163  bool useRainbow = useRainbowProperty_->getBool();
164  minColorProperty_->setHidden(useRainbow);
165  maxColorProperty_->setHidden(useRainbow);
166  invertRainbowProperty_->setHidden(!useRainbow);
167 }
168 
170 {
174 }
175 
177 {
178  float alpha = alphaProperty_->getFloat();
179  bool showGridLines = showGridLinesProperty_->getBool();
180  bool flatTerrain = heightModeProperty_->getOptionInt() == 1;
181  std::string heightLayer = heightTransformerProperty_->getStdString();
182  bool mapLayerColor = colorModeProperty_->getOptionInt() == 1;
183  bool flatColor = colorModeProperty_->getOptionInt() == 2;
184  bool noColor = colorModeProperty_->getOptionInt() == 3;
185  Ogre::ColourValue meshColor = colorProperty_->getOgreColor();
186  std::string colorLayer = colorTransformerProperty_->getStdString();
187  bool useRainbow = useRainbowProperty_->getBool();
188  bool invertRainbow = invertRainbowProperty_->getBool();
189  Ogre::ColourValue minColor = minColorProperty_->getOgreColor();
190  Ogre::ColourValue maxColor = maxColorProperty_->getOgreColor();
191  bool autocomputeIntensity = autocomputeIntensityBoundsProperty_->getBool();
192  float minIntensity = minIntensityProperty_->getFloat();
193  float maxIntensity = maxIntensityProperty_->getFloat();
194 
195  for (size_t i = 0; i < visuals_.size(); i++) {
196  visuals_[i]->computeVisualization(alpha, showGridLines, flatTerrain, heightLayer, flatColor, noColor, meshColor,
197  mapLayerColor, colorLayer, useRainbow, invertRainbow, minColor, maxColor,
198  autocomputeIntensity, minIntensity, maxIntensity);
199  }
200 }
201 
202 void GridMapDisplay::processMessage(const grid_map_msgs::GridMap::ConstPtr& msg)
203 {
204  // Check if transform between the message's frame and the fixed frame exists.
205  Ogre::Quaternion orientation;
206  Ogre::Vector3 position;
207  if (!context_->getFrameManager()->getTransform(msg->info.header.frame_id, msg->info.header.stamp,
208  position, orientation)) {
209  ROS_DEBUG("Error transforming from frame '%s' to frame '%s'", msg->info.header.frame_id.c_str(),
210  qPrintable(fixed_frame_));
211  return;
212  }
213 
215  if (visuals_.full()) {
216  visual = visuals_.front();
217  } else {
218  visual.reset(new GridMapVisual(context_->getSceneManager(), scene_node_));
219  }
220 
221  visual->setMessage(msg);
222  visual->setFramePosition(position);
223  visual->setFrameOrientation(orientation);
224 
225  visual->computeVisualization(alphaProperty_->getFloat(), showGridLinesProperty_->getBool(),
233 
234  std::vector<std::string> layer_names = visual->getLayerNames();
237  for (size_t i = 0; i < layer_names.size(); i++) {
238  heightTransformerProperty_->addOptionStd(layer_names[i]);
239  colorTransformerProperty_->addOptionStd(layer_names[i]);
240  }
241 
242  visuals_.push_back(visual);
243 }
244 
245 } // end namespace grid_map_rviz_plugin
246 
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 1 2021 02:13:47