grid_display.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <stdint.h>
31 
32 #include <boost/bind.hpp>
33 
34 #include <OgreSceneNode.h>
35 #include <OgreSceneManager.h>
36 
37 #include "rviz/display_context.h"
38 #include "rviz/frame_manager.h"
39 #include "rviz/ogre_helpers/grid.h"
43 
44 #include "grid_display.h"
45 
46 namespace rviz
47 {
49 {
52  "The TF frame this grid will use for its origin.", this, nullptr, true);
53 
55  new IntProperty("Plane Cell Count", 10, "The number of cells to draw in the plane of the grid.",
56  this, SLOT(updateCellCount()));
58 
59  height_property_ = new IntProperty("Normal Cell Count", 0,
60  "The number of cells to draw along the normal vector of the grid. "
61  " Setting to anything but 0 makes the grid 3D.",
62  this, SLOT(updateHeight()));
64 
66  new FloatProperty("Cell Size", 1.0f, "The length, in meters, of the side of each cell.", this,
67  SLOT(updateCellSize()));
68  cell_size_property_->setMin(0.0001);
69 
71  new EnumProperty("Line Style", "Lines", "The rendering operation to use to draw the grid lines.",
72  this, SLOT(updateStyle()));
75 
77  new FloatProperty("Line Width", 0.03, "The width, in meters, of each grid line.", style_property_,
78  SLOT(updateLineWidth()), this);
81 
83  new ColorProperty("Color", Qt::gray, "The color of the grid lines.", this, SLOT(updateColor()));
85  new FloatProperty("Alpha", 0.5f, "The amount of transparency to apply to the grid lines.", this,
86  SLOT(updateColor()));
89 
91  new EnumProperty("Plane", "XY", "The plane to draw the grid along.", this, SLOT(updatePlane()));
95 
97  "Offset", Ogre::Vector3::ZERO,
98  "Allows you to offset the grid from the origin of the reference frame. In meters.", this,
99  SLOT(updateOffset()));
100 }
101 
103 {
104  if (initialized())
105  {
106  delete grid_;
107  }
108 }
109 
111 {
112  QColor color = color_property_->getColor();
113  color.setAlphaF(alpha_property_->getFloat());
114 
119 
120  grid_->getSceneNode()->setVisible(false);
121  updatePlane();
122 }
123 
124 void GridDisplay::update(float /*dt*/, float /*ros_dt*/)
125 {
126  QString qframe = frame_property_->getFrame();
127  std::string frame = qframe.toStdString();
128 
129  Ogre::Vector3 position;
130  Ogre::Quaternion orientation;
131  if (context_->getFrameManager()->getTransform(frame, ros::Time(), position, orientation))
132  {
133  scene_node_->setPosition(position);
134  scene_node_->setOrientation(orientation);
135  setStatus(StatusProperty::Ok, "Transform", "Transform OK");
136  }
137  else
138  {
139  std::string error;
140  if (context_->getFrameManager()->transformHasProblems(frame, ros::Time(), error))
141  {
142  setStatus(StatusProperty::Error, "Transform", QString::fromStdString(error));
143  }
144  else
145  {
146  setStatus(StatusProperty::Error, "Transform",
147  "Could not transform from [" + qframe + "] to [" + fixed_frame_ + "]");
148  }
149  }
150 }
151 
153 {
154  QColor color = color_property_->getColor();
155  color.setAlphaF(alpha_property_->getFloat());
156  grid_->setColor(qtToOgre(color));
158 }
159 
161 {
164 }
165 
167 {
170 }
171 
173 {
176 }
177 
179 {
182 }
183 
185 {
187  grid_->setStyle(style);
188 
189  switch (style)
190  {
191  case Grid::Billboards:
193  break;
194  case Grid::Lines:
195  default:
197  break;
198  }
200 }
201 
203 {
204  grid_->getSceneNode()->setPosition(offset_property_->getVector());
206 }
207 
209 {
210  Ogre::Quaternion orient;
211  switch ((Plane)plane_property_->getOptionInt())
212  {
213  case XZ:
214  orient = Ogre::Quaternion(1, 0, 0, 0);
215  break;
216  case YZ:
217  orient = Ogre::Quaternion(Ogre::Vector3(0, -1, 0), Ogre::Vector3(0, 0, 1), Ogre::Vector3(1, 0, 0));
218  break;
219  case XY:
220  default:
221  orient = Ogre::Quaternion(Ogre::Vector3(1, 0, 0), Ogre::Vector3(0, 0, -1), Ogre::Vector3(0, 1, 0));
222  break;
223  }
224  grid_->getSceneNode()->setOrientation(orient);
225 
227 }
228 
229 } // namespace rviz
230 
IntProperty * height_property_
Definition: grid_display.h:84
Ogre::SceneNode * getSceneNode()
Get the Ogre scene node associated with this grid.
Definition: grid.h:97
void setMin(float min)
EnumProperty * plane_property_
Definition: grid_display.h:90
void setMax(float max)
Grid * grid_
Handles actually drawing the grid.
Definition: grid_display.h:80
bool transformHasProblems(const std::string &frame, ros::Time time, std::string &error)
Check to see if a transform is known between a given frame and the fixed frame.
f
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz...
Definition: display.h:287
virtual QColor getColor() const
FloatProperty * line_width_property_
Definition: grid_display.h:86
FloatProperty * cell_size_property_
Definition: grid_display.h:85
IntProperty * cell_count_property_
Definition: grid_display.h:83
virtual Ogre::Vector3 getVector() const
void setMin(int min)
void setHeight(uint32_t count)
Definition: grid.cpp:141
Property specialized to enforce floating point max/min.
EnumProperty * style_property_
Definition: grid_display.h:87
Property specialized to provide max/min enforcement for integers.
Definition: int_property.h:37
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
Definition: display.h:295
void setStyle(Style style)
Definition: grid.cpp:134
Ogre::ColourValue qtToOgre(const QColor &c)
Definition: parse_color.cpp:83
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:312
void setCellCount(uint32_t count)
Definition: grid.cpp:95
void setCellLength(float len)
Definition: grid.cpp:102
FloatProperty * alpha_property_
Definition: grid_display.h:89
virtual void addOption(const QString &option, int value=0)
Displays a grid in either the XY, YZ, or XZ plane.
Definition: grid_display.h:51
ColorProperty * color_property_
Definition: grid_display.h:88
void show()
Show this Property in any PropertyTreeWidgets.
Definition: property.h:410
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
void onInitialize() override
Override this function to do subclass-specific initialization.
Displays a grid of cells, drawn with lines.
Definition: grid.h:62
Ogre::SceneManager * scene_manager_
A convenience variable equal to context_->getSceneManager().
Definition: display.h:292
virtual int getInt() const
Return the internal property value as an integer.
Definition: int_property.h:74
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
void setLineWidth(float width)
Definition: grid.cpp:109
static const QString FIXED_FRAME_STRING
virtual float getFloat() const
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
Return the pose for a header, relative to the fixed frame, in Ogre classes.
void setFrameManager(FrameManager *frame_manager)
void hide()
Hide this Property in any PropertyTreeWidgets.
Definition: property.h:401
~GridDisplay() override
bool initialized() const
Returns true if the display has been initialized.
Definition: display.h:275
virtual int getOptionInt()
Return the int value of the currently-chosen option, or 0 if the current option string does not have ...
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
Enum property.
Definition: enum_property.h:46
void setColor(const Ogre::ColourValue &color)
Definition: grid.cpp:116
void update(float dt, float ros_dt) override
Called periodically by the visualization manager.
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
Show status level and text. This is thread-safe.
Definition: display.cpp:175
TfFrameProperty * frame_property_
Definition: grid_display.h:82
VectorProperty * offset_property_
Definition: grid_display.h:91


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:24