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_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
00163 virtual unsigned int getSerializationLength(void) const;
00164
00166 virtual void serialize(void *serialization, const Control *ctrl) const;
00167
00169 virtual void deserialize(Control *ctrl, const void *serialization) const;
00170
00173 void computeSignature(std::vector<int> &signature) const;
00174
00176 virtual bool isCompound(void) const;
00177
00178 protected:
00179
00181 int type_;
00182
00184 base::StateSpacePtr stateSpace_;
00185
00187 ControlSamplerAllocator csa_;
00188
00189 private:
00190
00192 std::string name_;
00193 };
00194
00196 class CompoundControlSpace : public ControlSpace
00197 {
00198 public:
00199
00201 typedef CompoundControl ControlType;
00202
00204 CompoundControlSpace(const base::StateSpacePtr &stateSpace) : ControlSpace(stateSpace), componentCount_(0), locked_(false)
00205 {
00206 }
00207
00208 virtual ~CompoundControlSpace(void)
00209 {
00210 }
00211
00213 template<class T>
00214 T* as(const unsigned int index) const
00215 {
00217 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
00218
00219 return static_cast<T*>(getSubspace(index).get());
00220 }
00221
00223 virtual void addSubspace(const ControlSpacePtr &component);
00224
00226 unsigned int getSubspaceCount(void) const;
00227
00229 const ControlSpacePtr& getSubspace(const unsigned int index) const;
00230
00232 const ControlSpacePtr& getSubspace(const std::string &name) const;
00233
00234 virtual unsigned int getDimension(void) const;
00235
00236 virtual Control* allocControl(void) const;
00237
00238 virtual void freeControl(Control *control) const;
00239
00240 virtual void copyControl(Control *destination, const Control *source) const;
00241
00242 virtual bool equalControls(const Control *control1, const Control *control2) const;
00243
00244 virtual void nullControl(Control *control) const;
00245
00246 virtual ControlSamplerPtr allocDefaultControlSampler(void) const;
00247
00248 virtual double* getValueAddressAtIndex(Control *control, const unsigned int index) const;
00249
00250 virtual void printControl(const Control *control, std::ostream &out = std::cout) const;
00251
00252 virtual void printSettings(std::ostream &out) const;
00253
00254 virtual void setup(void);
00255
00257 virtual unsigned int getSerializationLength(void) const;
00258
00260 virtual void serialize(void *serialization, const Control *ctrl) const;
00261
00263 virtual void deserialize(Control *ctrl, const void *serialization) const;
00264
00265 virtual bool isCompound(void) const;
00266
00272 void lock(void);
00273
00274 protected:
00275
00277 std::vector<ControlSpacePtr> components_;
00278
00280 unsigned int componentCount_;
00281
00283 bool locked_;
00284 };
00285 }
00286 }
00287
00288 #endif