00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2008, Willow Garage, Inc. 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 Willow Garage 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_GOAL_ 00038 #define OMPL_BASE_GOAL_ 00039 00040 #include "ompl/base/State.h" 00041 #include "ompl/base/SpaceInformation.h" 00042 #include "ompl/base/Path.h" 00043 #include "ompl/util/ClassForward.h" 00044 #include "ompl/base/GoalTypes.h" 00045 #include <iostream> 00046 #include <boost/noncopyable.hpp> 00047 #include <boost/concept_check.hpp> 00048 00049 namespace ompl 00050 { 00051 namespace base 00052 { 00053 00055 ClassForward(Goal); 00056 00061 class Goal : private boost::noncopyable 00062 { 00063 public: 00064 00066 Goal(const SpaceInformationPtr &si); 00067 00069 virtual ~Goal(void) 00070 { 00071 } 00072 00074 template<class T> 00075 T* as(void) 00076 { 00078 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, Goal*>)); 00079 00080 return static_cast<T*>(this); 00081 } 00082 00084 template<class T> 00085 const T* as(void) const 00086 { 00088 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, Goal*>)); 00089 00090 return static_cast<const T*>(this); 00091 } 00092 00094 GoalType getType(void) const 00095 { 00096 return type_; 00097 } 00098 00100 bool hasType(GoalType type) const 00101 { 00102 return (type_ & type) == type; 00103 } 00104 00106 const SpaceInformationPtr& getSpaceInformation(void) const 00107 { 00108 return si_; 00109 } 00110 00113 virtual bool isSatisfied(const State *st) const = 0; 00114 00126 virtual bool isSatisfied(const State *st, double *distance) const; 00127 00137 bool isSatisfied(const State *st, double pathLength, double *distance) const; 00138 00145 virtual bool isStartGoalPairValid(const State * /* start */, const State * /* goal */) const 00146 { 00147 return true; 00148 } 00149 00151 bool isAchieved(void) const 00152 { 00153 return path_; 00154 } 00155 00157 double getMaximumPathLength(void) const 00158 { 00159 return maximumPathLength_; 00160 } 00161 00167 void setMaximumPathLength(double maximumPathLength) 00168 { 00169 maximumPathLength_ = maximumPathLength; 00170 } 00171 00173 bool isPathLengthSatisfied(double pathLength) const 00174 { 00175 return pathLength <= maximumPathLength_; 00176 } 00177 00182 const PathPtr& getSolutionPath(void) const 00183 { 00184 return path_; 00185 } 00186 00188 void setSolutionPath(const PathPtr &path, bool approximate = false) 00189 { 00190 path_ = path; 00191 approximate_ = approximate; 00192 } 00193 00195 void clearSolutionPath(void) 00196 { 00197 path_.reset(); 00198 } 00199 00203 double getDifference(void) const 00204 { 00205 return difference_; 00206 } 00207 00210 void setDifference(double difference) 00211 { 00212 difference_ = difference; 00213 } 00214 00218 bool isApproximate(void) const 00219 { 00220 return approximate_; 00221 } 00222 00224 virtual void print(std::ostream &out = std::cout) const 00225 { 00226 out << "Goal memory address " << this << std::endl; 00227 } 00228 00229 protected: 00230 00232 GoalType type_; 00233 00235 SpaceInformationPtr si_; 00236 00238 double maximumPathLength_; 00239 00241 PathPtr path_; 00242 00244 double difference_; 00245 00247 bool approximate_; 00248 00249 }; 00250 00251 } 00252 } 00253 00254 #endif