GAMS  1.4.0
Framed.h
Go to the documentation of this file.
1 
54 #include "ReferenceFrame.h"
55 
56 #ifndef _GAMS_POSE_FRAMED_H_
57 #define _GAMS_POSE_FRAMED_H_
58 
59 #include "gams/GamsExport.h"
60 #include <string>
61 #include <cfloat>
62 #include <utility>
63 #include "gams/CPP11_compat.h"
64 #include "madara/knowledge/containers/DoubleVector.h"
65 #include "madara/knowledge/containers/NativeDoubleVector.h"
66 #include "ReferenceFrameFwd.h"
67 #include "Coordinate.h"
68 
69 namespace gams { namespace pose {
70 
71 template<typename T>
72 inline auto try_transform_to(const T& v, const ReferenceFrame &frame) ->
73  typename std::enable_if<supports_transform_to<T>::value, T>::type
74 {
75  return v.transform_to(frame);
76 }
77 
78 template<typename T>
79 inline auto try_transform_to(const T& v, const ReferenceFrame &) ->
80  typename std::enable_if<!supports_transform_to<T>::value, const T &>::type
81 {
82  return v;
83 }
84 
86 {
87  return default_frame();
88 }
89 
90 template<typename T, typename... Args>
91 inline auto try_get_frame(const T& v, Args&&...) ->
92  typename std::enable_if<supports_transform_to<T>::value, ReferenceFrame>::type
93 {
94  return v.frame();
95 }
96 
97 template<typename T, typename... Args>
98 inline auto try_get_frame(const T&, Args&&... args) ->
99  typename std::enable_if<!supports_transform_to<T>::value, ReferenceFrame>::type
100 {
101  return try_get_frame(std::forward<Args>(args)...);
102 }
103 
106 template<typename Impl>
107 class Framed : public Impl
108 {
109 public:
110  using Impl::self;
111  using derived_type = typename Impl::derived_type;
112 
116  Framed() = default;
117 
118 #ifdef DOXYGEN
129  template<typename... Args>
130  Framed(Args&&... args);
131 #else
132  template<typename Arg, typename... Args,
133  typename std::enable_if<!std::is_same<typename std::decay<Arg>::type,
134  ReferenceFrame>::value && sizeof...(Args) >= 1, void*>::type = nullptr>
135  Framed(Arg&& arg, Args&&... args)
136  : Impl((Arg &)arg, ((Args &)args)...),
137  frame_(try_get_frame((Arg &)arg, ((Args &)args)...)) {}
138 
139  template<typename Arg,
140  typename std::enable_if<
141  !std::is_same<typename std::decay<Arg>::type,
142  ReferenceFrame>::value, void*>::type = nullptr>
143  explicit Framed(Arg&& arg)
144  : Impl((Arg &)arg), frame_(try_get_frame(arg)) {}
145 #endif
146 
153  : Impl(), frame_(frame) {}
154 
155 #ifdef DOXYGEN
164  template<typename... Args>
165  Framed(ReferenceFrame frame, Args&&... args);
166 #else
167  template<typename... Args,
168  typename std::enable_if<(sizeof...(Args) >= 1), void*>::type = nullptr>
169  Framed(ReferenceFrame frame, Args&&... args)
170  : Impl(try_transform_to(std::forward<Args>(args), frame)...),
171  frame_(frame) {}
172 #endif
173 
179  const ReferenceFrame &frame() const { return frame_; }
180 
191  {
192  using std::swap;
193  swap(frame_, new_frame);
194  return new_frame;
195  }
196 
207  template<typename Base2>
209  double epsilon) const
210  {
211  return std::fabs(self().distance_to(other.self())) < epsilon;
212  }
213 
214  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
215  * The four methods below are defined in ReferenceFrame.inl,
216  * due to circular dependencies
217  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
218 
233  transform_to(const ReferenceFrame &new_frame) const;
234 
247  void transform_this_to(const ReferenceFrame &new_frame);
248 
265  double distance_to(const derived_type &target) const;
266 
267  //using Base::distance_to;
268 
275  void normalize();
276 
277 private:
279 };
280 
281 } }
282 
283 #endif
#define WARN_UNUSED
Definition: CPP11_compat.h:7
Internal class implementing coordinates bound to reference frame.
Definition: Framed.h:108
ReferenceFrame frame(ReferenceFrame new_frame)
Setter for the ReferenceFrame this Coordinate belongs to.
Definition: Framed.h:190
void transform_this_to(const ReferenceFrame &new_frame)
Transform this coordinate, in place, to a new reference frame.
Framed(ReferenceFrame frame, Args &&... args)
Construct using a ReferenceFrame object.
derived_type WARN_UNUSED transform_to(const ReferenceFrame &new_frame) const
Copy and transform this coordinate to a new reference frame.
bool approximately_equal(const Framed< Base2 > &other, double epsilon) const
Tests if this Coordinate is within epsilon in distance (as defined by this Coordinate's reference fra...
Definition: Framed.h:208
const ReferenceFrame & frame() const
Getter for the ReferenceFrame this Coordinate belongs to.
Definition: Framed.h:179
ReferenceFrame frame_
Definition: Framed.h:278
Framed(ReferenceFrame frame)
Construct using just a ReferenceFrame object.
Definition: Framed.h:152
Framed()=default
Default Constructor.
Framed(Args &&... args)
Construct without a ReferenceFrame object.
void normalize()
Reduces this Coordinate to it's normalized form, should one exist.
typename Impl::derived_type derived_type
Definition: Framed.h:111
double distance_to(const derived_type &target) const
Calculate distance from this Coordinate to a target.
Provides Reference Frame (i.e., coordinate systemm) transforms.
GAMS_EXPORT const ReferenceFrame & default_frame(void)
Default frame.
ReferenceFrame try_get_frame()
Definition: Framed.h:85
auto try_transform_to(const T &v, const ReferenceFrame &frame) -> typename std::enable_if< supports_transform_to< T >::value, T >::type
Definition: Framed.h:72
gams::pose::ReferenceFrame ReferenceFrame
Base class for Reference Frames.
Contains all GAMS-related tools, classes and code.
Copyright (c) 2015 Carnegie Mellon University.
Copyright (c) 2015 Carnegie Mellon University.