ompl/base/StateSampler.h
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2010, Rice University
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Rice University nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 /* Author: Ioan Sucan */
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         OMPL_CLASS_FORWARD(StateSpace);
00056 
00058 
00059         OMPL_CLASS_FORWARD(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()
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()
00109             {
00110             }
00111 
00118             virtual void addSampler(const StateSamplerPtr &sampler, double weightImportance);
00119 
00120             virtual void sampleUniform(State *state);
00121 
00124             virtual void sampleUniformNear(State *state, const State *near, const double distance);
00125 
00128             virtual void sampleGaussian(State *state, const State *mean, const double stdDev);
00129 
00130         protected:
00131 
00133             std::vector<StateSamplerPtr> samplers_;
00134 
00136             std::vector<double>          weightImportance_;
00137 
00138         private:
00139 
00141             unsigned int                 samplerCount_;
00142 
00143         };
00144 
00146         class SubspaceStateSampler : public StateSampler
00147         {
00148         public:
00149 
00151             SubspaceStateSampler(const StateSpace *space, const StateSpace *subspace, double weight);
00152             virtual ~SubspaceStateSampler();
00153 
00154             virtual void sampleUniform(State *state);
00155 
00156             virtual void sampleUniformNear(State *state, const State *near, const double distance);
00157 
00158             virtual void sampleGaussian(State *state, const State *mean, const double stdDev);
00159 
00160         protected:
00161 
00163             const StateSpace        *subspace_;
00164 
00166             StateSamplerPtr          subspaceSampler_;
00167 
00169             double                   weight_;
00170 
00172             std::vector<std::string> subspaces_;
00173 
00174         private:
00175 
00177             State                   *work_;
00178 
00180             State                   *work2_;
00181         };
00182 
00184         typedef boost::function<StateSamplerPtr(const StateSpace*)> StateSamplerAllocator;
00185     }
00186 }
00187 
00188 
00189 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines