Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

ShapeSpacePlannerBase.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef _SHAPE_SPACE_PLANNER_BASE_H_
00003 #define _SHAPE_SPACE_PLANNER_BASE_H_
00004 
00005 #include "Motion/KinematicJoint.h"
00006 #include "Motion/Kinematics.h"
00007 #include "Planners/PlannerObstacles.h"
00008 #include "DualCoding/DualCoding.h"
00009 #include "DualCoding/ShapeCylinder.h"
00010 #include "GenericRRT.h"
00011 
00012 //================ ShapeSpaceCollisionCheckerBase ================
00013 
00014 //! Base class for doing collision checking in world shape space
00015 template <size_t N>
00016 class ShapeSpaceCollisionCheckerBase {
00017 protected:
00018   //! world bounds, must be closed to be used
00019   DualCoding::Shape<DualCoding::PolygonData> worldBounds;
00020   
00021   float const inflation;  //!< Amount in mm to add to obstacle bounding shape
00022   
00023   //! world or local map obstacles
00024   std::vector<PlannerObstacle<N>*> obstacles;
00025   
00026   //! world map obstacles for display
00027   std::vector<PlannerObstacle<N>*> displayWorldObstacles;
00028 
00029   //! robot obstacles for display
00030   std::vector<PlannerObstacle<N>*> displayRobotObstacles;
00031   
00032   //! Model the robot as a set of PlannerObstacles, based on its kinematic structure.
00033   void addRobotObstacles(const KinematicJoint &j);
00034 
00035   void createBodyObstacle(const LinkComponent& j, const fmat::Transform& robotT);
00036   
00037   void addDisplayRobotObstacles(const KinematicJoint &j);
00038   
00039 public:
00040   ShapeSpaceCollisionCheckerBase(ShapeSpace &shs,
00041                                  const Shape<PolygonData> &_worldBounds,
00042                                  float _inflation);
00043   
00044   virtual ~ShapeSpaceCollisionCheckerBase();
00045   
00046   const Shape<PolygonData> getWorldBounds() const { return worldBounds; }
00047   
00048   BoundingBox<N> getObstacleBoundingBox() const;
00049   BoundingBox<N> getBodyBoundingBox() const;
00050   
00051   //! Debugging tool to make obstacles visible
00052   void addObstaclesToShapeSpace(DualCoding::ShapeSpace & shs, const fmat::Transform &t=fmat::Transform());
00053 };
00054 
00055 template <size_t N>
00056 BoundingBox<N> ShapeSpaceCollisionCheckerBase<N>::getObstacleBoundingBox() const {
00057   if (obstacles.empty()) return BoundingBox<N>();
00058   
00059   BoundingBox<N> bounds = obstacles.front()->getBoundingBox();
00060   
00061   for (unsigned int i = 0; i < obstacles.size(); i++) {
00062     if (!obstacles[i]->isBodyObstacle())
00063       bounds.expand(obstacles[i]->getBoundingBox());
00064   }
00065   return bounds;
00066 }
00067 
00068 template <size_t N>
00069 BoundingBox<N> ShapeSpaceCollisionCheckerBase<N>::getBodyBoundingBox() const {
00070   if (obstacles.empty()) return BoundingBox<N>();
00071   
00072   BoundingBox<N> bounds = obstacles.front()->getBoundingBox();
00073   
00074   for (unsigned int i = 0; i < obstacles.size(); i++) {
00075     if (obstacles[i]->isBodyObstacle())
00076       bounds.expand(obstacles[i]->getBoundingBox());
00077   }
00078   return bounds;
00079 }
00080 
00081 template <size_t N>
00082 ShapeSpaceCollisionCheckerBase<N>::ShapeSpaceCollisionCheckerBase(ShapeSpace &shs,
00083                                                                   const Shape<PolygonData> &_worldBounds,
00084                                                                   float _inflation) :
00085   worldBounds(_worldBounds), inflation(_inflation), obstacles(),
00086   displayWorldObstacles(), displayRobotObstacles() {
00087   SHAPEROOTVEC_ITERATE(shs, s) {
00088     if ( s->getId() != DualCoding::VRmixin::theAgent->getId() && s->isObstacle() )
00089       PlannerObstacle<N>::convertShapeToPlannerObstacle(s, inflation, obstacles);
00090   } END_ITERATE;
00091   displayWorldObstacles = obstacles;
00092   
00093   addRobotObstacles(*(kine->getKinematicJoint(BaseFrameOffset)));
00094   
00095   DualCoding::Point location = VRmixin::theAgent->getCentroid();
00096 }
00097 
00098 template <size_t N>
00099 ShapeSpaceCollisionCheckerBase<N>::~ShapeSpaceCollisionCheckerBase() {
00100   for (unsigned int i = 0; i < obstacles.size(); i++)
00101     delete obstacles[i];
00102   // displayWorldObstacles[] points to a subset of obstacles[] so
00103   // we've already deleted its elements
00104   for (unsigned int i = 0; i < displayRobotObstacles.size(); i++)
00105     delete displayRobotObstacles[i];
00106 }
00107 
00108 template <>
00109 void ShapeSpaceCollisionCheckerBase<2>::addRobotObstacles(const KinematicJoint& j);
00110 
00111 template <>
00112 void ShapeSpaceCollisionCheckerBase<3>::addRobotObstacles(const KinematicJoint& j);
00113 
00114 template <>
00115 void ShapeSpaceCollisionCheckerBase<3>::createBodyObstacle(const LinkComponent& j, const fmat::Transform& robotT);
00116 
00117 template <>
00118 void ShapeSpaceCollisionCheckerBase<2>::addDisplayRobotObstacles(const KinematicJoint& j);
00119 
00120 template <>
00121 void ShapeSpaceCollisionCheckerBase<3>::addDisplayRobotObstacles(const KinematicJoint& j);
00122 
00123 template <>
00124 void ShapeSpaceCollisionCheckerBase<2>::addObstaclesToShapeSpace(ShapeSpace &shs, const fmat::Transform &t);
00125 
00126 template <>
00127 void ShapeSpaceCollisionCheckerBase<3>::addObstaclesToShapeSpace(ShapeSpace &shs, const fmat::Transform &t);
00128 
00129 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:51 2016 by Doxygen 1.6.3