Gazebo Rendering

API Reference

6.6.3
gz/rendering/base/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 GZ_RENDERING_BASE_BASEARROWVISUAL_HH_
18 #define GZ_RENDERING_BASE_BASEARROWVISUAL_HH_
19 
20 #include <string>
21 
22 #include <gz/common/MeshManager.hh>
23 
25 #include "gz/rendering/Scene.hh"
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  T::Destroy();
100  }
101 
103  template <class T>
105  {
106  return std::dynamic_pointer_cast<Visual>(this->ChildByIndex(2));
107  }
108 
110  template <class T>
112  {
113  return std::dynamic_pointer_cast<Visual>(this->ChildByIndex(1));
114  }
115 
117  template <class T>
119  {
120  return std::dynamic_pointer_cast<Visual>(this->ChildByIndex(0));
121  }
122 
124  template <class T>
126  {
127  NodePtr child = this->ChildByIndex(2);
128  VisualPtr visual = std::dynamic_pointer_cast<Visual>(child);
129  if (visual)
130  {
131  visual->SetVisible(_b);
132  }
133  }
134 
136  template <class T>
138  {
139  NodePtr child = this->ChildByIndex(1);
140  VisualPtr visual = std::dynamic_pointer_cast<Visual>(child);
141  if (visual)
142  {
143  visual->SetVisible(_b);
144  }
145  }
146 
148  template <class T>
150  {
151  NodePtr child = this->ChildByIndex(0);
152  VisualPtr visual = std::dynamic_pointer_cast<Visual>(child);
153  if (visual)
154  {
155  visual->SetVisible(_b);
156  this->rotationVisible = _b;
157  }
158  }
159 
161  template <class T>
162  void BaseArrowVisual<T>::SetVisible(bool _visible)
163  {
164  T::SetVisible(_visible);
165 
166  NodePtr child = this->ChildByIndex(0);
167  VisualPtr visual = std::dynamic_pointer_cast<Visual>(child);
168  if (visual)
169  {
170  // Force rotation visual visibility to false
171  // if the arrow visual is not visible.
172  // Else, rotation visual's visibility overrides
173  // its parent's visibility.
174  visual->SetVisible(this->rotationVisible && _visible);
175  }
176  }
177 
179  template <class T>
181  {
182  T::Init();
183 
184  VisualPtr cone = this->Scene()->CreateVisual();
185  cone->AddGeometry(this->Scene()->CreateCone());
186  cone->SetOrigin(0, 0, -0.5);
187  cone->SetLocalPosition(0, 0, 0);
188  cone->SetLocalScale(0.1, 0.1, 0.25);
189  this->AddChild(cone);
190 
191  VisualPtr cylinder = this->Scene()->CreateVisual();
192  cylinder->AddGeometry(this->Scene()->CreateCylinder());
193  cylinder->SetOrigin(0, 0, 0.5);
194  cylinder->SetLocalPosition(0, 0, 0);
195  cylinder->SetLocalScale(0.05, 0.05, 0.5);
196  this->AddChild(cylinder);
197 
199  std::string rotMeshName = "arrow_rotation";
200  if (!meshMgr->HasMesh(rotMeshName))
201  meshMgr->CreateTube(rotMeshName, 0.070f, 0.075f, 0.01f, 1, 32);
202 
203  VisualPtr rotationVis = this->Scene()->CreateVisual();
204  rotationVis->AddGeometry(this->Scene()->CreateMesh(rotMeshName));
205  rotationVis->SetOrigin(0, 0, -0.125);
206  rotationVis->SetLocalPosition(0, 0, 0);
207  rotationVis->SetVisible(this->rotationVisible);
208  this->AddChild(rotationVis);
209 
210  this->SetOrigin(0, 0, -0.5);
211  }
212  }
213  }
214 }
215 #endif
bool rotationVisible
Flag to indicate whether arrow rotation is visible.
Definition: gz/rendering/base/BaseArrowVisual.hh:72
STL class.
STL class.
BaseArrowVisual()
Constructor.
Definition: gz/rendering/base/BaseArrowVisual.hh:77
bool HasMesh(const std::string &_name) const
virtual void ShowArrowHead(bool _b) override
set true to show the arrow head, false otherwise
Definition: gz/rendering/base/BaseArrowVisual.hh:125
virtual VisualPtr Head() const override
Get arrow-head visual.
Definition: gz/rendering/base/BaseArrowVisual.hh:104
static MeshManager * Instance()
virtual void ShowArrowRotation(bool _b) override
Set true to show the rotation of the arrow, false otherwise.
Definition: gz/rendering/base/BaseArrowVisual.hh:149
virtual void Destroy() override
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
Definition: gz/rendering/base/BaseArrowVisual.hh:89
virtual VisualPtr CreateVisual()=0
Create new visual. A unique ID and name will automatically be assigned to the visual.
Manages a single scene-graph. This class updates scene-wide properties and holds the root scene node....
Definition: gz/rendering/Scene.hh:49
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 SetVisible(bool _visible) override
Specify if this visual is visible.
Definition: gz/rendering/base/BaseArrowVisual.hh:162
virtual void ShowArrowShaft(bool _b) override
set true to show the arrow shaft, false otherwise
Definition: gz/rendering/base/BaseArrowVisual.hh:137
virtual void Init() override
Definition: gz/rendering/base/BaseArrowVisual.hh:180
virtual VisualPtr Rotation() const override
Get arrow-rotation visual.
Definition: gz/rendering/base/BaseArrowVisual.hh:118
Definition: gz/rendering/base/BaseArrowVisual.hh:34
virtual VisualPtr Shaft() const override
Get arrow-shaft visual.
Definition: gz/rendering/base/BaseArrowVisual.hh:111
Represents a arrow composite visual.
Definition: gz/rendering/ArrowVisual.hh:31
virtual ~BaseArrowVisual()
Destructor.
Definition: gz/rendering/base/BaseArrowVisual.hh:83