Virtual Testbed
Ship dynamics simulator for extreme conditions
ship_hull_transformation.hh
1 #ifndef VTESTBED_DB_SHIP_HULL_TRANSFORMATION_HH
2 #define VTESTBED_DB_SHIP_HULL_TRANSFORMATION_HH
3 
4 #include <iosfwd>
5 #include <string>
6 #include <vector>
7 
8 #include <sqlitex/forward.hh>
9 
10 #include <vtestbed/geometry/polyhedron.hh>
11 
12 namespace vtb {
13 
14  namespace db {
15 
16  enum class Transformations {
17  Mirror = 1,
18  Flip = 2,
19  Centre_of_mass = 3,
20  Rotate = 4,
21  Scale = 5,
22  Centre_of_bounding_box = 6,
23  Move = 7,
24  Centre_auto = 8,
25  };
26 
27  const char*
28  to_string(Transformations rhs);
29 
31  operator<<(std::ostream& out, Transformations rhs);
32 
34  operator>>(std::istream& in, Transformations& rhs);
35 
36  template <class T>
38 
39  public:
41  using vertex_type = typename polyhedron_type::vertex_type;
42 
43  enum class Type {Integer, Real};
44 
45  struct Argument {
46  Type type;
47  union { int int_number; T real_number; };
48 
49  Argument(): type(Type::Integer), int_number(0) {}
50  Argument(int n): type(Type::Integer), int_number(n) {}
51  Argument(T n): type(Type::Real), real_number(n) {}
52 
53  };
54 
55  private:
56  Transformations _transformation{};
57  int _dimension = 0;
58  Argument _argument;
59 
60  public:
61 
62  Ship_hull_transformation() = default;
63 
64  inline
65  Ship_hull_transformation(Transformations tr):
66  _transformation{tr} {}
67 
68  inline
69  Ship_hull_transformation(Transformations tr, int dim):
70  _transformation{tr}, _dimension{dim} {}
71 
72  inline
73  Ship_hull_transformation(
74  Transformations tr,
75  int dim,
76  Argument arg
77  ):
78  _transformation{tr}, _dimension{dim}, _argument{arg} {}
79 
80  void
81  apply(polyhedron_type& hull) const;
82 
83  inline Transformations
84  transformation() const {
85  return this->_transformation;
86  }
87 
88  template <class X>
89  friend std::ostream&
90  operator<<(
91  std::ostream& out,
92  const Ship_hull_transformation<X>& rhs
93  );
94 
95  template <class X>
96  friend std::istream&
97  operator>>(
98  std::istream& in,
99  Ship_hull_transformation<X>& rhs
100  );
101 
102  };
103 
104  template <class T>
105  std::ostream&
106  operator<<(std::ostream& out, const Ship_hull_transformation<T>& rhs);
107 
108  template <class T>
109  std::istream&
110  operator>>(std::istream& in, Ship_hull_transformation<T>& rhs);
111 
112  template <class T>
114  to_string(const Ship_hull_transformation<T>& rhs);
115 
116  template <class T>
118 
119  public:
122  typedef typename transform_array::iterator iterator;
123  typedef typename transform_array::const_iterator const_iterator;
124 
125  private:
126  transform_array _transforms;
127  size_t _index = 0;
128 
129  public:
130 
131  inline const transform_array&
132  transformations() const {
133  return this->_transforms;
134  }
135 
136  inline size_t index() const { return this->_index; }
137 
138  inline void
139  undo() {
140  if (index() == 0) { return; };
141  --this->_index;
142  }
143 
144  inline void
145  redo() {
146  if (index() == this->_transforms.size()) { return; };
147  ++this->_index;
148  }
149 
150  inline void
151  clear() {
152  this->_transforms.clear();
153  this->_index = 0;
154  }
155 
156  inline const_iterator
157  begin() const {
158  return this->_transforms.begin();
159  }
160 
161  inline const_iterator
162  end() const {
163  return this->begin() + this->index();
164  }
165 
166  inline size_t
167  size() const {
168  return this->_index;
169  }
170 
171  inline void
172  push_back(transform_type t) {
173  auto& ts = this->_transforms;
174  ts.resize(this->_index);
175  this->_transforms.push_back(t);
176  ++this->_index;
177  }
178 
179  };
180 
181  template <class T>
182  std::ostream&
183  operator<<(std::ostream& out, const Transform_sequence<T>& rhs);
184 
185  template <class T>
186  std::istream&
187  operator>>(std::istream& in, Transform_sequence<T>& rhs);
188 
189  template <class T>
191  to_string(const Transform_sequence<T>& rhs);
192 
193  template <class T>
194  sqlite::cstream&
195  operator>>(sqlite::cstream& in, Transform_sequence<T>& rhs);
196 
197  }
198 
199 }
200 
201 #endif // vim:filetype=cpp
T to_string(T... args)
Main namespace.
Definition: convert.hh:9