setup.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018-2020, University of Edinburgh, University of Oxford
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef EXOTICA_CORE_SETUP_H_
31 #define EXOTICA_CORE_SETUP_H_
32 
33 #include <memory>
34 #include <vector>
35 
37 #include <exotica_core/factory.h>
39 #include <exotica_core/object.h>
41 #include <exotica_core/property.h>
42 
43 #include <pluginlib/class_loader.h>
44 
45 namespace exotica
46 {
47 class Setup : public Object, Uncopyable
48 {
49 public:
50  ~Setup() noexcept
51  {
52  }
53 
54  static std::shared_ptr<Setup> Instance()
55  {
58  }
59 
60  static void Destroy();
61 
62  static void PrintSupportedClasses();
63  static std::shared_ptr<exotica::MotionSolver> CreateSolver(const std::string& type, bool prepend = true) { return ToStdPtr(Instance()->solvers_.createInstance((prepend ? "exotica/" : "") + type)); }
64  static std::shared_ptr<exotica::TaskMap> CreateMap(const std::string& type, bool prepend = true) { return ToStdPtr(Instance()->maps_.createInstance((prepend ? "exotica/" : "") + type)); }
65  static std::shared_ptr<exotica::PlanningProblem> CreateProblem(const std::string& type, bool prepend = true) { return Instance()->problems_.CreateInstance((prepend ? "exotica/" : "") + type); }
66  static std::shared_ptr<exotica::CollisionScene> CreateCollisionScene(const std::string& type, bool prepend = true) { return ToStdPtr(Instance()->collision_scenes_.createInstance((prepend ? "exotica/" : "") + type)); }
67  static std::shared_ptr<exotica::DynamicsSolver> CreateDynamicsSolver(const std::string& type, bool prepend = true) { return ToStdPtr(Instance()->dynamics_solvers_.createInstance((prepend ? "exotica/" : "") + type)); }
68  static std::vector<std::string> GetSolvers();
69  static std::vector<std::string> GetProblems();
70  static std::vector<std::string> GetMaps();
71  static std::vector<std::string> GetCollisionScenes();
72  static std::vector<std::string> GetDynamicsSolvers();
73  static std::vector<Initializer> GetInitializers();
74 
75  static std::shared_ptr<exotica::MotionSolver> CreateSolver(const Initializer& init)
76  {
77  std::shared_ptr<exotica::MotionSolver> ret = ToStdPtr(Instance()->solvers_.createInstance(init.GetName()));
78  ret->InstantiateInternal(init);
79  return ret;
80  }
81  static std::shared_ptr<exotica::PlanningProblem> CreateProblem(const Initializer& init)
82  {
83  std::shared_ptr<exotica::PlanningProblem> ret = Instance()->problems_.CreateInstance(init.GetName());
84  ret->InstantiateInternal(init);
85  return ret;
86  }
87 
98  {
99  exotica::ScenePtr ret = std::make_shared<exotica::Scene>();
100  ret->InstantiateInternal(init);
101  return ret;
102  }
103 
104  static std::shared_ptr<exotica::DynamicsSolver> CreateDynamicsSolver(const Initializer& init)
105  {
106  auto ret = ToStdPtr(Instance()->dynamics_solvers_.createInstance(init.GetName()));
107  ret->InstantiateInternal(init);
108  return ret;
109  }
110 
111  static std::shared_ptr<exotica::CollisionScene> CreateCollisionScene(const Initializer& init)
112  {
113  auto ret = ToStdPtr(Instance()->collision_scenes_.createInstance(init.GetName()));
114  ret->InstantiateInternal(init);
115  return ret;
116  }
117 
118 private:
120  Setup();
121  static std::shared_ptr<Setup> singleton_initialiser_;
122  // Make sure the singleton does not get copied
123  Setup(Setup const&) = delete;
124  void operator=(Setup const&) = delete;
125 
126  static std::shared_ptr<exotica::TaskMap> CreateMap(const Initializer& init)
127  {
128  std::shared_ptr<exotica::TaskMap> ret = ToStdPtr(Instance()->maps_.createInstance(init.GetName()));
129  ret->InstantiateInternal(init);
130  return ret;
131  }
132 
138 };
139 
140 typedef std::shared_ptr<Setup> SetupPtr;
141 } // namespace exotica
142 
143 #endif // EXOTICA_CORE_SETUP_H_
~Setup() noexcept
Definition: setup.h:50
static std::vector< std::string > GetDynamicsSolvers()
Definition: setup.cpp:165
static exotica::ScenePtr CreateScene(const Initializer &init)
CreateScene instantiate a scene from an initialiser The returned scene is independent of the internal...
Definition: setup.h:97
static std::shared_ptr< exotica::DynamicsSolver > CreateDynamicsSolver(const Initializer &init)
Definition: setup.h:104
static std::shared_ptr< exotica::CollisionScene > CreateCollisionScene(const std::string &type, bool prepend=true)
Definition: setup.h:66
PlanningProblemFac problems_
Definition: setup.h:137
friend PlanningProblem
Definition: setup.h:119
static std::shared_ptr< exotica::MotionSolver > CreateSolver(const std::string &type, bool prepend=true)
Definition: setup.h:63
const std::string & GetName() const
Definition: property.cpp:75
std::shared_ptr< Scene > ScenePtr
Definition: scene.h:246
pluginlib::ClassLoader< exotica::TaskMap > maps_
Definition: setup.h:134
pluginlib::ClassLoader< exotica::DynamicsSolver > dynamics_solvers_
Definition: setup.h:136
static std::shared_ptr< Setup > singleton_initialiser_
Definition: setup.h:121
static std::vector< Initializer > GetInitializers()
Definition: setup.cpp:103
static void Destroy()
Definition: setup.cpp:42
static std::vector< std::string > GetCollisionScenes()
Definition: setup.cpp:164
std::shared_ptr< T > ToStdPtr(const boost::shared_ptr< T > &p)
Definition: tools.h:148
std::shared_ptr< Setup > SetupPtr
Definition: setup.h:140
static void PrintSupportedClasses()
Definition: setup.cpp:48
virtual std::string type() const
Type Information wrapper: must be virtual so that it is polymorphic...
Definition: object.h:61
static std::shared_ptr< exotica::DynamicsSolver > CreateDynamicsSolver(const std::string &type, bool prepend=true)
Definition: setup.h:67
static std::vector< std::string > GetProblems()
Definition: setup.cpp:162
pluginlib::ClassLoader< exotica::MotionSolver > solvers_
Definition: setup.h:133
static std::shared_ptr< exotica::CollisionScene > CreateCollisionScene(const Initializer &init)
Definition: setup.h:111
void operator=(Setup const &)=delete
static std::vector< std::string > GetMaps()
Definition: setup.cpp:163
static std::vector< std::string > GetSolvers()
Definition: setup.cpp:161
static std::shared_ptr< exotica::PlanningProblem > CreateProblem(const std::string &type, bool prepend=true)
Definition: setup.h:65
pluginlib::ClassLoader< exotica::CollisionScene > collision_scenes_
Definition: setup.h:135
static std::shared_ptr< exotica::MotionSolver > CreateSolver(const Initializer &init)
Definition: setup.h:75
static std::shared_ptr< exotica::TaskMap > CreateMap(const Initializer &init)
Definition: setup.h:126
static std::shared_ptr< exotica::PlanningProblem > CreateProblem(const Initializer &init)
Definition: setup.h:81
static std::shared_ptr< Setup > Instance()
Definition: setup.h:54
static std::shared_ptr< exotica::TaskMap > CreateMap(const std::string &type, bool prepend=true)
Definition: setup.h:64


exotica_core
Author(s): Yiming Yang, Michael Camilleri
autogenerated on Sat Apr 10 2021 02:34:49