Tatooine
autonomous_particles_flowmap.h
Go to the documentation of this file.
1#ifndef TATOOINE_FLOWEXPLORER_NODES_AUTONOMOUS_PARTICLES_FLOWMAP_H
2#define TATOOINE_FLOWEXPLORER_NODES_AUTONOMOUS_PARTICLES_FLOWMAP_H
3//==============================================================================
4#include <tatooine/flowexplorer/line_shader.h>
8//==============================================================================
10//==============================================================================
11struct autonomous_particles_flowmap : renderable<autonomous_particles_flowmap> {
13 std::unique_ptr<unstructured_triangular_grid<double, 2>> m_mesh;
15 int m_line_width = 1;
16 std::array<GLfloat, 4> m_line_color{0.0f, 0.0f, 0.0f, 1.0f};
17 //============================================================================
20 "Autonomous Particles Flowmap", s,
22 virtual ~autonomous_particles_flowmap() = default;
23 //----------------------------------------------------------------------------
24 auto draw_properties() -> bool override {
25 bool changed = false;
26 if (m_currently_read_path.empty()) {
27 ImGui::Text("no dataset read");
28 } else {
29 ImGui::TextUnformatted(m_currently_read_path.c_str());
30 }
31 if (ImGui::Button("load double gyre autonomous adaptive forward")) {
32 load(
33 "/home/steve/libs/tatooine2/build/autonomous_particles/"
34 "doublegyre_autonomous_forward_flowmap.vtk");
35 changed = true;
36 }
37 ImGui::SameLine();
38 if (ImGui::Button("load double gyre autonomous adaptive backward")) {
39 load(
40 "/home/steve/libs/tatooine2/build/autonomous_particles/"
41 "doublegyre_autonomous_backward_flowmap.vtk");
42 changed = true;
43 }
44 if (ImGui::Button("load double gyre regular forward")) {
45 load(
46 "/home/steve/libs/tatooine2/build/autonomous_particles/"
47 "doublegyre_regular_forward_flowmap.vtk");
48 changed = true;
49 }
50 ImGui::SameLine();
51 if (ImGui::Button("load double gyre regular backward")) {
52 load(
53 "/home/steve/libs/tatooine2/build/autonomous_particles/"
54 "doublegyre_regular_backward_flowmap.vtk");
55 changed = true;
56 }
57 changed |= ImGui::SliderInt("line width", &m_line_width, 1, 50);
58 changed |= ImGui::ColorEdit4("line color", m_line_color.data());
59 return changed;
60 return changed;
61 }
62 auto load(filesystem::path const& path) -> void {
63 std::cerr << "loading ... ";
65 m_mesh = std::make_unique<unstructured_triangular_grid_2>(path);
66 {
67 m_edges.vertexbuffer().resize(m_mesh->vertices().size());
68 auto map = m_edges.vertexbuffer().wmap();
69 for (auto v : m_mesh->vertices()) {
70 map[v.i] = vec3f{m_mesh->at(v)(0), m_mesh->at(v)(1), 0.0f};
71 }
72 }
73 m_edges.indexbuffer().clear();
74 m_edges.indexbuffer().reserve(m_mesh->cells().size() * 6);
75 for (auto c : m_mesh->cells()) {
76 auto [v0, v1, v2] = m_mesh->at(c);
77 m_edges.indexbuffer().push_back(v0.i);
78 m_edges.indexbuffer().push_back(v1.i);
79 m_edges.indexbuffer().push_back(v1.i);
80 m_edges.indexbuffer().push_back(v2.i);
81 m_edges.indexbuffer().push_back(v2.i);
82 m_edges.indexbuffer().push_back(v0.i);
83 }
84 std::cerr << "done\n";
85 }
86 //------------------------------------------------------------------------------
87 auto render(mat4f const& P, mat4f const& V) -> void override {
88 if (m_edges.indexbuffer().size() > 0) {
89 auto& shader = line_shader::get();
90 shader.bind();
91 shader.set_projection_matrix(P);
92 shader.set_modelview_matrix(V);
94 shader.set_color(m_line_color[0], m_line_color[1], m_line_color[2],
95 m_line_color[3]);
96 m_edges.draw_lines();
97 }
98 }
99 //----------------------------------------------------------------------------
100 bool is_transparent() const override { return m_line_color[3] < 1; }
101 //----------------------------------------------------------------------------
102 auto data_available() const -> bool { return m_mesh != nullptr; }
103 auto mesh() const -> auto const& { return *m_mesh; }
104};
105//==============================================================================
106} // namespace tatooine::flowexplorer::nodes
107//==============================================================================
110 TATOOINE_REFLECTION_INSERT_METHOD(line_width, m_line_width),
111 TATOOINE_REFLECTION_INSERT_METHOD(line_color, m_line_color))
112#endif
Definition: indexeddata.h:13
TATOOINE_FLOWEXPLORER_REGISTER_RENDERABLE(tatooine::flowexplorer::nodes::aabb2d, TATOOINE_REFLECTION_INSERT_GETTER(min), TATOOINE_REFLECTION_INSERT_GETTER(max), TATOOINE_REFLECTION_INSERT_GETTER(line_width), TATOOINE_REFLECTION_INSERT_GETTER(line_color))
Definition: abcflow.h:7
DLL_API auto line_width(GLfloat width) -> void
auto constexpr map(F &&f, Ts &&... ts)
maps unary function f to all single parameters of parameter pack ts
Definition: map.h:10
Definition: autonomous_particles_flowmap.h:11
std::array< GLfloat, 4 > m_line_color
Definition: autonomous_particles_flowmap.h:16
auto draw_properties() -> bool override
Definition: autonomous_particles_flowmap.h:24
autonomous_particles_flowmap(flowexplorer::scene &s)
Definition: autonomous_particles_flowmap.h:18
std::unique_ptr< unstructured_triangular_grid< double, 2 > > m_mesh
Definition: autonomous_particles_flowmap.h:13
auto load(filesystem::path const &path) -> void
Definition: autonomous_particles_flowmap.h:62
int m_line_width
Definition: autonomous_particles_flowmap.h:15
auto render(mat4f const &P, mat4f const &V) -> void override
Definition: autonomous_particles_flowmap.h:87
std::string m_currently_read_path
Definition: autonomous_particles_flowmap.h:12
gl::indexeddata< vec3f > m_edges
Definition: autonomous_particles_flowmap.h:14
bool is_transparent() const override
Definition: autonomous_particles_flowmap.h:100
auto mesh() const -> auto const &
Definition: autonomous_particles_flowmap.h:103
auto data_available() const -> bool
Definition: autonomous_particles_flowmap.h:102
Definition: renderable.h:42
Definition: scene.h:17
Definition: mat.h:14
Definition: vec.h:12