StateSampler.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2010, Rice University
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Rice University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #ifndef OMPL_BASE_STATE_SAMPLER_
38 #define OMPL_BASE_STATE_SAMPLER_
39 
40 #include "ompl/base/State.h"
41 #include "ompl/util/RandomNumbers.h"
42 #include "ompl/util/ClassForward.h"
43 #include <vector>
44 #include <string>
45 #include <boost/function.hpp>
46 #include <boost/noncopyable.hpp>
47 
48 namespace ompl
49 {
50  namespace base
51  {
52 
54  OMPL_CLASS_FORWARD(StateSpace);
56 
58 
59  OMPL_CLASS_FORWARD(StateSampler);
61 
66  class StateSampler : private boost::noncopyable
67  {
68  public:
69 
71  StateSampler(const StateSpace *space) : space_(space)
72  {
73  }
74 
75  virtual ~StateSampler()
76  {
77  }
78 
80  virtual void sampleUniform(State *state) = 0;
81 
83  virtual void sampleUniformNear(State *state, const State *near, const double distance) = 0;
84 
86  virtual void sampleGaussian(State *state, const State *mean, const double stdDev) = 0;
87 
88  protected:
89 
92 
95  };
96 
99  {
100  public:
101 
103  CompoundStateSampler(const StateSpace *space) : StateSampler(space), samplerCount_(0)
104  {
105  }
106 
109  {
110  }
111 
118  virtual void addSampler(const StateSamplerPtr &sampler, double weightImportance);
119 
120  virtual void sampleUniform(State *state);
121 
124  virtual void sampleUniformNear(State *state, const State *near, const double distance);
125 
128  virtual void sampleGaussian(State *state, const State *mean, const double stdDev);
129 
130  protected:
131 
133  std::vector<StateSamplerPtr> samplers_;
134 
136  std::vector<double> weightImportance_;
137 
138  private:
139 
141  unsigned int samplerCount_;
142 
143  };
144 
147  {
148  public:
149 
151  SubspaceStateSampler(const StateSpace *space, const StateSpace *subspace, double weight);
152  virtual ~SubspaceStateSampler();
153 
154  virtual void sampleUniform(State *state);
155 
156  virtual void sampleUniformNear(State *state, const State *near, const double distance);
157 
158  virtual void sampleGaussian(State *state, const State *mean, const double stdDev);
159 
160  protected:
161 
164 
167 
169  double weight_;
170 
172  std::vector<std::string> subspaces_;
173 
174  private:
175 
177  State *work_;
178 
180  State *work2_;
181  };
182 
184  typedef boost::function<StateSamplerPtr(const StateSpace*)> StateSamplerAllocator;
185  }
186 }
187 
188 
189 #endif
boost::function< StateSamplerPtr(const StateSpace *)> StateSamplerAllocator
Definition of a function that can allocate a state sampler.
Definition: StateSampler.h:184
virtual void sampleGaussian(State *state, const State *mean, const double stdDev)=0
Sample a state using a Gaussian distribution with given mean and standard deviation (stdDev) ...
const StateSpace * space_
The state space this sampler samples.
Definition: StateSampler.h:91
std::vector< std::string > subspaces_
The names of common subspaces between space_ and subspace_; these are the ones copied after sampling ...
Definition: StateSampler.h:172
virtual void sampleGaussian(State *state, const State *mean, const double stdDev)
Sample a state using a Gaussian distribution with given mean and standard deviation (stdDev) ...
virtual void sampleUniform(State *state)
Sample a state.
A boost shared pointer wrapper for ompl::base::StateSampler.
RNG rng_
An instance of a random number generator.
Definition: StateSampler.h:94
virtual void sampleUniform(State *state)=0
Sample a state.
std::vector< StateSamplerPtr > samplers_
The samplers that are composed.
Definition: StateSampler.h:133
StateSamplerPtr subspaceSampler_
The sampler for the subspace.
Definition: StateSampler.h:166
SubspaceStateSampler(const StateSpace *space, const StateSpace *subspace, double weight)
Construct a sampler for space but only sample components common to subspace. Use weight as a multipli...
virtual void addSampler(const StateSamplerPtr &sampler, double weightImportance)
Add a sampler as part of the new compound sampler. This sampler is used to sample part of the compoun...
CompoundStateSampler(const StateSpace *space)
Constructor.
Definition: StateSampler.h:103
Main namespace. Contains everything in this library.
Definition: Cost.h:42
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Definition: RandomNumbers.h:54
virtual void sampleUniformNear(State *state, const State *near, const double distance)
Sample a state near another, within specified distance.
virtual ~CompoundStateSampler()
Destructor. This frees the added samplers as well.
Definition: StateSampler.h:108
StateSampler(const StateSpace *space)
Constructor.
Definition: StateSampler.h:71
virtual void sampleGaussian(State *state, const State *mean, const double stdDev)
Call sampleGaussian for each of the subspace states with stdDev scaled by the corresponding subspace ...
const StateSpace * subspace_
The subspace to sample.
Definition: StateSampler.h:163
Representation of a space in which planning can be performed. Topology specific sampling, interpolation and distance are defined.
Definition: StateSpace.h:73
Definition of an abstract state.
Definition: State.h:50
virtual void sampleUniformNear(State *state, const State *near, const double distance)
Call sampleUniformNear for each of the subspace states with distance scaled by the corresponding subs...
double weight_
The weigth factor to multiply distance and stdDev when sampling in the vicinity of a state...
Definition: StateSampler.h:169
virtual void sampleUniform(State *state)
Sample a state.
virtual void sampleUniformNear(State *state, const State *near, const double distance)=0
Sample a state near another, within specified distance.
Definition of a compound state sampler. This is useful to construct samplers for compound states...
Definition: StateSampler.h:98
Abstract definition of a state space sampler.
Definition: StateSampler.h:66
Construct a sampler that samples only within a subspace of the space.
Definition: StateSampler.h:146
std::vector< double > weightImportance_
The weight of each sampler (used when sampling near a state)
Definition: StateSampler.h:136