spline_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 
39 #include <rviz/frame_manager.h>
40 
41 #include <spline/spline_visual.h>
42 #include <spline/spline_display.h>
43 
44 namespace tuw_spline_rviz_plugin {
45 
46 // The constructor must have no arguments, so we can't give the
47 // constructor the parameters it needs to fully initialize.
49  color_path_property_ = new rviz::ColorProperty ( "Path Color", QColor ( 50, 51, 204 ),
50  "Color to draw the spline.",
51  this, SLOT ( updatePathColor() ) );
52 
53  shape_property_ = new rviz::EnumProperty ( "Path Shape", QString::fromStdString ( "Sphere" ),
54  "Shape of the spline.",
55  this, SLOT ( updateShape() ) );
59 
60  points_nr_path_property_ = new rviz::IntProperty ( "Path Points Nr", 100,
61  "Number of points to display along path.",
62  this, SLOT ( updatePathPointsNr() ) );
64  points_nr_path_property_->setMax ( 100000 );
65 
66  scale_path_property_ = new rviz::FloatProperty ( "Path Points Scale", 0.1,
67  "Scale of the spline contour.",
68  this, SLOT ( updatePathScale() ) );
71 
72  color_orient_property_ = new rviz::ColorProperty ( "Orientation Color", QColor ( 50, 51, 204 ),
73  "Color to draw the spline orientation arrows.",
74  this, SLOT ( updateOrientColor() ) );
75  points_nr_orient_property_ = new rviz::IntProperty ( "Orientation Points Nr", 50,
76  "Number of arrows to display along path.",
77  this, SLOT ( updateOrientPointsNr() ) );
80 
81  scale_orient_property_ = new rviz::FloatProperty ( "Orientation Points Scale", 0.1,
82  "Scale of the spline orientation arrows.",
83  this, SLOT ( updateOrientScale() ) );
86 
87  history_length_property_ = new rviz::IntProperty ( "History Length", 1,
88  "Number of prior measurements to display.",
89  this, SLOT ( updateHistoryLength() ) );
91  history_length_property_->setMax ( 100000 );
92 }
93 
94 // After the top-level rviz::Display::initialize() does its own setup,
95 // it calls the subclass's onInitialize() function. This is where we
96 // instantiate all the workings of the class. We make sure to also
97 // call our immediate super-class's onInitialize() function, since it
98 // does important stuff setting up the message filter.
99 //
100 // Note that "MFDClass" is a typedef of
101 // ``MessageFilterDisplay<message type>``, to save typing that long
102 // templated class name every time you need to refer to the
103 // superclass.
107 }
108 
110 }
111 
112 // Clear the visuals by deleting their objects.
114  MFDClass::reset();
115  visuals_.clear();
116 }
117 
118 // Set the current color values for each visual.
120  Ogre::ColourValue color = color_path_property_->getOgreColor();
121  for ( auto& visualsI: visuals_ ) { visualsI->setPathColor ( color ); }
122 }
124  Ogre::ColourValue color = color_orient_property_->getOgreColor();
125  for ( auto& visualsI: visuals_ ) { visualsI->setOrientColor ( color ); }
126 }
127 
128 // Set the current shape for each visual.
131  for ( auto& visualsI: visuals_ ) { visualsI->setShape ( shape_type ); }
132 }
133 
134 // Set the current scale for each visual.
136  float scale = scale_path_property_->getFloat();
137  for ( auto& visualsI: visuals_ ) { visualsI->setPathScale ( scale ); }
138 }
140  float scale = scale_orient_property_->getFloat();
141  for ( auto& visualsI: visuals_ ) { visualsI->setOrientScale ( scale ); }
142 }
143 
144 // Set the number of past visuals to show.
146  visuals_.rset_capacity ( history_length_property_->getInt() );
147 }
148 
150  int pointsNr = points_nr_path_property_->getInt();
151  for ( auto& visualsI: visuals_ ) { visualsI->setPathPointsNr ( pointsNr ); }
152 }
154  int pointsNr = points_nr_orient_property_->getInt();
155  for ( auto& visualsI: visuals_ ) { visualsI->setOrientPointsNr ( pointsNr ); }
156 }
157 
158 
159 // This is our callback to handle an incoming message.
160 void SplineDisplay::processMessage ( const tuw_spline_msgs::Spline::ConstPtr& msg ) {
161  // Here we call the rviz::FrameManager to get the transform from the
162  // fixed frame to the frame in the header of this Imu message. If
163  // it fails, we can't do anything else so we return.
164  Ogre::Quaternion orientation;
165  Ogre::Vector3 position;
166  if ( !context_->getFrameManager()->getTransform ( msg->header.frame_id,
167  msg->header.stamp,
168  position, orientation ) ) {
169  ROS_DEBUG ( "Error transforming from frame '%s' to frame '%s'",
170  msg->header.frame_id.c_str(), qPrintable ( fixed_frame_ ) );
171  return;
172  }
173 
174  // We are keeping a circular buffer of visual pointers. This gets
175  // the next one, or creates and stores it if the buffer is not full
177  if ( visuals_.full() ) {
178  visual = visuals_.front();
179  } else {
180  visual.reset ( new SplineVisual ( context_->getSceneManager(), scene_node_ ) );
181  }
182 
183  // Now set or update the contents of the chosen visual.
184  visual->setMessage ( msg );
185  visual->setFramePosition ( position );
186  visual->setFrameOrientation ( orientation );
187 
188  visual->setPathColor ( color_path_property_->getOgreColor() );
189  visual->setShape ( ( rviz::Shape::Type ) shape_property_->getOptionInt() );
190  visual->setPathScale ( scale_path_property_->getFloat() );
191  visual->setPathPointsNr ( points_nr_path_property_->getInt() );
192 
193  visual->setOrientColor ( color_orient_property_->getOgreColor() );
194  visual->setOrientScale ( scale_orient_property_->getFloat() );
195  visual->setOrientPointsNr( points_nr_orient_property_->getInt() );
196 
197  // And send it to the end of the circular buffer
198  visuals_.push_back ( visual );
199 }
200 
201 } // end namespace tuw_spline_rviz_plugin
202 
203 // Tell pluginlib about this class. It is important to do this in
204 // global scope, outside our package's namespace.
void setMin(float min)
boost::circular_buffer< boost::shared_ptr< SplineVisual > > visuals_
void setMax(float max)
Ogre::ColourValue getOgreColor() const
rviz::ColorProperty * color_orient_property_
DisplayContext * context_
virtual int getInt() const
virtual float getFloat() const
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void setMin(int min)
Ogre::SceneNode * scene_node_
void setMax(int max)
rviz::IntProperty * points_nr_path_property_
QString fixed_frame_
virtual FrameManager * getFrameManager() const =0
rviz::ColorProperty * color_path_property_
rviz::FloatProperty * scale_orient_property_
void addOptionStd(const std::string &option, int value=0)
virtual Ogre::SceneManager * getSceneManager() const =0
rviz::IntProperty * points_nr_orient_property_
rviz::FloatProperty * scale_path_property_
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
void processMessage(const tuw_spline_msgs::Spline::ConstPtr &msg)
rviz::IntProperty * history_length_property_
virtual int getOptionInt()
#define ROS_DEBUG(...)


tuw_spline_rviz_plugin
Author(s):
autogenerated on Mon Aug 1 2016 04:05:16