DART  6.10.1
InverseKinematicsPtr.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2021, 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  template <class, class>
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
81  {
82  return mIK;
83  }
84 
86  template <class OtherIkT>
87  TemplateInverseKinematicsPtr(const std::shared_ptr<OtherIkT>& sptr)
88  {
89  set(sptr);
90  }
91 
93  template <class OtherIkT, class OtherJacNodePtrT>
96  {
97  set(_ptr.mIK);
98  return *this;
99  }
100 
102  template <class SharedPtrT>
103  TemplateInverseKinematicsPtr& operator=(const SharedPtrT& _ptr)
104  {
105  set(_ptr);
106  return *this;
107  }
108 
111  {
112  set(nullptr);
113  return *this;
114  }
115 
117  operator bool() const
118  {
119  return (nullptr != mIK);
120  }
121 
124  {
125  return *get();
126  }
127 
130  {
131  return get();
132  }
133 
135  element_type* get() const
136  {
137  if (nullptr == mJacNodePtr)
138  return nullptr;
139 
140  return mIK.get();
141  }
142 
144  std::shared_ptr<element_type> get_shared() const
145  {
146  if (nullptr == mJacNodePtr)
147  return nullptr;
148 
149  return mIK;
150  }
151 
154  void set(const std::shared_ptr<IkType>& sptr)
155  {
156  if (nullptr == sptr)
157  {
158  mIK = nullptr;
159  mJacNodePtr = nullptr;
160  return;
161  }
162 
163  mJacNodePtr = sptr->getAffiliation();
164  mIK = sptr;
165  }
166 
167  //----------------------------------------------------------------------------
169  //----------------------------------------------------------------------------
170 
172  template <class OtherIkT, class OtherJacNodeT>
175  {
176  return (mIK == _rhs.mIK);
177  }
178 
180  template <class OtherIkT, class OtherJacNodeT>
183  {
184  return !(*this == _rhs);
185  }
186 
188  template <class OtherIkT, class OtherJacNodeT>
189  bool operator<(
191  {
192  return (mIK < _rhs.mIK);
193  }
194 
196  template <class OtherIkT, class OtherJacNodeT>
197  bool operator>(
199  {
200  return (mIK > _rhs.mIK);
201  }
202 
204  template <class OtherIkT, class OtherJacNodeT>
207  {
208  return (*this < _rhs) || (*this == _rhs);
209  }
210 
212  template <class OtherIkT, class OtherJacNodeT>
215  {
216  return (*this > _rhs) || (*this == _rhs);
217  }
218 
220 
221 protected:
223  std::shared_ptr<element_type> mIK;
224 
226  JacobianNodePtrT mJacNodePtr;
227 };
228 
229 // Comparison to nullptr
230 template <class IkType, class BodyNodeT>
231 inline bool operator==(
232  const TemplateInverseKinematicsPtr<IkType, BodyNodeT>& _ik, std::nullptr_t)
233 {
234  return nullptr == _ik.get();
235 }
236 
237 // Comparison to nullptr
238 template <class IkType, class BodyNodeT>
239 inline bool operator==(
240  std::nullptr_t, const TemplateInverseKinematicsPtr<IkType, BodyNodeT>& _ik)
241 {
242  return nullptr == _ik.get();
243 }
244 
245 // Comparison to nullptr
246 template <class IkType, class BodyNodeT>
247 inline bool operator!=(
248  const TemplateInverseKinematicsPtr<IkType, BodyNodeT>& _ik, std::nullptr_t)
249 {
250  return nullptr != _ik.get();
251 }
252 
253 // Comparison to nullptr
254 template <class IkType, class BodyNodeT>
255 inline bool operator!=(
256  std::nullptr_t, const TemplateInverseKinematicsPtr<IkType, BodyNodeT>& _ik)
257 {
258  return nullptr != _ik.get();
259 }
260 
266 template <class InverseKinematicsT, class JacobianNodePtrT>
268 {
269 public:
270  template <class, class>
272 
273  typedef InverseKinematicsT element_type;
274 
277 
279  template <class PtrType>
280  TemplateWeakInverseKinematicsPtr(const PtrType& _ptr)
281  {
282  set(_ptr);
283  }
284 
286  template <class PtrType>
288  {
289  set(_ptr);
290  return *this;
291  }
292 
297  const
298  {
299  JacobianNodePtrT jacNode = mWeakJacNode.lock();
300  if (nullptr == jacNode)
301  return nullptr;
302 
304  mWeakIK.lock());
305  }
306 
308  template <class OtherIkT, class OtherJacNodePtrT>
310  {
311  if (nullptr == _ptr)
312  {
313  mWeakIK = nullptr;
314  mWeakJacNode = nullptr;
315  return;
316  }
317 
318  mWeakIK = _ptr.get();
319  mWeakJacNode = _ptr.get()->getEntity();
320  }
321 
323  template <class OtherIkT, class OtherJacNodeT>
324  void set(
326  {
327  mWeakIK = _ptr.mWeakIK;
328  mWeakJacNode = _ptr.mWeakJacNode;
329  }
330 
331 protected:
333  std::weak_ptr<InverseKinematicsT> mWeakIK;
334 
336  JacobianNodePtrT mWeakJacNode;
337 };
338 
339 } // namespace dynamics
340 } // namespace dart
341 
342 #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:189
TemplateInverseKinematicsPtr & operator=(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodePtrT > &_ptr)
Assignment operator.
Definition: InverseKinematicsPtr.hpp:94
element_type & operator*() const
Dereferencing operator.
Definition: InverseKinematicsPtr.hpp:123
bool operator>(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Greater than.
Definition: InverseKinematicsPtr.hpp:197
bool operator>=(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Greater than or equal to.
Definition: InverseKinematicsPtr.hpp:213
TemplateInverseKinematicsPtr(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodePtrT > &_ptr)
Constructor that takes in a strong InverseKinematicsPtr.
Definition: InverseKinematicsPtr.hpp:73
TemplateInverseKinematicsPtr & operator=(std::nullptr_t)
Assignment operator for nullptr.
Definition: InverseKinematicsPtr.hpp:110
bool operator!=(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Inequality.
Definition: InverseKinematicsPtr.hpp:181
JacobianNodePtrT mJacNodePtr
Pointer to the Node associated with the IK module.
Definition: InverseKinematicsPtr.hpp:226
TemplateInverseKinematicsPtr(const std::shared_ptr< OtherIkT > &sptr)
Constructor that takes in a shared_ptr.
Definition: InverseKinematicsPtr.hpp:87
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:144
bool operator<=(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Less than or equal to.
Definition: InverseKinematicsPtr.hpp:205
IkType element_type
Definition: InverseKinematicsPtr.hpp:54
std::shared_ptr< element_type > mIK
Pointer to the IK module.
Definition: InverseKinematicsPtr.hpp:223
bool operator==(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Equality.
Definition: InverseKinematicsPtr.hpp:173
void set(const std::shared_ptr< IkType > &sptr)
Set the InverseKinematics module for this InverseKinematicsPtr from a shared_ptr.
Definition: InverseKinematicsPtr.hpp:154
TemplateInverseKinematicsPtr & operator=(const SharedPtrT &_ptr)
Assignment operator for shared_ptr.
Definition: InverseKinematicsPtr.hpp:103
element_type * get() const
Get the raw pointer.
Definition: InverseKinematicsPtr.hpp:135
TemplateInverseKinematicsPtr(std::nullptr_t)
Constructor that accepts a nullptr.
Definition: InverseKinematicsPtr.hpp:63
element_type * operator->() const
Dereferencing operation.
Definition: InverseKinematicsPtr.hpp:129
TemplateWeakInverseKinematicsPtr is a templated class that enables users to create a non-reference-ho...
Definition: InverseKinematicsPtr.hpp:268
TemplateInverseKinematicsPtr< InverseKinematicsT, JacobianNodePtrT > lock() const
Locks the InverseKinematics module to ensure that the referenced module is currently still available.
Definition: InverseKinematicsPtr.hpp:296
void set(const TemplateWeakInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_ptr)
Set using a weak pointer.
Definition: InverseKinematicsPtr.hpp:324
void set(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodePtrT > &_ptr)
Set using a strong pointer.
Definition: InverseKinematicsPtr.hpp:309
TemplateWeakInverseKinematicsPtr & operator=(const PtrType &_ptr)
Assignment operator for various templated pointer types.
Definition: InverseKinematicsPtr.hpp:287
TemplateWeakInverseKinematicsPtr()=default
Default constructor.
JacobianNodePtrT mWeakJacNode
Weak pointer to the JacobianNode.
Definition: InverseKinematicsPtr.hpp:336
std::weak_ptr< InverseKinematicsT > mWeakIK
Weak pointer to the IK module.
Definition: InverseKinematicsPtr.hpp:333
TemplateWeakInverseKinematicsPtr(const PtrType &_ptr)
Constructor for various pointer types.
Definition: InverseKinematicsPtr.hpp:280
InverseKinematicsT element_type
Definition: InverseKinematicsPtr.hpp:273
bool operator==(const TemplateInverseKinematicsPtr< IkType, BodyNodeT > &_ik, std::nullptr_t)
Definition: InverseKinematicsPtr.hpp:231
bool operator!=(const TemplateInverseKinematicsPtr< IkType, BodyNodeT > &_ik, std::nullptr_t)
Definition: InverseKinematicsPtr.hpp:247
Definition: BulletCollisionDetector.cpp:65