DART  6.7.3
InverseKinematicsPtr.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2019, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_DYNAMICS_DETAIL_INVERSEKINEMATICSPTR_HPP_
34 #define DART_DYNAMICS_DETAIL_INVERSEKINEMATICSPTR_HPP_
35 
36 #include <memory>
38 
39 namespace dart {
40 namespace dynamics {
41 
47 template <class IkType, class JacobianNodePtrT>
49 {
50 public:
51 
52  template<class, class> friend class TemplateInverseKinematicsPtr;
53 
54  typedef IkType element_type;
55 
57  TemplateInverseKinematicsPtr(const std::shared_ptr<element_type>& sptr)
58  {
59  set(sptr);
60  }
61 
64  {
65  // Do nothing
66  }
67 
70 
72  template <class OtherIkT, class OtherJacNodePtrT>
75  {
76  set(_ptr.mIK);
77  }
78 
80  operator std::shared_ptr<element_type>() const { return mIK; }
81 
83  template <class OtherIkT>
84  TemplateInverseKinematicsPtr(const std::shared_ptr<OtherIkT>& sptr)
85  {
86  set(sptr);
87  }
88 
90  template <class OtherIkT, class OtherJacNodePtrT>
93  {
94  set(_ptr.mIK);
95  return *this;
96  }
97 
99  template <class SharedPtrT>
100  TemplateInverseKinematicsPtr& operator = (const SharedPtrT& _ptr)
101  {
102  set(_ptr);
103  return *this;
104  }
105 
108  {
109  set(nullptr);
110  return *this;
111  }
112 
114  operator bool() const { return (nullptr != mIK); }
115 
117  element_type& operator*() const { return *get(); }
118 
120  element_type* operator->() const { return get(); }
121 
123  element_type* get() const
124  {
125  if(nullptr == mJacNodePtr)
126  return nullptr;
127 
128  return mIK.get();
129  }
130 
132  std::shared_ptr<element_type> get_shared() const
133  {
134  if(nullptr == mJacNodePtr)
135  return nullptr;
136 
137  return mIK;
138  }
139 
142  void set(const std::shared_ptr<IkType>& sptr)
143  {
144  if(nullptr == sptr)
145  {
146  mIK = nullptr;
147  mJacNodePtr = nullptr;
148  return;
149  }
150 
151  mJacNodePtr = sptr->getAffiliation();
152  mIK = sptr;
153  }
154 
155  //----------------------------------------------------------------------------
157  //----------------------------------------------------------------------------
158 
160  template <class OtherIkT, class OtherJacNodeT>
163  {
164  return (mIK == _rhs.mIK);
165  }
166 
168  template <class OtherIkT, class OtherJacNodeT>
171  {
172  return !( *this == _rhs );
173  }
174 
176  template <class OtherIkT, class OtherJacNodeT>
179  {
180  return (mIK < _rhs.mIK);
181  }
182 
184  template <class OtherIkT, class OtherJacNodeT>
187  {
188  return (mIK > _rhs.mIK);
189  }
190 
192  template <class OtherIkT, class OtherJacNodeT>
195  {
196  return (*this < _rhs) || (*this == _rhs);
197  }
198 
200  template <class OtherIkT, class OtherJacNodeT>
203  {
204  return (*this > _rhs) || (*this == _rhs);
205  }
206 
208 
209 protected:
210 
212  std::shared_ptr<element_type> mIK;
213 
215  JacobianNodePtrT mJacNodePtr;
216 
217 };
218 
219 // Comparison to nullptr
220 template <class IkType, class BodyNodeT>
221 inline bool operator == (
222  const TemplateInverseKinematicsPtr<IkType, BodyNodeT>& _ik, std::nullptr_t)
223 {
224  return nullptr == _ik.get();
225 }
226 
227 // Comparison to nullptr
228 template <class IkType, class BodyNodeT>
229 inline bool operator == (
230  std::nullptr_t, const TemplateInverseKinematicsPtr<IkType, BodyNodeT>& _ik)
231 {
232  return nullptr == _ik.get();
233 }
234 
235 // Comparison to nullptr
236 template <class IkType, class BodyNodeT>
237 inline bool operator != (
238  const TemplateInverseKinematicsPtr<IkType, BodyNodeT>& _ik, std::nullptr_t)
239 {
240  return nullptr != _ik.get();
241 }
242 
243 // Comparison to nullptr
244 template <class IkType, class BodyNodeT>
245 inline bool operator != (
246  std::nullptr_t, const TemplateInverseKinematicsPtr<IkType, BodyNodeT>& _ik)
247 {
248  return nullptr != _ik.get();
249 }
250 
251 
257 template <class InverseKinematicsT, class JacobianNodePtrT>
259 {
260 public:
261 
262  template<class, class> friend class TemplateWeakInverseKinematicsPtr;
263 
264  typedef InverseKinematicsT element_type;
265 
268 
270  template <class PtrType>
271  TemplateWeakInverseKinematicsPtr(const PtrType& _ptr)
272  {
273  set(_ptr);
274  }
275 
277  template <class PtrType>
279  {
280  set(_ptr);
281  return *this;
282  }
283 
288  {
289  JacobianNodePtrT jacNode = mWeakJacNode.lock();
290  if(nullptr == jacNode)
291  return nullptr;
292 
294  mWeakIK.lock());
295  }
296 
298  template <class OtherIkT, class OtherJacNodePtrT>
300  {
301  if(nullptr == _ptr)
302  {
303  mWeakIK = nullptr;
304  mWeakJacNode = nullptr;
305  return;
306  }
307 
308  mWeakIK = _ptr.get();
309  mWeakJacNode = _ptr.get()->getEntity();
310  }
311 
313  template <class OtherIkT, class OtherJacNodeT>
315  OtherIkT, OtherJacNodeT>& _ptr)
316  {
317  mWeakIK = _ptr.mWeakIK;
318  mWeakJacNode = _ptr.mWeakJacNode;
319  }
320 
321 protected:
322 
324  std::weak_ptr<InverseKinematicsT> mWeakIK;
325 
327  JacobianNodePtrT mWeakJacNode;
328 
329 };
330 
331 } // namespace dynamics
332 } // namespace dart
333 
334 #endif // DART_DYNAMICS_DETAIL_INVERSEKINEMATICSPTR_HPP_
TemplateInverseKinematicsPtr is a templated class that enables users to create a reference-counting I...
Definition: InverseKinematicsPtr.hpp:49
TemplateInverseKinematicsPtr()=default
Default constructor.
bool operator<(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Less than.
Definition: InverseKinematicsPtr.hpp:177
TemplateInverseKinematicsPtr & operator=(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodePtrT > &_ptr)
Assignment operator.
Definition: InverseKinematicsPtr.hpp:91
element_type & operator*() const
Dereferencing operator.
Definition: InverseKinematicsPtr.hpp:117
bool operator>(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Greater than.
Definition: InverseKinematicsPtr.hpp:185
bool operator>=(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Greater than or equal to.
Definition: InverseKinematicsPtr.hpp:201
TemplateInverseKinematicsPtr(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodePtrT > &_ptr)
Constructor that takes in a strong InverseKinematicsPtr.
Definition: InverseKinematicsPtr.hpp:73
bool operator!=(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Inequality.
Definition: InverseKinematicsPtr.hpp:169
JacobianNodePtrT mJacNodePtr
Pointer to the Node associated with the IK module.
Definition: InverseKinematicsPtr.hpp:215
TemplateInverseKinematicsPtr(const std::shared_ptr< OtherIkT > &sptr)
Constructor that takes in a shared_ptr.
Definition: InverseKinematicsPtr.hpp:84
TemplateInverseKinematicsPtr(const std::shared_ptr< element_type > &sptr)
Constructor that accepts a shared_ptr.
Definition: InverseKinematicsPtr.hpp:57
std::shared_ptr< element_type > get_shared() const
Get the shared_ptr held by this InverseKinematicsPtr.
Definition: InverseKinematicsPtr.hpp:132
bool operator<=(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Less than or equal to.
Definition: InverseKinematicsPtr.hpp:193
IkType element_type
Definition: InverseKinematicsPtr.hpp:54
std::shared_ptr< element_type > mIK
Pointer to the IK module.
Definition: InverseKinematicsPtr.hpp:212
bool operator==(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Equality.
Definition: InverseKinematicsPtr.hpp:161
void set(const std::shared_ptr< IkType > &sptr)
Set the InverseKinematics module for this InverseKinematicsPtr from a shared_ptr.
Definition: InverseKinematicsPtr.hpp:142
element_type * get() const
Get the raw pointer.
Definition: InverseKinematicsPtr.hpp:123
TemplateInverseKinematicsPtr(std::nullptr_t)
Constructor that accepts a nullptr.
Definition: InverseKinematicsPtr.hpp:63
element_type * operator->() const
Dereferencing operation.
Definition: InverseKinematicsPtr.hpp:120
TemplateWeakInverseKinematicsPtr is a templated class that enables users to create a non-reference-ho...
Definition: InverseKinematicsPtr.hpp:259
TemplateInverseKinematicsPtr< InverseKinematicsT, JacobianNodePtrT > lock() const
Locks the InverseKinematics module to ensure that the referenced module is currently still available.
Definition: InverseKinematicsPtr.hpp:287
void set(const TemplateWeakInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_ptr)
Set using a weak pointer.
Definition: InverseKinematicsPtr.hpp:314
void set(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodePtrT > &_ptr)
Set using a strong pointer.
Definition: InverseKinematicsPtr.hpp:299
TemplateWeakInverseKinematicsPtr & operator=(const PtrType &_ptr)
Assignment operator for various templated pointer types.
Definition: InverseKinematicsPtr.hpp:278
TemplateWeakInverseKinematicsPtr()=default
Default constructor.
JacobianNodePtrT mWeakJacNode
Weak pointer to the JacobianNode.
Definition: InverseKinematicsPtr.hpp:327
std::weak_ptr< InverseKinematicsT > mWeakIK
Weak pointer to the IK module.
Definition: InverseKinematicsPtr.hpp:324
TemplateWeakInverseKinematicsPtr(const PtrType &_ptr)
Constructor for various pointer types.
Definition: InverseKinematicsPtr.hpp:271
InverseKinematicsT element_type
Definition: InverseKinematicsPtr.hpp:264
bool operator==(const TemplateInverseKinematicsPtr< IkType, BodyNodeT > &_ik, std::nullptr_t)
Definition: InverseKinematicsPtr.hpp:221
bool operator!=(const TemplateInverseKinematicsPtr< IkType, BodyNodeT > &_ik, std::nullptr_t)
Definition: InverseKinematicsPtr.hpp:237
Definition: BulletCollisionDetector.cpp:63