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/util/Console.h"
00044 #include "ompl/util/ClassForward.h"
00045 #include <boost/concept_check.hpp>
00046 #include <boost/noncopyable.hpp>
00047 #include <iostream>
00048 #include <vector>
00049 
00050 namespace ompl
00051 {
00052 
00053     namespace control
00054     {
00055 
00057         ClassForward(ControlSpace);
00058 
00063         class ControlSpace : private boost::noncopyable
00064         {
00065         public:
00066 
00068             ControlSpace(const base::StateSpacePtr &stateSpace);
00069 
00070             virtual ~ControlSpace(void);
00071 
00073             template<class T>
00074             T* as(void)
00075             {
00077                 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
00078 
00079                 return static_cast<T*>(this);
00080             }
00081 
00083             template<class T>
00084             const T* as(void) const
00085             {
00087                 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
00088 
00089                 return static_cast<const T*>(this);
00090             }
00091 
00093             const std::string& getName(void) const;
00094 
00096             void setName(const std::string &name);
00097 
00099             const base::StateSpacePtr& getStateSpace(void) const
00100             {
00101                 return stateSpace_;
00102             }
00103 
00105             virtual unsigned int getDimension(void) const = 0;
00106 
00108             virtual Control* allocControl(void) const = 0;
00109 
00111             virtual void freeControl(Control *control) const = 0;
00112 
00114             virtual void copyControl(Control *destination, const Control *source) const = 0;
00115 
00117             virtual bool equalControls(const Control *control1, const Control *control2) const = 0;
00118 
00120             virtual void nullControl(Control *control) const = 0;
00121 
00123             virtual ControlSamplerPtr allocControlSampler(void) const = 0;
00124 
00129             virtual double* getValueAddressAtIndex(Control *control, const unsigned int index) const;
00130 
00132             virtual void printControl(const Control *control, std::ostream &out) const;
00133 
00135             virtual void printSettings(std::ostream &out) const;
00136 
00138             virtual void setup(void);
00139 
00140         protected:
00141 
00143             base::StateSpacePtr    stateSpace_;
00144 
00145         private:
00146 
00148             std::string            name_;
00149         };
00150 
00152         class CompoundControlSpace : public ControlSpace
00153         {
00154         public:
00155 
00157             typedef CompoundControl ControlType;
00158 
00160             CompoundControlSpace(const base::StateSpacePtr &stateSpace) : ControlSpace(stateSpace), componentCount_(0), locked_(false)
00161             {
00162             }
00163 
00164             virtual ~CompoundControlSpace(void)
00165             {
00166             }
00167 
00169             template<class T>
00170             T* as(const unsigned int index) const
00171             {
00173                 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
00174 
00175                 return static_cast<T*>(getSubSpace(index).get());
00176             }
00177 
00179             virtual void addSubSpace(const ControlSpacePtr &component);
00180 
00182             unsigned int getSubSpaceCount(void) const;
00183 
00185             const ControlSpacePtr& getSubSpace(const unsigned int index) const;
00186 
00188             const ControlSpacePtr& getSubSpace(const std::string &name) const;
00189 
00190             virtual unsigned int getDimension(void) const;
00191 
00192             virtual Control* allocControl(void) const;
00193 
00194             virtual void freeControl(Control *control) const;
00195 
00196             virtual void copyControl(Control *destination, const Control *source) const;
00197 
00198             virtual bool equalControls(const Control *control1, const Control *control2) const;
00199 
00200             virtual void nullControl(Control *control) const;
00201 
00202             virtual ControlSamplerPtr allocControlSampler(void) const;
00203 
00204             virtual double* getValueAddressAtIndex(Control *control, const unsigned int index) const;
00205 
00206             virtual void printControl(const Control *control, std::ostream &out = std::cout) const;
00207 
00208             virtual void printSettings(std::ostream &out) const;
00209 
00210             virtual void setup(void);
00211 
00217             void lock(void);
00218 
00219         protected:
00220 
00222             std::vector<ControlSpacePtr>    components_;
00223 
00225             unsigned int                    componentCount_;
00226 
00228             bool                            locked_;
00229         };
00230     }
00231 }
00232 
00233 #endif