Virtual Testbed
Ship dynamics simulator for extreme conditions
vessel.hh
1 #ifndef VTESTBED_VSL_VESSEL_HH
2 #define VTESTBED_VSL_VESSEL_HH
3 
4 #include <iosfwd>
5 #include <string>
6 #include <vector>
7 
8 #include <blitz/array.h>
9 
10 #include <vtestbed/geometry/polygon.hh>
11 #include <vtestbed/iges/types.hh>
12 #include <vtestbed/vsl/description.hh>
13 #include <vtestbed/vsl/name.hh>
14 
15 namespace vtb {
16 
18  namespace vsl {
19 
20  template <class T> class Section;
21  template <class T> class Vessel;
22 
24  template <class T>
25  class Section {
26 
27  private:
28  using vec2 = blitz::TinyVector<T,2>;
29  using vec3 = blitz::TinyVector<T,3>;
30  using vertex_array = std::vector<vec3>;
31  using frame_container = std::vector<vertex_array>;
32  using polygon_type = vtb::geometry::Polygon<T,2>;
33 
34  private:
35  frame_container _frames;
36  frame_container _bottom_frames;
37  frame_container _top_frames;
38  vertex_array _arr;
39  vertex_array _terminal_frame;
40  polygon_type _polygon;
41  vertex_array _width;
42 
43  public:
44  inline const frame_container& bottom_frames() const { return this->_bottom_frames; }
45  inline const frame_container& top_frames() const { return this->_top_frames; }
46  inline const frame_container& frames() const { return this->_frames; }
47  inline const vertex_array& terminal_frame() const { return this->_terminal_frame; }
48  inline const vertex_array& polyline() const { return this->_arr; }
49  void clear();
50 
51  friend class Vessel<T>;
52 
53  private:
54  void read_vertices_zx(std::istream& in);
55  void read_vertices_zy(std::istream& in);
56  void read_frame(std::istream& in);
57  void aft_width();
58  void bow_width();
59  void aft_polygon();
60  void bow_polygon();
62  void clip_to_polygon(size_t begin_offset, size_t end_offset);
63  void aft_generate_horizontal_frames();
64  void bow_generate_horizontal_frames();
65  void bow_terminal_frame();
66  void main_generate_horizontal_frames();
67 
68  };
69 
82  template <class T>
83  class Vessel {
84 
85  private:
86  using vec2 = blitz::TinyVector<T,2>;
87  using vec3 = blitz::TinyVector<T,3>;
88  using vertex_array = std::vector<vec3>;
89  using frame_container = std::vector<vertex_array>;
90  using section_type = Section<T>;
91 
92  private:
93  enum class Reading {
94  Name, Size, Extents,
95  Aft, AftWidth,
96  FrameStart, Frame, FrameEnd,
97  BowWidth, Bow,
98  End
99  };
100 
101  private:
102  std::string _filename;
103  Name _name;
104  Description _description;
105  size_t _nframes = 0;
106  size_t _middleframe = 0;
107  T _length{0};
108  T _beam{0};
109  T _draught{0};
110  vertex_array _aft_width;
111  vertex_array _bow_width;
112  section_type _aft_section;
113  section_type _bow_section;
114  section_type _main_section;
115 
116  public:
117  void read(std::istream& in);
118  void clear();
119  void dump(std::ostream& out) const;
120  void dump_gnuplot(std::ostream& out) const;
121  void gnuplot_sections(std::ostream& out) const;
122  void gnuplot_bow(std::ostream& out) const;
123 
124  inline const Name& name() const { return this->_name; }
125  inline T length() const { return this->_length; }
126  inline T beam() const { return this->_beam; }
127  inline T draught() const { return this->_draught; }
128  inline const section_type& aft() const { return this->_aft_section; }
129  inline const section_type& bow() const { return this->_bow_section; }
130  inline const section_type& main_section() const { return this->_main_section; }
131  inline void filename(const std::string& filename) { this->_filename = filename; }
132  inline const std::string& filename() const { return this->_filename; }
133  inline const Description& description() const { return this->_description; }
134 
135  private:
136  void read_line(std::istream& str, Reading& state);
137  void read_size(std::istream& in);
138  void read_extents(std::istream& in);
139  void set_bow_and_aft_x_coordinates();
140  void decompose();
141  void detach_aft(T max_x);
142  void detach_bow(T min_x);
143  void sculpt_main();
144  void sculpt_aft();
145  void sculpt_bow();
146  std::string frame_string() const;
147 
148  };
149 
150  template <class T>
151  inline std::istream&
152  operator>>(std::istream& in, Vessel<T>& rhs) {
153  rhs.read(in);
154  return in;
155  }
156 
157  }
158 
159 }
160 
161 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9
Section
Section codes.
Definition: section.hh:9