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 <functional>
46 
47 namespace ompl
48 {
49  namespace base
50  {
51 
53  OMPL_CLASS_FORWARD(StateSpace);
55 
57 
58  OMPL_CLASS_FORWARD(StateSampler);
60 
66  {
67  public:
68  // non-copyable
69  StateSampler(const StateSampler&) = delete;
70  StateSampler& operator=(const StateSampler&) = delete;
71 
73  StateSampler(const StateSpace *space) : space_(space)
74  {
75  }
76 
77  virtual ~StateSampler()
78  {
79  }
80 
82  virtual void sampleUniform(State *state) = 0;
83 
94  virtual void sampleUniformNear(State *state, const State *near, const double distance) = 0;
95 
102  virtual void sampleGaussian(State *state, const State *mean, const double stdDev) = 0;
103 
104  protected:
105 
108 
111  };
112 
115  {
116  public:
117 
119  CompoundStateSampler(const StateSpace *space) : StateSampler(space), samplerCount_(0)
120  {
121  }
122 
125  {
126  }
127 
134  virtual void addSampler(const StateSamplerPtr &sampler, double weightImportance);
135 
136  virtual void sampleUniform(State *state);
137 
140  virtual void sampleUniformNear(State *state, const State *near, const double distance);
141 
144  virtual void sampleGaussian(State *state, const State *mean, const double stdDev);
145 
146  protected:
147 
149  std::vector<StateSamplerPtr> samplers_;
150 
152  std::vector<double> weightImportance_;
153 
154  private:
155 
157  unsigned int samplerCount_;
158 
159  };
160 
163  {
164  public:
165 
167  SubspaceStateSampler(const StateSpace *space, const StateSpace *subspace, double weight);
168  virtual ~SubspaceStateSampler();
169 
170  virtual void sampleUniform(State *state);
171 
172  virtual void sampleUniformNear(State *state, const State *near, const double distance);
173 
174  virtual void sampleGaussian(State *state, const State *mean, const double stdDev);
175 
176  protected:
177 
180 
183 
185  double weight_;
186 
188  std::vector<std::string> subspaces_;
189 
190  private:
191 
193  State *work_;
194 
196  State *work2_;
197  };
198 
200  typedef std::function<StateSamplerPtr(const StateSpace*)> StateSamplerAllocator;
201  }
202 }
203 
204 
205 #endif
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:107
std::vector< std::string > subspaces_
The names of common subspaces between space_ and subspace_; these are the ones copied after sampling ...
Definition: StateSampler.h:188
A shared pointer wrapper for ompl::base::StateSampler.
RNG rng_
An instance of a random number generator.
Definition: StateSampler.h:110
virtual void sampleUniform(State *state)=0
Sample a state.
std::vector< StateSamplerPtr > samplers_
The samplers that are composed.
Definition: StateSampler.h:149
StateSamplerPtr subspaceSampler_
The sampler for the subspace.
Definition: StateSampler.h:182
std::function< StateSamplerPtr(const StateSpace *)> StateSamplerAllocator
Definition of a function that can allocate a state sampler.
Definition: StateSampler.h:200
CompoundStateSampler(const StateSpace *space)
Constructor.
Definition: StateSampler.h:119
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:58
virtual ~CompoundStateSampler()
Destructor. This frees the added samplers as well.
Definition: StateSampler.h:124
StateSampler(const StateSpace *space)
Constructor.
Definition: StateSampler.h:73
const StateSpace * subspace_
The subspace to sample.
Definition: StateSampler.h:179
Representation of a space in which planning can be performed. Topology specific sampling, interpolation and distance are defined.
Definition: StateSpace.h:72
Definition of an abstract state.
Definition: State.h:50
double weight_
The weigth factor to multiply distance and stdDev when sampling in the vicinity of a state...
Definition: StateSampler.h:185
virtual void sampleUniformNear(State *state, const State *near, const double distance)=0
Sample a state near another, within a neighborhood controlled by a distance parameter.
Definition of a compound state sampler. This is useful to construct samplers for compound states...
Definition: StateSampler.h:114
Abstract definition of a state space sampler.
Definition: StateSampler.h:65
Construct a sampler that samples only within a subspace of the space.
Definition: StateSampler.h:162
std::vector< double > weightImportance_
The weight of each sampler (used when sampling near a state)
Definition: StateSampler.h:152