PathDisplay.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2016 by George Todoran <george.todoran@tuwien.ac.at> *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * 2. Redistributions in binary form must reproduce the above copyright *
12  * notice, this list of conditions and the following disclaimer in *
13  * the documentation and/or other materials provided with the *
14  * distribution. *
15  * 3. Neither the name of the copyright holder nor the names of its *
16  * contributors may be used to endorse or promote products derived *
17  * from this software without specific prior written permission. *
18  * *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY *
29  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30  * POSSIBILITY OF SUCH DAMAGE. *
31  ***************************************************************************/
32 
33 #include <OGRE/OgreSceneNode.h>
34 #include <OGRE/OgreSceneManager.h>
35 
36 #include <tf/transform_listener.h>
37 
42 #include <rviz/frame_manager.h>
43 
44 #include <Path/PathVisual.h>
45 #include <Path/PathDisplay.h>
46 
47 namespace tuw_nav_rviz {
48 
49 // The constructor must have no arguments, so we can't give the
50 // constructor the parameters it needs to fully initialize.
52  color_path_property_ = new rviz::ColorProperty ( "Path Color", QColor ( 50, 51, 204 ),
53  "Color to draw the path.",
54  this, SLOT ( updatePathColor() ) );
55 
56  shape_property_ = new rviz::EnumProperty ( "Path Shape", QString::fromStdString ( "Sphere" ),
57  "Shape of the path.",
58  this, SLOT ( updateShape() ) );
62 
63  scale_path_property_ = new rviz::FloatProperty ( "Path Points Scale", 0.1,
64  "Scale of the path contour.",
65  this, SLOT ( updatePathScale() ) );
68 
69  color_orient_property_ = new rviz::ColorProperty ( "Orientation Color", QColor ( 50, 51, 204 ),
70  "Color to draw the path orientation arrows.",
71  this, SLOT ( updateOrientColor() ) );
72  path_delta_s_orient_property_ = new rviz::FloatProperty ( "Distance between arrows", 0.5,
73  "Distance between pose arrows [m]",
74  this, SLOT ( updateOrientPointsNr() ) );
77 
78  scale_orient_property_ = new rviz::FloatProperty ( "Orientation Points Scale", 0.1,
79  "Scale of the path orientation arrows.",
80  this, SLOT ( updateOrientScale() ) );
83 
84  history_length_property_ = new rviz::IntProperty ( "History Length", 1,
85  "Number of prior measurements to display.",
86  this, SLOT ( updateHistoryLength() ) );
88  history_length_property_->setMax ( 100000 );
89 }
90 
91 // After the top-level rviz::Display::initialize() does its own setup,
92 // it calls the subclass's onInitialize() function. This is where we
93 // instantiate all the workings of the class. We make sure to also
94 // call our immediate super-class's onInitialize() function, since it
95 // does important stuff setting up the message filter.
96 //
97 // Note that "MFDClass" is a typedef of
98 // ``MessageFilterDisplay<message type>``, to save typing that long
99 // templated class name every time you need to refer to the
100 // superclass.
104 }
105 
107 }
108 
109 // Clear the visuals by deleting their objects.
111  MFDClass::reset();
112  visuals_.clear();
113 }
114 
115 // Set the current color values for each visual.
117  Ogre::ColourValue color = color_path_property_->getOgreColor();
118  for ( auto& visualsI: visuals_ ) { visualsI->setPathColor ( color ); }
119 }
121  Ogre::ColourValue color = color_orient_property_->getOgreColor();
122  for ( auto& visualsI: visuals_ ) { visualsI->setOrientColor ( color ); }
123 }
124 
125 // Set the current shape for each visual.
128  for ( auto& visualsI: visuals_ ) { visualsI->setShape ( shape_type ); }
129 }
130 
131 // Set the current scale for each visual.
133  float scale = scale_path_property_->getFloat();
134  for ( auto& visualsI: visuals_ ) { visualsI->setPathScale ( scale ); }
135 }
137  float scale = scale_orient_property_->getFloat();
138  for ( auto& visualsI: visuals_ ) { visualsI->setOrientScale ( scale ); }
139 }
140 
141 // Set the number of past visuals to show.
143  visuals_.rset_capacity ( history_length_property_->getInt() );
144 }
145 
147  double deltaS = path_delta_s_orient_property_->getFloat();
148  for ( auto& visualsI: visuals_ ) { visualsI->setOrientDeltaS ( deltaS ); }
149 }
150 
151 
152 // This is our callback to handle an incoming message.
153 void PathDisplay::processMessage ( const nav_msgs::Path::ConstPtr& msg ) {
154  // Here we call the rviz::FrameManager to get the transform from the
155  // fixed frame to the frame in the header of this Imu message. If
156  // it fails, we can't do anything else so we return.
157  Ogre::Quaternion orientation;
158  Ogre::Vector3 position;
159  if ( !context_->getFrameManager()->getTransform ( msg->header.frame_id,
160  msg->header.stamp,
161  position, orientation ) ) {
162  ROS_DEBUG ( "Error transforming from frame '%s' to frame '%s'",
163  msg->header.frame_id.c_str(), qPrintable ( fixed_frame_ ) );
164  return;
165  }
166 
167  // We are keeping a circular buffer of visual pointers. This gets
168  // the next one, or creates and stores it if the buffer is not full
170  if ( visuals_.full() ) {
171  visual = visuals_.front();
172  } else {
173  visual.reset ( new PathVisual ( context_->getSceneManager(), scene_node_ ) );
174  }
175 
176  // Now set or update the contents of the chosen visual.
177  visual->setMessage ( msg );
178  visual->setFramePosition ( position );
179  visual->setFrameOrientation ( orientation );
180 
181  visual->setPathColor ( color_path_property_->getOgreColor() );
182  visual->setShape ( ( rviz::Shape::Type ) shape_property_->getOptionInt() );
183  visual->setPathScale ( scale_path_property_->getFloat() );
184 
185  visual->setOrientColor ( color_orient_property_->getOgreColor() );
186  visual->setOrientScale ( scale_orient_property_->getFloat() );
187  visual->setOrientDeltaS ( path_delta_s_orient_property_->getFloat() );
188 
189  // And send it to the end of the circular buffer
190  visuals_.push_back ( visual );
191 }
192 
193 } // end namespace tuw_nav_rviz
194 
195 // Tell pluginlib about this class. It is important to do this in
196 // global scope, outside our package's namespace.
void setMin(float min)
rviz::FloatProperty * scale_path_property_
Definition: PathDisplay.h:114
void setMax(float max)
Ogre::ColourValue getOgreColor() const
rviz::EnumProperty * shape_property_
Definition: PathDisplay.h:113
DisplayContext * context_
rviz::FloatProperty * path_delta_s_orient_property_
Definition: PathDisplay.h:118
virtual int getInt() const
virtual float getFloat() const
void setMin(int min)
rviz::IntProperty * history_length_property_
Definition: PathDisplay.h:120
rviz::ColorProperty * color_path_property_
Definition: PathDisplay.h:112
Ogre::SceneNode * scene_node_
void setMax(int max)
QString fixed_frame_
rviz::FloatProperty * scale_orient_property_
Definition: PathDisplay.h:117
rviz::ColorProperty * color_orient_property_
Definition: PathDisplay.h:116
boost::circular_buffer< boost::shared_ptr< PathVisual > > visuals_
Definition: PathDisplay.h:108
virtual FrameManager * getFrameManager() const =0
void addOptionStd(const std::string &option, int value=0)
virtual Ogre::SceneManager * getSceneManager() const =0
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
virtual void onInitialize()
virtual int getOptionInt()
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void processMessage(const nav_msgs::Path::ConstPtr &msg)
#define ROS_DEBUG(...)


tuw_nav_rviz
Author(s):
autogenerated on Mon Jun 10 2019 15:40:12