Ignition Rendering

API Reference

6.3.1
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 IGNITION_RENDERING_BASE_BASEAXISVISUAL_HH_
18 #define IGNITION_RENDERING_BASE_BASEAXISVISUAL_HH_
19 
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  {
80  this->ChildByIndex(i));
81  if (arrow)
82  {
83  arrow->Destroy();
84  }
85  }
86  }
87 
89  template <class T>
91  {
92  if (this->ChildCount() > 0) {
93  return this->ChildByIndex(0)->LocalScale();
94  }
95  return math::Vector3d::Zero;
96  }
97 
99  template <class T>
101  {
102  for (unsigned int i = 0; i < this->ChildCount(); ++i)
103  this->ChildByIndex(i)->SetLocalScale(_scale.X(),
104  _scale.Y(),
105  _scale.Z());
106  }
107 
109  template <class T>
111  {
112  for (unsigned int i = 0; i < this->ChildCount(); ++i)
113  {
115  this->ChildByIndex(i));
116  if (arrow)
117  {
118  arrow->ShowArrowHead(_b);
119  }
120  }
121  }
122 
124  template <class T>
125  void BaseAxisVisual<T>::ShowAxisHead(unsigned int _axis, bool _b)
126  {
128  this->ChildByIndex(2u - _axis));
129  if (arrow)
130  {
131  arrow->ShowArrowHead(_b);
132  }
133  }
134 
136  template <class T>
138  {
139  T::Init();
140 
141  ArrowVisualPtr xArrow = this->Scene()->CreateArrowVisual();
142  xArrow->SetLocalPosition(0, 0, 0);
143  xArrow->SetLocalRotation(0, IGN_PI / 2, 0);
144  xArrow->SetMaterial("Default/TransRed");
145  this->AddChild(xArrow);
146 
147  ArrowVisualPtr yArrow = this->Scene()->CreateArrowVisual();
148  yArrow->SetLocalPosition(0, 0, 0);
149  yArrow->SetLocalRotation(-IGN_PI / 2, 0, 0);
150  yArrow->SetMaterial("Default/TransGreen");
151  this->AddChild(yArrow);
152 
153  ArrowVisualPtr zArrow = this->Scene()->CreateArrowVisual();
154  zArrow->SetLocalPosition(0, 0, 0);
155  zArrow->SetLocalRotation(0, 0, 0);
156  zArrow->SetMaterial("Default/TransBlue");
157  this->AddChild(zArrow);
158  }
159 
161  template <class T>
162  void BaseAxisVisual<T>::SetVisible(bool _visible)
163  {
164  T::SetVisible(_visible);
165 
166  for (unsigned int i = 0; i < this->ChildCount(); ++i)
167  {
169  this->ChildByIndex(i));
170  if (arrow != nullptr)
171  arrow->SetVisible(_visible);
172  }
173  }
174  }
175  }
176 }
177 #endif
Represents a arrow composite visual.
Definition: ArrowVisual.hh:31
virtual void SetVisible(bool _visible)=0
Specify if this visual is visible.
virtual void SetLocalScale(const math::Vector3d &_scale) override
Set the local scale.
Definition: BaseAxisVisual.hh:100
Represents a axis composite visual.
Definition: AxisVisual.hh:31
void ShowAxisHead(bool _b) override
set true to show the axis heads, false otherwise
Definition: BaseAxisVisual.hh:110
virtual void Destroy() override
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
Definition: BaseAxisVisual.hh:75
virtual void ShowArrowHead(bool _b)=0
set true to show the arrow head, false otherwise
virtual math::Vector3d LocalScale() const override
Get the local scale.
Definition: BaseAxisVisual.hh:90
BaseAxisVisual()
Definition: BaseAxisVisual.hh:63
Manages a single scene-graph. This class updates scene-wide properties and holds the root scene node...
Definition: Scene.hh:49
Definition: BaseAxisVisual.hh:31
T dynamic_pointer_cast(T... args)
virtual ~BaseAxisVisual()
Definition: BaseAxisVisual.hh:69
virtual void SetVisible(bool _visible) override
Specify if this visual is visible.
Definition: BaseAxisVisual.hh:162
virtual void Destroy()=0
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
virtual void Init() override
Definition: BaseAxisVisual.hh:137
static const Vector3 Zero
#define IGN_PI
virtual ArrowVisualPtr CreateArrowVisual()=0
Create new arrow visual. A unique ID and name will automatically be assigned to the visual...