00001
00002
00003
00004
00005
00006
00007 #ifndef _THRESH_CONTACT_SIMULATOR_H
00008 #define _THRESH_CONTACT_SIMULATOR_H
00009
00010 #include <map>
00011 #include <Physsim/sorted_pair>
00012 #include <Physsim/Simulator.h>
00013 #include <Physsim/CollisionMethod.h>
00014 #include <Physsim/CollisionDetection.h>
00015 #include <Physsim/ContactData.h>
00016 #include <Physsim/Contact.h>
00017 #include <Physsim/RestingContactMethod.h>
00018
00019 namespace Physsim {
00020
00021 struct TCSMinimalStateStruct;
00022 class Contact;
00023 class CollisionDetection;
00024 class CollisionGeometry;
00025 class RigidBody;
00026 class ArticulatedBody;
00027
00029
00052 class ThreshContactSimulator : public Simulator
00053 {
00054 public:
00055 ThreshContactSimulator();
00056 virtual ~ThreshContactSimulator() {}
00057 virtual void step_full(Real step_size, Real smallest_step);
00058 virtual void determine_external_forces();
00059 CollisionGeometryPtr find_collision_geometry(const std::string& name) const;
00060 virtual void clone(BasePtr& cloned, bimap<BasePtr, BasePtr>* object_map = NULL) const;
00061 virtual bool is_struct_identical(BaseConstPtr object) const;
00062 virtual void load_state(BaseConstPtr object, bimap<BasePtr, BasePtr>* object_map = NULL);
00063 virtual void save_state(BasePtr object, bimap<BasePtr, BasePtr>* object_map = NULL) const;
00064 virtual void load_from_xml(XMLTreeConstPtr node, std::map<std::string, BasePtr>& id_map);
00065 virtual void save_to_xml(XMLTreePtr node, std::list<BaseConstPtr>& shared_objects) const;
00066 virtual void output_object_state(std::ostream& out) const;
00067
00069 const std::map<sorted_pair<BasePtr>, boost::shared_ptr<ContactData> >& get_contact_data() const { return _contact_data; }
00070
00072 const std::list<ContactPtr>& get_impacting_contacts() const { return _impacting_contacts; }
00073
00075 const std::list<ContactPtr>& get_resting_contacts() const { return _resting_contacts; }
00076
00078 void clear_contact_data() { _contact_data.clear(); }
00079
00081 void add_contact_data(boost::shared_ptr<ContactData> cd) { _contact_data[cd->objects] = cd ; }
00082
00084 boost::shared_ptr<CollisionDetection> get_collision_detection() { return _coll_det; }
00085
00087 void set_collision_detection(boost::shared_ptr<CollisionDetection> colldet) { _coll_det = colldet; }
00088
00090
00095 virtual Real step(Real step_size);
00096
00098 void set_callback_function(void (*fn)(ContactPtr)) { _callback_fn = fn; }
00099
00101 void (*get_callback_function())(ContactPtr) { return _callback_fn; }
00102
00104 Real get_collision_tolerance() const { return _collision_tolerance; }
00105
00107 void set_collision_tolerance(Real collision_tolerance) { assert(collision_tolerance >= 0); _collision_tolerance = collision_tolerance; }
00108
00110 Real get_contact_resting_vel_thresh() const { return _contact_resting_vel_thresh; }
00111
00113 void set_contact_resting_vel_thresh(Real resting_vel_thresh) { _contact_resting_vel_thresh = resting_vel_thresh; }
00114
00115 protected:
00116 void update_contact_phases(const std::map<sorted_pair<CollisionGeometryPtr>, QueryPtr>& colliding_pairs);
00117 void preprocess_contact(ContactPtr contact) const;
00118 Contact::ContactPhaseType det_contact_type(ContactPtr c, Contact::ContactPhaseType current_phase);
00119 boost::shared_ptr<ContactData> get_contact_data(CollisionGeometryPtr g1, boost::shared_ptr<CollisionGeometry> g2) const;
00120 bool impact_contact(boost::shared_ptr<TCSMinimalStateStruct> state_t0, boost::shared_ptr<TCSMinimalStateStruct> state_tf);
00121 void regress_to_first_TOI(boost::shared_ptr<TCSMinimalStateStruct> state_t0, boost::shared_ptr<TCSMinimalStateStruct> state_tf, Real tolerance);
00122 boost::shared_ptr<TCSMinimalStateStruct> clone_minimal() const;
00123 void load_state_minimal(boost::shared_ptr<TCSMinimalStateStruct> mss);
00124
00125 std::list<ContactPtr> _resting_contacts;
00126 std::list<ContactPtr> _impacting_contacts;
00127 Real _contact_resting_vel_thresh;
00128 Real _collision_tolerance;
00129 std::map<sorted_pair<BasePtr>, boost::shared_ptr<ContactData> > _contact_data;
00130 boost::shared_ptr<CollisionDetection> _coll_det;
00131 void (*_callback_fn)(ContactPtr);
00132 };
00133
00134 }
00135
00136 #endif