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 {
45  bool default_value,
46  const QString& description,
47  Property* parent,
48  const char* changed_slot,
49  QObject* receiver)
50  // NOTE: changed() signal will only be initialized at the end of this constructor
51  : BoolProperty(name, default_value, description, parent)
52 {
54  new BoolProperty("Position", true, "Whether or not to show the position part of covariances", this,
55  SLOT(updateVisibility()));
57 
59  new ColorProperty("Color", QColor(204, 51, 204), "Color to draw the position covariance ellipse.",
61 
63  new FloatProperty("Alpha", 0.3f, "0 is fully transparent, 1.0 is fully opaque.",
67 
69  new FloatProperty("Scale", 1.0f,
70  "Scale factor to be applied to covariance ellipse. "
71  "Corresponds to the number of standard deviations to display",
74 
76  new BoolProperty("Orientation", true, "Whether or not to show the orientation part of covariances",
77  this, SLOT(updateVisibility()));
79 
81  new EnumProperty("Frame", "Local", "The frame used to display the orientation covariance.",
85 
87  "Color Style", "Unique",
88  "Style to color the orientation covariance: XYZ with same unique color or following RGB order",
92 
94  new ColorProperty("Color", QColor(255, 255, 127), "Color to draw the covariance ellipse.",
96 
98  new FloatProperty("Alpha", 0.5f, "0 is fully transparent, 1.0 is fully opaque.",
102 
104  "Offset", 1.0f,
105  "For 3D poses is the distance where to position the ellipses representing orientation covariance. "
106  "For 2D poses is the height of the triangle representing the variance on yaw.",
109 
111  new FloatProperty("Scale", 1.0f,
112  "Scale factor to be applied to orientation covariance shapes. "
113  "Corresponds to the number of standard deviations to display.",
116 
117  connect(this, SIGNAL(changed()), this, SLOT(updateVisibility()));
118 
119  // Connect changed() signal here instead of doing it through the initialization of BoolProperty().
120  // We do this here to make changed_slot be called _after_ updateVisibility()
121  if (changed_slot && (parent || receiver))
122  {
123  if (receiver)
124  connect(this, SIGNAL(changed()), receiver, changed_slot);
125  else
126  connect(this, SIGNAL(changed()), parent, changed_slot);
127  }
128 
130 }
131 
133 {
134 }
135 
137 {
138  bool use_unique_color = (orientation_colorstyle_property_->getOptionInt() == Unique);
139  orientation_color_property_->setHidden(!use_unique_color);
141 }
142 
144 {
145  D_Covariance::iterator it_cov = covariances_.begin();
146  D_Covariance::iterator end_cov = covariances_.end();
147  for (; it_cov != end_cov; ++it_cov)
149 }
150 
152 {
153  float pos_alpha = position_alpha_property_->getFloat();
154  float pos_scale = position_scale_property_->getFloat();
155  QColor pos_color = position_color_property_->getColor();
156  visual->setPositionColor(pos_color.redF(), pos_color.greenF(), pos_color.blueF(), pos_alpha);
157  visual->setPositionScale(pos_scale);
158 
159  float ori_alpha = orientation_alpha_property_->getFloat();
160  float ori_offset = orientation_offset_property_->getFloat();
161  float ori_scale = orientation_scale_property_->getFloat();
163  {
164  QColor ori_color = orientation_color_property_->getColor();
165  visual->setOrientationColor(ori_color.redF(), ori_color.greenF(), ori_color.blueF(), ori_alpha);
166  }
167  else
168  {
169  visual->setOrientationColorToRGB(ori_alpha);
170  }
171  visual->setOrientationOffset(ori_offset);
172  visual->setOrientationScale(ori_scale);
173 }
174 
176 {
177  D_Covariance::iterator it_cov = covariances_.begin();
178  D_Covariance::iterator end_cov = covariances_.end();
179  for (; it_cov != end_cov; ++it_cov)
180  updateVisibility(*it_cov);
181 }
182 
184 {
185  bool show_covariance = getBool();
186  if (!show_covariance)
187  {
188  visual->setVisible(false);
189  }
190  else
191  {
192  bool show_position_covariance = position_property_->getBool();
193  ;
194  bool show_orientation_covariance = orientation_property_->getBool();
195  visual->setPositionVisible(show_position_covariance);
196  visual->setOrientationVisible(show_orientation_covariance);
197  }
198 }
199 
201 {
202  D_Covariance::iterator it_cov = covariances_.begin();
203  D_Covariance::iterator end_cov = covariances_.end();
204  for (; it_cov != end_cov; ++it_cov)
205  updateOrientationFrame(*it_cov);
206 }
207 
209 {
210  bool use_rotating_frame = (orientation_frame_property_->getOptionInt() == Local);
211  visual->setRotatingFrame(use_rotating_frame);
212 }
213 
215 {
216  covariances_.pop_front();
217 }
218 
220 {
221  covariances_.clear();
222 }
223 
225 {
226  return covariances_.size();
227 }
228 
230 CovarianceProperty::createAndPushBackVisual(Ogre::SceneManager* scene_manager,
231  Ogre::SceneNode* parent_node)
232 {
233  bool use_rotating_frame = (orientation_frame_property_->getOptionInt() == Local);
234  CovarianceVisualPtr visual(new CovarianceVisual(scene_manager, parent_node, use_rotating_frame));
235  updateVisibility(visual);
236  updateOrientationFrame(visual);
238  covariances_.push_back(visual);
239  return visual;
240 }
241 
243 {
244  return position_property_->getBool();
245 }
246 
248 {
249  return orientation_property_->getBool();
250 }
251 
252 } // end namespace rviz
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)
virtual QColor getColor() const
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
Property specialized to enforce floating point max/min.
rviz::FloatProperty * position_scale_property_
CovarianceVisualPtr createAndPushBackVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node)
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_
BoolProperty(const QString &name=QString(), bool default_value=false, const QString &description=QString(), Property *parent=nullptr, const char *changed_slot=nullptr, QObject *receiver=nullptr)
virtual void setHidden(bool hidden)
Hide or show this property in any PropertyTreeWidget viewing its parent.
Definition: property.cpp:552
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
virtual float getFloat() const
virtual bool getBool() const
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_
CovarianceProperty(const QString &name="Covariance", bool default_value=false, const QString &description=QString(), rviz::Property *parent=nullptr, const char *changed_slot=nullptr, QObject *receiver=nullptr)
Enum property.
Definition: enum_property.h:46
rviz::ColorProperty * position_color_property_
rviz::FloatProperty * position_alpha_property_
rviz::BoolProperty * position_property_


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:24