ColdetModel.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  */
00013 #ifndef HRPCOLLISION_COLDET_MODEL_H_INCLUDED
00014 #define HRPCOLLISION_COLDET_MODEL_H_INCLUDED
00015 
00016 #include "config.h"
00017 #include <string>
00018 #include <hrpUtil/Eigen3d.h>
00019 #include <hrpUtil/Referenced.h>
00020 #include <vector>
00021 #include <map>
00022 
00023 
00024 namespace IceMaths {
00025     class Matrix4x4;
00026 }
00027 
00028 namespace hrp {
00029 
00030     class ColdetModelSharedDataSet;
00031     class Edge
00032     {
00033         int vertex[2];
00034     public :
00035         Edge(int vertexIndex1, int vertexIndex2){
00036             if(vertexIndex1 < vertexIndex2){
00037                 vertex[0] = vertexIndex1;
00038                 vertex[1] = vertexIndex2;
00039             } else {
00040                 vertex[0] = vertexIndex2;
00041                 vertex[1] = vertexIndex1;
00042             }
00043         }
00044         bool operator<(const Edge& rhs) const {
00045             if(vertex[0] < rhs.vertex[0]){
00046                 return true;
00047             } else if(vertex[0] == rhs.vertex[0]){
00048                 return (vertex[1] < rhs.vertex[1]);
00049             } else {
00050                 return false;
00051             }
00052         }
00053     };
00054 
00055     struct trianglePair {
00056         int t[2];
00057     };
00058 
00059     typedef std::map< Edge, trianglePair > EdgeToTriangleMap;
00060 
00061     class HRP_COLLISION_EXPORT ColdetModel : public Referenced
00062     {
00063       public:
00064         enum PrimitiveType { SP_MESH, SP_BOX, SP_CYLINDER, SP_CONE, SP_SPHERE, SP_PLANE };
00065 
00069         ColdetModel();
00070 
00076         ColdetModel(const ColdetModel& org);
00077 
00081         virtual ~ColdetModel();
00082 
00087         void setName(const std::string& name) { name_ = name; }
00088 
00093         const std::string& name() const { return name_; }
00094 
00099         void setNumVertices(int n);
00100 
00105         int getNumVertices() const;
00106 
00111         void setNumTriangles(int n);
00112 
00113         int getNumTriangles() const;
00114 
00122         void setVertex(int index, float x, float y, float z);
00123 
00127         void addVertex(float x, float y, float z);
00128 
00136         void getVertex(int index, float& out_x, float& out_y, float& out_z) const;
00137 
00145         void setTriangle(int index, int v1, int v2, int v3);
00146 
00150         void addTriangle(int v1, int v2, int v3);
00151 
00152         void getTriangle(int index, int& out_v1, int& out_v2, int& out_v3) const;
00153 
00159         void build();
00160 
00165         bool isValid() const { return isValid_; }
00166 
00172         void setPosition(const Matrix33& R, const Vector3& p);
00173 
00179         void setPosition(const double* R, const double* p);
00180 
00185         void setPrimitiveType(PrimitiveType ptype);
00186 
00191         PrimitiveType getPrimitiveType() const;
00192 
00197         void setNumPrimitiveParams(unsigned int nparam);
00198 
00205         bool setPrimitiveParam(unsigned int index, float value);
00206 
00213         bool getPrimitiveParam(unsigned int index, float &value) const;
00214 
00220         void setPrimitivePosition(const double* R, const double* p);
00221         
00228         double computeDistanceWithRay(const double *point, const double *dir);
00229 
00236         bool checkCollisionWithPointCloud(const std::vector<Vector3> &i_cloud,
00237                                           double i_radius);
00238 
00239         void getBoundingBoxData(const int depth, std::vector<Vector3>& out_boxes);
00240         
00241         int getAABBTreeDepth();
00242         int getAABBmaxNum();
00243         int numofBBtoDepth(int minNumofBB);
00244 
00245         ColdetModelSharedDataSet *getDataSet() { return dataSet; }
00246       private:
00250         void initialize();
00251         void setNeighborTriangle(int triangle, int vertex0, int vertex1, int vertex2);
00252         void initNeighbor(int n);
00253 
00254         
00255         ColdetModelSharedDataSet* dataSet;
00256         IceMaths::Matrix4x4* transform;
00257         IceMaths::Matrix4x4* pTransform; 
00258         std::string name_;
00259         bool isValid_;
00260         EdgeToTriangleMap triangleMap;
00261 
00262         bool setNeighborTriangleSub(int triangle, int vertex0, int vertex1);
00263         void setNeighbor(int triangle0, int triangle1);
00264 
00265         friend class ColdetModelPair;
00266     };
00267 
00268     typedef boost::intrusive_ptr<ColdetModel> ColdetModelPtr;
00269 }
00270 
00271 
00272 #endif


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:15