Choreonoid  1.8
ColdetModelPair.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_AIST_COLLIDION_DETECTOR_COLDET_MODEL_PAIR_H
6 #define CNOID_AIST_COLLIDION_DETECTOR_COLDET_MODEL_PAIR_H
7 
8 #include "CollisionData.h"
9 #include "ColdetModel.h"
10 #include "CollisionPairInserter.h"
11 #include "exportdecl.h"
12 
13 namespace cnoid {
14 
15 class CNOID_EXPORT ColdetModelPair : public Referenced
16 {
17 public:
19  ColdetModelPair(ColdetModel* model0, ColdetModel* model1, double tolerance = 0.0);
20  ColdetModelPair(const ColdetModelPair& org);
21 
22  virtual ~ColdetModelPair();
23 
24  void set(ColdetModel* model0, ColdetModel* model1);
25 
26  ColdetModel* model(int index) { return models[index]; }
27 
28  std::vector<collision_data>& detectCollisions() {
29  return detectCollisionsSub(true);
30  }
31 
32  std::vector<collision_data>& collisions() {
33  return collisionPairInserter->cdContact;
34  }
35 
37  collisionPairInserter->cdContact.clear();
38  }
39 
40  bool checkCollision() {
41  return !detectCollisionsSub(false).empty();
42  }
43 
44  static double computeDistance(ColdetModel* model0, ColdetModel* model1, double* point0, double* point1);
45  double computeDistance(double* point0, double* point1);
46 
51  double computeDistance(int& out_triangle0, double* out_point0, int& out_triangle1, double* out_point1);
52 
53  bool detectIntersection();
54 
55  double tolerance() const { return tolerance_; }
56 
57  void setTolerance(double tolerance){
58  tolerance_ = tolerance;
59  }
60 
61  void setCollisionPairInserter(Opcode::CollisionPairInserter *inserter);
62 
63  int calculateCentroidIntersection(float &cx, float &cy, float &A, float radius, std::vector<float> vx, std::vector<float> vy);
64 
65  int makeCCW(std::vector<float> &vx, std::vector<float> &vy);
66 
67  float calculatePolygonArea(const std::vector<float> &vx, const std::vector<float> &vy);
68  void calculateSectorCentroid(float &cx, float &cy, float radius, float th1, float th2);
69 
70  inline bool isInsideCircle(float r, float x, float y) {
71  return sqrt(pow(x, 2) + pow(y, 2)) <= r;
72  }
73  bool isInsideTriangle(float x, float y, const std::vector<float> &vx, const std::vector<float> &vy);
74 
75  int calculateIntersection(std::vector<float> &x, std::vector<float> &y, float radius, float x1, float y1, float x2, float y2);
76 
77 private:
78 
79  std::vector<collision_data>& detectCollisionsSub(bool detectAllContacts);
80  bool detectMeshMeshCollisions(bool detectAllContacts);
81  bool detectSphereSphereCollisions(bool detectAllContacts);
82  bool detectSphereMeshCollisions(bool detectAllContacts);
83  bool detectPlaneCylinderCollisions(bool detectAllContacts);
84  bool detectPlaneMeshCollisions(bool detectAllContacts);
85 
86  ColdetModelPtr models[2];
87  double tolerance_;
88  Opcode::CollisionPairInserter* collisionPairInserter;
89  int boxTestsCount;
90  int triTestsCount;
91 };
92 
94 
95 }
96 
97 #endif
CollisionData.h
cnoid::ColdetModelPair::clearCollisions
void clearCollisions()
Definition: ColdetModelPair.h:36
cnoid::ColdetModel
Definition: ColdetModel.h:22
cnoid::ColdetModelPair::collisions
std::vector< collision_data > & collisions()
Definition: ColdetModelPair.h:32
cnoid::ColdetModelPair::isInsideCircle
bool isInsideCircle(float r, float x, float y)
Definition: ColdetModelPair.h:70
cnoid::ColdetModelPair::model
ColdetModel * model(int index)
Definition: ColdetModelPair.h:26
cnoid::ColdetModelPair::tolerance
double tolerance() const
Definition: ColdetModelPair.h:55
cnoid::ref_ptr< ColdetModel >
cnoid::ColdetModelPair
Definition: ColdetModelPair.h:15
cnoid
Definition: AbstractSceneLoader.h:11
ColdetModel.h
cnoid::ColdetModelPair::checkCollision
bool checkCollision()
Definition: ColdetModelPair.h:40
CollisionPairInserter.h
cnoid::Referenced
Definition: Referenced.h:54
cnoid::ColdetModelPair::setTolerance
void setTolerance(double tolerance)
Definition: ColdetModelPair.h:57
cnoid::ColdetModelPair::detectCollisions
std::vector< collision_data > & detectCollisions()
Definition: ColdetModelPair.h:28
cnoid::ColdetModelPairPtr
ref_ptr< ColdetModelPair > ColdetModelPairPtr
Definition: ColdetModelPair.h:93