axes.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 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 "axes.h"
31 #include "shape.h"
32 
33 #include <OgreSceneManager.h>
34 #include <OgreSceneNode.h>
36 #include <OgreQuaternion.h>
37 
38 #include <sstream>
39 
40 namespace rviz
41 {
42 Axes::Axes(Ogre::SceneManager* scene_manager,
43  Ogre::SceneNode* parent_node,
44  float length,
45  float radius,
46  float alpha)
47  : Object(scene_manager)
48  , default_x_color_(1, 0, 0, alpha)
49  , default_y_color_(0, 1, 0, alpha)
50  , default_z_color_(0, 0, 1, alpha)
51 
52 {
53  if (!parent_node)
54  {
55  parent_node = scene_manager_->getRootSceneNode();
56  }
57 
58  scene_node_ = parent_node->createChildSceneNode();
59 
63 
64  set(length, radius, alpha);
65 }
66 
68 {
69  delete x_axis_;
70  delete y_axis_;
71  delete z_axis_;
72 
73  scene_manager_->destroySceneNode(scene_node_);
74 }
75 
76 void Axes::set(float length, float radius, float alpha)
77 {
78  x_axis_->setScale(Ogre::Vector3(radius, length, radius));
79  y_axis_->setScale(Ogre::Vector3(radius, length, radius));
80  z_axis_->setScale(Ogre::Vector3(radius, length, radius));
81 
82  x_axis_->setPosition(Ogre::Vector3(length / 2.0f, 0.0f, 0.0f));
83  x_axis_->setOrientation(Ogre::Quaternion(Ogre::Degree(-90), Ogre::Vector3::UNIT_Z));
84  y_axis_->setPosition(Ogre::Vector3(0.0f, length / 2.0f, 0.0f));
85  z_axis_->setPosition(Ogre::Vector3(0.0, 0.0f, length / 2.0f));
86  z_axis_->setOrientation(Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3::UNIT_X));
87 
88  updateAlpha(alpha);
90 }
91 
92 void Axes::setPosition(const Ogre::Vector3& position)
93 {
94  scene_node_->setPosition(position);
95 }
96 
97 void Axes::setOrientation(const Ogre::Quaternion& orientation)
98 {
99  scene_node_->setOrientation(orientation);
100 }
101 
102 void Axes::setScale(const Ogre::Vector3& scale)
103 {
104  scene_node_->setScale(scale);
105 }
106 
107 void Axes::setColor(float /*r*/, float /*g*/, float /*b*/, float /*a*/)
108 {
109  // cannot change color globally, use set[XYZ]Color() instead
110 }
111 
112 const Ogre::Vector3& Axes::getPosition()
113 {
114  return scene_node_->getPosition();
115 }
116 
117 const Ogre::Quaternion& Axes::getOrientation()
118 {
119  return scene_node_->getOrientation();
120 }
121 
122 void Axes::setUserData(const Ogre::Any& data)
123 {
124  x_axis_->setUserData(data);
125  y_axis_->setUserData(data);
126  z_axis_->setUserData(data);
127 }
128 
129 void Axes::setXColor(const Ogre::ColourValue& col)
130 {
131  x_axis_->setColor(col.r, col.g, col.b, col.a);
132 }
133 
134 void Axes::setYColor(const Ogre::ColourValue& col)
135 {
136  y_axis_->setColor(col.r, col.g, col.b, col.a);
137 }
138 
139 void Axes::setZColor(const Ogre::ColourValue& col)
140 {
141  z_axis_->setColor(col.r, col.g, col.b, col.a);
142 }
143 
144 void Axes::updateAlpha(float alpha)
145 {
146  default_x_color_.a = alpha;
147  default_y_color_.a = alpha;
148  default_z_color_.a = alpha;
149 }
150 
152 {
156 }
157 
158 const Ogre::ColourValue& Axes::getDefaultXColor()
159 {
160  return default_x_color_;
161 }
162 
163 const Ogre::ColourValue& Axes::getDefaultYColor()
164 {
165  return default_y_color_;
166 }
167 
168 const Ogre::ColourValue& Axes::getDefaultZColor()
169 {
170  return default_z_color_;
171 }
172 
173 } // namespace rviz
shape.h
axes.h
rviz::Shape::Cylinder
@ Cylinder
Definition: shape.h:58
rviz::Axes::getDefaultYColor
const Ogre::ColourValue & getDefaultYColor()
Definition: axes.cpp:163
rviz::Axes::getDefaultZColor
const Ogre::ColourValue & getDefaultZColor()
Definition: axes.cpp:168
rviz::Shape::setColor
void setColor(float r, float g, float b, float a) override
Set the color of the object. Values are in the range [0, 1].
Definition: shape.cpp:136
rviz::Axes::y_axis_
Shape * y_axis_
Cylinder for the Y-axis.
Definition: axes.h:137
rviz::Axes::setScale
void setScale(const Ogre::Vector3 &scale) override
Set the scale of the object. Always relative to the identity orientation of the object.
Definition: axes.cpp:102
rviz::Axes::getOrientation
const Ogre::Quaternion & getOrientation() override
Get the local orientation of this object.
Definition: axes.cpp:117
rviz::Axes::setUserData
void setUserData(const Ogre::Any &data) override
Sets user data on all ogre objects we own.
Definition: axes.cpp:122
rviz::Axes::~Axes
~Axes() override
Definition: axes.cpp:67
rviz::Axes::setXColor
void setXColor(const Ogre::ColourValue &col)
Definition: axes.cpp:129
rviz::Object::scene_manager_
Ogre::SceneManager * scene_manager_
Ogre scene manager this object is part of.
Definition: object.h:103
rviz::Axes::x_axis_
Shape * x_axis_
Cylinder for the X-axis.
Definition: axes.h:136
f
f
rviz::Axes::Axes
Axes(Ogre::SceneManager *manager, Ogre::SceneNode *parent_node=nullptr, float length=1.0f, float radius=0.1f, float alpha=1.0f)
Constructor.
Definition: axes.cpp:42
rviz::Axes::setZColor
void setZColor(const Ogre::ColourValue &col)
Definition: axes.cpp:139
rviz
Definition: add_display_dialog.cpp:54
rviz::Axes::updateAlpha
void updateAlpha(float alpha)
Definition: axes.cpp:144
rviz::Axes::getDefaultXColor
const Ogre::ColourValue & getDefaultXColor()
Definition: axes.cpp:158
rviz::Axes::z_axis_
Shape * z_axis_
Cylinder for the Z-axis.
Definition: axes.h:138
ogre_vector.h
rviz::Axes::setYColor
void setYColor(const Ogre::ColourValue &col)
Definition: axes.cpp:134
rviz::Axes::default_z_color_
Ogre::ColourValue default_z_color_
Definition: axes.h:142
rviz::Axes::default_y_color_
Ogre::ColourValue default_y_color_
Definition: axes.h:141
rviz::Axes::default_x_color_
Ogre::ColourValue default_x_color_
Definition: axes.h:140
rviz::Shape::setUserData
void setUserData(const Ogre::Any &data) override
Sets user data on all ogre objects we own.
Definition: shape.cpp:171
rviz::Axes::setToDefaultColors
void setToDefaultColors()
Definition: axes.cpp:151
length
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
rviz::Axes::setColor
void setColor(float r, float g, float b, float a) override
Set the color of the object. Values are in the range [0, 1].
Definition: axes.cpp:107
rviz::Shape
Definition: shape.h:51
rviz::Axes::getPosition
const Ogre::Vector3 & getPosition() override
Get the local position of this object.
Definition: axes.cpp:112
rviz::Axes::set
void set(float length, float radius, float alpha=1.0f)
Set the parameters on this object.
Definition: axes.cpp:76
rviz::Object
Base class for visible objects, providing a minimal generic interface.
Definition: object.h:47
rviz::Axes::setPosition
void setPosition(const Ogre::Vector3 &position) override
Set the position of this object.
Definition: axes.cpp:92
rviz::Shape::setScale
void setScale(const Ogre::Vector3 &scale) override
Set the scale of the object. Always relative to the identity orientation of the object.
Definition: shape.cpp:156
rviz::Axes::setOrientation
void setOrientation(const Ogre::Quaternion &orientation) override
Set the orientation of the object.
Definition: axes.cpp:97
rviz::Shape::setPosition
void setPosition(const Ogre::Vector3 &position) override
Set the position of this object.
Definition: shape.cpp:146
rviz::Shape::setOrientation
void setOrientation(const Ogre::Quaternion &orientation) override
Set the orientation of the object.
Definition: shape.cpp:151
rviz::Axes::scene_node_
Ogre::SceneNode * scene_node_
Definition: axes.h:134


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Aug 2 2024 08:43:09