Parasol Planning Library (PPL)
MPTools.h
Go to the documentation of this file.
1 #ifndef MP_TOOLS_H_
2 #define MP_TOOLS_H_
3 
4 #define CLEARANCE_UTILS_AVAILABLE 1
5 #define MED_AXIS_AVAILABLE 1
6 #define POINT_CONSTRUCTION_AVAILABLE 1
7 #define REACHABILITY_UTIL_AVAILABLE 1
8 #define SAFE_INTERVAL_TOOL_AVAILABLE 1
9 #define SKELETON_CLEARANCE_AVAILABLE 1
10 #define TOPOLOGICAL_MAP_AVAILABLE 1
11 #define TET_GEN_DECOMP_AVAILABLE 1
12 #define REEB_GRAPH_AVAILABLE 1
13 #define MEAN_CURVE_SKEL_AVAILABLE 1
14 #define WRENCH_ACCESS_TOOL_AVAILABLE 1
15 
16 #include <string>
17 #include <unordered_map>
18 
19 #include "Utilities/XMLNode.h"
20 
21 #ifdef CLEARANCE_UTILS_AVAILABLE
22  #include "ClearanceUtilities.h"
23 #endif
24 
25 #ifdef MED_AXIS_AVAILABLE
26  #include "MedialAxisUtilities.h"
27 #endif
28 
29 #ifdef MEAN_CURVE_SKEL_AVAILABLE
30  #include "MeanCurvatureSkeleton3D.h"
31 #endif
32 
33 #ifdef REEB_GRAPH_AVAILABLE
34  #include "ReebGraphConstruction.h"
35 #endif
36 
37 #ifdef SAFE_INTERVAL_TOOL_AVAILABLE
38  #include "SafeIntervalTool.h"
39 #endif
40 
41 #ifdef SKELETON_CLEARANCE_AVAILABLE
43 #endif
44 
45 #ifdef TET_GEN_DECOMP_AVAILABLE
46  #include "TetGenDecomposition.h"
48 #endif
49 
50 #ifdef TOPOLOGICAL_MAP_AVAILABLE
51  #include "TopologicalMap.h"
52 #endif
53 
54 #ifdef REACHABILITY_UTIL_AVAILABLE
55  #include "ReachabilityUtil.h"
56 #endif
57 
58 #ifdef POINT_CONSTRUCTION_AVAILABLE
59  #include "PointConstruction.h"
60 #endif
61 
62 #ifdef WRENCH_ACCESS_TOOL_AVAILABLE
63  #include "WrenchAccessibilityTool.h"
64 #endif
65 
66 
67 class MPLibrary;
68 
69 
87 class MPToolsType final {
88 
91 
92 
93 
97 
98  template <typename Utility>
99  using LabelMap = std::unordered_map<std::string, Utility*>;
100 
104 
105  MPLibrary* const m_library;
106 
107  #ifdef CLEARANCE_UTILS_AVAILABLE
108  LabelMap<ClearanceUtility> m_clearanceUtils;
109  #endif
110 
111  #ifdef MED_AXIS_AVAILABLE
112  LabelMap<MedialAxisUtility> m_medialAxisUtils;
113  #endif
114 
115  #ifdef SKELETON_CLEARANCE_AVAILABLE
116  LabelMap<SkeletonClearanceUtility> m_skeletonUtils;
117  #endif
118 
119  #ifdef TOPOLOGICAL_MAP_AVAILABLE
120  LabelMap<TopologicalMap> m_topologicalMaps;
121  #endif
122 
123  #ifdef SAFE_INTERVAL_TOOL_AVAILABLE
124  LabelMap<SafeIntervalTool> m_safeIntervalTools;
125  #endif
126 
127  #ifdef REACHABILITY_UTIL_AVAILABLE
128  LabelMap<ReachabilityUtil> m_reachabilityUtils;
129  #endif
130 
131  #ifdef POINT_CONSTRUCTION_AVAILABLE
132  LabelMap<PointConstruction> m_pointConstruction;
133  #endif
134 
135  #ifdef WRENCH_ACCESS_TOOL_AVAILABLE
136  LabelMap<WrenchAccessibilityTool> m_wrenchAccessibilityTools;
137  #endif
138 
139  #ifdef TET_GEN_DECOMP_AVAILABLE
140  std::unordered_map<std::string, TetGenDecomposition> m_tetgens;
141  std::unordered_map<std::string, const WorkspaceDecomposition*> m_decompositions;
142  #endif
143 
145 
146  public:
147 
150 
153  MPToolsType(MPLibrary* const _library);
154 
157  void ParseXML(XMLNode& _node);
158 
160  void Initialize();
161 
163  void Uninitialize();
164 
165  ~MPToolsType();
166 
168 
169  #ifdef CLEARANCE_UTILS_AVAILABLE
172 
177  ClearanceUtility* GetClearanceUtility(const std::string& _label)
178  const;
179 
184  void SetClearanceUtility(const std::string& _label,
185  ClearanceUtility* const _utility);
186 
188  #endif
189 
190  #ifdef MED_AXIS_AVAILABLE
193 
198  MedialAxisUtility* GetMedialAxisUtility(const std::string& _label)
199  const;
200 
205  void SetMedialAxisUtility(const std::string& _label,
206  MedialAxisUtility* const _utility);
207 
209  #endif
210 
211  #ifdef SKELETON_CLEARANCE_AVAILABLE
214 
220  const std::string& _label) const;
221 
226  void SetSkeletonClearanceUtility(const std::string& _label,
227  SkeletonClearanceUtility* const _utility);
228 
230  #endif
231 
232  #ifdef TOPOLOGICAL_MAP_AVAILABLE
235 
240  TopologicalMap* GetTopologicalMap(const std::string& _label) const;
241 
246  void SetTopologicalMap(const std::string& _label,
247  TopologicalMap* const _utility);
248 
250  #endif
251 
252  #ifdef SAFE_INTERVAL_TOOL_AVAILABLE
255 
260  SafeIntervalTool* GetSafeIntervalTool(const std::string& _label)
261  const;
262 
267  void SetSafeIntervalTool(const std::string& _label,
268  SafeIntervalTool* const _utility);
269 
271  #endif
272 
273  #ifdef TET_GEN_DECOMP_AVAILABLE
276 
279  const WorkspaceDecomposition* GetDecomposition(const std::string& _label);
280 
285  void SetDecomposition(const std::string& _label,
286  const WorkspaceDecomposition* _decomposition);
287 
289  #endif
290 
291  #ifdef REACHABILITY_UTIL_AVAILABLE
294 
297  ReachabilityUtil* GetReachabilityUtil(const std::string& _label) const;
298 
302  void SetReachabilityUtil(const std::string& _label,
303  ReachabilityUtil* _util);
304 
306  #endif
307 
308  #ifdef POINT_CONSTRUCTION_AVAILABLE
311 
314  PointConstruction* GetPointConstruction(const std::string& _label) const;
315 
319  void SetPointConstruction(const std::string& _label,
320  PointConstruction* _util);
321 
323  #endif
324 
325  #ifdef WRENCH_ACCESS_TOOL_AVAILABLE
332  WrenchAccessibilityTool* GetWrenchAccessibilityTool(const std::string& _label) const;
333 
338  void SetWrenchAccessibilityTool(const std::string& _label,
339  WrenchAccessibilityTool* const _utility);
340 
342  #endif
343 
344  private:
345 
348 
353  template <typename Utility>
354  Utility* GetUtility(const std::string& _label,
355  const LabelMap<Utility>& _map) const;
356 
357 
362  template <typename Utility>
363  void SetUtility(const std::string& _label, Utility* _utility,
364  LabelMap<Utility>& _map) const;
365 
367 
368 };
369 
370 /*---------------------------------- Helpers ---------------------------------*/
371 
372 template <typename Utility>
373 inline
374 Utility*
375 MPToolsType::
376 GetUtility(const std::string& _label, const LabelMap<Utility>& _map) const {
377  try {
378  return _map.at(_label);
379  }
380  catch(const std::out_of_range&) {
381  Utility dummy;
382  throw RunTimeException(WHERE) << "Requested " << dummy.GetName()
383  << " '" << _label << "' does not exist.";
384  }
385  catch(const std::exception& _e) {
386  Utility dummy;
387  throw RunTimeException(WHERE) << "Error when fetching " << dummy.GetName()
388  << " '" << _label << "': " << _e.what();
389  }
390  catch(...) {
391  Utility dummy;
392  throw RunTimeException(WHERE) << "Error when fetching " << dummy.GetName()
393  << " '" << _label << "': (unknown).";
394  }
395 }
396 
397 
398 template <typename Utility>
399 void
400 MPToolsType::
401 SetUtility(const std::string& _label, Utility* _utility,
402  LabelMap<Utility>& _map) const {
403  // Set the library pointer.
404  _utility->SetMPLibrary(m_library);
405 
406  // Check if this label is already in use.
407  auto iter = _map.find(_label);
408  const bool alreadyExists = iter != _map.end();
409 
410  // If the label already exists, we need to release the previous utility first.
411  if(alreadyExists) {
412  delete iter->second;
413  iter->second = _utility;
414  }
415  else
416  _map.insert({_label, _utility});
417 }
418 
419 #endif
#define WHERE
Macro for retrieving info about file, function, and line number.
Definition: RuntimeUtils.h:32
Definition: ClearanceUtilities.h:48
Definition: MPLibrary.h:47
Definition: MPTools.h:87
void SetPointConstruction(const std::string &_label, PointConstruction *_util)
Definition: MPTools.cpp:432
TopologicalMap * GetTopologicalMap(const std::string &_label) const
Definition: MPTools.cpp:327
PointConstruction * GetPointConstruction(const std::string &_label) const
Definition: MPTools.cpp:425
WrenchAccessibilityTool * GetWrenchAccessibilityTool(const std::string &_label) const
Definition: MPTools.cpp:444
ReachabilityUtil * GetReachabilityUtil(const std::string &_label) const
Definition: MPTools.cpp:406
SafeIntervalTool * GetSafeIntervalTool(const std::string &_label) const
Definition: MPTools.cpp:346
SkeletonClearanceUtility * GetSkeletonClearanceUtility(const std::string &_label) const
Definition: MPTools.cpp:308
void SetWrenchAccessibilityTool(const std::string &_label, WrenchAccessibilityTool *const _utility)
Definition: MPTools.cpp:451
void SetReachabilityUtil(const std::string &_label, ReachabilityUtil *_util)
Definition: MPTools.cpp:413
void SetSkeletonClearanceUtility(const std::string &_label, SkeletonClearanceUtility *const _utility)
Definition: MPTools.cpp:315
void SetTopologicalMap(const std::string &_label, TopologicalMap *const _utility)
Definition: MPTools.cpp:334
void Initialize()
Initialize the clearance and MA tools prior to use.
Definition: MPTools.cpp:164
const WorkspaceDecomposition * GetDecomposition(const std::string &_label)
Definition: MPTools.cpp:364
void Uninitialize()
Uninitialize the clearance and MA tools.
Definition: MPTools.cpp:209
void SetClearanceUtility(const std::string &_label, ClearanceUtility *const _utility)
Definition: MPTools.cpp:277
~MPToolsType()
Definition: MPTools.cpp:218
void SetMedialAxisUtility(const std::string &_label, MedialAxisUtility *const _utility)
Definition: MPTools.cpp:296
MedialAxisUtility * GetMedialAxisUtility(const std::string &_label) const
Definition: MPTools.cpp:289
MPToolsType(MPLibrary *const _library)
Definition: MPTools.cpp:8
void SetSafeIntervalTool(const std::string &_label, SafeIntervalTool *const _utility)
Definition: MPTools.cpp:353
void SetDecomposition(const std::string &_label, const WorkspaceDecomposition *_decomposition)
Definition: MPTools.cpp:384
ClearanceUtility * GetClearanceUtility(const std::string &_label) const
Definition: MPTools.cpp:270
void ParseXML(XMLNode &_node)
Definition: MPTools.cpp:13
Definition: MedialAxisUtilities.h:16
Definition: PointConstruction.h:7
Definition: ReachabilityUtil.h:19
Definition: SafeIntervalTool.h:18
Definition: SkeletonClearanceUtility.h:13
Definition: TopologicalMap.h:38
Definition: WorkspaceDecomposition.h:24
Definition: WrenchAccessibilityTool.h:15
Definition: XMLNode.h:27
Definition: PMPLExceptions.h:62