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 {
48 
50 : Display()
51 {
53  "The TF frame this grid will use for its origin.",
54  this, 0, true );
55 
56  cell_count_property_ = new IntProperty( "Plane Cell Count", 10,
57  "The number of cells to draw in the plane of the grid.",
58  this, SLOT( updateCellCount() ));
60 
61  height_property_ = new IntProperty( "Normal Cell Count", 0,
62  "The number of cells to draw along the normal vector of the grid. "
63  " Setting to anything but 0 makes the grid 3D.",
64  this, SLOT( updateHeight() ));
66 
67  cell_size_property_ = new FloatProperty( "Cell Size", 1.0f,
68  "The length, in meters, of the side of each cell.",
69  this, SLOT( updateCellSize() ));
70  cell_size_property_->setMin( 0.0001 );
71 
72  style_property_ = new EnumProperty( "Line Style", "Lines",
73  "The rendering operation to use to draw the grid lines.",
74  this, SLOT( updateStyle() ));
76  style_property_->addOption( "Billboards", Grid::Billboards );
77 
78  line_width_property_ = new FloatProperty( "Line Width", 0.03,
79  "The width, in meters, of each grid line.",
80  style_property_, SLOT( updateLineWidth() ), this );
81  line_width_property_->setMin( 0.001 );
83 
84  color_property_ = new ColorProperty( "Color", Qt::gray,
85  "The color of the grid lines.",
86  this, SLOT( updateColor() ));
87  alpha_property_ = new FloatProperty( "Alpha", 0.5f,
88  "The amount of transparency to apply to the grid lines.",
89  this, SLOT( updateColor() ));
90  alpha_property_->setMin( 0.0f );
91  alpha_property_->setMax( 1.0f );
92 
93  plane_property_ = new EnumProperty( "Plane", "XY",
94  "The plane to draw the grid along.",
95  this, SLOT( updatePlane() ));
96  plane_property_->addOption( "XY", XY );
97  plane_property_->addOption( "XZ", XZ );
98  plane_property_->addOption( "YZ", YZ );
99 
100  offset_property_ = new VectorProperty( "Offset", Ogre::Vector3::ZERO,
101  "Allows you to offset the grid from the origin of the reference frame. In meters.",
102  this, SLOT( updateOffset() ));
103 }
104 
106 {
107  if ( initialized() )
108  {
109  delete grid_;
110  }
111 }
112 
114 {
115  QColor color = color_property_->getColor();
116  color.setAlphaF( alpha_property_->getFloat() );
117 
124  qtToOgre( color ));
125 
126  grid_->getSceneNode()->setVisible( false );
127  updatePlane();
128 }
129 
130 void GridDisplay::update(float dt, float ros_dt)
131 {
132  QString qframe = frame_property_->getFrame();
133  std::string frame = qframe.toStdString();
134 
135  Ogre::Vector3 position;
136  Ogre::Quaternion orientation;
137  if( context_->getFrameManager()->getTransform( frame, ros::Time(), position, orientation ))
138  {
139  scene_node_->setPosition( position );
140  scene_node_->setOrientation( orientation );
141  setStatus( StatusProperty::Ok, "Transform", "Transform OK" );
142  }
143  else
144  {
145  std::string error;
146  if( context_->getFrameManager()->transformHasProblems( frame, ros::Time(), error ))
147  {
148  setStatus( StatusProperty::Error, "Transform", QString::fromStdString( error ));
149  }
150  else
151  {
152  setStatus( StatusProperty::Error, "Transform",
153  "Could not transform from [" + qframe + "] to [" + fixed_frame_ + "]" );
154  }
155  }
156 }
157 
159 {
160  QColor color = color_property_->getColor();
161  color.setAlphaF( alpha_property_->getFloat() );
162  grid_->setColor( qtToOgre( color ));
164 }
165 
167 {
170 }
171 
173 {
176 }
177 
179 {
182 }
183 
185 {
188 }
189 
191 {
193  grid_->setStyle( style );
194 
195  switch( style )
196  {
197  case Grid::Billboards:
199  break;
200  case Grid::Lines:
201  default:
203  break;
204  }
206 }
207 
209 {
210  grid_->getSceneNode()->setPosition( offset_property_->getVector() );
212 }
213 
215 {
216  Ogre::Quaternion orient;
217  switch( (Plane) plane_property_->getOptionInt() )
218  {
219  case XZ:
220  orient = Ogre::Quaternion( 1, 0, 0, 0 );
221  break;
222  case YZ:
223  orient = Ogre::Quaternion( Ogre::Vector3( 0, -1, 0 ), Ogre::Vector3( 0, 0, 1 ), Ogre::Vector3( 1, 0, 0 ));
224  break;
225  case XY:
226  default:
227  orient = Ogre::Quaternion( Ogre::Vector3( 1, 0, 0 ), Ogre::Vector3( 0, 0, -1 ), Ogre::Vector3( 0, 1, 0 ));
228  break;
229  }
230  grid_->getSceneNode()->setOrientation( orient );
231 
233 }
234 
235 } // namespace rviz
236 
virtual QColor getColor() const
IntProperty * height_property_
Definition: grid_display.h:84
Ogre::SceneNode * getSceneNode()
Get the Ogre scene node associated with this grid.
Definition: grid.h:91
void setMin(float min)
EnumProperty * plane_property_
Definition: grid_display.h:90
void setMax(float max)
virtual ~GridDisplay()
Grid * grid_
Handles actually drawing the grid.
Definition: grid_display.h:80
virtual void update(float dt, float ros_dt)
Called periodically by the visualization manager.
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
virtual void onInitialize()
Override this function to do subclass-specific initialization.
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz...
Definition: display.h:256
virtual int getInt() const
Return the internal property value as an integer.
Definition: int_property.h:73
FloatProperty * line_width_property_
Definition: grid_display.h:86
FloatProperty * cell_size_property_
Definition: grid_display.h:85
virtual float getFloat() const
IntProperty * cell_count_property_
Definition: grid_display.h:83
void setMin(int min)
void setHeight(uint32_t count)
Definition: grid.cpp:135
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:38
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
Definition: display.h:264
void setStyle(Style style)
Definition: grid.cpp:128
Ogre::ColourValue qtToOgre(const QColor &c)
Definition: parse_color.cpp:87
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:281
void setCellCount(uint32_t count)
Definition: grid.cpp:89
void setCellLength(float len)
Definition: grid.cpp:96
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:377
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
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:261
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
virtual Ogre::Vector3 getVector() const
void setLineWidth(float width)
Definition: grid.cpp:103
static const QString FIXED_FRAME_STRING
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:371
bool initialized() const
Returns true if the display has been initialized.
Definition: display.h:247
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:47
void setColor(const Ogre::ColourValue &color)
Definition: grid.cpp:110
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
Show status level and text. This is thread-safe.
Definition: display.cpp:186
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 Wed Aug 28 2019 04:01:51