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 // The following replaces <rviz/frame_manager.h>
15 
16 #include <OGRE/OgreSceneNode.h>
17 #include <OGRE/OgreSceneManager.h>
18 
19 #include <tf/transform_listener.h>
20 
28 
29 namespace grid_map_rviz_plugin {
30 
32 {
33  qRegisterMetaType<grid_map_msgs::GridMap::ConstPtr>("grid_map_msgs::GridMap::ConstPtr");
34 
35  alphaProperty_ = new rviz::FloatProperty("Alpha", 1.0,
36  "0 is fully transparent, 1.0 is fully opaque.", this,
37  SLOT(updateVisualization()));
38 
39  historyLengthProperty_ = new rviz::IntProperty("History Length", 1,
40  "Number of prior grid maps to display.", this,
41  SLOT(updateHistoryLength()));
42 
43  showGridLinesProperty_ = new rviz::BoolProperty("Show Grid Lines", true, "Whether to show the lines connecting the grid cells.", this,
44  SLOT(updateGridLines()));
45 
47  new rviz::FloatProperty("Grid Line Thickness", 0.1, "Set thickness for the grid lines.", this, SLOT(updateVisualization()));
48  gridCellDecimationProperty_ = new rviz::IntProperty("Grid Cell Decimation", 1, "Decimation factor for the grid map cell display.", this,
49  SLOT(updateVisualization()));
50 
51  heightModeProperty_ = new rviz::EnumProperty("Height Transformer", "GridMapLayer",
52  "Select the transformer to use to set the height.",
53  this, SLOT(updateHeightMode()));
54  heightModeProperty_->addOption("Layer", 0);
55  heightModeProperty_->addOption("Flat", 1);
56 
58  "Height Layer", "elevation", "Select the grid map layer to compute the height.", this,
59  SLOT(updateVisualization()));
60 
61  colorModeProperty_ = new rviz::EnumProperty("Color Transformer", "GridMapLayer",
62  "Select the transformer to use to set the color.",
63  this, SLOT(updateColorMode()));
64  colorModeProperty_->addOption("IntensityLayer", 0);
65  colorModeProperty_->addOption("ColorLayer", 1);
66  colorModeProperty_->addOption("FlatColor", 2);
67  colorModeProperty_->addOption("None", 3);
68 
70  "Color Layer", "elevation", "Select the grid map layer to compute the color.", this,
71  SLOT(updateVisualization()));
72 
74  "ColorMap", "default", "Select the colormap to be used.", this,
75  SLOT(updateVisualization()));
76 
77  colorProperty_ = new rviz::ColorProperty("Color", QColor(200, 200, 200),
78  "Color to draw the mesh.", this,
79  SLOT(updateVisualization()));
81 
83  "Use ColorMap", true,
84  "Whether to use a colormap or to interpolate between two colors.", this,
85  SLOT(updateUseColorMap()));
86 
88  "Invert ColorMap", false,
89  "Whether to invert the colormap colors.", this,
90  SLOT(updateVisualization()));
91 
93  "Min Color", QColor(0, 0, 0), "Color to assign to cells with the minimum intensity. "
94  "Actual color is interpolated between this and Max Color.",
95  this, SLOT(updateVisualization()));
97 
99  "Max Color", QColor(255, 255, 255), "Color to assign to cells with the maximum intensity. "
100  "Actual color is interpolated between Min Color and this.",
101  this, SLOT(updateVisualization()));
103 
105  "Autocompute Intensity Bounds", true,
106  "Whether to automatically compute the intensity min/max values.", this,
108 
110  "Min Intensity", 0.0,
111  "Minimum possible intensity value, used to interpolate from Min Color to Max Color.", this,
112  SLOT(updateVisualization()));
114 
116  "Max Intensity", 10.0,
117  "Maximum possible intensity value, used to interpolate from Min Color to Max Color.", this,
118  SLOT(updateVisualization()));
120 
123 }
124 
126 {
127 }
128 
130 {
131  MFDClass::onInitialize(); // "MFDClass" = typedef of "MessageFilterDisplay<message type>"
134 }
135 
137 {
138  isEnabled_ = true;
141 }
142 
145  isEnabled_ = false;
146 }
147 
149 {
151  MFDClass::reset();
152  visuals_.clear();
153  if(isEnabled_){
154  onEnable();
155  }
156 }
157 
159 {
160  visuals_.rset_capacity(historyLengthProperty_->getInt());
161 }
162 
164 {
167 }
168 
170 {
172 
173  bool intensityColor = colorModeProperty_->getOptionInt() == 0;
174  bool flatColor = colorModeProperty_->getOptionInt() == 2;
175  bool none = colorModeProperty_->getOptionInt() == 3;
176  colorProperty_->setHidden(!flatColor);
177  colorTransformerProperty_->setHidden(flatColor || none);
178  useColorMapProperty_->setHidden(!intensityColor);
179  invertColorMapProperty_->setHidden(!intensityColor);
181  bool useColorMap = useColorMapProperty_->getBool();
182  minColorProperty_->setHidden(!intensityColor || useColorMap);
183  maxColorProperty_->setHidden(!intensityColor || useColorMap);
184  bool autocomputeIntensity = autocomputeIntensityBoundsProperty_->getBool();
185  minIntensityProperty_->setHidden(!intensityColor || autocomputeIntensity);
186  minIntensityProperty_->setHidden(!intensityColor || autocomputeIntensity);
187 }
188 
190 {
192  bool useColorMap = useColorMapProperty_->getBool();
193  minColorProperty_->setHidden(useColorMap);
194  maxColorProperty_->setHidden(useColorMap);
195  invertColorMapProperty_->setHidden(!useColorMap);
196 }
197 
199 {
201  const bool isShowGridLines = showGridLinesProperty_->getBool();
202  gridLinesThicknessProperty_->setHidden(!isShowGridLines);
203  gridCellDecimationProperty_->setHidden(!isShowGridLines);
204 }
205 
207 {
211 }
212 
214 {
215  float alpha = alphaProperty_->getFloat();
216  bool showGridLines = showGridLinesProperty_->getBool();
217  bool flatTerrain = heightModeProperty_->getOptionInt() == 1;
218  std::string heightLayer = heightTransformerProperty_->getStdString();
219  bool mapLayerColor = colorModeProperty_->getOptionInt() == 1;
220  bool flatColor = colorModeProperty_->getOptionInt() == 2;
221  bool noColor = colorModeProperty_->getOptionInt() == 3;
222  Ogre::ColourValue meshColor = colorProperty_->getOgreColor();
223  std::string colorLayer = colorTransformerProperty_->getStdString();
224  std::string colorMap = colorMapProperty_->getStdString();
225  bool useColorMap = useColorMapProperty_->getBool();
226  bool invertColorMap = invertColorMapProperty_->getBool();
227  Ogre::ColourValue minColor = minColorProperty_->getOgreColor();
228  Ogre::ColourValue maxColor = maxColorProperty_->getOgreColor();
229  bool autocomputeIntensity = autocomputeIntensityBoundsProperty_->getBool();
230  float minIntensity = minIntensityProperty_->getFloat();
231  float maxIntensity = maxIntensityProperty_->getFloat();
232  const float gridLineThickness = gridLinesThicknessProperty_->getFloat();
233  const int gridCellDecimation = gridCellDecimationProperty_->getInt();
234 
235  for (size_t i = 0; i < visuals_.size(); i++) {
236  visuals_[i]->computeVisualization(alpha, showGridLines, flatTerrain, heightLayer, flatColor, noColor, meshColor, mapLayerColor,
237  colorLayer, colorMap, useColorMap, invertColorMap, minColor, maxColor, autocomputeIntensity, minIntensity,
238  maxIntensity, gridLineThickness, gridCellDecimation);
239  }
240 }
241 
242 void GridMapDisplay::processMessage(const grid_map_msgs::GridMap::ConstPtr& msg)
243 {
244  process(msg);
245 }
246 
247 void GridMapDisplay::onProcessMessage(const grid_map_msgs::GridMap::ConstPtr& msg)
248 {
249  // Check if the display was already reset.
250  if (!isEnabled_) {
251  return;
252  }
253 
254  // Check if transform between the message's frame and the fixed frame exists.
255  Ogre::Quaternion orientation;
256  Ogre::Vector3 position;
257  if (!context_->getFrameManager()->getTransform(msg->info.header.frame_id, msg->info.header.stamp,
258  position, orientation)) {
259  ROS_DEBUG("Error transforming from frame '%s' to frame '%s'", msg->info.header.frame_id.c_str(),
260  qPrintable(fixed_frame_));
261  return;
262  }
263 
265  if (visuals_.full()) {
266  visual = visuals_.front();
267  } else {
268  visual.reset(new GridMapVisual(context_->getSceneManager(), scene_node_));
269  }
270 
271  visual->setMessage(msg);
272  visual->setFramePosition(position);
273  visual->setFrameOrientation(orientation);
274 
275  visual->computeVisualization(alphaProperty_->getFloat(), showGridLinesProperty_->getBool(),
285 
286  std::vector<std::string> layer_names = visual->getLayerNames();
289  for (size_t i = 0; i < layer_names.size(); i++) {
290  heightTransformerProperty_->addOptionStd(layer_names[i]);
291  colorTransformerProperty_->addOptionStd(layer_names[i]);
292  }
293 
294  visuals_.push_back(visual);
295 }
296 
298 {
300  for (auto cmap : getColorMapNames()) {
302  }
303 }
304 
305 
306 } // end namespace grid_map_rviz_plugin
307 
rviz::BoolProperty * showGridLinesProperty_
static std::vector< std::string > getColorMapNames()
rviz::EditableEnumProperty * colorMapProperty_
rviz::ColorProperty * minColorProperty_
DisplayContext * context_
virtual void clearOptions()
rviz::IntProperty * historyLengthProperty_
void onProcessMessage(const grid_map_msgs::GridMap::ConstPtr &msg)
Ogre::ColourValue getOgreColor() const
void setMin(int min)
const std::map< std::string, std::vector< std::vector< float > > > colorMap
void addOptionStd(const std::string &option)
rviz::BoolProperty * autocomputeIntensityBoundsProperty_
Ogre::SceneNode * scene_node_
rviz::BoolProperty * useColorMapProperty_
std::string getStdString()
void setMax(int max)
QString fixed_frame_
rviz::ColorProperty * maxColorProperty_
rviz::FloatProperty * gridLinesThicknessProperty_
virtual void addOption(const QString &option, int value=0)
rviz::IntProperty * gridCellDecimationProperty_
void process(const grid_map_msgs::GridMap::ConstPtr &msg)
virtual FrameManager * getFrameManager() const=0
virtual int getInt() const
BoolProperty(const QString &name=QString(), bool default_value=false, const QString &description=QString(), Property *parent=nullptr, const char *changed_slot=nullptr, QObject *receiver=nullptr)
virtual Ogre::SceneManager * getSceneManager() const=0
virtual void setHidden(bool hidden)
rviz::EnumProperty * heightModeProperty_
virtual float getFloat() const
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
rviz::FloatProperty * minIntensityProperty_
rviz::EditableEnumProperty * colorTransformerProperty_
rviz::BoolProperty * invertColorMapProperty_
virtual bool getBool() const
virtual int getOptionInt()
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
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 Wed Jul 5 2023 02:23:55