00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef OMPL_BASE_PLANNER_TERMINATION_CONDITION_
00038 #define OMPL_BASE_PLANNER_TERMINATION_CONDITION_
00039
00040 #include <boost/function.hpp>
00041 #include <boost/thread.hpp>
00042
00043 namespace ompl
00044 {
00045
00046 namespace base
00047 {
00048
00056 typedef boost::function0<bool> PlannerTerminationConditionFn;
00057
00064 class PlannerTerminationCondition
00065 {
00066 public:
00067
00071 PlannerTerminationCondition(const PlannerTerminationConditionFn &fn = PlannerTerminationConditionFn()) : fn_(fn), terminate_(false)
00072 {
00073 }
00074
00075 virtual ~PlannerTerminationCondition(void)
00076 {
00077 }
00078
00080 bool operator()(void) const
00081 {
00082 return terminate_ || eval();
00083 }
00084
00086 virtual void terminate(bool flag);
00087
00089 virtual bool eval(void) const;
00090
00091 protected:
00092
00094 PlannerTerminationConditionFn fn_;
00095
00097 bool terminate_;
00098 };
00099
00101 class PlannerNonTerminatingCondition : public PlannerTerminationCondition
00102 {
00103 public:
00104 PlannerNonTerminatingCondition(void);
00105 };
00106
00108 class PlannerAlwaysTerminatingCondition : public PlannerTerminationCondition
00109 {
00110 public:
00111 PlannerAlwaysTerminatingCondition(void);
00112 };
00113
00124 class PlannerThreadedTerminationCondition : public PlannerTerminationCondition
00125 {
00126 public:
00127
00132 PlannerThreadedTerminationCondition(double period);
00133
00138 PlannerThreadedTerminationCondition(const PlannerTerminationConditionFn &fn, double period);
00139
00140 virtual ~PlannerThreadedTerminationCondition(void);
00141
00148 virtual void terminate(bool flag);
00149
00151 virtual bool eval(void) const;
00152
00153 protected:
00154
00156 virtual bool computeEval(void);
00157
00159 void startEvalThread(void);
00160
00162 void stopEvalThread(void);
00163
00165 void periodicEval(void);
00166
00168 boost::thread *thread_;
00169
00171 bool evalValue_;
00172
00174 double period_;
00175 };
00176
00178 class PlannerOrTerminationCondition : public PlannerTerminationCondition
00179 {
00180 public:
00181 PlannerOrTerminationCondition(const PlannerTerminationCondition &c1, const PlannerTerminationCondition &c2) :
00182 PlannerTerminationCondition(), c1_(c1), c2_(c2)
00183 {
00184 }
00185
00187 virtual bool eval(void) const;
00188
00189 private:
00190
00191 PlannerTerminationCondition c1_;
00192 PlannerTerminationCondition c2_;
00193 };
00194
00196 class PlannerAndTerminationCondition : public PlannerTerminationCondition
00197 {
00198 public:
00199 PlannerAndTerminationCondition(const PlannerTerminationCondition &c1, const PlannerTerminationCondition &c2) :
00200 PlannerTerminationCondition(), c1_(c1), c2_(c2)
00201 {
00202 }
00203
00205 virtual bool eval(void) const;
00206
00207 private:
00208
00209 PlannerTerminationCondition c1_;
00210 PlannerTerminationCondition c2_;
00211 };
00212
00213
00215 PlannerTerminationCondition operator+(const PlannerTerminationCondition &a, const PlannerTerminationCondition &b);
00216
00218 PlannerTerminationCondition operator*(const PlannerTerminationCondition &a, const PlannerTerminationCondition &b);
00219
00221 PlannerTerminationCondition timedPlannerTerminationCondition(double duration);
00222 }
00223
00224 }
00225
00226 #endif