ColdetModelPair.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * National Institute of Advanced Industrial Science and Technology (AIST)
00008  */
00014 #ifndef HRPCOLLISION_COLDET_MODEL_PAIR_H_INCLUDED
00015 #define HRPCOLLISION_COLDET_MODEL_PAIR_H_INCLUDED
00016 
00017 #define LOCAL_EPSILON 0.0001f
00018 
00019 #include "config.h"
00020 #include "CollisionData.h"
00021 #include "ColdetModel.h"
00022 #include "CollisionPairInserterBase.h"
00023 #include <vector>
00024 #include <hrpUtil/Referenced.h>
00025 #include <hrpUtil/config.h>
00026 
00027 namespace hrp {
00028 
00029     class HRP_COLLISION_EXPORT ColdetModelPair : public Referenced
00030     {
00031       public:
00032         ColdetModelPair();
00033         ColdetModelPair(ColdetModelPtr model0, ColdetModelPtr model1,
00034                         double tolerance=0);
00035         ColdetModelPair(const ColdetModelPair& org);
00036         virtual ~ColdetModelPair();
00037 
00038         void set(ColdetModelPtr model0, ColdetModelPtr model1);
00039 
00040         ColdetModel* model(int index) { return models[index].get(); }
00041         IceMaths::Matrix4x4* transform(int index) { return models[index]->transform; }
00042 
00043         std::vector<collision_data>& detectCollisions() {
00044             return detectCollisionsSub(true);
00045         }
00046 
00047         std::vector<collision_data>& collisions() {
00048             return collisionPairInserter->cdContact;
00049         }
00050 
00051         void clearCollisions(){
00052             collisionPairInserter->cdContact.clear();
00053         }
00054 
00055         bool checkCollision() {
00056             return !detectCollisionsSub(false).empty();
00057         }
00058 
00059         double computeDistance(double *point0, double *point1);
00060 
00065         double computeDistance(int& out_triangle0, double* out_point0, int& out_triangle1, double* out_point1);
00066 
00067         bool detectIntersection();
00068 
00069         double tolerance() const { return tolerance_; }
00070 
00071         void setCollisionPairInserter(CollisionPairInserterBase *inserter); 
00072 
00073         int calculateCentroidIntersection(float &cx, float &cy, float &A, float radius, std::vector<float> vx, std::vector<float> vy);
00074                 
00075         int makeCCW(std::vector<float> &vx, std::vector<float> &vy);
00076                 
00077         float calculatePolygonArea(const std::vector<float> &vx, const std::vector<float> &vy);
00078         void calculateSectorCentroid(float &cx, float &cy, float radius, float th1, float th2);
00079 
00080         inline bool isInsideCircle(float r, float x, float y) {
00081                 return sqrt(pow(x, 2) + pow(y, 2)) <= r;
00082         }
00083         bool isInsideTriangle(float x, float y, const std::vector<float> &vx, const std::vector<float> &vy);
00084 
00085         int calculateIntersection(std::vector<float> &x, std::vector<float> &y, float radius, float x1, float y1, float x2, float y2);
00086 
00087       private:
00088         std::vector<collision_data>& detectCollisionsSub(bool detectAllContacts);
00089         bool detectMeshMeshCollisions(bool detectAllContacts);
00090                 bool detectSphereSphereCollisions(bool detectAllContacts);
00091                 bool detectSphereMeshCollisions(bool detectAllContacts);
00092         bool detectPlaneCylinderCollisions(bool detectAllContacts);
00093         bool detectPlaneMeshCollisions(bool detectAllContacts);
00094 
00095         ColdetModelPtr models[2];
00096         double tolerance_;
00097 
00098         CollisionPairInserterBase *collisionPairInserter;
00099 
00100         int boxTestsCount;
00101         int triTestsCount;
00102         
00103         enum pointType {vertex, inter};
00104         enum figType {tri, sector};
00105 
00106         struct pointStruct {
00107                 float x, y, angle;
00108                 pointType type;
00109                 int code;
00110         };
00111         
00112         struct figStruct {
00113                 figType type;
00114                 int p1, p2;
00115                 float area;
00116                 float cx, cy;
00117         };
00118     };
00119 
00120     typedef boost::intrusive_ptr<ColdetModelPair> ColdetModelPairPtr;
00121 }
00122 
00123 
00124 #endif


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:53