All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
ControlSpace.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_CONTROL_CONTROL_SPACE_
00038 #define OMPL_CONTROL_CONTROL_SPACE_
00039 
00040 #include "ompl/base/StateSpace.h"
00041 #include "ompl/control/Control.h"
00042 #include "ompl/control/ControlSampler.h"
00043 #include "ompl/control/ControlSpaceTypes.h"
00044 #include "ompl/util/Console.h"
00045 #include "ompl/util/ClassForward.h"
00046 #include <boost/concept_check.hpp>
00047 #include <boost/noncopyable.hpp>
00048 #include <iostream>
00049 #include <vector>
00050 
00051 namespace ompl
00052 {
00053 
00054     namespace control
00055     {
00056 
00058 
00059         ClassForward(ControlSpace);
00061 
00066         class ControlSpace : private boost::noncopyable
00067         {
00068         public:
00069 
00071             ControlSpace(const base::StateSpacePtr &stateSpace);
00072 
00073             virtual ~ControlSpace(void);
00074 
00076             template<class T>
00077             T* as(void)
00078             {
00080                 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
00081 
00082                 return static_cast<T*>(this);
00083             }
00084 
00086             template<class T>
00087             const T* as(void) const
00088             {
00090                 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
00091 
00092                 return static_cast<const T*>(this);
00093             }
00094 
00096             const std::string& getName(void) const;
00097 
00099             void setName(const std::string &name);
00100 
00104             int getType(void) const
00105             {
00106                 return type_;
00107             }
00108 
00110             const base::StateSpacePtr& getStateSpace(void) const
00111             {
00112                 return stateSpace_;
00113             }
00114 
00116             virtual unsigned int getDimension(void) const = 0;
00117 
00119             virtual Control* allocControl(void) const = 0;
00120 
00122             virtual void freeControl(Control *control) const = 0;
00123 
00125             virtual void copyControl(Control *destination, const Control *source) const = 0;
00126 
00128             virtual bool equalControls(const Control *control1, const Control *control2) const = 0;
00129 
00131             virtual void nullControl(Control *control) const = 0;
00132 
00134             virtual ControlSamplerPtr allocDefaultControlSampler(void) const = 0;
00135 
00139             virtual ControlSamplerPtr allocControlSampler(void) const;
00140 
00142             void setControlSamplerAllocator(const ControlSamplerAllocator &csa);
00143 
00145             void clearControlSamplerAllocator(void);
00146 
00151             virtual double* getValueAddressAtIndex(Control *control, const unsigned int index) const;
00152 
00154             virtual void printControl(const Control *control, std::ostream &out) const;
00155 
00157             virtual void printSettings(std::ostream &out) const;
00158 
00160             virtual void setup(void);
00161 
00162         protected:
00163 
00165             int                     type_;
00166 
00168             base::StateSpacePtr     stateSpace_;
00169 
00171             ControlSamplerAllocator csa_;
00172 
00173         private:
00174 
00176             std::string             name_;
00177         };
00178 
00180         class CompoundControlSpace : public ControlSpace
00181         {
00182         public:
00183 
00185             typedef CompoundControl ControlType;
00186 
00188             CompoundControlSpace(const base::StateSpacePtr &stateSpace) : ControlSpace(stateSpace), componentCount_(0), locked_(false)
00189             {
00190             }
00191 
00192             virtual ~CompoundControlSpace(void)
00193             {
00194             }
00195 
00197             template<class T>
00198             T* as(const unsigned int index) const
00199             {
00201                 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
00202 
00203                 return static_cast<T*>(getSubSpace(index).get());
00204             }
00205 
00207             virtual void addSubSpace(const ControlSpacePtr &component);
00208 
00210             unsigned int getSubSpaceCount(void) const;
00211 
00213             const ControlSpacePtr& getSubSpace(const unsigned int index) const;
00214 
00216             const ControlSpacePtr& getSubSpace(const std::string &name) const;
00217 
00218             virtual unsigned int getDimension(void) const;
00219 
00220             virtual Control* allocControl(void) const;
00221 
00222             virtual void freeControl(Control *control) const;
00223 
00224             virtual void copyControl(Control *destination, const Control *source) const;
00225 
00226             virtual bool equalControls(const Control *control1, const Control *control2) const;
00227 
00228             virtual void nullControl(Control *control) const;
00229 
00230             virtual ControlSamplerPtr allocDefaultControlSampler(void) const;
00231 
00232             virtual double* getValueAddressAtIndex(Control *control, const unsigned int index) const;
00233 
00234             virtual void printControl(const Control *control, std::ostream &out = std::cout) const;
00235 
00236             virtual void printSettings(std::ostream &out) const;
00237 
00238             virtual void setup(void);
00239 
00245             void lock(void);
00246 
00247         protected:
00248 
00250             std::vector<ControlSpacePtr>    components_;
00251 
00253             unsigned int                    componentCount_;
00254 
00256             bool                            locked_;
00257         };
00258     }
00259 }
00260 
00261 #endif