Simbody  3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 BrickHalfSpaceContactImpl;
65 class TriangleMeshContactImpl;
66 
67 class PointContactImpl; // deprecated
68 
69 
70 //==============================================================================
71 // CONTACT
72 //==============================================================================
84 public:
87  enum Condition {
93  Broken
94  };
98  static const char* nameOfCondition(Condition);
99 
101  Contact() : impl(0) {}
104  Contact(const Contact& source);
107  ~Contact() {clear();}
110  Contact& operator=(const Contact& source);
113  void clear();
115  bool isEmpty() const {return impl==0;}
116 
120  ContactId getContactId() const;
122  Condition getCondition() const;
125  ContactSurfaceIndex getSurface1() const;
128  ContactSurfaceIndex getSurface2() const;
132  const Transform& getTransform() const;
133 
136  Contact& setContactId(ContactId id);
138  Contact& setCondition(Condition condition);
140  Contact& setSurfaces(ContactSurfaceIndex surf1, ContactSurfaceIndex surf2);
142  Contact& setTransform(const Transform& X_S1S2);
143 
146  ContactTypeId getTypeId() const;
147 
151  static ContactId createNewContactId();
152 
153  const ContactImpl& getImpl() const {assert(impl); return *impl;}
154  ContactImpl& updImpl() {assert(impl); return *impl;}
155 protected:
156  explicit Contact(ContactImpl* impl);
157 private:
158  ContactImpl* impl;
159 };
160 
161 inline std::ostream& operator<<(std::ostream& o, const Contact& c) {
162  o << "Contact id=" << c.getContactId()
163  << " (typeId=" << c.getTypeId() << "):\n";
164  o << " surf1,surf2=" << c.getSurface1() << ","
165  << c.getSurface2() << "\n";
166  o << " condition=" << Contact::nameOfCondition(c.getCondition()) << "\n";
167  return o;
168 }
169 
170 
171 
172 //==============================================================================
173 // UNTRACKED CONTACT
174 //==============================================================================
181 public:
190 
192  static bool isInstance(const Contact& contact);
194  static ContactTypeId classTypeId();
195 
196 private:
197  const UntrackedContactImpl& getImpl() const
198  { assert(isInstance(*this));
199  return reinterpret_cast<const UntrackedContactImpl&>
200  (Contact::getImpl()); }
201 };
202 
203 
204 
205 //==============================================================================
206 // BROKEN CONTACT
207 //==============================================================================
215 public:
223  const Transform& X_S1S2, Real separation);
224 
228  Real getSeparation() const;
229 
231  static bool isInstance(const Contact& contact);
233  static ContactTypeId classTypeId();
234 
235 private:
236  const BrokenContactImpl& getImpl() const
237  { assert(isInstance(*this));
238  return reinterpret_cast<const BrokenContactImpl&>(Contact::getImpl()); }
239 };
240 
241 
242 
243 //==============================================================================
244 // CIRCULAR POINT CONTACT
245 //==============================================================================
259 public:
275  (ContactSurfaceIndex surf1, Real radius1,
276  ContactSurfaceIndex surf2, Real radius2,
277  const Transform& X_S1S2, Real radius, Real depth,
278  const Vec3& origin_S1, const UnitVec3& normal_S1);
279 
281  Real getRadius1() const;
283  Real getRadius2() const;
286  Real getEffectiveRadius() const;
291  Real getDepth() const;
293  const Vec3& getOrigin() const;
297  const UnitVec3& getNormal() const;
298 
300  static bool isInstance(const Contact& contact);
301  static const CircularPointContact& getAs(const Contact& contact)
302  { assert(isInstance(contact));
303  return static_cast<const CircularPointContact&>(contact); }
305  { assert(isInstance(contact));
306  return static_cast<CircularPointContact&>(contact); }
307 
309  static ContactTypeId classTypeId();
310 
311 private:
312  const CircularPointContactImpl& getImpl() const
313  { assert(isInstance(*this));
314  return reinterpret_cast<const CircularPointContactImpl&>
315  (Contact::getImpl()); }
316 };
317 
318 
319 
320 //==============================================================================
321 // ELLIPTICAL POINT CONTACT
322 //==============================================================================
354 public:
370  const Transform& X_S1S2,
371  const Transform& X_S1C, const Vec2& k, Real depth);
372 
375  const Vec2& getCurvatures() const;
382  const Transform& getContactFrame() const;
387  Real getDepth() const;
388 
390  static bool isInstance(const Contact& contact);
391  static const EllipticalPointContact& getAs(const Contact& contact)
392  { assert(isInstance(contact));
393  return static_cast<const EllipticalPointContact&>(contact); }
395  { assert(isInstance(contact));
396  return static_cast<EllipticalPointContact&>(contact); }
397 
399  static ContactTypeId classTypeId();
400 
401 private:
402  const EllipticalPointContactImpl& getImpl() const
403  { assert(isInstance(*this));
404  return reinterpret_cast<const EllipticalPointContactImpl&>
405  (Contact::getImpl()); }
406 };
407 
408 
409 
410 //==============================================================================
411 // BRICK HALFSPACE CONTACT
412 //==============================================================================
417 public:
429  ContactSurfaceIndex brick,
430  const Transform& X_HB,
431  int lowestVertex,
432  Real depth);
433 
436  int getLowestVertex() const;
437 
440  Real getDepth() const;
441 
443  static bool isInstance(const Contact& contact);
444 
447  static const BrickHalfSpaceContact& getAs(const Contact& contact)
448  { assert(isInstance(contact));
449  return static_cast<const BrickHalfSpaceContact&>(contact); }
450 
454  { assert(isInstance(contact));
455  return static_cast<BrickHalfSpaceContact&>(contact); }
456 
459  static ContactTypeId classTypeId();
460 
461 private:
462  const BrickHalfSpaceContactImpl& getImpl() const
463  { assert(isInstance(*this));
464  return reinterpret_cast<const BrickHalfSpaceContactImpl&>
465  (Contact::getImpl()); }
466 };
467 
468 
469 
470 //==============================================================================
471 // TRIANGLE MESH CONTACT
472 //==============================================================================
477 public:
490  ContactSurfaceIndex surf2,
491  const Transform& X_S1S2,
492  const std::set<int>& faces1,
493  const std::set<int>& faces2);
494 
498  const std::set<int>& getSurface1Faces() const;
502  const std::set<int>& getSurface2Faces() const;
503 
505  static bool isInstance(const Contact& contact);
508  static const TriangleMeshContact& getAs(const Contact& contact)
509  { assert(isInstance(contact));
510  return static_cast<const TriangleMeshContact&>(contact); }
514  { assert(isInstance(contact));
515  return static_cast<TriangleMeshContact&>(contact); }
516 
519  static ContactTypeId classTypeId();
520 
521 private:
522  const TriangleMeshContactImpl& getImpl() const
523  { assert(isInstance(*this));
524  return reinterpret_cast<const TriangleMeshContactImpl&>
525  (Contact::getImpl()); }
526 };
527 
528 
529 
530 
531 //==============================================================================
532 // POINT CONTACT
533 //==============================================================================
541 public:
559  Vec3& location, Vec3& normal, Real radius1, Real radius2, Real depth);
576  Vec3& location, Vec3& normal, Real radius, Real depth);
582  Vec3 getLocation() const;
587  Vec3 getNormal() const;
591  Real getRadiusOfCurvature1() const;
595  Real getRadiusOfCurvature2() const;
600  Real getEffectiveRadiusOfCurvature() const;
606  Real getDepth() const;
610  static bool isInstance(const Contact& contact);
614  static ContactTypeId classTypeId();
615 
616 private:
617  const PointContactImpl& getImpl() const
618  { assert(isInstance(*this));
619  return reinterpret_cast<const PointContactImpl&>(Contact::getImpl()); }
620 };
621 
622 } // namespace SimTK
623 
624 #endif // SimTK_SIMMATH_CONTACT_H_
static EllipticalPointContact & updAs(Contact &contact)
Definition: Contact.h:394
bool isEmpty() const
See if this handle is empty.
Definition: Contact.h:115
ContactImpl & updImpl()
Definition: Contact.h:154
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:87
const ContactImpl & getImpl() const
Definition: Contact.h:153
static BrickHalfSpaceContact & updAs(Contact &contact)
Recast a brick-halfspace contact given as a generic Contact object to a writable reference to a concr...
Definition: Contact.h:453
static const CircularPointContact & getAs(const Contact &contact)
Definition: Contact.h:301
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
static const BrickHalfSpaceContact & getAs(const Contact &contact)
Recast a brick-halfspace contact given as a generic Contact object to a const reference to a concrete...
Definition: Contact.h:447
This subclass of Contact represents a pair of contact surfaces that were in contact (meaning within c...
Definition: Contact.h:214
first time seen; needs a ContactId assigned
Definition: Contact.h:91
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:101
This subclass of Contact is used when one ContactGeometry object is a half plane and the other is a B...
Definition: Contact.h:416
This is a unique integer Id assigned to each contact pair when we first begin to track it...
SimTK_Real Real
This is the default compiled-in floating point type for SimTK, either float or double.
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:577
this pair not yet being tracked; might not contact
Definition: Contact.h:89
This subclass of Contact is used when one or both of the ContactGeometry objects is a TriangleMesh...
Definition: Contact.h:476
Includes internal headers providing declarations for the basic SimTK Core classes, including Simmatrix.
OBSOLETE – use CircularPointContact or EllipticalPointContact.
Definition: Contact.h:540
This subclass of Contact represents a contact between two non-conforming surfaces 1 and 2 that initia...
Definition: Contact.h:258
This subclass of Contact represents a pair of contact surfaces that are not yet being tracked; there ...
Definition: Contact.h:180
UntrackedContact()
Default constructor creates an empty handle.
Definition: Contact.h:183
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:353
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:304
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:508
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:83
was new or ongoing before; still in contact now
Definition: Contact.h:92
static const EllipticalPointContact & getAs(const Contact &contact)
Definition: Contact.h:391
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:513
#define SimTK_SIMMATH_EXPORT
Definition: SimTKmath/include/simmath/internal/common.h:64
this is an illegal value
Definition: Contact.h:88
~Contact()
Destructor clears the handle, deleting the referenced object if this was the last reference...
Definition: Contact.h:107
we expect these to contact soon
Definition: Contact.h:90