pose_array_display.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <OgreManualObject.h>
00031 #include <OgreSceneManager.h>
00032 #include <OgreSceneNode.h>
00033 
00034 #include "rviz/display_context.h"
00035 #include "rviz/frame_manager.h"
00036 #include "rviz/properties/color_property.h"
00037 #include "rviz/properties/float_property.h"
00038 #include "rviz/validate_floats.h"
00039 
00040 #include "rviz/default_plugin/pose_array_display.h"
00041 
00042 namespace rviz
00043 {
00044 
00045 PoseArrayDisplay::PoseArrayDisplay()
00046   : manual_object_( NULL )
00047 {
00048   color_property_ = new ColorProperty( "Color", QColor( 255, 25, 0 ), "Color to draw the arrows.", this );
00049   length_property_ = new FloatProperty( "Arrow Length", 0.3, "Length of the arrows.", this );
00050 }
00051 
00052 PoseArrayDisplay::~PoseArrayDisplay()
00053 {
00054   if ( initialized() )
00055   {
00056     scene_manager_->destroyManualObject( manual_object_ );
00057   }
00058 }
00059 
00060 void PoseArrayDisplay::onInitialize()
00061 {
00062   MFDClass::onInitialize();
00063   manual_object_ = scene_manager_->createManualObject();
00064   manual_object_->setDynamic( true );
00065   scene_node_->attachObject( manual_object_ );
00066 }
00067 
00068 bool validateFloats( const geometry_msgs::PoseArray& msg )
00069 {
00070   return validateFloats( msg.poses );
00071 }
00072 
00073 void PoseArrayDisplay::processMessage( const geometry_msgs::PoseArray::ConstPtr& msg )
00074 {
00075   if( !validateFloats( *msg ))
00076   {
00077     setStatus( StatusProperty::Error, "Topic", "Message contained invalid floating point values (nans or infs)" );
00078     return;
00079   }
00080 
00081   manual_object_->clear();
00082 
00083   Ogre::Vector3 position;
00084   Ogre::Quaternion orientation;
00085   if( !context_->getFrameManager()->getTransform( msg->header, position, orientation ))
00086   {
00087     ROS_DEBUG( "Error transforming from frame '%s' to frame '%s'", msg->header.frame_id.c_str(), qPrintable( fixed_frame_ ));
00088   }
00089 
00090   scene_node_->setPosition( position );
00091   scene_node_->setOrientation( orientation );
00092 
00093   manual_object_->clear();
00094 
00095   Ogre::ColourValue color = color_property_->getOgreColor();
00096   float length = length_property_->getFloat();
00097   size_t num_poses = msg->poses.size();
00098   manual_object_->estimateVertexCount( num_poses * 6 );
00099   manual_object_->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST );
00100   for( size_t i=0; i < num_poses; ++i )
00101   {
00102     Ogre::Vector3 pos( msg->poses[i].position.x,
00103                        msg->poses[i].position.y,
00104                        msg->poses[i].position.z );
00105     Ogre::Quaternion orient( msg->poses[i].orientation.w,
00106                              msg->poses[i].orientation.x,
00107                              msg->poses[i].orientation.y,
00108                              msg->poses[i].orientation.z );
00109     // orient here is not normalized, so the scale of the quaternion
00110     // will affect the scale of the arrow.
00111 
00112     Ogre::Vector3 vertices[6];
00113     vertices[0] = pos; // back of arrow
00114     vertices[1] = pos + orient * Ogre::Vector3( length, 0, 0 ); // tip of arrow
00115     vertices[2] = vertices[ 1 ];
00116     vertices[3] = pos + orient * Ogre::Vector3( 0.75*length, 0.2*length, 0 );
00117     vertices[4] = vertices[ 1 ];
00118     vertices[5] = pos + orient * Ogre::Vector3( 0.75*length, -0.2*length, 0 );
00119 
00120     for( int i = 0; i < 6; ++i )
00121     {
00122       manual_object_->position( vertices[i] );
00123       manual_object_->colour( color );
00124     }
00125   }
00126   manual_object_->end();
00127 
00128   context_->queueRender();
00129 }
00130 
00131 void PoseArrayDisplay::reset()
00132 {
00133   MFDClass::reset();
00134   if( manual_object_ )
00135   {
00136     manual_object_->clear();
00137   }
00138 }
00139 
00140 } // namespace rviz
00141 
00142 #include <pluginlib/class_list_macros.h>
00143 PLUGINLIB_EXPORT_CLASS( rviz::PoseArrayDisplay, rviz::Display )


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Thu Aug 27 2015 15:02:27