All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
ControlSpace.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2010, Rice University
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Rice University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #ifndef OMPL_CONTROL_CONTROL_SPACE_
38 #define OMPL_CONTROL_CONTROL_SPACE_
39 
40 #include "ompl/base/StateSpace.h"
41 #include "ompl/control/Control.h"
42 #include "ompl/control/ControlSampler.h"
43 #include "ompl/control/ControlSpaceTypes.h"
44 #include "ompl/util/Console.h"
45 #include "ompl/util/ClassForward.h"
46 #include <boost/concept_check.hpp>
47 #include <boost/noncopyable.hpp>
48 #include <iostream>
49 #include <vector>
50 
51 namespace ompl
52 {
53 
54  namespace control
55  {
56 
58 
59  OMPL_CLASS_FORWARD(ControlSpace);
61 
66  class ControlSpace : private boost::noncopyable
67  {
68  public:
69 
71  ControlSpace(const base::StateSpacePtr &stateSpace);
72 
73  virtual ~ControlSpace(void);
74 
76  template<class T>
77  T* as(void)
78  {
80  BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
81 
82  return static_cast<T*>(this);
83  }
84 
86  template<class T>
87  const T* as(void) const
88  {
90  BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
91 
92  return static_cast<const T*>(this);
93  }
94 
96  const std::string& getName(void) const;
97 
99  void setName(const std::string &name);
100 
104  int getType(void) const
105  {
106  return type_;
107  }
108 
111  {
112  return stateSpace_;
113  }
114 
116  virtual unsigned int getDimension(void) const = 0;
117 
119  virtual Control* allocControl(void) const = 0;
120 
122  virtual void freeControl(Control *control) const = 0;
123 
125  virtual void copyControl(Control *destination, const Control *source) const = 0;
126 
128  virtual bool equalControls(const Control *control1, const Control *control2) const = 0;
129 
131  virtual void nullControl(Control *control) const = 0;
132 
134  virtual ControlSamplerPtr allocDefaultControlSampler(void) const = 0;
135 
139  virtual ControlSamplerPtr allocControlSampler(void) const;
140 
143 
145  void clearControlSamplerAllocator(void);
146 
151  virtual double* getValueAddressAtIndex(Control *control, const unsigned int index) const;
152 
154  virtual void printControl(const Control *control, std::ostream &out) const;
155 
157  virtual void printSettings(std::ostream &out) const;
158 
160  virtual void setup(void);
161 
163  virtual unsigned int getSerializationLength(void) const;
164 
166  virtual void serialize(void *serialization, const Control *ctrl) const;
167 
169  virtual void deserialize(Control *ctrl, const void *serialization) const;
170 
173  void computeSignature(std::vector<int> &signature) const;
174 
176  virtual bool isCompound(void) const;
177 
178  protected:
179 
181  int type_;
182 
185 
188 
189  private:
190 
192  std::string name_;
193  };
194 
197  {
198  public:
199 
202 
204  CompoundControlSpace(const base::StateSpacePtr &stateSpace) : ControlSpace(stateSpace), componentCount_(0), locked_(false)
205  {
206  }
207 
208  virtual ~CompoundControlSpace(void)
209  {
210  }
211 
213  template<class T>
214  T* as(const unsigned int index) const
215  {
217  BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
218 
219  return static_cast<T*>(getSubspace(index).get());
220  }
221 
223  virtual void addSubspace(const ControlSpacePtr &component);
224 
226  unsigned int getSubspaceCount(void) const;
227 
229  const ControlSpacePtr& getSubspace(const unsigned int index) const;
230 
232  const ControlSpacePtr& getSubspace(const std::string &name) const;
233 
234  virtual unsigned int getDimension(void) const;
235 
236  virtual Control* allocControl(void) const;
237 
238  virtual void freeControl(Control *control) const;
239 
240  virtual void copyControl(Control *destination, const Control *source) const;
241 
242  virtual bool equalControls(const Control *control1, const Control *control2) const;
243 
244  virtual void nullControl(Control *control) const;
245 
246  virtual ControlSamplerPtr allocDefaultControlSampler(void) const;
247 
248  virtual double* getValueAddressAtIndex(Control *control, const unsigned int index) const;
249 
250  virtual void printControl(const Control *control, std::ostream &out = std::cout) const;
251 
252  virtual void printSettings(std::ostream &out) const;
253 
254  virtual void setup(void);
255 
257  virtual unsigned int getSerializationLength(void) const;
258 
260  virtual void serialize(void *serialization, const Control *ctrl) const;
261 
263  virtual void deserialize(Control *ctrl, const void *serialization) const;
264 
265  virtual bool isCompound(void) const;
266 
272  void lock(void);
273 
274  protected:
275 
277  std::vector<ControlSpacePtr> components_;
278 
280  unsigned int componentCount_;
281 
283  bool locked_;
284  };
285  }
286 }
287 
288 #endif