Ignition Rendering

API Reference

6.3.1
BaseArrowVisual.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_BASEARROWVISUAL_HH_
18 #define IGNITION_RENDERING_BASE_BASEARROWVISUAL_HH_
19 
20 #include <string>
21 
23 
26 
27 namespace ignition
28 {
29  namespace rendering
30  {
31  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
32  //
33  template <class T>
35  public virtual ArrowVisual,
36  public virtual T
37  {
39  protected: BaseArrowVisual();
40 
42  public: virtual ~BaseArrowVisual();
43 
44  // Documentation inherited.
45  protected: virtual void Destroy() override;
46 
47  // Documentation inherited.
48  public: virtual VisualPtr Head() const override;
49 
50  // Documentation inherited.
51  public: virtual VisualPtr Shaft() const override;
52 
53  // Documentation inherited.
54  public: virtual VisualPtr Rotation() const override;
55 
56  // Documentation inherited
57  public: virtual void ShowArrowHead(bool _b) override;
58 
59  // Documentation inherited
60  public: virtual void ShowArrowShaft(bool _b) override;
61 
62  // Documentation inherited
63  public: virtual void ShowArrowRotation(bool _b) override;
64 
65  // Documentation inherited
66  public: virtual void SetVisible(bool _visible) override;
67 
68  // Documentation inherited.
69  protected: virtual void Init() override;
70 
72  protected: bool rotationVisible = false;
73  };
74 
76  template <class T>
78  {
79  }
80 
82  template <class T>
84  {
85  }
86 
88  template <class T>
90  {
91  while (this->ChildCount() > 0u)
92  {
93  auto visual = std::dynamic_pointer_cast<Visual>(this->ChildByIndex(0));
94  if (visual)
95  {
96  visual->Destroy();
97  }
98  }
99  }
100 
102  template <class T>
104  {
105  return std::dynamic_pointer_cast<Visual>(this->ChildByIndex(2));
106  }
107 
109  template <class T>
111  {
112  return std::dynamic_pointer_cast<Visual>(this->ChildByIndex(1));
113  }
114 
116  template <class T>
118  {
119  return std::dynamic_pointer_cast<Visual>(this->ChildByIndex(0));
120  }
121 
123  template <class T>
125  {
126  NodePtr child = this->ChildByIndex(2);
127  VisualPtr visual = std::dynamic_pointer_cast<Visual>(child);
128  if (visual)
129  {
130  visual->SetVisible(_b);
131  }
132  }
133 
135  template <class T>
137  {
138  NodePtr child = this->ChildByIndex(1);
139  VisualPtr visual = std::dynamic_pointer_cast<Visual>(child);
140  if (visual)
141  {
142  visual->SetVisible(_b);
143  }
144  }
145 
147  template <class T>
149  {
150  NodePtr child = this->ChildByIndex(0);
151  VisualPtr visual = std::dynamic_pointer_cast<Visual>(child);
152  if (visual)
153  {
154  visual->SetVisible(_b);
155  this->rotationVisible = _b;
156  }
157  }
158 
160  template <class T>
161  void BaseArrowVisual<T>::SetVisible(bool _visible)
162  {
163  T::SetVisible(_visible);
164 
165  NodePtr child = this->ChildByIndex(0);
166  VisualPtr visual = std::dynamic_pointer_cast<Visual>(child);
167  if (visual)
168  {
169  // Force rotation visual visibility to false
170  // if the arrow visual is not visible.
171  // Else, rotation visual's visibility overrides
172  // its parent's visibility.
173  visual->SetVisible(this->rotationVisible && _visible);
174  }
175  }
176 
178  template <class T>
180  {
181  T::Init();
182 
183  VisualPtr cone = this->Scene()->CreateVisual();
184  cone->AddGeometry(this->Scene()->CreateCone());
185  cone->SetOrigin(0, 0, -0.5);
186  cone->SetLocalPosition(0, 0, 0);
187  cone->SetLocalScale(0.1, 0.1, 0.25);
188  this->AddChild(cone);
189 
190  VisualPtr cylinder = this->Scene()->CreateVisual();
191  cylinder->AddGeometry(this->Scene()->CreateCylinder());
192  cylinder->SetOrigin(0, 0, 0.5);
193  cylinder->SetLocalPosition(0, 0, 0);
194  cylinder->SetLocalScale(0.05, 0.05, 0.5);
195  this->AddChild(cylinder);
196 
198  std::string rotMeshName = "arrow_rotation";
199  if (!meshMgr->HasMesh(rotMeshName))
200  meshMgr->CreateTube(rotMeshName, 0.070f, 0.075f, 0.01f, 1, 32);
201 
202  VisualPtr rotationVis = this->Scene()->CreateVisual();
203  rotationVis->AddGeometry(this->Scene()->CreateMesh(rotMeshName));
204  rotationVis->SetOrigin(0, 0, -0.125);
205  rotationVis->SetLocalPosition(0, 0, 0);
206  rotationVis->SetVisible(this->rotationVisible);
207  this->AddChild(rotationVis);
208 
209  this->SetOrigin(0, 0, -0.5);
210  }
211  }
212  }
213 }
214 #endif
Represents a arrow composite visual.
Definition: ArrowVisual.hh:31
virtual void Destroy() override
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
Definition: BaseArrowVisual.hh:89
virtual void ShowArrowHead(bool _b) override
set true to show the arrow head, false otherwise
Definition: BaseArrowVisual.hh:124
virtual VisualPtr Head() const override
Get arrow-head visual.
Definition: BaseArrowVisual.hh:103
BaseArrowVisual()
Constructor.
Definition: BaseArrowVisual.hh:77
virtual void Init() override
Definition: BaseArrowVisual.hh:179
STL class.
bool HasMesh(const std::string &_name) const
virtual void ShowArrowRotation(bool _b) override
Set true to show the rotation of the arrow, false otherwise.
Definition: BaseArrowVisual.hh:148
Manages a single scene-graph. This class updates scene-wide properties and holds the root scene node...
Definition: Scene.hh:49
static MeshManager * Instance()
T dynamic_pointer_cast(T... args)
virtual VisualPtr Shaft() const override
Get arrow-shaft visual.
Definition: BaseArrowVisual.hh:110
Represents a visual node in a scene graph. A Visual is the only node that can have Geometry and other...
Definition: Visual.hh:33
virtual void SetVisible(bool _visible) override
Specify if this visual is visible.
Definition: BaseArrowVisual.hh:161
void CreateTube(const std::string &_name, const float _innerRadius, const float _outterRadius, const float _height, const int _rings, const int _segments, const double _arc=2.0 *IGN_PI)
virtual void ShowArrowShaft(bool _b) override
set true to show the arrow shaft, false otherwise
Definition: BaseArrowVisual.hh:136
virtual VisualPtr Rotation() const override
Get arrow-rotation visual.
Definition: BaseArrowVisual.hh:117
virtual void Destroy()=0
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
virtual ~BaseArrowVisual()
Destructor.
Definition: BaseArrowVisual.hh:83
virtual VisualPtr CreateVisual()=0
Create new visual. A unique ID and name will automatically be assigned to the visual.
Definition: BaseArrowVisual.hh:34