00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef OMPL_BASE_SPACE_INFORMATION_
00038 #define OMPL_BASE_SPACE_INFORMATION_
00039
00040 #include "ompl/base/State.h"
00041 #include "ompl/base/StateValidityChecker.h"
00042 #include "ompl/base/MotionValidator.h"
00043 #include "ompl/base/StateSpace.h"
00044 #include "ompl/base/ValidStateSampler.h"
00045
00046 #include "ompl/util/ClassForward.h"
00047 #include "ompl/util/Console.h"
00048 #include "ompl/util/Exception.h"
00049
00050 #include <boost/noncopyable.hpp>
00051 #include <boost/function.hpp>
00052 #include <boost/bind.hpp>
00053
00054 #include <cstdlib>
00055 #include <vector>
00056 #include <iostream>
00057
00059 namespace ompl
00060 {
00061
00066 namespace base
00067 {
00068
00070 ClassForward(SpaceInformation);
00071
00078 typedef boost::function1<bool, const State*> StateValidityCheckerFn;
00079
00080
00084 class SpaceInformation : private boost::noncopyable
00085 {
00086 public:
00087
00089 SpaceInformation(const StateSpacePtr &space);
00090
00091 virtual ~SpaceInformation(void)
00092 {
00093 }
00094
00096 bool isValid(const State *state) const
00097 {
00098 return stateValidityChecker_->isValid(state);
00099 }
00100
00102 const StateSpacePtr& getStateSpace(void) const
00103 {
00104 return stateSpace_;
00105 }
00106
00111 bool equalStates(const State *state1, const State *state2) const
00112 {
00113 return stateSpace_->equalStates(state1, state2);
00114 }
00115
00117 bool satisfiesBounds(const State *state) const
00118 {
00119 return stateSpace_->satisfiesBounds(state);
00120 }
00121
00123 double distance(const State *state1, const State *state2) const
00124 {
00125 return stateSpace_->distance(state1, state2);
00126 }
00127
00129 void enforceBounds(State *state) const
00130 {
00131 stateSpace_->enforceBounds(state);
00132 }
00133
00135 void printState(const State *state, std::ostream &out = std::cout) const
00136 {
00137 stateSpace_->printState(state, out);
00138 }
00139
00148 void setStateValidityChecker(const StateValidityCheckerPtr &svc)
00149 {
00150 stateValidityChecker_ = svc;
00151 setup_ = false;
00152 }
00153
00159 void setStateValidityChecker(const StateValidityCheckerFn &svc);
00160
00162 const StateValidityCheckerPtr& getStateValidityChecker(void) const
00163 {
00164 return stateValidityChecker_;
00165 }
00166
00170 void setMotionValidator(const MotionValidatorPtr &mv)
00171 {
00172 motionValidator_ = mv;
00173 setup_ = false;
00174 }
00175
00177 const MotionValidatorPtr& getMotionValidator(void) const
00178 {
00179 return motionValidator_;
00180 }
00181
00188 void setStateValidityCheckingResolution(double resolution)
00189 {
00190 stateSpace_->setLongestValidSegmentFraction(resolution);
00191 setup_ = false;
00192 }
00193
00198 double getStateValidityCheckingResolution(void) const
00199 {
00200 return stateSpace_->getLongestValidSegmentFraction();
00201 }
00202
00203
00207 unsigned int getStateDimension(void) const
00208 {
00209 return stateSpace_->getDimension();
00210 }
00211
00216 State* allocState(void) const
00217 {
00218 return stateSpace_->allocState();
00219 }
00220
00222 void freeState(State *state) const
00223 {
00224 stateSpace_->freeState(state);
00225 }
00226
00228 void copyState(State *destination, const State *source) const
00229 {
00230 stateSpace_->copyState(destination, source);
00231 }
00232
00234 State* cloneState(const State *source) const
00235 {
00236 State *copy = stateSpace_->allocState();
00237 stateSpace_->copyState(copy, source);
00238 return copy;
00239 }
00240
00248 StateSamplerPtr allocStateSampler(void) const
00249 {
00250 return stateSpace_->allocStateSampler();
00251 }
00252
00256 ValidStateSamplerPtr allocValidStateSampler(void) const;
00257
00258
00261 void setValidStateSamplerAllocator(const ValidStateSamplerAllocator &vssa)
00262 {
00263 vssa_ = vssa;
00264 setup_ = false;
00265 }
00266
00275 double getMaximumExtent(void) const
00276 {
00277 return stateSpace_->getMaximumExtent();
00278 }
00279
00287 bool searchValidNearby(State *state, const State *near, double distance, unsigned int attempts) const;
00288
00296 bool searchValidNearby(const ValidStateSamplerPtr &sampler, State *state, const State *near, double distance) const;
00297
00304 unsigned int randomBounceMotion(const StateSamplerPtr &sss, const State *start, unsigned int steps, std::vector<State*> &states, bool alloc) const;
00305
00312 bool checkMotion(const State *s1, const State *s2, std::pair<State*, double> &lastValid) const
00313 {
00314 return motionValidator_->checkMotion(s1, s2, lastValid);
00315 }
00316
00317
00319 bool checkMotion(const State *s1, const State *s2) const
00320 {
00321 return motionValidator_->checkMotion(s1, s2);
00322 }
00323
00329 bool checkMotion(const std::vector<State*> &states, unsigned int count, unsigned int &firstInvalidStateIndex) const;
00330
00332 bool checkMotion(const std::vector<State*> &states, unsigned int count) const;
00333
00342 unsigned int getMotionStates(const State *s1, const State *s2, std::vector<State*> &states, unsigned int count, bool endpoints, bool alloc) const;
00343
00347 virtual void printSettings(std::ostream &out = std::cout) const;
00348
00353 virtual void setup(void);
00354
00356 bool isSetup(void) const;
00357
00358 protected:
00359
00361 StateSpacePtr stateSpace_;
00362
00364 StateValidityCheckerPtr stateValidityChecker_;
00365
00367 MotionValidatorPtr motionValidator_;
00368
00370 bool setup_;
00371
00373 ValidStateSamplerAllocator vssa_;
00374
00376 msg::Interface msg_;
00377 };
00378
00379 }
00380
00381 }
00382
00383 #endif