libVFRendering  0.14.0

A vector field rendering library
IsosurfaceRenderer.hxx
1 #ifndef VFRENDERING_ISOSURFACE_RENDERER_HXX
2 #define VFRENDERING_ISOSURFACE_RENDERER_HXX
3 
4 #include <functional>
5 
6 #include <VFRendering/VectorFieldRenderer.hxx>
7 
8 namespace VFRendering {
10 public:
11 
12  typedef float isovalue_type;
13  typedef std::function<isovalue_type(const glm::vec3&, const glm::vec3&)> value_function_type;
14 
15  enum Option {
16  ISOVALUE = 700,
17  LIGHTING_IMPLEMENTATION,
18  VALUE_FUNCTION,
19  FLIP_NORMALS
20  };
21 
22  IsosurfaceRenderer(const View& view, const VectorField& vf);
23  virtual ~IsosurfaceRenderer();
24  virtual void draw(float aspect_ratio) override;
25  virtual void optionsHaveChanged(const std::vector<int>& changed_options) override;
26 
27 protected:
28  virtual void update(bool keep_geometry) override;
29 
30 private:
31  void updateShaderProgram();
32  void updateIsosurfaceIndices();
33  void initialize();
34 
35  bool m_is_initialized = false;
36  unsigned int m_program = 0;
37  unsigned int m_vao = 0;
38  unsigned int m_ibo = 0;
39  unsigned int m_position_vbo = 0;
40  unsigned int m_direction_vbo = 0;
41  unsigned int m_normal_vbo = 0;
42  unsigned int m_num_indices = 0;
43 
44  bool m_value_function_changed;
45  bool m_isovalue_changed;
46 };
47 
48 namespace Utilities {
49 template<>
50 struct Options::Option<IsosurfaceRenderer::Option::ISOVALUE> {
51  VFRendering::IsosurfaceRenderer::isovalue_type default_value = 0;
52 };
53 
54 template<>
55 struct Options::Option<IsosurfaceRenderer::Option::LIGHTING_IMPLEMENTATION> {
56  std::string default_value = "float lighting(vec3 position, vec3 normal) { return 1.0; }";
57 };
58 
59 template<>
60 struct Options::Option<IsosurfaceRenderer::Option::VALUE_FUNCTION> {
61  IsosurfaceRenderer::value_function_type default_value = [] (const glm::vec3& position, const glm::vec3& direction) {
62  (void)position;
63  return direction.z;
64  };
65 };
66 
67 template<>
68 struct Options::Option<IsosurfaceRenderer::Option::FLIP_NORMALS> {
69  bool default_value = false;
70 };
71 }
72 }
73 
74 #endif
VFRendering::VectorField
Definition: VectorField.hxx:16
VFRendering::IsosurfaceRenderer
Definition: IsosurfaceRenderer.hxx:9
VFRendering::VectorFieldRenderer
Definition: VectorFieldRenderer.hxx:13
VFRendering::View
Definition: View.hxx:23