libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
CollisionSpace.hpp
1 /*
2  * CollisionSpace.h
3  * BioMove3D
4  *
5  * Created by Jim Mainprice on 07/06/10.
6  * Copyright 2010 LAAS/CNRS. All rights reserved.
7  *
8  */
9 
10 #ifndef GRID_COLLISION_CHECKER_H_
11 #define GRID_COLLISION_CHECKER_H_
12 
13 #include "API/Grids/gridsAPI.hpp"
14 //#include "API/ConfigSpace/localpath.hpp"
15 
16 #include "planner/Greedy/BodySurfaceSampler.hpp"
17 #include "planner/Greedy/CollisionPoint.hpp"
18 
19 //#include <vector>
20 
21 #ifndef _P3D_H
22 typedef struct obj;
23 #endif
24 
25 class CollisionSpaceCell;
26 
28 {
29 public:
30  //constructors and destructors
31  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
32 
33  CollisionSpace(Robot* rob);
34  virtual ~CollisionSpace();
35 
36  // returns the robot associated with the collisionspace
37  Robot* getRobot() { return m_Robot; }
38 
39  // setters and getters
40  inline int getNbCellsOverX(void){return _nbCellsX;}
41  inline int getNbCellsOverY(void){return _nbCellsY;}
42  inline int getNbCellsOverZ(void){return _nbCellsZ;}
43 
44  // the sampler on body and obstacles with all points
45  BodySurfaceSampler* getBodySampler() { return m_sampler; }
46 
47  // functions
48  void init(void);
49 
50  // ---------------------------------------------------------------
51  // point cloud collision checker
52  // ---------------------------------------------------------------
53  std::vector<CollisionSpaceCell*> getCellListForObject(obj* obj, const Eigen::Affine3d& Trans);
54  std::vector<CollisionSpaceCell*> getOccupiedCells() { return m_OccupationCells; }
55  void resetOccupationCells();
56  void updateRobotOccupationCells(Robot* rob);
57 
58  //std::vector<CollisionSpaceCell*> computeOccupiedCells(LocalPath& path);
59  bool areCellsValid(const std::vector<CollisionSpaceCell*>& cells);
60 
61  void unvalidObjectCells(obj* obj);
62  bool collisionCheck();
63 
64  // ---------------------------------------------------------------
65  // Distance field
66  // ---------------------------------------------------------------
67  void addRobotBody(Joint* jnt);
68  void addRobot(Robot* rob);
69  void addAllPointsToField();
70  double addPointsToField(const std::vector<Eigen::Vector3d>& points);
71 
72  void initNeighborhoods();
73  int getDirectionNumber(int dx, int dy, int dz) const;
74  double getDistanceGradient(const Eigen::Vector3d& point,Eigen::Vector3d& gradient) const;
75  double getDistance(CollisionSpaceCell* cell) const;
76  bool getCollisionPointPotentialGradient(const CollisionPoint& collision_point,
77  const Eigen::Vector3d& collision_point_pos,
78  double& distance,
79  double& potential,
80  Eigen::Vector3d& gradient) const;
81 
82  bool isRobotColliding(double& distance) const;
83 
84  // ---------------------------------------------------------------
85  // OpenGl display
86  // ---------------------------------------------------------------
87  void drawSquaredDist();
88  void drawGradient();
89  void drawStaticVoxels();
90  void drawCollisionPoints();
91  void draw();
92 
93 protected:
94  API::ThreeDCell* createNewCell(unsigned int index,
95  unsigned int x,unsigned int y,unsigned int z );
96 
97 private:
98 
99  double getDistanceFromCell(int x, int y, int z) const;
100 
101  //The position of the origin of the grid regarding th eorigin of the world
102  int m_nbMaxCells; //the number of cell along the longest axis of the environment
103 
104  Robot* m_Robot;
105 
106  std::vector<CollisionSpaceCell*> m_OccupationCells;
107 
108  double m_size;
109  double m_invTwiceResolution;
110 
111  BodySurfaceSampler* m_sampler;
112 
113  double m_MaxClearance;
114 
115  //double a__,b__,c__; //,e__,f__,g__;
116 
117  // The variables for distance field
118  // Implementation
119  std::vector<double> m_SqrtTable;
120  std::vector<std::vector<std::vector<std::vector<int> > > > m_Neighborhoods;
121  std::vector<std::vector<int> > m_DirectionNumberToDirection;
122 };
123 
124 extern CollisionSpace* global_collisionSpace;
125 
126 #endif
void drawStaticVoxels()
Draws a sphere in all voxels the color of the sphere represent the distance to the nearest obstacle...
Definition: CollisionSpace.cpp:670
Definition: CollisionPoint.hpp:48
void draw()
Draw a openGl view of the grid.
Definition: CollisionSpace.cpp:787
bool getCollisionPointPotentialGradient(const CollisionPoint &collision_point, const Eigen::Vector3d &collision_point_pos, double &distance, double &potential, Eigen::Vector3d &gradient) const
The distance potential and the gradient is computed for a collision point First the distance d of the...
Definition: CollisionSpace.cpp:559
void drawGradient()
Definition: CollisionSpace.cpp:679
Definition: ThreeDGrid.hpp:24
This class holds a the robot represented by a kinematic chain.
Definition: robot.hpp:42
double getDistanceGradient(const Eigen::Vector3d &point, Eigen::Vector3d &gradient) const
Computes the finiate differenting gradient.
Definition: CollisionSpace.cpp:521
API::ThreeDCell * createNewCell(unsigned int index, unsigned int x, unsigned int y, unsigned int z)
Virtual function that creates a new Cell.
Definition: CollisionSpace.cpp:88
This class holds a Joint and is associated with a Body (Link) It's the basic element of a kinematic c...
Definition: joint.hpp:27
Definition: CollisionSpace.hpp:27
Definition: ThreeDCell.hpp:25
Definition: CollisionSpaceCell.hpp:16
Definition: BodySurfaceSampler.hpp:27
bool isRobotColliding(double &distance) const
Goes through all points and computes whether the robot is colliding Computes the transform of all poi...
Definition: CollisionSpace.cpp:606