DART 6.12.2
Loading...
Searching...
No Matches
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>
37
39
40namespace dart {
41namespace dynamics {
42
48template <class IkType, class JacobianNodePtrT>
50{
51public:
52 template <class, class>
54
55 typedef IkType element_type;
56
58 TemplateInverseKinematicsPtr(const std::shared_ptr<element_type>& sptr)
59 {
60 set(sptr);
61 }
62
65 {
66 // Do nothing
67 }
68
71
73 template <class OtherIkT, class OtherJacNodePtrT>
79
81 operator std::shared_ptr<element_type>() const
82 {
83 return mIK;
84 }
85
87 template <class OtherIkT>
88 TemplateInverseKinematicsPtr(const std::shared_ptr<OtherIkT>& sptr)
89 {
90 set(sptr);
91 }
92
94 template <class OtherIkT, class OtherJacNodePtrT>
101
103 template <class SharedPtrT>
105 {
106 set(_ptr);
107 return *this;
108 }
109
112 {
113 set(nullptr);
114 return *this;
115 }
116
118 operator bool() const
119 {
120 return (nullptr != mIK);
121 }
122
125 {
126 return *get();
127 }
128
131 {
132 return get();
133 }
134
137 {
138 if (nullptr == mJacNodePtr)
139 return nullptr;
140
141 return mIK.get();
142 }
143
145 std::shared_ptr<element_type> get_shared() const
146 {
147 if (nullptr == mJacNodePtr)
148 return nullptr;
149
150 return mIK;
151 }
152
155 void set(const std::shared_ptr<IkType>& sptr)
156 {
157 if (nullptr == sptr)
158 {
159 mIK = nullptr;
160 mJacNodePtr = nullptr;
161 return;
162 }
163
164 mJacNodePtr = sptr->getAffiliation();
165 mIK = sptr;
166 }
167
168 //----------------------------------------------------------------------------
170 //----------------------------------------------------------------------------
171
173 template <class OtherIkT, class OtherJacNodeT>
176 {
177 return (mIK == _rhs.mIK);
178 }
179
181 template <class OtherIkT, class OtherJacNodeT>
184 {
185 return !(*this == _rhs);
186 }
187
189 template <class OtherIkT, class OtherJacNodeT>
192 {
193 return (mIK < _rhs.mIK);
194 }
195
197 template <class OtherIkT, class OtherJacNodeT>
200 {
201 return (mIK > _rhs.mIK);
202 }
203
205 template <class OtherIkT, class OtherJacNodeT>
208 {
209 return (*this < _rhs) || (*this == _rhs);
210 }
211
213 template <class OtherIkT, class OtherJacNodeT>
216 {
217 return (*this > _rhs) || (*this == _rhs);
218 }
219
221
222protected:
224 std::shared_ptr<element_type> mIK;
225
227 JacobianNodePtrT mJacNodePtr;
228};
229
230// Comparison to nullptr
231template <class IkType, class BodyNodeT>
232inline bool operator==(
233 const TemplateInverseKinematicsPtr<IkType, BodyNodeT>& _ik, std::nullptr_t)
234{
235 return nullptr == _ik.get();
236}
237
238// Comparison to nullptr
239template <class IkType, class BodyNodeT>
240inline bool operator==(
241 std::nullptr_t, const TemplateInverseKinematicsPtr<IkType, BodyNodeT>& _ik)
242{
243 return nullptr == _ik.get();
244}
245
246// Comparison to nullptr
247template <class IkType, class BodyNodeT>
248inline bool operator!=(
249 const TemplateInverseKinematicsPtr<IkType, BodyNodeT>& _ik, std::nullptr_t)
250{
251 return nullptr != _ik.get();
252}
253
254// Comparison to nullptr
255template <class IkType, class BodyNodeT>
256inline bool operator!=(
257 std::nullptr_t, const TemplateInverseKinematicsPtr<IkType, BodyNodeT>& _ik)
258{
259 return nullptr != _ik.get();
260}
261
267template <class InverseKinematicsT, class JacobianNodePtrT>
269{
270public:
271 template <class, class>
273
274 typedef InverseKinematicsT element_type;
275
278
280 template <class PtrType>
282 {
283 set(_ptr);
284 }
285
287 template <class PtrType>
289 {
290 set(_ptr);
291 return *this;
292 }
293
298 const
299 {
300 JacobianNodePtrT jacNode = mWeakJacNode.lock();
301 if (nullptr == jacNode)
302 return nullptr;
303
305 mWeakIK.lock());
306 }
307
309 template <class OtherIkT, class OtherJacNodePtrT>
311 {
312 if (nullptr == _ptr)
313 {
314 mWeakIK = nullptr;
315 mWeakJacNode = nullptr;
316 return;
317 }
318
319 mWeakIK = _ptr.get();
320 mWeakJacNode = _ptr.get()->getEntity();
321 }
322
324 template <class OtherIkT, class OtherJacNodeT>
331
332protected:
334 std::weak_ptr<InverseKinematicsT> mWeakIK;
335
337 JacobianNodePtrT mWeakJacNode;
338};
339
340} // namespace dynamics
341} // namespace dart
342
343#endif // DART_DYNAMICS_DETAIL_INVERSEKINEMATICSPTR_HPP_
TemplateInverseKinematicsPtr is a templated class that enables users to create a reference-counting I...
Definition InverseKinematicsPtr.hpp:50
TemplateInverseKinematicsPtr()=default
Default constructor.
bool operator<(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Less than.
Definition InverseKinematicsPtr.hpp:190
bool operator>(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Greater than.
Definition InverseKinematicsPtr.hpp:198
bool operator>=(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Greater than or equal to.
Definition InverseKinematicsPtr.hpp:214
TemplateInverseKinematicsPtr(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodePtrT > &_ptr)
Constructor that takes in a strong InverseKinematicsPtr.
Definition InverseKinematicsPtr.hpp:74
TemplateInverseKinematicsPtr & operator=(std::nullptr_t)
Assignment operator for nullptr.
Definition InverseKinematicsPtr.hpp:111
bool operator!=(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Inequality.
Definition InverseKinematicsPtr.hpp:182
element_type & operator*() const
Dereferencing operator.
Definition InverseKinematicsPtr.hpp:124
JacobianNodePtrT mJacNodePtr
Pointer to the Node associated with the IK module.
Definition InverseKinematicsPtr.hpp:227
element_type * get() const
Get the raw pointer.
Definition InverseKinematicsPtr.hpp:136
TemplateInverseKinematicsPtr(const std::shared_ptr< OtherIkT > &sptr)
Constructor that takes in a shared_ptr.
Definition InverseKinematicsPtr.hpp:88
TemplateInverseKinematicsPtr(const std::shared_ptr< element_type > &sptr)
Constructor that accepts a shared_ptr.
Definition InverseKinematicsPtr.hpp:58
bool operator<=(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Less than or equal to.
Definition InverseKinematicsPtr.hpp:206
IkType element_type
Definition InverseKinematicsPtr.hpp:55
TemplateInverseKinematicsPtr & operator=(const SharedPtrT &_ptr)
Assignment operator for shared_ptr.
Definition InverseKinematicsPtr.hpp:104
std::shared_ptr< element_type > mIK
Pointer to the IK module.
Definition InverseKinematicsPtr.hpp:224
bool operator==(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_rhs) const
Equality.
Definition InverseKinematicsPtr.hpp:174
void set(const std::shared_ptr< IkType > &sptr)
Set the InverseKinematics module for this InverseKinematicsPtr from a shared_ptr.
Definition InverseKinematicsPtr.hpp:155
element_type * operator->() const
Dereferencing operation.
Definition InverseKinematicsPtr.hpp:130
std::shared_ptr< element_type > get_shared() const
Get the shared_ptr held by this InverseKinematicsPtr.
Definition InverseKinematicsPtr.hpp:145
TemplateInverseKinematicsPtr(std::nullptr_t)
Constructor that accepts a nullptr.
Definition InverseKinematicsPtr.hpp:64
TemplateInverseKinematicsPtr & operator=(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodePtrT > &_ptr)
Assignment operator.
Definition InverseKinematicsPtr.hpp:95
TemplateWeakInverseKinematicsPtr is a templated class that enables users to create a non-reference-ho...
Definition InverseKinematicsPtr.hpp:269
void set(const TemplateWeakInverseKinematicsPtr< OtherIkT, OtherJacNodeT > &_ptr)
Set using a weak pointer.
Definition InverseKinematicsPtr.hpp:325
TemplateWeakInverseKinematicsPtr & operator=(const PtrType &_ptr)
Assignment operator for various templated pointer types.
Definition InverseKinematicsPtr.hpp:288
void set(const TemplateInverseKinematicsPtr< OtherIkT, OtherJacNodePtrT > &_ptr)
Set using a strong pointer.
Definition InverseKinematicsPtr.hpp:310
TemplateWeakInverseKinematicsPtr()=default
Default constructor.
JacobianNodePtrT mWeakJacNode
Weak pointer to the JacobianNode.
Definition InverseKinematicsPtr.hpp:337
std::weak_ptr< InverseKinematicsT > mWeakIK
Weak pointer to the IK module.
Definition InverseKinematicsPtr.hpp:334
TemplateInverseKinematicsPtr< InverseKinematicsT, JacobianNodePtrT > lock() const
Locks the InverseKinematics module to ensure that the referenced module is currently still available.
Definition InverseKinematicsPtr.hpp:297
TemplateWeakInverseKinematicsPtr(const PtrType &_ptr)
Constructor for various pointer types.
Definition InverseKinematicsPtr.hpp:281
InverseKinematicsT element_type
Definition InverseKinematicsPtr.hpp:274
bool operator==(const TemplateInverseKinematicsPtr< IkType, BodyNodeT > &_ik, std::nullptr_t)
Definition InverseKinematicsPtr.hpp:232
bool operator!=(const TemplateInverseKinematicsPtr< IkType, BodyNodeT > &_ik, std::nullptr_t)
Definition InverseKinematicsPtr.hpp:248
Definition BulletCollisionDetector.cpp:60