Simbody  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Contact.h
Go to the documentation of this file.
1 #ifndef SimTK_SIMMATH_CONTACT_H_
2 #define SimTK_SIMMATH_CONTACT_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * Simbody(tm): SimTKmath *
6  * -------------------------------------------------------------------------- *
7  * This is part of the SimTK biosimulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11  * *
12  * Portions copyright (c) 2008-12 Stanford University and the Authors. *
13  * Authors: Peter Eastman, Michael Sherman *
14  * Contributors: *
15  * *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17  * not use this file except in compliance with the License. You may obtain a *
18  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19  * *
20  * Unless required by applicable law or agreed to in writing, software *
21  * distributed under the License is distributed on an "AS IS" BASIS, *
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23  * See the License for the specific language governing permissions and *
24  * limitations under the License. *
25  * -------------------------------------------------------------------------- */
26 
27 #include "SimTKcommon.h"
29 
30 namespace SimTK {
31 
32 
37 SimTK_DEFINE_UNIQUE_INDEX_TYPE(ContactSurfaceIndex);
38 
49 
56 SimTK_DEFINE_UNIQUE_INDEX_TYPE(ContactTypeId);
57 
58 
59 class ContactImpl;
60 class UntrackedContactImpl;
61 class BrokenContactImpl;
62 class CircularPointContactImpl;
63 class EllipticalPointContactImpl;
64 class TriangleMeshContactImpl;
65 class PointContactImpl;
66 
67 
68 //==============================================================================
69 // CONTACT
70 //==============================================================================
82 public:
85  enum Condition {
91  Broken
92  };
96  static const char* nameOfCondition(Condition);
97 
99  Contact() : impl(0) {}
102  Contact(const Contact& source);
105  ~Contact() {clear();}
108  Contact& operator=(const Contact& source);
111  void clear();
113  bool isEmpty() const {return impl==0;}
114 
118  ContactId getContactId() const;
120  Condition getCondition() const;
123  ContactSurfaceIndex getSurface1() const;
126  ContactSurfaceIndex getSurface2() const;
130  const Transform& getTransform() const;
131 
134  Contact& setContactId(ContactId id);
136  Contact& setCondition(Condition condition);
138  Contact& setSurfaces(ContactSurfaceIndex surf1, ContactSurfaceIndex surf2);
140  Contact& setTransform(const Transform& X_S1S2);
141 
144  ContactTypeId getTypeId() const;
145 
149  static ContactId createNewContactId();
150 
151  const ContactImpl& getImpl() const {assert(impl); return *impl;}
152  ContactImpl& updImpl() {assert(impl); return *impl;}
153 protected:
154  explicit Contact(ContactImpl* impl);
155 private:
156  ContactImpl* impl;
157 };
158 
159 inline std::ostream& operator<<(std::ostream& o, const Contact& c) {
160  o << "Contact id=" << c.getContactId()
161  << " (typeId=" << c.getTypeId() << "):\n";
162  o << " surf1,surf2=" << c.getSurface1() << ","
163  << c.getSurface2() << "\n";
164  o << " condition=" << Contact::nameOfCondition(c.getCondition()) << "\n";
165  return o;
166 }
167 
168 
169 
170 //==============================================================================
171 // UNTRACKED CONTACT
172 //==============================================================================
179 public:
188 
190  static bool isInstance(const Contact& contact);
192  static ContactTypeId classTypeId();
193 
194 private:
195  const UntrackedContactImpl& getImpl() const
196  { assert(isInstance(*this));
197  return reinterpret_cast<const UntrackedContactImpl&>
198  (Contact::getImpl()); }
199 };
200 
201 
202 
203 //==============================================================================
204 // BROKEN CONTACT
205 //==============================================================================
213 public:
221  const Transform& X_S1S2, Real separation);
222 
226  Real getSeparation() const;
227 
229  static bool isInstance(const Contact& contact);
231  static ContactTypeId classTypeId();
232 
233 private:
234  const BrokenContactImpl& getImpl() const
235  { assert(isInstance(*this));
236  return reinterpret_cast<const BrokenContactImpl&>(Contact::getImpl()); }
237 };
238 
239 
240 
241 //==============================================================================
242 // CIRCULAR POINT CONTACT
243 //==============================================================================
257 public:
273  (ContactSurfaceIndex surf1, Real radius1,
274  ContactSurfaceIndex surf2, Real radius2,
275  const Transform& X_S1S2, Real radius, Real depth,
276  const Vec3& origin_S1, const UnitVec3& normal_S1);
277 
279  Real getRadius1() const;
281  Real getRadius2() const;
284  Real getEffectiveRadius() const;
289  Real getDepth() const;
291  const Vec3& getOrigin() const;
295  const UnitVec3& getNormal() const;
296 
298  static bool isInstance(const Contact& contact);
299  static const CircularPointContact& getAs(const Contact& contact)
300  { assert(isInstance(contact));
301  return static_cast<const CircularPointContact&>(contact); }
303  { assert(isInstance(contact));
304  return static_cast<CircularPointContact&>(contact); }
305 
307  static ContactTypeId classTypeId();
308 
309 private:
310  const CircularPointContactImpl& getImpl() const
311  { assert(isInstance(*this));
312  return reinterpret_cast<const CircularPointContactImpl&>
313  (Contact::getImpl()); }
314 };
315 
316 
317 
318 //==============================================================================
319 // ELLIPTICAL POINT CONTACT
320 //==============================================================================
352 public:
368  const Transform& X_S1S2,
369  const Transform& X_S1C, const Vec2& k, Real depth);
370 
373  const Vec2& getCurvatures() const;
380  const Transform& getContactFrame() const;
385  Real getDepth() const;
386 
388  static bool isInstance(const Contact& contact);
389  static const EllipticalPointContact& getAs(const Contact& contact)
390  { assert(isInstance(contact));
391  return static_cast<const EllipticalPointContact&>(contact); }
393  { assert(isInstance(contact));
394  return static_cast<EllipticalPointContact&>(contact); }
395 
397  static ContactTypeId classTypeId();
398 
399 private:
400  const EllipticalPointContactImpl& getImpl() const
401  { assert(isInstance(*this));
402  return reinterpret_cast<const EllipticalPointContactImpl&>
403  (Contact::getImpl()); }
404 };
405 
406 
407 
408 
409 //==============================================================================
410 // TRIANGLE MESH CONTACT
411 //==============================================================================
416 public:
429  ContactSurfaceIndex surf2,
430  const Transform& X_S1S2,
431  const std::set<int>& faces1,
432  const std::set<int>& faces2);
433 
437  const std::set<int>& getSurface1Faces() const;
441  const std::set<int>& getSurface2Faces() const;
442 
444  static bool isInstance(const Contact& contact);
447  static const TriangleMeshContact& getAs(const Contact& contact)
448  { assert(isInstance(contact));
449  return static_cast<const TriangleMeshContact&>(contact); }
453  { assert(isInstance(contact));
454  return static_cast<TriangleMeshContact&>(contact); }
455 
458  static ContactTypeId classTypeId();
459 
460 private:
461  const TriangleMeshContactImpl& getImpl() const
462  { assert(isInstance(*this));
463  return reinterpret_cast<const TriangleMeshContactImpl&>
464  (Contact::getImpl()); }
465 };
466 
467 
468 
469 
470 //==============================================================================
471 // POINT CONTACT
472 //==============================================================================
480 public:
498  Vec3& location, Vec3& normal, Real radius1, Real radius2, Real depth);
515  Vec3& location, Vec3& normal, Real radius, Real depth);
521  Vec3 getLocation() const;
526  Vec3 getNormal() const;
530  Real getRadiusOfCurvature1() const;
534  Real getRadiusOfCurvature2() const;
539  Real getEffectiveRadiusOfCurvature() const;
545  Real getDepth() const;
549  static bool isInstance(const Contact& contact);
553  static ContactTypeId classTypeId();
554 
555 private:
556  const PointContactImpl& getImpl() const
557  { assert(isInstance(*this));
558  return reinterpret_cast<const PointContactImpl&>(Contact::getImpl()); }
559 };
560 
561 } // namespace SimTK
562 
563 #endif // SimTK_SIMMATH_CONTACT_H_
static EllipticalPointContact & updAs(Contact &contact)
Definition: Contact.h:392
bool isEmpty() const
See if this handle is empty.
Definition: Contact.h:113
ContactImpl & updImpl()
Definition: Contact.h:152
This defines a unique index for all the contact surfaces being handled either by a ContactTrackerSubs...
SimTK_DEFINE_UNIQUE_INDEX_TYPE(AssemblyConditionIndex)
ContactSurfaceIndex getSurface2() const
Get the second surface involved in the contact, specified by its index within its contact set or Cont...
Condition
The Contact::Condition tracks the status of a Contact through its lifetime.
Definition: Contact.h:85
const ContactImpl & getImpl() const
Definition: Contact.h:151
static const CircularPointContact & getAs(const Contact &contact)
Definition: Contact.h:299
This subclass of Contact represents a pair of contact surfaces that were in contact (meaning within c...
Definition: Contact.h:212
first time seen; needs a ContactId assigned
Definition: Contact.h:89
This is a small integer that serves as the unique typeid for each type of concrete Contact class...
Contact()
The default constructor creates an empty handle.
Definition: Contact.h:99
This is a unique integer Id assigned to each contact pair when we first begin to track it...
this pair not yet being tracked; might not contact
Definition: Contact.h:87
This subclass of Contact is used when one or both of the ContactGeometry objects is a TriangleMesh...
Definition: Contact.h:415
Includes internal headers providing declarations for the basic SimTK Core classes, including Simmatrix.
OBSOLETE – use CircularPointContact or EllipticalPointContact.
Definition: Contact.h:479
This subclass of Contact represents a contact between two non-conforming surfaces 1 and 2 that initia...
Definition: Contact.h:256
This subclass of Contact represents a pair of contact surfaces that are not yet being tracked; there ...
Definition: Contact.h:178
UntrackedContact()
Default constructor creates an empty handle.
Definition: Contact.h:181
static const char * nameOfCondition(Condition)
Returns a human-readable name corresponding to the given Condition; useful for debugging.
std::ostream & operator<<(std::ostream &o, const ContactForce &f)
Definition: CompliantContactSubsystem.h:387
This subclass of Contact represents a contact between two non-conforming surfaces 1 and 2 that initia...
Definition: Contact.h:351
ContactTypeId getTypeId() const
Return a unique small integer corresponding to the concrete type of Contact object being referenced b...
ContactSurfaceIndex getSurface1() const
Get the first surface involved in the contact, specified by its index within its contact set or Conta...
ContactId getContactId() const
Get the persistent ContactId that has been assigned to this Contact object if there is one (otherwise...
static CircularPointContact & updAs(Contact &contact)
Definition: Contact.h:302
This is the header file that every Simmath compilation unit should include first. ...
static const TriangleMeshContact & getAs(const Contact &contact)
Recast a triangle mesh given as a generic Contact object to a const reference to a concrete TriangleM...
Definition: Contact.h:447
Condition getCondition() const
Find out the current condition of this Contact object.
A Contact contains information about the spatial relationship between two surfaces that are near...
Definition: Contact.h:81
was new or ongoing before; still in contact now
Definition: Contact.h:90
static const EllipticalPointContact & getAs(const Contact &contact)
Definition: Contact.h:389
static TriangleMeshContact & updAs(Contact &contact)
Recast a triangle mesh given as a generic Contact object to a writable reference to a concrete Triang...
Definition: Contact.h:452
#define SimTK_SIMMATH_EXPORT
Definition: SimTKmath/include/simmath/internal/common.h:64
this is an illegal value
Definition: Contact.h:86
~Contact()
Destructor clears the handle, deleting the referenced object if this was the last reference...
Definition: Contact.h:105
we expect these to contact soon
Definition: Contact.h:88