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/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.",
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.",
64 
66  new FloatProperty("Cell Size", 1.0f, "The length, in meters, of the side of each cell.", this,
68  cell_size_property_->setMin(0.0001);
69 
71  new EnumProperty("Line Style", "Lines", "The rendering operation to use to draw the grid lines.",
75 
77  new FloatProperty("Line Width", 0.03, "The width, in meters, of each grid line.", style_property_,
81 
82  color_property_ = new ColorProperty("Color", Qt::gray, "The color of the grid lines.", this,
85  new FloatProperty("Alpha", 0.5f, "The amount of transparency to apply to the grid lines.", this,
89 
90  plane_property_ = new EnumProperty("Plane", "XY", "The plane to draw the grid along.", this,
95 
97  "Offset", Ogre::Vector3::ZERO,
98  "Allows you to offset the grid from the origin of the reference frame. In meters.", this,
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 
rviz::GridDisplay::XY
@ XY
Definition: grid_display.h:57
rviz::EnumProperty::getOptionInt
virtual int getOptionInt()
Return the int value of the currently-chosen option, or 0 if the current option string does not have ...
Definition: enum_property.cpp:56
rviz::IntProperty::setMin
void setMin(int min)
Definition: int_property.cpp:52
rviz::ColorProperty::getColor
virtual QColor getColor() const
Definition: color_property.h:79
rviz::GridDisplay::line_width_property_
FloatProperty * line_width_property_
Definition: grid_display.h:86
rviz::qtToOgre
Ogre::ColourValue qtToOgre(const QColor &c)
Definition: parse_color.cpp:83
frame_manager.h
rviz::DisplayContext::queueRender
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
rviz::Display::initialized
bool initialized() const
Returns true if the display has been initialized.
Definition: display.h:275
rviz::GridDisplay::grid_
Grid * grid_
Handles actually drawing the grid.
Definition: grid_display.h:80
rviz::StatusProperty::Error
@ Error
Definition: status_property.h:46
rviz::GridDisplay::YZ
@ YZ
Definition: grid_display.h:59
rviz::GridDisplay::updateLineWidth
void updateLineWidth()
Definition: grid_display.cpp:172
rviz::Property::show
void show()
Show this Property in any PropertyTreeWidgets.
Definition: property.h:471
property.h
rviz::GridDisplay::~GridDisplay
~GridDisplay() override
Definition: grid_display.cpp:102
rviz::FloatProperty::setMax
void setMax(float max)
Definition: float_property.cpp:57
rviz::Grid::setLineWidth
void setLineWidth(float width)
Definition: grid.cpp:108
grid.h
grid_display.h
selection_manager.h
rviz::Display::fixed_frame_
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:312
rviz::FloatProperty::setMin
void setMin(float min)
Definition: float_property.cpp:51
rviz::GridDisplay::updateColor
void updateColor()
Definition: grid_display.cpp:152
f
f
rviz::ColorProperty
Definition: color_property.h:40
rviz::Display
Definition: display.h:63
rviz::GridDisplay::updateCellCount
void updateCellCount()
Definition: grid_display.cpp:166
rviz::EnumProperty
Enum property.
Definition: enum_property.h:46
rviz::FloatProperty
Property specialized to enforce floating point max/min.
Definition: float_property.h:37
rviz::GridDisplay::cell_size_property_
FloatProperty * cell_size_property_
Definition: grid_display.h:85
rviz::Property::hide
void hide()
Hide this Property in any PropertyTreeWidgets.
Definition: property.h:462
rviz::Display::setStatus
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
Show status level and text. This is thread-safe.
Definition: display.cpp:176
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::FloatProperty::getFloat
virtual float getFloat() const
Definition: float_property.h:79
rviz::Grid::setColor
void setColor(const Ogre::ColourValue &color)
Definition: grid.cpp:115
rviz::EnumProperty::addOption
virtual void addOption(const QString &option, int value=0)
Definition: enum_property.cpp:50
rviz::Grid::setHeight
void setHeight(uint32_t count)
Definition: grid.cpp:140
rviz
Definition: add_display_dialog.cpp:54
rviz::Display::scene_node_
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
Definition: display.h:295
rviz::GridDisplay::height_property_
IntProperty * height_property_
Definition: grid_display.h:84
rviz::GridDisplay::Plane
Plane
Definition: grid_display.h:55
rviz::GridDisplay::updateCellSize
void updateCellSize()
Definition: grid_display.cpp:160
rviz::StatusProperty::Ok
@ Ok
Definition: status_property.h:44
rviz::GridDisplay::GridDisplay
GridDisplay()
Definition: grid_display.cpp:48
rviz::Display::scene_manager_
Ogre::SceneManager * scene_manager_
A convenience variable equal to context_->getSceneManager().
Definition: display.h:292
rviz::Grid::getSceneNode
Ogre::SceneNode * getSceneNode()
Get the Ogre scene node associated with this grid.
Definition: grid.h:97
rviz::Grid::Billboards
@ Billboards
Definition: grid.h:68
rviz::Grid::setCellCount
void setCellCount(uint32_t count)
Definition: grid.cpp:94
rviz::Grid::Style
Style
Definition: grid.h:65
rviz::DisplayContext::getFrameManager
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
rviz::GridDisplay::alpha_property_
FloatProperty * alpha_property_
Definition: grid_display.h:89
rviz::Grid
Displays a grid of cells, drawn with lines.
Definition: grid.h:62
rviz::GridDisplay::plane_property_
EnumProperty * plane_property_
Definition: grid_display.h:90
rviz::TfFrameProperty
Definition: tf_frame_property.h:41
rviz::FrameManager::getTransform
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.
Definition: frame_manager.h:125
rviz::TfFrameProperty::FIXED_FRAME_STRING
static const QString FIXED_FRAME_STRING
Definition: tf_frame_property.h:92
rviz::Display::context_
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz....
Definition: display.h:287
ros::Time
rviz::Grid::Lines
@ Lines
Definition: grid.h:67
rviz::TfFrameProperty::getFrame
QString getFrame() const
Definition: tf_frame_property.cpp:99
rviz::GridDisplay::offset_property_
VectorProperty * offset_property_
Definition: grid_display.h:91
rviz::GridDisplay
Displays a grid in either the XY, YZ, or XZ plane.
Definition: grid_display.h:51
rviz::GridDisplay::cell_count_property_
IntProperty * cell_count_property_
Definition: grid_display.h:83
rviz::GridDisplay::frame_property_
TfFrameProperty * frame_property_
Definition: grid_display.h:82
rviz::GridDisplay::updateStyle
void updateStyle()
Definition: grid_display.cpp:184
class_list_macros.hpp
rviz::Grid::setStyle
void setStyle(Style style)
Definition: grid.cpp:133
rviz::GridDisplay::onInitialize
void onInitialize() override
Override this function to do subclass-specific initialization.
Definition: grid_display.cpp:110
rviz::IntProperty::getInt
virtual int getInt() const
Return the internal property value as an integer.
Definition: int_property.h:96
rviz::TfFrameProperty::setFrameManager
void setFrameManager(FrameManager *frame_manager)
Definition: tf_frame_property.cpp:67
rviz::GridDisplay::updatePlane
void updatePlane()
Definition: grid_display.cpp:208
display_context.h
rviz::VectorProperty
Definition: vector_property.h:39
rviz::GridDisplay::update
void update(float dt, float ros_dt) override
Called periodically by the visualization manager.
Definition: grid_display.cpp:124
rviz::GridDisplay::XZ
@ XZ
Definition: grid_display.h:58
rviz::VectorProperty::getVector
virtual Ogre::Vector3 getVector() const
Definition: vector_property.h:73
rviz::GridDisplay::updateOffset
void updateOffset()
Definition: grid_display.cpp:202
rviz::GridDisplay::style_property_
EnumProperty * style_property_
Definition: grid_display.h:87
rviz::Grid::setCellLength
void setCellLength(float len)
Definition: grid.cpp:101
rviz::FrameManager::transformHasProblems
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.
Definition: frame_manager.cpp:272
rviz::GridDisplay::updateHeight
void updateHeight()
Definition: grid_display.cpp:178
rviz::IntProperty
Property specialized to provide max/min enforcement for integers.
Definition: int_property.h:37
parse_color.h
rviz::GridDisplay::color_property_
ColorProperty * color_property_
Definition: grid_display.h:88


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:02