Projection.h
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2021,
5  * Max Planck Institute for Intelligent Systems (MPI-IS).
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the MPI-IS nor the names
19  * of its contributors may be used to endorse or promote products
20  * derived from this software without specific prior written
21  * permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *********************************************************************/
36 
37 /* Author: Andreas Orthey */
38 
39 #ifndef OMPL_MULTILEVEL_PLANNERS_BUNDLESPACE_BUNDLE_PROJECTION_
40 #define OMPL_MULTILEVEL_PLANNERS_BUNDLESPACE_BUNDLE_PROJECTION_
41 #include <ompl/base/State.h>
42 #include <ompl/base/StateSpace.h>
43 #include <ompl/multilevel/datastructures/ProjectionTypes.h>
44 
45 namespace ompl
46 {
47  namespace base
48  {
50 
51  OMPL_CLASS_FORWARD(StateSpace);
53  }
54  namespace multilevel
55  {
57 
58  OMPL_CLASS_FORWARD(Projection);
60 
61  /* \brief A projection which consists of a set of component projections
62  * */
63  class Projection
64  {
65  public:
66  Projection() = delete;
67  Projection(base::StateSpacePtr bundleSpace, base::StateSpacePtr baseSpace);
68 
69  virtual ~Projection() = default;
70 
71  /* \brief All subclasses need to be able to project onto base space
72  * */
73  virtual void project(const ompl::base::State *xBundle, ompl::base::State *xBase) const = 0;
74 
75  /* \brief All subclasses need to be able to lift from base space
76  * into the total bundle space */
77  virtual void lift(const ompl::base::State *xBase, ompl::base::State *xBundle) const = 0;
78 
79  /* \brief Check if projection is fibered (has explicit fiber space) */
80  virtual bool isFibered() const;
81 
82  /* \brief Co-dimension of projection (dimension of null space) */
83  unsigned int getCoDimension() const;
84 
85  /* \brief Dimension of bundle space of projection */
86  unsigned int getDimension() const;
87 
88  /* \brief Dimension of base space */
89  unsigned int getBaseDimension() const;
90 
91  /* \brief Get bundle space */
92  base::StateSpacePtr getBundle() const;
93 
94  /* \brief Get base space */
95  base::StateSpacePtr getBase() const;
96 
97  /* \brief Check if projection is admissible (NYI) */
98  virtual bool isAdmissible() const;
99 
100  /* \brief Type of Bundle Space Projection */
101  ProjectionType getType() const;
102  /* \brief Set type of Bundle Space Projection */
103  void setType(const ProjectionType);
104 
105  /* \brief Projection type to std::string */
106  std::string getTypeAsString() const;
107  /* \brief Bundle space as std::string */
108  std::string getBundleTypeAsString() const;
109  /* \brief Base space as std::string */
110  std::string getBaseTypeAsString() const;
111 
113  friend std::ostream &operator<<(std::ostream &out, const Projection &);
114 
116  virtual void print(std::ostream &out) const;
117 
119  std::string stateTypeToString(base::StateSpacePtr) const;
120 
121  protected:
122  base::StateSpacePtr bundleSpace_{nullptr};
123  base::StateSpacePtr baseSpace_{nullptr};
124 
125  ProjectionType type_;
126  };
127 
128  class CompoundProjection : public Projection
129  {
130  public:
131  CompoundProjection(const base::StateSpacePtr &bundleSpace, const base::StateSpacePtr &baseSpace,
132  const std::vector<ProjectionPtr> &components);
133 
134  virtual ~CompoundProjection() = default;
135 
136  /* \brief All subclasses need to be able to project onto base space
137  * */
138  void project(const ompl::base::State *xBundle, ompl::base::State *xBase) const override;
139 
140  /* \brief All subclasses need to be able to lift from base space
141  * into the total bundle space
142  * */
143  void lift(const ompl::base::State *xBase, ompl::base::State *xBundle) const override;
145  virtual void print(std::ostream &out) const override;
146 
148  unsigned int getBaseDimension() const;
150  unsigned int getDimension() const;
152  unsigned int getCoDimension() const;
153 
155  bool isFibered() const override;
156 
157  private:
158  std::vector<ProjectionType> types_;
159 
160  std::vector<ProjectionPtr> components_;
161  };
162  }
163 }
164 #endif
bool isFibered() const override
Check that every compound has an explicit fiber representation.
Definition: Projection.cpp:287
Definition of an abstract state.
Definition: State.h:113
friend std::ostream & operator<<(std::ostream &out, const Projection &)
Print to stream (actual implementation in print(std::ostream &out))
Definition: Projection.cpp:196
virtual void print(std::ostream &out) const
Print to stream.
Definition: Projection.cpp:187
unsigned int getDimension() const
Dimension of Bundle Space.
Definition: Projection.cpp:252
virtual void print(std::ostream &out) const override
Print to stream.
Definition: Projection.cpp:297
unsigned int getCoDimension() const
Dimension of Bundle - Dimension of Base.
Definition: Projection.cpp:264
unsigned int getBaseDimension() const
Dimension of Base Space.
Definition: Projection.cpp:275
std::string stateTypeToString(base::StateSpacePtr) const
Return string representing type of ompl::base::StateSpace.
Definition: Projection.cpp:103
Main namespace. Contains everything in this library.