Ignition Rendering

API Reference

0.1.0
BaseNode.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_BASENODE_HH_
18 #define IGNITION_RENDERING_BASE_BASENODE_HH_
19 
22 
23 namespace ignition
24 {
25  namespace rendering
26  {
27  template <class T>
28  class IGNITION_RENDERING_VISIBLE BaseNode :
29  public virtual Node,
30  public virtual T
31  {
32  protected: BaseNode();
33 
34  public: virtual ~BaseNode();
35 
36  public: virtual VisualPtr Parent() const = 0;
37 
38  public: virtual void RemoveParent();
39 
40  public: virtual math::Pose3d LocalPose() const;
41 
42  public: virtual void SetLocalPose(const math::Pose3d &_pose);
43 
44  public: virtual math::Vector3d LocalPosition() const;
45 
46  public: virtual void SetLocalPosition(double _x, double _y, double _z);
47 
48  public: virtual void SetLocalPosition(const math::Vector3d &_position);
49 
50  public: virtual math::Quaterniond LocalRotation() const;
51 
52  public: virtual void SetLocalRotation(double _r, double _p, double _y);
53 
54  public: virtual void SetLocalRotation(double _w, double _x, double _y,
55  double _z);
56 
57  public: virtual void SetLocalRotation(const math::Quaterniond &_rotation);
58 
59  public: virtual math::Pose3d WorldPose() const;
60 
61  public: virtual void SetWorldPose(const math::Pose3d &_pose);
62 
63  public: virtual math::Vector3d WorldPosition() const;
64 
65  public: virtual void SetWorldPosition(double _x, double _y, double _z);
66 
67  public: virtual void SetWorldPosition(const math::Vector3d &_position);
68 
69  public: virtual math::Quaterniond WorldRotation() const;
70 
71  public: virtual void SetWorldRotation(double _r, double _p, double _y);
72 
73  public: virtual void SetWorldRotation(double _w, double _x, double _y,
74  double _z);
75 
76  public: virtual void SetWorldRotation(const math::Quaterniond &_rotation);
77 
78  public: virtual math::Pose3d WorldToLocal(const math::Pose3d &_pose)
79  const;
80 
81  public: virtual math::Vector3d Origin() const;
82 
83  public: virtual void SetOrigin(double _x, double _y, double _z);
84 
85  public: virtual void SetOrigin(const math::Vector3d &_origin);
86 
87  public: virtual void Destroy();
88 
89  protected: virtual math::Pose3d RawLocalPose() const = 0;
90 
91  protected: virtual void SetRawLocalPose(const math::Pose3d &_pose) = 0;
92 
93  protected: math::Vector3d origin;
94  };
95 
97  template <class T>
99  {
100  }
101 
103  template <class T>
105  {
106  }
107 
109  template <class T>
111  {
112  VisualPtr parent = this->Parent();
113 
114  if (parent)
115  {
116  auto baseShared = this->shared_from_this();
117  auto thisShared = std::dynamic_pointer_cast<BaseNode<T>>(baseShared);
118  parent->RemoveChild(thisShared);
119  }
120  }
121 
123  template <class T>
124  math::Pose3d BaseNode<T>::LocalPose() const
125  {
126  math::Pose3d pose = this->RawLocalPose();
127  pose.Pos() += pose.Rot() * this->origin;
128  return pose;
129  }
130 
132  template <class T>
133  void BaseNode<T>::SetLocalPose(const math::Pose3d &_pose)
134  {
135  math::Pose3d pose = _pose;
136  pose.Pos() = pose.Pos() - pose.Rot() * this->origin;
137  this->SetRawLocalPose(pose);
138  }
139 
141  template <class T>
142  math::Vector3d BaseNode<T>::LocalPosition() const
143  {
144  return this->LocalPose().Pos();
145  }
146 
148  template <class T>
149  void BaseNode<T>::SetLocalPosition(double _x, double _y, double _z)
150  {
151  this->SetLocalPosition(math::Vector3d(_x, _y, _z));
152  }
153 
155  template <class T>
156  void BaseNode<T>::SetLocalPosition(const math::Vector3d &_position)
157  {
158  math::Pose3d pose = this->LocalPose();
159  pose.Pos() = _position;
160  this->SetLocalPose(pose);
161  }
162 
164  template <class T>
165  math::Quaterniond BaseNode<T>::LocalRotation() const
166  {
167  return this->LocalPose().Rot();
168  }
169 
171  template <class T>
172  void BaseNode<T>::SetLocalRotation(double _r, double _p, double _y)
173  {
174  this->SetLocalRotation(math::Quaterniond(_r, _p, _y));
175  }
176 
178  template <class T>
179  void BaseNode<T>::SetLocalRotation(double _w, double _x, double _y,
180  double _z)
181  {
182  this->SetLocalRotation(math::Quaterniond(_w, _x, _y, _z));
183  }
184 
186  template <class T>
187  void BaseNode<T>::SetLocalRotation(const math::Quaterniond &_rotation)
188  {
189  math::Pose3d pose = this->LocalPose();
190  pose.Rot() = _rotation;
191  this->SetLocalPose(pose);
192  }
193 
195  template <class T>
196  math::Pose3d BaseNode<T>::WorldPose() const
197  {
198  VisualPtr parent = this->Parent();
199  math::Pose3d pose = this->LocalPose();
200 
201  if (!parent)
202  {
203  return pose;
204  }
205 
206  return pose + parent->WorldPose();
207  }
208 
210  template <class T>
211  void BaseNode<T>::SetWorldPose(const math::Pose3d &_pose)
212  {
213  math::Pose3d pose = this->WorldToLocal(_pose);
214  this->SetLocalPose(pose);
215  }
216 
218  template <class T>
219  void BaseNode<T>::SetWorldPosition(double _x, double _y, double _z)
220  {
221  this->SetWorldPosition(math::Vector3d(_x, _y, _z));
222  }
223 
225  template <class T>
226  math::Vector3d BaseNode<T>::WorldPosition() const
227  {
228  return this->WorldPose().Pos();
229  }
230 
232  template <class T>
233  void BaseNode<T>::SetWorldPosition(const math::Vector3d &_position)
234  {
235  math::Pose3d pose = this->WorldPose();
236  pose.Pos() =_position;
237  this->SetWorldPose(pose);
238  }
239 
241  template <class T>
242  math::Quaterniond BaseNode<T>::WorldRotation() const
243  {
244  return this->WorldPose().Rot();
245  }
246 
248  template <class T>
249  void BaseNode<T>::SetWorldRotation(double _r, double _p, double _y)
250  {
251  this->SetWorldRotation(math::Quaterniond(_r, _p, _y));
252  }
253 
255  template <class T>
256  void BaseNode<T>::SetWorldRotation(double _w, double _x, double _y,
257  double _z)
258  {
259  this->SetWorldRotation(math::Quaterniond(_w, _x, _y, _z));
260  }
261 
263  template <class T>
264  void BaseNode<T>::SetWorldRotation(const math::Quaterniond &_rotation)
265  {
266  math::Pose3d pose = this->WorldPose();
267  pose.Rot() = _rotation;
268  this->SetWorldPose(pose);
269  }
270 
272  template <class T>
273  math::Pose3d BaseNode<T>::WorldToLocal(const math::Pose3d &_pose) const
274  {
275  VisualPtr parent = this->Parent();
276 
277  if (!parent)
278  {
279  return _pose;
280  }
281 
282  return _pose - parent->WorldPose();
283  }
284 
286  template <class T>
287  math::Vector3d BaseNode<T>::Origin() const
288  {
289  return this->origin;
290  }
291 
293  template <class T>
294  void BaseNode<T>::SetOrigin(double _x, double _y, double _z)
295  {
296  this->SetOrigin(math::Vector3d(_x, _y, _z));
297  }
298 
300  template <class T>
301  void BaseNode<T>::SetOrigin(const math::Vector3d &_origin)
302  {
303  this->origin = _origin;
304  }
305 
307  template <class T>
309  {
310  T::Destroy();
311  this->RemoveParent();
312  }
313  }
314 }
315 #endif
virtual void SetLocalPose(const math::Pose3d &_pose)
Set the local pose.
Definition: BaseNode.hh:133
virtual math::Quaterniond LocalRotation() const
Get the local rotation.
Definition: BaseNode.hh:165
virtual void SetWorldPosition(double _x, double _y, double _z)
Set the world position.
Definition: BaseNode.hh:219
virtual math::Vector3d WorldPosition() const
Get the world position.
Definition: BaseNode.hh:226
virtual void RemoveParent()
Detach this Geometry from its parent Visual. If this Geometry does not have a parent, no work will be done.
Definition: BaseNode.hh:110
virtual void SetWorldRotation(double _r, double _p, double _y)
Set the world rotation.
Definition: BaseNode.hh:249
virtual void SetLocalPosition(double _x, double _y, double _z)
Set the local position.
Definition: BaseNode.hh:149
virtual math::Pose3d LocalPose() const
Get the local pose.
Definition: BaseNode.hh:124
virtual math::Quaterniond WorldRotation() const
Get the world rotation.
Definition: BaseNode.hh:242
Represents a single posable node in the scene graph.
Definition: Node.hh:34
virtual ~BaseNode()
Definition: BaseNode.hh:104
virtual void SetOrigin(double _x, double _y, double _z)
Set position of origin. The position should be relative to the original origin of the geometry...
Definition: BaseNode.hh:294
virtual math::Vector3d Origin() const
Get position of origin.
Definition: BaseNode.hh:287
T dynamic_pointer_cast(T... args)
virtual math::Pose3d WorldPose() const
Get the world pose.
Definition: BaseNode.hh:196
virtual void SetLocalRotation(double _r, double _p, double _y)
Set the local rotation.
Definition: BaseNode.hh:172
virtual void Destroy()
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
Definition: BaseNode.hh:308
BaseNode()
Definition: BaseNode.hh:98
virtual void SetWorldPose(const math::Pose3d &_pose)
Set the world pose.
Definition: BaseNode.hh:211
virtual math::Pose3d WorldToLocal(const math::Pose3d &_pose) const
Convert given world pose to local pose.
Definition: BaseNode.hh:273
Definition: ArrowVisual.hh:22
Definition: BaseNode.hh:28
virtual math::Vector3d LocalPosition() const
Get the local position.
Definition: BaseNode.hh:142
math::Vector3d origin
Definition: BaseNode.hh:93