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 00166 void setMaximumPathLength(double maximumPathLength) 00167 { 00168 maximumPathLength_ = maximumPathLength; 00169 } 00170 00175 const PathPtr& getSolutionPath(void) const 00176 { 00177 return path_; 00178 } 00179 00181 void setSolutionPath(const PathPtr &path, bool approximate = false) 00182 { 00183 path_ = path; 00184 approximate_ = approximate; 00185 } 00186 00188 void clearSolutionPath(void) 00189 { 00190 path_.reset(); 00191 } 00192 00196 double getDifference(void) const 00197 { 00198 return difference_; 00199 } 00200 00203 void setDifference(double difference) 00204 { 00205 difference_ = difference; 00206 } 00207 00211 bool isApproximate(void) const 00212 { 00213 return approximate_; 00214 } 00215 00217 virtual void print(std::ostream &out = std::cout) const 00218 { 00219 out << "Goal memory address " << this << std::endl; 00220 } 00221 00222 protected: 00223 00225 GoalType type_; 00226 00228 SpaceInformationPtr si_; 00229 00231 double maximumPathLength_; 00232 00234 PathPtr path_; 00235 00237 double difference_; 00238 00240 bool approximate_; 00241 00242 }; 00243 00244 } 00245 } 00246 00247 #endif