00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _graspitcollision_h_
00027 #define _graspitcollision_h_
00028
00034 #include <map>
00035 #include <set>
00036 #include <list>
00037 #include <vector>
00038
00039 #include "collisionInterface.h"
00040
00041 namespace Collision{
00042 class CollisionModel;
00043 }
00044 using namespace Collision;
00045
00046 class GraspitCollision : public CollisionInterface
00047 {
00048 private:
00049
00051 std::vector<CollisionModel*> mModels;
00052
00054 std::map<const Body*, CollisionModel*> mModelMap;
00056 std::map<const CollisionModel*, Body*> mBodyMap;
00057
00058 inline Body* getBody(const CollisionModel* model);
00059 inline CollisionModel* getModel(const Body* body);
00060
00061 typedef std::multimap<const CollisionModel*,
00062 const CollisionModel*>::iterator DisabledIterator;
00064
00068 std::multimap<const CollisionModel*, const CollisionModel*> mDisabledMap;
00069
00070 typedef std::pair<const CollisionModel*, const CollisionModel*> CollisionPair;
00072 void getActivePairs(std::list<CollisionPair> *activePairs,
00073 const std::set<CollisionModel*> *interestList);
00074
00075 void convertInterestList(const std::vector<Body*> *inList, std::set<CollisionModel*> *outSet);
00076
00077 public:
00078 GraspitCollision(){}
00079 virtual ~GraspitCollision(){}
00080
00081
00082 virtual bool addBody(Body *body, bool ExpectEmpty = false);
00083 virtual void removeBody(Body *body);
00084 virtual void cloneBody(Body*, const Body*);
00085 virtual void setBodyTransform(Body *body, const transf &t);
00086
00087
00088 virtual void activateBody(const Body*, bool);
00089 virtual void activatePair(const Body*, const Body*, bool);
00090 virtual bool isActive(const Body*, const Body*);
00091
00092
00093 virtual int allCollisions(DetectionType type, CollisionReport *report,
00094 const std::vector<Body*> *interestList);
00095
00096
00097 virtual int allContacts(CollisionReport *report, double threshold,
00098 const std::vector<Body*> *interestList);
00099 virtual int contact(ContactReport *report, double threshold,
00100 const Body *body1, const Body *body2);
00101
00102
00103 virtual double pointToBodyDistance(const Body *body1, position point,
00104 position &closestPoint, vec3 &closestNormal);
00105 virtual double bodyToBodyDistance(const Body *body1, const Body *body2,
00106 position &p1, position &p2);
00107
00108
00109 virtual void bodyRegion(const Body *body, position point, vec3 normal,
00110 double radius, Neighborhood *neighborhood);
00111
00112
00113 virtual void getBoundingVolumes(const Body*, int, std::vector<BoundingBox>*);
00114
00115
00116 virtual void newThread(){}
00117 virtual int getThread(){return 0;}
00118 };
00119
00120 Body*
00121 GraspitCollision::getBody(const CollisionModel* model)
00122 {
00123 std::map<const CollisionModel*, Body*>::const_iterator it = mBodyMap.find(model);
00124 if (it==mBodyMap.end()) return NULL;
00125 return (*it).second;
00126 }
00127
00128 CollisionModel*
00129 GraspitCollision::getModel(const Body* body)
00130 {
00131 std::map<const Body*, CollisionModel*>::const_iterator it = mModelMap.find(body);
00132 if (it==mModelMap.end()) return NULL;
00133 return (*it).second;
00134 }
00135
00136 #endif