libVFRendering  0.14.0

A vector field rendering library
View.hxx
1 #ifndef VFRENDERING_VIEW_HXX
2 #define VFRENDERING_VIEW_HXX
3 
4 #include <array>
5 #include <memory>
6 
7 #include <glm/glm.hpp>
8 
9 #include <VFRendering/Options.hxx>
10 #include <VFRendering/FPSCounter.hxx>
11 #include <VFRendering/Utilities.hxx>
12 #include <VFRendering/Geometry.hxx>
13 
14 namespace VFRendering {
15 class RendererBase;
16 
17 enum class CameraMovementModes {
18  TRANSLATE,
19  ROTATE_BOUNDED,
20  ROTATE_FREE
21 };
22 
23 class View {
24 public:
25  enum Option {
26  SYSTEM_CENTER,
27  VERTICAL_FIELD_OF_VIEW,
28  BACKGROUND_COLOR,
29  COLORMAP_IMPLEMENTATION,
30  IS_VISIBLE_IMPLEMENTATION,
31  CAMERA_POSITION,
32  CENTER_POSITION,
33  UP_VECTOR,
34  CLEAR
35  };
36 
37  View();
38  virtual ~View();
39  void draw();
40 
41  void mouseMove(const glm::vec2& position_before, const glm::vec2& position_after, CameraMovementModes mode);
42  void mouseScroll(const float& wheel_delta);
43  void setFramebufferSize(float width, float height);
44  float getFramerate() const;
45  glm::vec2 getFramebufferSize() const;
46 
47  void updateOptions(const Options& options);
48  template<int index>
49  void setOption(const typename Options::Type<index>::type& value);
50  void options(const Options& options);
51  const Options& options() const;
52  template<int index>
53  typename Options::Type<index>::type getOption() const;
54 
55  void renderers(const std::vector<std::pair<std::shared_ptr<RendererBase>, std::array<float, 4>>>& renderers, bool update_renderer_options=true);
56 
57 private:
58  void setCamera(glm::vec3 camera_position, glm::vec3 center_position, glm::vec3 up_vector);
59  void optionsHaveChanged(const std::vector<int>& changed_options);
60  void initialize();
61 
62  bool m_is_initialized = false;
63  std::vector<std::pair<std::shared_ptr<RendererBase>, std::array<float, 4>>> m_renderers;
64  Utilities::FPSCounter m_fps_counter;
65  glm::vec2 m_framebuffer_size;
66  bool m_is_centered = false;
67 
68  Options m_options;
69 };
70 
71 template<int index>
72 void View::setOption(const typename Options::Type<index>::type& value) {
73  updateOptions(Options::withOption<index>(value));
74 }
75 
76 template<int index>
77 typename Options::Type<index>::type View::getOption() const {
78  return m_options.get<index>();
79 }
80 
81 namespace Utilities {
83 template<>
84 struct Options::Option<View::Option::SYSTEM_CENTER> {
85  glm::vec3 default_value = {0, 0, 0};
86 };
87 
89 template<>
90 struct Options::Option<View::Option::VERTICAL_FIELD_OF_VIEW> {
91  float default_value = 45.0;
92 };
93 
95 template<>
96 struct Options::Option<View::Option::BACKGROUND_COLOR> {
97  glm::vec3 default_value = {0, 0, 0};
98 };
99 
101 template<>
102 struct Options::Option<View::Option::COLORMAP_IMPLEMENTATION> {
103  std::string default_value = Utilities::getColormapImplementation(VFRendering::Utilities::Colormap::DEFAULT);
104 };
105 
107 template<>
108 struct Options::Option<View::Option::IS_VISIBLE_IMPLEMENTATION> {
109  std::string default_value = "bool is_visible(vec3 position, vec3 direction) { return true; }";
110 };
111 
113 template<>
114 struct Options::Option<View::Option::CAMERA_POSITION> {
115  glm::vec3 default_value = {14.5, 14.5, 30};
116 };
117 
119 template<>
120 struct Options::Option<View::Option::CENTER_POSITION> {
121  glm::vec3 default_value = {14.5, 14.5, 0};
122 };
123 
125 template<>
126 struct Options::Option<View::Option::UP_VECTOR> {
127  glm::vec3 default_value = {0, 1, 0};
128 };
129 
131 template<>
132 struct Options::Option<View::Option::CLEAR> {
133  bool default_value = true;
134 };
135 }
136 }
137 
138 #endif
VFRendering::Utilities::FPSCounter
Definition: FPSCounter.hxx:9
VFRendering::Utilities::Options
Definition: Options.hxx:12
VFRendering::Utilities::Options::Type
Definition: Options.hxx:20
VFRendering::View
Definition: View.hxx:23