All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
src/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         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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines