Contact.h

Go to the documentation of this file.
00001 #ifndef SimTK_SIMBODY_CONTACT_H_
00002 #define SimTK_SIMBODY_CONTACT_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                      SimTK Core: SimTK Simbody(tm)                         *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK Core biosimulation toolkit originating from      *
00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00010  * Medical Research, grant U54 GM072970. See https://simtk.org.               *
00011  *                                                                            *
00012  * Portions copyright (c) 2008-10 Stanford University and the Authors.        *
00013  * Authors: Peter Eastman                                                     *
00014  * Contributors: Michael Sherman                                              *
00015  *                                                                            *
00016  * Permission is hereby granted, free of charge, to any person obtaining a    *
00017  * copy of this software and associated documentation files (the "Software"), *
00018  * to deal in the Software without restriction, including without limitation  *
00019  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
00020  * and/or sell copies of the Software, and to permit persons to whom the      *
00021  * Software is furnished to do so, subject to the following conditions:       *
00022  *                                                                            *
00023  * The above copyright notice and this permission notice shall be included in *
00024  * all copies or substantial portions of the Software.                        *
00025  *                                                                            *
00026  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
00027  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
00028  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
00029  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
00030  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
00031  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
00032  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
00033  * -------------------------------------------------------------------------- */
00034 
00035 #include "SimTKcommon.h"
00036 
00037 #include "simbody/internal/common.h"
00038 
00039 namespace SimTK {
00040 
00041 
00045 SimTK_DEFINE_UNIQUE_INDEX_TYPE(ContactSurfaceIndex);
00046 
00055 SimTK_DEFINE_UNIQUE_INDEX_TYPE(ContactId);
00056 
00062 SimTK_DEFINE_UNIQUE_INDEX_TYPE(ContactTypeId);
00063 
00064 
00065 class ContactImpl;
00066 class UntrackedContactImpl;
00067 class BrokenContactImpl;
00068 class CircularPointContactImpl;
00069 class TriangleMeshContactImpl;
00070 class PointContactImpl;
00071 
00072 
00073 //==============================================================================
00074 //                                CONTACT
00075 //==============================================================================
00084 class SimTK_SIMBODY_EXPORT Contact {
00085 public:
00088     enum Condition {
00089         Unknown,    
00090         Untracked,  
00091         Anticipated,
00092         NewContact, 
00093         Ongoing,    
00094         Broken      
00095     };
00099     static const char* nameOfCondition(Condition);
00100 
00102     Contact() : impl(0) {}
00105     Contact(const Contact& source);
00108     ~Contact() {clear();}
00111     Contact& operator=(const Contact& source);
00114     void clear();
00116     bool isEmpty() const {return impl==0;}
00117 
00121     ContactId getContactId() const;
00123     Condition getCondition() const;
00126     ContactSurfaceIndex getSurface1() const;
00129     ContactSurfaceIndex getSurface2() const;
00133     const Transform& getTransform() const;
00134 
00137     Contact& setContactId(ContactId id);
00139     Contact& setCondition(Condition condition);
00141     Contact& setSurfaces(ContactSurfaceIndex surf1, ContactSurfaceIndex surf2);
00143     Contact& setTransform(const Transform& X_S1S2);
00144 
00147     ContactTypeId getTypeId() const;
00148 
00152     static ContactId createNewContactId();
00153 
00154     const ContactImpl& getImpl() const {assert(impl); return *impl;}
00155     ContactImpl&       updImpl()       {assert(impl); return *impl;}
00156 protected:
00157     explicit Contact(ContactImpl* impl);
00158 private:
00159     ContactImpl* impl;
00160 };
00161 
00162 inline std::ostream& operator<<(std::ostream& o, const Contact& c) {
00163     o << "Contact id=" << c.getContactId() 
00164                        << " (typeId=" << c.getTypeId() << "):\n";
00165     o << "  surf1,surf2=" << c.getSurface1() << ","
00166                           << c.getSurface2() << "\n";
00167     o << "  condition=" << Contact::nameOfCondition(c.getCondition()) << "\n";
00168     return o;
00169 }
00170 
00171 
00172 
00173 //==============================================================================
00174 //                            UNTRACKED CONTACT
00175 //==============================================================================
00181 class SimTK_SIMBODY_EXPORT UntrackedContact : public Contact {
00182 public:
00184     UntrackedContact() {}
00190     UntrackedContact(ContactSurfaceIndex surf1, ContactSurfaceIndex surf2); 
00191 
00193     static bool isInstance(const Contact& contact);
00195     static ContactTypeId classTypeId();
00196 
00197 private:
00198     const UntrackedContactImpl& getImpl() const 
00199     {   assert(isInstance(*this)); 
00200         return reinterpret_cast<const UntrackedContactImpl&>
00201                     (Contact::getImpl()); }
00202 };
00203 
00204 
00205 
00206 //==============================================================================
00207 //                            BROKEN CONTACT
00208 //==============================================================================
00215 class SimTK_SIMBODY_EXPORT BrokenContact : public Contact {
00216 public:
00223     BrokenContact(ContactSurfaceIndex surf1, ContactSurfaceIndex surf2,
00224                   const Transform& X_S1S2, Real separation); 
00225 
00229     Real getSeparation() const;
00230 
00232     static bool isInstance(const Contact& contact);
00234     static ContactTypeId classTypeId();
00235 
00236 private:
00237     const BrokenContactImpl& getImpl() const 
00238     {   assert(isInstance(*this)); 
00239         return reinterpret_cast<const BrokenContactImpl&>(Contact::getImpl()); }
00240 };
00241 
00242 
00243 
00244 //==============================================================================
00245 //                           CIRCULAR POINT CONTACT
00246 //==============================================================================
00259 class SimTK_SIMBODY_EXPORT CircularPointContact : public Contact {
00260 public:
00275     CircularPointContact
00276        (ContactSurfaceIndex surf1, Real radius1, 
00277         ContactSurfaceIndex surf2, Real radius2, 
00278         const Transform& X_S1S2, Real radius, Real depth, 
00279         const Vec3& origin_S1, const UnitVec3& normal_S1);
00280 
00282     Real getRadius1() const;
00284     Real getRadius2() const;
00287     Real getEffectiveRadius() const;
00292     Real getDepth() const;
00294     const Vec3& getOrigin() const;
00298     const UnitVec3& getNormal() const;
00299 
00301     static bool isInstance(const Contact& contact);
00302     static const CircularPointContact& getAs(const Contact& contact)
00303     {   assert(isInstance(contact)); 
00304         return static_cast<const CircularPointContact&>(contact); }
00305     static CircularPointContact& updAs(Contact& contact)
00306     {   assert(isInstance(contact)); 
00307         return static_cast<CircularPointContact&>(contact); }
00308 
00310     static ContactTypeId classTypeId();
00311 
00312 private:
00313     const CircularPointContactImpl& getImpl() const 
00314     {   assert(isInstance(*this)); 
00315         return reinterpret_cast<const CircularPointContactImpl&>
00316                     (Contact::getImpl()); }
00317 };
00318 
00319 
00320 
00321 //==============================================================================
00322 //                           TRIANGLE MESH CONTACT
00323 //==============================================================================
00327 class SimTK_SIMBODY_EXPORT TriangleMeshContact : public Contact {
00328 public:
00340     TriangleMeshContact(ContactSurfaceIndex     surf1, 
00341                         ContactSurfaceIndex     surf2,
00342                         const Transform&        X_S1S2,
00343                         const std::set<int>&    faces1, 
00344                         const std::set<int>&    faces2);
00345 
00349     const std::set<int>& getSurface1Faces() const;
00353     const std::set<int>& getSurface2Faces() const;
00354 
00356     static bool isInstance(const Contact& contact);
00359     static const TriangleMeshContact& getAs(const Contact& contact)
00360     {   assert(isInstance(contact)); 
00361         return static_cast<const TriangleMeshContact&>(contact); }
00364     static TriangleMeshContact& updAs(Contact& contact)
00365     {   assert(isInstance(contact)); 
00366         return static_cast<TriangleMeshContact&>(contact); }
00367 
00370     static ContactTypeId classTypeId();
00371 
00372 private:
00373     const TriangleMeshContactImpl& getImpl() const 
00374     {   assert(isInstance(*this)); 
00375         return reinterpret_cast<const TriangleMeshContactImpl&>
00376                     (Contact::getImpl()); }
00377 };
00378 
00379 
00380 
00381 
00382 //==============================================================================
00383 //                           POINT CONTACT (OBSOLETE)
00384 //==============================================================================
00385 // OBSOLETE: this incorrectly includes the patch radius as part of the 
00386 // geometric information, but the returned value assumes a Hertz elastic
00387 // contact model. Use CircularPointContact instead.
00394 class SimTK_SIMBODY_EXPORT PointContact : public Contact {
00395 public:
00411     PointContact(ContactSurfaceIndex surf1, ContactSurfaceIndex surf2, 
00412                  Vec3& location, Vec3& normal, Real radius, Real depth);
00418     Vec3 getLocation() const;
00423     Vec3 getNormal() const;
00427     Real getRadius() const;
00433     Real getDepth() const;
00437     static bool isInstance(const Contact& contact);
00441     static ContactTypeId classTypeId();
00442 
00443 private:
00444     const PointContactImpl& getImpl() const 
00445     {   assert(isInstance(*this)); 
00446         return reinterpret_cast<const PointContactImpl&>(Contact::getImpl()); }
00447 };
00448 
00449 } // namespace SimTK
00450 
00451 #endif // SimTK_SIMBODY_CONTACT_H_

Generated on Thu Aug 12 16:37:06 2010 for SimTKcore by  doxygen 1.6.1