covariance_property.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, Ellon Paiva Mendes @ LAAS-CNRS
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 "covariance_property.h"
31 #include "covariance_visual.h"
32 
36 
37 #include <QColor>
38 
39 #include <OgreSceneManager.h>
40 #include <OgreSceneNode.h>
41 
42 namespace rviz
43 {
44 
46  bool default_value,
47  const QString& description,
48  Property* parent,
49  const char *changed_slot,
50  QObject* receiver )
51  // NOTE: changed_slot and receiver aren't passed to BoolProperty here, but initialized at the end of this constructor
52  : BoolProperty( name, default_value, description, parent )
53 {
54 
55  position_property_ = new BoolProperty( "Position", true,
56  "Whether or not to show the position part of covariances",
57  this, SLOT( updateVisibility() ));
59 
60  position_color_property_ = new ColorProperty( "Color", QColor( 204, 51, 204 ),
61  "Color to draw the position covariance ellipse.",
63 
64  position_alpha_property_ = new FloatProperty( "Alpha", 0.3f,
65  "0 is fully transparent, 1.0 is fully opaque.",
69 
70  position_scale_property_ = new FloatProperty( "Scale", 1.0f,
71  "Scale factor to be applied to covariance ellipse. Corresponds to the number of standard deviations to display",
74 
75  orientation_property_ = new BoolProperty( "Orientation", true,
76  "Whether or not to show the orientation part of covariances",
77  this, SLOT( updateVisibility() ));
79 
80  orientation_frame_property_ = new EnumProperty( "Frame", "Local", "The frame used to display the orientation covariance.",
84 
85  orientation_colorstyle_property_ = new EnumProperty( "Color Style", "Unique", "Style to color the orientation covariance: XYZ with same unique color or following RGB order",
89 
90  orientation_color_property_ = new ColorProperty( "Color", QColor( 255, 255, 127 ),
91  "Color to draw the covariance ellipse.",
93 
94  orientation_alpha_property_ = new FloatProperty( "Alpha", 0.5f,
95  "0 is fully transparent, 1.0 is fully opaque.",
99 
100  orientation_offset_property_ = new FloatProperty( "Offset", 1.0f,
101  "For 3D poses is the distance where to position the ellipses representing orientation covariance. For 2D poses is the height of the triangle representing the variance on yaw",
104 
105  orientation_scale_property_ = new FloatProperty( "Scale", 1.0f,
106  "Scale factor to be applied to orientation covariance shapes. Corresponds to the number of standard deviations to display",
109 
110  connect(this, SIGNAL( changed() ), this, SLOT( updateVisibility() ));
111 
112  // Connect changed() signal here instead of doing it through the initialization of BoolProperty().
113  // We do this here to make changed_slot be called _after_ updateVisibility()
114  if(changed_slot && (parent || receiver))
115  {
116  if(receiver)
117  connect(this, SIGNAL( changed() ), receiver, changed_slot);
118  else
119  connect(this, SIGNAL( changed() ), parent, changed_slot);
120  }
121 
123 }
124 
126 {
127 }
128 
130 {
131  bool use_unique_color = ( orientation_colorstyle_property_->getOptionInt() == Unique );
132  orientation_color_property_->setHidden( !use_unique_color );
134 }
135 
137 {
138  D_Covariance::iterator it_cov = covariances_.begin();
139  D_Covariance::iterator end_cov = covariances_.end();
140  for ( ; it_cov != end_cov; ++it_cov )
142 }
143 
145 {
146  float pos_alpha = position_alpha_property_->getFloat();
147  float pos_scale = position_scale_property_->getFloat();
148  QColor pos_color = position_color_property_->getColor();
149  visual->setPositionColor( pos_color.redF(), pos_color.greenF(), pos_color.blueF(), pos_alpha );
150  visual->setPositionScale( pos_scale );
151 
152  float ori_alpha = orientation_alpha_property_->getFloat();
153  float ori_offset = orientation_offset_property_->getFloat();
154  float ori_scale = orientation_scale_property_->getFloat();
156  {
157  QColor ori_color = orientation_color_property_->getColor();
158  visual->setOrientationColor( ori_color.redF(), ori_color.greenF(), ori_color.blueF(), ori_alpha );
159  }
160  else
161  {
162  visual->setOrientationColorToRGB( ori_alpha );
163  }
164  visual->setOrientationOffset( ori_offset );
165  visual->setOrientationScale( ori_scale );
166 }
167 
169 {
170  D_Covariance::iterator it_cov = covariances_.begin();
171  D_Covariance::iterator end_cov = covariances_.end();
172  for ( ; it_cov != end_cov; ++it_cov )
173  updateVisibility(*it_cov);
174 }
175 
177 {
178  bool show_covariance = getBool();
179  if( !show_covariance )
180  {
181  visual->setVisible( false );
182  }
183  else
184  {
185  bool show_position_covariance = position_property_->getBool();;
186  bool show_orientation_covariance = orientation_property_->getBool();
187  visual->setPositionVisible( show_position_covariance );
188  visual->setOrientationVisible( show_orientation_covariance );
189  }
190 }
191 
193 {
194  D_Covariance::iterator it_cov = covariances_.begin();
195  D_Covariance::iterator end_cov = covariances_.end();
196  for ( ; it_cov != end_cov; ++it_cov )
197  updateOrientationFrame(*it_cov);
198 }
199 
201 {
202  bool use_rotating_frame = ( orientation_frame_property_->getOptionInt() == Local );
203  visual->setRotatingFrame( use_rotating_frame );
204 }
205 
207 {
208  covariances_.pop_front();
209 }
210 
212 {
213  covariances_.clear();
214 }
215 
217 {
218  return covariances_.size();
219 }
220 
221 CovarianceProperty::CovarianceVisualPtr CovarianceProperty::createAndPushBackVisual(Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node)
222 {
223  bool use_rotating_frame = ( orientation_frame_property_->getOptionInt() == Local );
224  CovarianceVisualPtr visual(new CovarianceVisual(scene_manager, parent_node, use_rotating_frame) );
225  updateVisibility(visual);
226  updateOrientationFrame(visual);
228  covariances_.push_back(visual);
229  return visual;
230 }
231 
233 {
234  return position_property_->getBool();
235 }
236 
238 {
239  return orientation_property_->getBool();
240 }
241 
242 } // end namespace rviz
virtual QColor getColor() const
void setMin(float min)
rviz::EnumProperty * orientation_colorstyle_property_
void setMax(float max)
f
void changed()
Emitted by setValue() just after the value has changed.
void setDisableChildrenIfFalse(bool disable)
CovarianceVisual consisting in a ellipse for position and 2D ellipses along the axis for orientation...
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
virtual float getFloat() const
Property specialized to enforce floating point max/min.
rviz::FloatProperty * position_scale_property_
CovarianceVisualPtr createAndPushBackVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node)
virtual bool getBool() const
virtual void addOption(const QString &option, int value=0)
rviz::FloatProperty * orientation_scale_property_
rviz::FloatProperty * orientation_alpha_property_
rviz::ColorProperty * orientation_color_property_
rviz::EnumProperty * orientation_frame_property_
rviz::FloatProperty * orientation_offset_property_
virtual void setHidden(bool hidden)
Hide or show this property in any PropertyTreeWidget viewing its parent.
Definition: property.cpp:530
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
virtual int getOptionInt()
Return the int value of the currently-chosen option, or 0 if the current option string does not have ...
rviz::BoolProperty * orientation_property_
Enum property.
Definition: enum_property.h:47
BoolProperty(const QString &name=QString(), bool default_value=false, const QString &description=QString(), Property *parent=0, const char *changed_slot=0, QObject *receiver=0)
rviz::ColorProperty * position_color_property_
rviz::FloatProperty * position_alpha_property_
rviz::BoolProperty * position_property_
CovarianceProperty(const QString &name="Covariance", bool default_value=false, const QString &description=QString(), rviz::Property *parent=0, const char *changed_slot=0, QObject *receiver=0)


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:41