pose_with_covariance_display.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 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 <OGRE/OgreSceneNode.h>
31 #include <OGRE/OgreSceneManager.h>
32 
33 #include <tf/transform_listener.h>
34 
38 #include <rviz/frame_manager.h>
39 
42 
43 namespace tuw_pose_rviz_plugin {
44 
45 // The constructor must have no arguments, so we can't give the
46 // constructor the parameters it needs to fully initialize.
48  property_scale_pose_ = new rviz::FloatProperty ( "Scale Pose", 0.4,
49  "Scale of the pose's pose.",
50  this, SLOT ( updateScalePose() ) );
53 
54  property_color_pose_ = new rviz::ColorProperty ( "Color Pose", QColor ( 204, 51, 0 ),
55  "Color to draw the pose's pose.",
56  this, SLOT ( updateColorPose() ) );
57 
58  property_color_variance_ = new rviz::ColorProperty ( "Color Variance", QColor ( 204, 51, 204 ),
59  "Color to draw the pose's variance.",
60  this, SLOT ( updateColorVariance() ) );
61 }
62 
63 // After the top-level rviz::Display::initialize() does its own setup,
64 // it calls the subclass's onInitialize() function. This is where we
65 // instantiate all the workings of the class. We make sure to also
66 // call our immediate super-class's onInitialize() function, since it
67 // does important stuff setting up the message filter.
68 //
69 // Note that "MFDClass" is a typedef of
70 // ``MessageFilterDisplay<message type>``, to save typing that long
71 // templated class name every time you need to refer to the
72 // superclass.
76 }
77 
79 }
80 
81 // Clear the visual by deleting its object.
84 }
85 
86 // Set the current scale for the visual's pose.
88  float scale = property_scale_pose_->getFloat();
89  visual_->setScalePose ( scale );
90 }
91 
92 // Set the current color for the visual's pose.
94  Ogre::ColourValue color = property_color_pose_->getOgreColor();
95  visual_->setColorPose ( color );
96 }
97 
98 // Set the current color for the visual's variance.
100  Ogre::ColourValue color = property_color_variance_->getOgreColor();
101  visual_->setColorVariance ( color );
102 }
103 
104 // This is our callback to handle an incoming message.
105 void PoseWithCovarianceDisplay::processMessage ( const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& msg ) {
106  // Here we call the rviz::FrameManager to get the transform from the
107  // fixed frame to the frame in the header of this Imu message. If
108  // it fails, we can't do anything else so we return.
109  Ogre::Quaternion orientation;
110  Ogre::Vector3 position;
111 
112  if ( !context_->getFrameManager()->getTransform ( msg->header.frame_id, msg->header.stamp, position, orientation ) ) {
113  ROS_DEBUG ( "Error transforming from frame '%s' to frame '%s'",
114  msg->header.frame_id.c_str(), qPrintable ( fixed_frame_ ) );
115  return;
116  }
117 
118  // Now set or update the contents of the visual.
119  visual_->setMessage ( msg );
120  visual_->setFramePosition ( position );
121  visual_->setFrameOrientation ( orientation );
122  visual_->setScalePose ( property_scale_pose_->getFloat() );
123  visual_->setColorPose ( property_color_pose_->getOgreColor() );
124  visual_->setColorVariance ( property_color_variance_->getOgreColor() );
125 }
126 
127 } // end namespace tuw_pose_rviz_plugin
128 
129 // Tell pluginlib about this class. It is important to do this in
130 // global scope, outside our package's namespace.
void setMin(float min)
void setMax(float max)
Ogre::ColourValue getOgreColor() const
DisplayContext * context_
virtual float getFloat() const
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
Ogre::SceneNode * scene_node_
QString fixed_frame_
virtual FrameManager * getFrameManager() const =0
void processMessage(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr &msg)
virtual Ogre::SceneManager * getSceneManager() const =0
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
boost::shared_ptr< PoseWithCovarianceVisual > visual_
#define ROS_DEBUG(...)


tuw_pose_rviz_plugin
Author(s):
autogenerated on Mon Aug 1 2016 04:05:13