ompl/base/goals/GoalLazySamples.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_GOALS_GOAL_LAZY_SAMPLES_ 00038 #define OMPL_BASE_GOALS_GOAL_LAZY_SAMPLES_ 00039 00040 #include "ompl/base/goals/GoalStates.h" 00041 #include <boost/thread/thread.hpp> 00042 #include <boost/function.hpp> 00043 #include <limits> 00044 00045 namespace ompl 00046 { 00047 00048 namespace base 00049 { 00050 00051 class GoalLazySamples; 00052 00056 typedef boost::function<bool(const GoalLazySamples*, State*)> GoalSamplingFn; 00057 00072 class GoalLazySamples : public GoalStates 00073 { 00074 public: 00075 00079 typedef boost::function<void(const base::State*)> NewStateCallbackFn; 00080 00104 GoalLazySamples(const SpaceInformationPtr &si, const GoalSamplingFn &samplerFunc, 00105 bool autoStart = true, double minDist = std::numeric_limits<double>::epsilon()); 00106 00107 virtual ~GoalLazySamples(); 00108 00109 virtual void sampleGoal(State *st) const; 00110 00111 virtual double distanceGoal(const State *st) const; 00112 00113 virtual void addState(const State *st); 00114 00116 void startSampling(); 00117 00119 void stopSampling(); 00120 00122 bool isSampling() const; 00123 00126 void setMinNewSampleDistance(double dist) 00127 { 00128 minDist_ = dist; 00129 } 00130 00133 double getMinNewSampleDistance() const 00134 { 00135 return minDist_; 00136 } 00137 00139 unsigned int samplingAttemptsCount() const 00140 { 00141 return samplingAttempts_; 00142 } 00143 00146 void setNewStateCallback(const NewStateCallbackFn &callback); 00147 00149 bool addStateIfDifferent(const State *st, double minDistance); 00150 00152 virtual bool couldSample() const; 00153 00154 virtual bool hasStates() const; 00155 virtual const State* getState(unsigned int index) const; 00156 virtual std::size_t getStateCount() const; 00157 00158 virtual void clear(); 00159 00160 protected: 00161 00163 void goalSamplingThread(); 00164 00166 mutable boost::mutex lock_; 00167 00169 GoalSamplingFn samplerFunc_; 00170 00172 bool terminateSamplingThread_; 00173 00175 boost::thread *samplingThread_; 00176 00178 unsigned int samplingAttempts_; 00179 00182 double minDist_; 00183 00185 NewStateCallbackFn callback_; 00186 }; 00187 00188 } 00189 } 00190 00191 #endif