Gazebo Rendering

API Reference

6.6.3
gz/rendering/base/BaseAxisVisual.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #ifndef GZ_RENDERING_BASE_BASEAXISVISUAL_HH_
18 #define GZ_RENDERING_BASE_BASEAXISVISUAL_HH_
19 
22 #include "gz/rendering/Scene.hh"
23 
24 namespace ignition
25 {
26  namespace rendering
27  {
28  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
29  //
30  template <class T>
32  public virtual AxisVisual,
33  public virtual T
34  {
35  protected: BaseAxisVisual();
36 
37  public: virtual ~BaseAxisVisual();
38 
39  public: virtual void Init() override;
40 
41  // Documentation inherited.
42  protected: virtual void Destroy() override;
43 
44  // Documentation inherited.
45  public: virtual void SetLocalScale(
46  const math::Vector3d &_scale) override;
47 
48  // Documentation inherited.
49  public: virtual math::Vector3d LocalScale() const override;
50 
51  // Documentation inherited.
52  public: void ShowAxisHead(bool _b) override;
53 
54  // Documentation inherited.
55  public: void ShowAxisHead(unsigned int _axis, bool _b) override;
56 
57  // Documentation inherited.
58  public: virtual void SetVisible(bool _visible) override;
59  };
60 
62  template <class T>
64  {
65  }
66 
68  template <class T>
70  {
71  }
72 
74  template <class T>
76  {
77  for (unsigned int i = 0; i < this->ChildCount(); ++i)
78  {
79  auto arrow = std::dynamic_pointer_cast<rendering::ArrowVisual>(
80  this->ChildByIndex(i));
81  if (arrow)
82  {
83  arrow->Destroy();
84  }
85  }
86  T::Destroy();
87  }
88 
90  template <class T>
92  {
93  if (this->ChildCount() > 0) {
94  return this->ChildByIndex(0)->LocalScale();
95  }
96  return math::Vector3d::Zero;
97  }
98 
100  template <class T>
102  {
103  for (unsigned int i = 0; i < this->ChildCount(); ++i)
104  this->ChildByIndex(i)->SetLocalScale(_scale.X(),
105  _scale.Y(),
106  _scale.Z());
107  }
108 
110  template <class T>
112  {
113  for (unsigned int i = 0; i < this->ChildCount(); ++i)
114  {
115  auto arrow = std::dynamic_pointer_cast<rendering::ArrowVisual>(
116  this->ChildByIndex(i));
117  if (arrow)
118  {
119  arrow->ShowArrowHead(_b);
120  }
121  }
122  }
123 
125  template <class T>
126  void BaseAxisVisual<T>::ShowAxisHead(unsigned int _axis, bool _b)
127  {
128  auto arrow = std::dynamic_pointer_cast<rendering::ArrowVisual>(
129  this->ChildByIndex(2u - _axis));
130  if (arrow)
131  {
132  arrow->ShowArrowHead(_b);
133  }
134  }
135 
137  template <class T>
139  {
140  T::Init();
141 
142  ArrowVisualPtr xArrow = this->Scene()->CreateArrowVisual();
143  xArrow->SetLocalPosition(0, 0, 0);
144  xArrow->SetLocalRotation(0, IGN_PI / 2, 0);
145  xArrow->SetMaterial("Default/TransRed");
146  this->AddChild(xArrow);
147 
148  ArrowVisualPtr yArrow = this->Scene()->CreateArrowVisual();
149  yArrow->SetLocalPosition(0, 0, 0);
150  yArrow->SetLocalRotation(-IGN_PI / 2, 0, 0);
151  yArrow->SetMaterial("Default/TransGreen");
152  this->AddChild(yArrow);
153 
154  ArrowVisualPtr zArrow = this->Scene()->CreateArrowVisual();
155  zArrow->SetLocalPosition(0, 0, 0);
156  zArrow->SetLocalRotation(0, 0, 0);
157  zArrow->SetMaterial("Default/TransBlue");
158  this->AddChild(zArrow);
159  }
160 
162  template <class T>
163  void BaseAxisVisual<T>::SetVisible(bool _visible)
164  {
165  T::SetVisible(_visible);
166 
167  for (unsigned int i = 0; i < this->ChildCount(); ++i)
168  {
169  auto arrow = std::dynamic_pointer_cast<rendering::ArrowVisual>(
170  this->ChildByIndex(i));
171  if (arrow != nullptr)
172  arrow->SetVisible(_visible);
173  }
174  }
175  }
176  }
177 }
178 #endif
virtual math::Vector3d LocalScale() const override
Get the local scale.
Definition: gz/rendering/base/BaseAxisVisual.hh:91
STL class.
#define IGN_PI
BaseAxisVisual()
Definition: gz/rendering/base/BaseAxisVisual.hh:63
virtual void Destroy() override
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
Definition: gz/rendering/base/BaseAxisVisual.hh:75
Manages a single scene-graph. This class updates scene-wide properties and holds the root scene node....
Definition: gz/rendering/Scene.hh:49
virtual void SetVisible(bool _visible) override
Specify if this visual is visible.
Definition: gz/rendering/base/BaseAxisVisual.hh:163
static const Vector3 Zero
void ShowAxisHead(bool _b) override
set true to show the axis heads, false otherwise
Definition: gz/rendering/base/BaseAxisVisual.hh:111
Definition: gz/rendering/base/BaseAxisVisual.hh:31
Represents a axis composite visual.
Definition: gz/rendering/AxisVisual.hh:31
virtual ArrowVisualPtr CreateArrowVisual()=0
Create new arrow visual. A unique ID and name will automatically be assigned to the visual.
virtual ~BaseAxisVisual()
Definition: gz/rendering/base/BaseAxisVisual.hh:69
virtual void Init() override
Definition: gz/rendering/base/BaseAxisVisual.hh:138
virtual void SetLocalScale(const math::Vector3d &_scale) override
Set the local scale.
Definition: gz/rendering/base/BaseAxisVisual.hh:101