mf
Media Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
space_object.h
Go to the documentation of this file.
1 #ifndef MF_SPACE_OBJECT_H_
2 #define MF_SPACE_OBJECT_H_
3 
4 #include "geometry/pose.h"
5 #include "geometry/angle.h"
6 #include "eigen.h"
7 #include <set>
8 #include <string>
9 #include <mutex>
10 
11 namespace mf {
12 
13 struct bounding_box;
14 
16 
19 class space_object {
20 private:
21  space_object* parent_;
22  std::set<space_object*> children_;
23  pose pose_;
24 
25  void transform_(const Eigen_affine3&);
26 
27  void detach_from_parent_();
28  void detach_from_children_();
29  void attach_to_parent_();
30 
31 protected:
32  virtual void do_update_pose() { }
33 
34 public:
35  explicit space_object(const pose& = pose());
36  space_object(const pose&, space_object& par);
37 
38  space_object(const space_object&);
40  virtual ~space_object();
41 
42  bool has_parent_space_object() const;
43  const space_object& parent_space_object() const;
45 
46  const pose& relative_pose() const;
47  pose absolute_pose() const;
48 
49  void set_relative_pose(const pose&);
51 
54 
55  void set_parent(space_object&, const pose& new_relative_pose = pose());
56  void set_no_parent(const pose& new_pose = pose());
57 
58  void make_sibling(const space_object&, const pose& new_pose = pose());
59 
60  template<typename Transformation>
61  void transform(const Transformation& t) {
62  transform_(Eigen_affine3(t));
63  }
64 
65  template<typename Transformation>
66  void transform(const Transformation& rt, const space_object& relative_to) {
68  Eigen_affine3 t = btw * rt * btw.inverse();
69  transform_(t);
70  }
71 
72  void move(const Eigen_vec3& t) { transform(Eigen_translation3(t)); }
73  void move(float x, float y, float z) { move(Eigen_vec3(x, y, z)); }
74  void move_x(float x) { move(x, 0, 0); }
75  void move_y(float y) { move(0, y, 0); }
76  void move_z(float z) { move(0, 0, z); }
77 
78  void rotate_x_axis(angle a, const Eigen_vec3& c = Eigen_vec3::Zero());
79  void rotate_y_axis(angle a, const Eigen_vec3& c = Eigen_vec3::Zero());
80  void rotate_z_axis(angle a, const Eigen_vec3& c = Eigen_vec3::Zero());
81 
82  void look_at(const space_object&);
83 
84  virtual bounding_box box() const;
85 };
86 
87 
89  return from.transformation_to(to);
90 }
91 
92 
93 
94 }
95 
96 #endif
space_object & operator=(const space_object &)
Definition: space_object.cc:25
Eigen_affine3 transformation_to_world() const
Affine transformation from pose coordinate system to world space.
Definition: pose.cc:30
void set_relative_pose(const pose &)
Definition: space_object.cc:87
virtual bounding_box box() const
Definition: space_object.cc:126
pose absolute_pose() const
Definition: space_object.cc:79
const pose & relative_pose() const
Definition: space_object.cc:74
Eigen_affine3 pose_transformation(const space_object &from, const space_object &to)
Definition: space_object.h:88
void move(float x, float y, float z)
Definition: space_object.h:73
void set_no_parent(const pose &new_pose=pose())
Definition: space_object.cc:102
void move(const Eigen_vec3 &t)
Definition: space_object.h:72
Eigen::Transform< Eigen_scalar, 3, Eigen::Affine > Eigen_affine3
Definition: eigen.h:37
void rotate_z_axis(angle a, const Eigen_vec3 &c=Eigen_vec3::Zero())
Definition: space_object.cc:156
void look_at(const space_object &)
Definition: space_object.cc:163
void rotate_x_axis(angle a, const Eigen_vec3 &c=Eigen_vec3::Zero())
Definition: space_object.cc:144
Position and orientation in space.
Definition: pose.h:15
space_object(const pose &=pose())
Definition: space_object.cc:15
virtual void do_update_pose()
Definition: space_object.h:32
void move_z(float z)
Definition: space_object.h:76
bool has_parent_space_object() const
Definition: space_object.cc:58
void set_parent(space_object &, const pose &new_relative_pose=pose())
Definition: space_object.cc:93
void transform(const Transformation &t)
Definition: space_object.h:61
Eigen::Translation< Eigen_scalar, 3 > Eigen_translation3
Definition: eigen.h:33
virtual ~space_object()
Definition: space_object.cc:37
void set_no_relative_pose()
Definition: space_object.h:50
Axis-aligned 3D cuboid bounding box.
Definition: bounding_box.h:16
Eigen_affine3 transformation_to(const space_object &) const
Definition: space_object.cc:132
void transform(const Transformation &rt, const space_object &relative_to)
Definition: space_object.h:66
void make_sibling(const space_object &, const pose &new_pose=pose())
Definition: space_object.cc:109
Object that has a pose in 3D space relative to a coordinate system, base class.
Definition: space_object.h:19
Eigen_affine3 transformation_from(const space_object &) const
Definition: space_object.cc:139
void move_x(float x)
Definition: space_object.h:74
void move_y(float y)
Definition: space_object.h:75
void rotate_y_axis(angle a, const Eigen_vec3 &c=Eigen_vec3::Zero())
Definition: space_object.cc:150
Angle, represented in radiants.
Definition: angle.h:12
const space_object & parent_space_object() const
Definition: space_object.cc:63
Eigen_mat< 3, 1 > Eigen_vec3
Definition: eigen.h:25