RouteSegmentsDisplay.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2016 by Markus Bader <markus.bader@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 
46 
47 namespace tuw_nav_rviz_plugin {
48 
49 // The constructor must have no arguments, so we can't give the
50 // constructor the parameters it needs to fully initialize.
52 
53 
54  color_lines_ = new rviz::ColorProperty ( "Line Segment Color", QColor ( 170, 0, 170 ),
55  "Color Line Segment", this, SLOT ( updateColorLines() ) );
56  show_lines_property_ = new rviz::BoolProperty ( "Show lines", true,
57  "Shows line segments", this, SLOT ( updateShowLines() ) );
58 
59  color_arcs_ = new rviz::ColorProperty ( "Arc Segment Color", QColor ( 0, 170, 170 ),
60  "Color Arc Segment", this, SLOT ( updateColorArcs() ) );
61  show_arcs_property_ = new rviz::BoolProperty ( "Show arcs", true,
62  "Shows arc segments", this, SLOT ( updateShowArcs() ) );
63 
64  show_start_point_ = new rviz::BoolProperty ( "Show Start Point", true,
65  "Shows segments start", this, SLOT ( updateShowStartPoints() ) );
66  color_start_point_ = new rviz::ColorProperty ( "Start Point Color", QColor ( 170, 0, 0 ),
67  "Color to start point", this, SLOT ( updateStartPointColor() ) );
68  shape_start_point_ = new rviz::EnumProperty ( "Start Point Shape", QString::fromStdString ( "Sphere" ),
69  "Shape of start point", this, SLOT ( updateStartPointShape() ) );
74  scale_start_point_ = new rviz::FloatProperty ( "Start Points Scale", 0.05,
75  "Scale start point", this, SLOT ( updateStartPointScale() ) );
78 
79 
80  show_end_point_ = new rviz::BoolProperty ( "Show End Point", false,
81  "Shows segments end", this, SLOT ( updateShowEndPoints() ) );
82  color_end_point_ = new rviz::ColorProperty ( "End Point Color", QColor ( 0, 170, 0 ),
83  "Color to end point", this, SLOT ( updateEndPointColor() ) );
84  shape_end_point_ = new rviz::EnumProperty ( "End Point Shape", QString::fromStdString ( "Cube" ),
85  "Shape of end point", this, SLOT ( updateEndPointShape() ) );
90  scale_end_point_ = new rviz::FloatProperty ( "End Points Scale", 0.04,
91  "Scale end point", this, SLOT ( updateEndPointScale() ) );
92  scale_end_point_->setMin ( 0 );
93  scale_end_point_->setMax ( 1 );
94 
95 
96  show_center_point_ = new rviz::BoolProperty ( "Show Center Point", false,
97  "Shows segments center", this, SLOT ( updateShowCenterPoints() ) );
98  color_center_point_ = new rviz::ColorProperty ( "Center Point Color", QColor ( 0, 0, 170 ),
99  "Color to center point", this, SLOT ( updateCenterPointColor() ) );
100  shape_center_point_ = new rviz::EnumProperty ( "Center Point Shape", QString::fromStdString ( "Sphere" ),
101  "Shape of center point", this, SLOT ( updateCenterPointShape() ) );
106  scale_center_point_ = new rviz::FloatProperty ( "Center Points Scale", 0.05,
107  "Scale center point", this, SLOT ( updateCenterPointScale() ) );
110 
111  history_length_property_ = new rviz::IntProperty ( "History Length", 1,
112  "Number of prior measurements to display.",
113  this, SLOT ( updateHistoryLength() ) );
115  history_length_property_->setMax ( 100000 );
116 
117 }
118 
119 // After the top-level rviz::Display::initialize() does its own setup,
120 // it calls the subclass's onInitialize() function. This is where we
121 // instantiate all the workings of the class. We make sure to also
122 // call our immediate super-class's onInitialize() function, since it
123 // does important stuff setting up the message filter.
124 //
125 // Note that "MFDClass" is a typedef of
126 // ``MessageFilterDisplay<message type>``, to save typing that long
127 // templated class name every time you need to refer to the
128 // superclass.
132 }
133 
135 }
136 
137 // Clear the visuals by deleting their objects.
139  MFDClass::reset();
140  visuals_.clear();
141 }
142 
143 // Set the current color values for each visual.
145  for ( auto& visualsI: visuals_ ) { visualsI->setStartPointColor ( color_start_point_->getOgreColor() ); }
146 }
147 
148 // Set the current shape for each visual.
151  for ( auto& visualsI: visuals_ ) { visualsI->setStartPointShape ( shape_type ); }
152 }
153 
154 // Set the current scale for each visual.
156  for ( auto& visualsI: visuals_ ) { visualsI->setStartPointScale ( scale_start_point_->getFloat() ); }
157 }
158 
159 
160 // Set the current color values for each visual.
162  for ( auto& visualsI: visuals_ ) { visualsI->setEndPointColor ( color_end_point_->getOgreColor() ); }
163 }
164 
165 // Set the current shape for each visual.
168  for ( auto& visualsI: visuals_ ) { visualsI->setEndPointShape ( shape_type ); }
169 }
170 
171 // Set the current scale for each visual.
173  for ( auto& visualsI: visuals_ ) { visualsI->setEndPointScale ( scale_end_point_->getFloat() ); }
174 }
175 
176 // Set the current color values for each visual.
178  for ( auto& visualsI: visuals_ ) { visualsI->setEndPointColor ( color_center_point_->getOgreColor() ); }
179 }
180 
181 // Set the current shape for each visual.
184  for ( auto& visualsI: visuals_ ) { visualsI->setCenterPointShape ( shape_type ); }
185 }
186 
187 // Set the current scale for each visual.
189  for ( auto& visualsI: visuals_ ) { visualsI->setCenterPointScale ( scale_center_point_->getFloat() ); }
190 }
191 
192 
193 // Set the number of past visuals to show.
195  visuals_.rset_capacity ( history_length_property_->getInt() );
196 }
197 
198 
199 // Set the current color values for each visual.
201  for ( auto& visualsI: visuals_ ) { visualsI->setLineColor ( color_lines_->getOgreColor() ); }
202 }
203 
204 // Set the number of past visuals to show.
206  for ( auto& visualsI: visuals_ ) { visualsI->setShowLines ( show_lines_property_->getBool() ); }
207 }
208 
209 // Set the current color values for each visual.
211  for ( auto& visualsI: visuals_ ) { visualsI->setArcColor ( color_arcs_->getOgreColor() ); }
212 }
213 
214 // Set the number of past visuals to show.
216  for ( auto& visualsI: visuals_ ) { visualsI->setShowArcs ( show_arcs_property_->getBool() ); }
217 }
218 // Set the number of past visuals to show.
220  for ( auto& visualsI: visuals_ ) { visualsI->setShowStartPoints ( show_start_point_->getBool() ); }
221 }
222 // Set the number of past visuals to show.
224  for ( auto& visualsI: visuals_ ) { visualsI->setShowEndPoints ( show_end_point_->getBool() ); }
225 }
226 // Set the number of past visuals to show.
228  for ( auto& visualsI: visuals_ ) { visualsI->setShowCenterPoints ( show_center_point_->getBool() ); }
229 }
230 
231 
232 // This is our callback to handle an incoming message.
233 void RouteSegmentsDisplay::processMessage ( const tuw_nav_msgs::RouteSegments::ConstPtr& msg ) {
234  // Here we call the rviz::FrameManager to get the transform from the
235  // fixed frame to the frame in the header of this Imu message. If
236  // it fails, we can't do anything else so we return.
237  Ogre::Quaternion orientation;
238  Ogre::Vector3 position;
239  if ( !context_->getFrameManager()->getTransform ( msg->header.frame_id,
240  msg->header.stamp,
241  position, orientation ) ) {
242  ROS_DEBUG ( "Error transforming from frame '%s' to frame '%s'",
243  msg->header.frame_id.c_str(), qPrintable ( fixed_frame_ ) );
244  return;
245  }
246 
247  // We are keeping a circular buffer of visual pointers. This gets
248  // the next one, or creates and stores it if the buffer is not full
250  if ( visuals_.full() ) {
251  visual = visuals_.front();
252  } else {
253  visual.reset ( new RouteSegmentsVisual ( context_->getSceneManager(), scene_node_ ) );
254  }
255 
256  // Now set or update the contents of the chosen visual.
257  visual->setMessage ( msg );
258  visual->setFramePosition ( position );
259  visual->setFrameOrientation ( orientation );
260 
261  visual->setStartPointColor ( color_start_point_->getOgreColor() );
262  visual->setStartPointShape ( ( rviz::Shape::Type ) shape_start_point_->getOptionInt() );
263  visual->setStartPointScale ( scale_start_point_->getFloat() );
264 
265 
266  visual->setEndPointColor ( color_end_point_->getOgreColor() );
267  visual->setEndPointShape ( ( rviz::Shape::Type ) shape_end_point_->getOptionInt() );
268  visual->setEndPointScale ( scale_end_point_->getFloat() );
269 
270  visual->setCenterPointColor ( color_center_point_->getOgreColor() );
271  visual->setCenterPointShape ( ( rviz::Shape::Type ) shape_center_point_->getOptionInt() );
272  visual->setCenterPointScale ( scale_center_point_->getFloat() );
273 
274  visual->setShowArcs(show_arcs_property_->getBool());
275  visual->setShowLines(show_lines_property_->getBool());
276 
277  // And send it to the end of the circular buffer
278  visuals_.push_back ( visual );
279 }
280 
281 } // end namespace tuw_nav_rviz_plugin
282 
283 // Tell pluginlib about this class. It is important to do this in
284 // global scope, outside our package's namespace.
void setMin(float min)
void setMax(float max)
Ogre::ColourValue getOgreColor() const
boost::circular_buffer< boost::shared_ptr< RouteSegmentsVisual > > visuals_
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)
virtual bool getBool() const
QString fixed_frame_
virtual FrameManager * getFrameManager() const =0
void processMessage(const tuw_nav_msgs::RouteSegments::ConstPtr &msg)
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 int getOptionInt()
#define ROS_DEBUG(...)


tuw_nav_rviz_plugin
Author(s):
autogenerated on Sun Aug 28 2016 03:53:55