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_STATE_SAMPLER_
00038 #define OMPL_BASE_STATE_SAMPLER_
00039
00040 #include "ompl/base/State.h"
00041 #include "ompl/util/RandomNumbers.h"
00042 #include "ompl/util/ClassForward.h"
00043 #include <vector>
00044 #include <string>
00045 #include <boost/function.hpp>
00046 #include <boost/noncopyable.hpp>
00047
00048 namespace ompl
00049 {
00050 namespace base
00051 {
00052
00054 ClassForward(StateSpace);
00056
00058
00059 ClassForward(StateSampler);
00061
00066 class StateSampler : private boost::noncopyable
00067 {
00068 public:
00069
00071 StateSampler(const StateSpace *space) : space_(space)
00072 {
00073 }
00074
00075 virtual ~StateSampler(void)
00076 {
00077 }
00078
00080 virtual void sampleUniform(State *state) = 0;
00081
00083 virtual void sampleUniformNear(State *state, const State *near, const double distance) = 0;
00084
00086 virtual void sampleGaussian(State *state, const State *mean, const double stdDev) = 0;
00087
00088 protected:
00089
00091 const StateSpace *space_;
00092
00094 RNG rng_;
00095 };
00096
00098 class CompoundStateSampler : public StateSampler
00099 {
00100 public:
00101
00103 CompoundStateSampler(const StateSpace* space) : StateSampler(space), samplerCount_(0)
00104 {
00105 }
00106
00108 virtual ~CompoundStateSampler(void)
00109 {
00110 }
00111
00118 virtual void addSampler(const StateSamplerPtr &sampler, double weightImportance);
00119
00120 virtual void sampleUniform(State *state);
00121
00122 virtual void sampleUniformNear(State *state, const State *near, const double distance);
00123
00124 virtual void sampleGaussian(State *state, const State *mean, const double stdDev);
00125
00126 protected:
00127
00129 std::vector<StateSamplerPtr> samplers_;
00130
00132 std::vector<double> weightImportance_;
00133
00134 private:
00135
00137 unsigned int samplerCount_;
00138
00139 };
00140
00142 class SubspaceStateSampler : public StateSampler
00143 {
00144 public:
00145
00147 SubspaceStateSampler(const StateSpace *space, const StateSpace *subspace, double weight);
00148 virtual ~SubspaceStateSampler(void);
00149
00150 virtual void sampleUniform(State *state);
00151
00152 virtual void sampleUniformNear(State *state, const State *near, const double distance);
00153
00154 virtual void sampleGaussian(State *state, const State *mean, const double stdDev);
00155
00156 protected:
00157
00159 const StateSpace *subspace_;
00160
00162 StateSamplerPtr subspaceSampler_;
00163
00165 double weight_;
00166
00168 std::vector<std::string> subspaces_;
00169
00170 private:
00171
00173 State *work_;
00174
00176 State *work2_;
00177 };
00178
00180 typedef boost::function<StateSamplerPtr(const StateSpace*)> StateSamplerAllocator;
00181 }
00182 }
00183
00184
00185 #endif