All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
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  ClassForward(StateSpace);
56 
58 
59  ClassForward(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(void)
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 
108  virtual ~CompoundStateSampler(void)
109  {
110  }
111 
118  virtual void addSampler(const StateSamplerPtr &sampler, double weightImportance);
119 
120  virtual void sampleUniform(State *state);
121 
122  virtual void sampleUniformNear(State *state, const State *near, const double distance);
123 
124  virtual void sampleGaussian(State *state, const State *mean, const double stdDev);
125 
126  protected:
127 
129  std::vector<StateSamplerPtr> samplers_;
130 
132  std::vector<double> weightImportance_;
133 
134  private:
135 
137  unsigned int samplerCount_;
138 
139  };
140 
143  {
144  public:
145 
147  SubspaceStateSampler(const StateSpace *space, const StateSpace *subspace, double weight);
148  virtual ~SubspaceStateSampler(void);
149 
150  virtual void sampleUniform(State *state);
151 
152  virtual void sampleUniformNear(State *state, const State *near, const double distance);
153 
154  virtual void sampleGaussian(State *state, const State *mean, const double stdDev);
155 
156  protected:
157 
160 
163 
165  double weight_;
166 
168  std::vector<std::string> subspaces_;
169 
170  private:
171 
173  State *work_;
174 
176  State *work2_;
177  };
178 
180  typedef boost::function<StateSamplerPtr(const StateSpace*)> StateSamplerAllocator;
181  }
182 }
183 
184 
185 #endif