00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <stdint.h>
00031 #include "grid_display.h"
00032 #include "rviz/visualization_manager.h"
00033 #include "rviz/properties/property.h"
00034 #include "rviz/properties/property_manager.h"
00035 #include "rviz/frame_manager.h"
00036
00037 #include "ogre_tools/grid.h"
00038
00039 #include <boost/bind.hpp>
00040
00041 #include <OGRE/OgreSceneNode.h>
00042 #include <OGRE/OgreSceneManager.h>
00043
00044 namespace rviz
00045 {
00046
00047 GridDisplay::GridDisplay( const std::string& name, VisualizationManager* manager )
00048 : Display( name, manager )
00049 , color_( 0.5f, 0.5f, 0.5f )
00050 , alpha_( 0.5f )
00051 , plane_(XY)
00052 {
00053 offset_ = Ogre::Vector3::ZERO;
00054
00055 scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
00056 grid_ = new ogre_tools::Grid( scene_manager_, scene_node_, ogre_tools::Grid::Lines, 10, 1.0f, 0.03f, Ogre::ColourValue(color_.r_, color_.g_, color_.b_, alpha_) );
00057 grid_->getSceneNode()->setVisible( false );
00058
00059 setStyle(ogre_tools::Grid::Lines);
00060 setFrame(FIXED_FRAME_STRING);
00061 }
00062
00063 GridDisplay::~GridDisplay()
00064 {
00065 delete grid_;
00066 scene_manager_->destroySceneNode(scene_node_);
00067 }
00068
00069 void GridDisplay::onEnable()
00070 {
00071 grid_->getSceneNode()->setVisible( true );
00072 }
00073
00074 void GridDisplay::onDisable()
00075 {
00076 grid_->getSceneNode()->setVisible( false );
00077 }
00078
00079 void GridDisplay::setCellSize( float size )
00080 {
00081 grid_->setCellLength(size);
00082
00083 propertyChanged(cell_size_property_);
00084
00085 causeRender();
00086 }
00087
00088 void GridDisplay::setCellCount( uint32_t count )
00089 {
00090 grid_->setCellCount(count);
00091
00092 propertyChanged(cell_count_property_);
00093
00094 causeRender();
00095 }
00096
00097 void GridDisplay::setColor( const Color& color )
00098 {
00099 color_ = color;
00100 grid_->setColor(Ogre::ColourValue(color.r_, color.g_, color.b_, alpha_));
00101
00102 propertyChanged(color_property_);
00103
00104 causeRender();
00105 }
00106
00107 void GridDisplay::setLineWidth( float width )
00108 {
00109 grid_->setLineWidth(width);
00110
00111 propertyChanged(line_width_property_);
00112
00113 causeRender();
00114 }
00115
00116 void GridDisplay::setStyle( int style )
00117 {
00118 grid_->setStyle((ogre_tools::Grid::Style)style);
00119
00120 switch (style)
00121 {
00122 case ogre_tools::Grid::Billboards:
00123 showProperty(line_width_property_);
00124 break;
00125 case ogre_tools::Grid::Lines:
00126 hideProperty(line_width_property_);
00127 break;
00128 }
00129
00130 propertyChanged(style_property_);
00131
00132 causeRender();
00133 }
00134
00135 void GridDisplay::setAlpha( float a )
00136 {
00137 alpha_ = a;
00138
00139 grid_->setColor(Ogre::ColourValue(color_.r_, color_.g_, color_.b_, alpha_));
00140
00141 propertyChanged(alpha_property_);
00142
00143 causeRender();
00144 }
00145
00146 void GridDisplay::setHeight( uint32_t height )
00147 {
00148 grid_->setHeight( height );
00149
00150 propertyChanged(height_property_);
00151
00152 causeRender();
00153 }
00154
00155 void GridDisplay::setOffset( const Ogre::Vector3& offset )
00156 {
00157 offset_ = offset;
00158
00159 Ogre::Vector3 ogre_offset = offset;
00160
00161 grid_->getSceneNode()->setPosition(ogre_offset);
00162
00163 propertyChanged(offset_property_);
00164
00165 causeRender();
00166 }
00167
00168 void GridDisplay::setPlane(int plane)
00169 {
00170 plane_ = (Plane)plane;
00171
00172 if (plane_ == XY)
00173 {
00174 grid_->getSceneNode()->setOrientation(Ogre::Quaternion(Ogre::Vector3(1.0f, 0.0f, 0.0f), Ogre::Vector3(0.0f, 0.0f, -1.0f), Ogre::Vector3(0.0f, 1.0f, 0.0f)));
00175 }
00176 else if (plane_ == XZ)
00177 {
00178 grid_->getSceneNode()->setOrientation(1.0f, 0.0f, 0.0f, 0.0f);
00179 }
00180 else if (plane_ == YZ)
00181 {
00182 grid_->getSceneNode()->setOrientation(Ogre::Quaternion(Ogre::Vector3(0.0f, -1.0f, 0.0f), Ogre::Vector3(0.0f, 0.0f, 1.0f), Ogre::Vector3(1.0f, 0.0f, 0.0f)));
00183 }
00184
00185 propertyChanged(plane_property_);
00186
00187 causeRender();
00188 }
00189
00190 void GridDisplay::setFrame(const std::string& frame)
00191 {
00192 frame_ = frame;
00193 propertyChanged(frame_property_);
00194 }
00195
00196 void GridDisplay::update(float dt, float ros_dt)
00197 {
00198 std::string frame = frame_;
00199 if (frame == FIXED_FRAME_STRING)
00200 {
00201 frame = fixed_frame_;
00202 }
00203
00204 Ogre::Vector3 position;
00205 Ogre::Quaternion orientation;
00206 if (vis_manager_->getFrameManager()->getTransform(frame, ros::Time(), position, orientation))
00207 {
00208 scene_node_->setPosition(position);
00209 scene_node_->setOrientation(orientation);
00210 setStatus(status_levels::Ok, "Transform", "Transform OK");
00211 }
00212 else
00213 {
00214 std::string error;
00215 if (vis_manager_->getFrameManager()->transformHasProblems(frame, ros::Time(), error))
00216 {
00217 setStatus(status_levels::Error, "Transform", error);
00218 }
00219 else
00220 {
00221 std::stringstream ss;
00222 ss << "Could not transform from [" << frame << "] to [" << fixed_frame_ << "]";
00223 setStatus(status_levels::Error, "Transform", ss.str());
00224 }
00225 }
00226 }
00227
00228 void GridDisplay::createProperties()
00229 {
00230 frame_property_ = property_manager_->createProperty<TFFrameProperty>("Reference Frame", property_prefix_, boost::bind(&GridDisplay::getFrame, this),
00231 boost::bind(&GridDisplay::setFrame, this, _1), parent_category_, this);
00232 setPropertyHelpText(frame_property_, "The TF frame this grid will use for its origin.");
00233
00234 cell_count_property_ = property_manager_->createProperty<IntProperty>( "Plane Cell Count", property_prefix_, boost::bind( &ogre_tools::Grid::getCellCount, grid_),
00235 boost::bind( &GridDisplay::setCellCount, this, _1 ), parent_category_, this );
00236 setPropertyHelpText(cell_count_property_, "The number of cells to draw in the plane of the grid.");
00237 IntPropertyPtr int_prop = cell_count_property_.lock();
00238 int_prop->setMin( 1 );
00239 int_prop->addLegacyName("Cell Count");
00240
00241 height_property_ = property_manager_->createProperty<IntProperty>( "Normal Cell Count", property_prefix_, boost::bind( &ogre_tools::Grid::getHeight, grid_),
00242 boost::bind( &GridDisplay::setHeight, this, _1 ), parent_category_, this );
00243 setPropertyHelpText(height_property_, "The number of cells to draw along the normal vector of the grid. Setting to anything but 0 makes the grid 3D.");
00244 int_prop = height_property_.lock();
00245 int_prop->setMin( 0 );
00246
00247 cell_size_property_ = property_manager_->createProperty<FloatProperty>( "Cell Size", property_prefix_, boost::bind( &ogre_tools::Grid::getCellLength, grid_ ),
00248 boost::bind( &GridDisplay::setCellSize, this, _1 ), parent_category_, this );
00249 setPropertyHelpText(cell_size_property_, "The length, in meters, of the side of each cell.");
00250 FloatPropertyPtr float_prop = cell_size_property_.lock();
00251 float_prop->setMin( 0.0001 );
00252
00253 style_property_ = property_manager_->createProperty<EnumProperty>( "Line Style", property_prefix_, boost::bind( &ogre_tools::Grid::getStyle, grid_ ),
00254 boost::bind( &GridDisplay::setStyle, this, _1 ), parent_category_, this );
00255 setPropertyHelpText(style_property_, "The rendering operation to use to draw the grid lines.");
00256 EnumPropertyPtr enum_prop = style_property_.lock();
00257 enum_prop->addOption("Lines", ogre_tools::Grid::Lines);
00258 enum_prop->addOption("Billboards", ogre_tools::Grid::Billboards);
00259
00260 line_width_property_ = property_manager_->createProperty<FloatProperty>( "Line Width", property_prefix_, boost::bind( &ogre_tools::Grid::getLineWidth, grid_ ),
00261 boost::bind( &GridDisplay::setLineWidth, this, _1 ), parent_category_, this );
00262 setPropertyHelpText(line_width_property_, "The width, in meters, of each grid line.");
00263 float_prop = line_width_property_.lock();
00264 float_prop->setMin( 0.001 );
00265 float_prop->hide();
00266
00267 color_property_ = property_manager_->createProperty<ColorProperty>( "Color", property_prefix_, boost::bind( &GridDisplay::getColor, this ),
00268 boost::bind( &GridDisplay::setColor, this, _1 ), parent_category_, this );
00269 setPropertyHelpText(color_property_, "The color of the grid lines.");
00270 alpha_property_ = property_manager_->createProperty<FloatProperty>( "Alpha", property_prefix_, boost::bind( &GridDisplay::getAlpha, this ),
00271 boost::bind( &GridDisplay::setAlpha, this, _1 ), parent_category_, this );
00272 setPropertyHelpText(alpha_property_, "The amount of transparency to apply to the grid lines.");
00273 float_prop = alpha_property_.lock();
00274 float_prop->setMin( 0.0 );
00275 float_prop->setMax( 1.0f );
00276
00277 plane_property_ = property_manager_->createProperty<EnumProperty>( "Plane", property_prefix_, boost::bind( &GridDisplay::getPlane, this ),
00278 boost::bind( &GridDisplay::setPlane, this, _1 ), parent_category_, this );
00279 setPropertyHelpText(plane_property_, "The plane to draw the grid along.");
00280 enum_prop = plane_property_.lock();
00281 enum_prop->addOption("XY", XY);
00282 enum_prop->addOption("XZ", XZ);
00283 enum_prop->addOption("YZ", YZ);
00284
00285 offset_property_ = property_manager_->createProperty<Vector3Property>( "Offset", property_prefix_, boost::bind( &GridDisplay::getOffset, this ),
00286 boost::bind( &GridDisplay::setOffset, this, _1 ), parent_category_, this );
00287 setPropertyHelpText(offset_property_, "Allows you to offset the grid from the origin of the reference frame. In meters.");
00288 }
00289
00290 }