Tatooine
vtk_line_reader.h
Go to the documentation of this file.
1#ifndef TATOOINE_FLOWEXPLORER_NODES_VTK_LINE_READER_H
2#define TATOOINE_FLOWEXPLORER_NODES_VTK_LINE_READER_H
3//==============================================================================
6#include <tatooine/flowexplorer/line_shader.h>
8#include <tatooine/line.h>
10
11#include <mutex>
12//==============================================================================
14//==============================================================================
15struct vtk_line_reader : renderable<vtk_line_reader> {
16 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
17 // internal
18 private:
21
22 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23 // user data
24 std::string m_path;
25 std::array<GLfloat, 4> m_line_color{0.0f, 0.0f, 0.0f, 1.0f};
26 int m_line_width = 1;
27
28 public:
29 //----------------------------------------------------------------------------
30 // ctors
31 //----------------------------------------------------------------------------
32 vtk_line_reader(flowexplorer::scene& s) : renderable{"VTK Line Reader", s} {}
33
34 //----------------------------------------------------------------------------
35 // methods
36 //----------------------------------------------------------------------------
37 auto render(mat4f const& P, mat4f const& V) -> void override {
38 auto& shader = line_shader::get();
39 shader.bind();
40 shader.set_color(m_line_color[0], m_line_color[1], m_line_color[2],
41 m_line_color[3]);
42 shader.set_projection_matrix(P);
43 shader.set_modelview_matrix(V);
45 m_gpu_data.draw_lines();
46 }
47 //----------------------------------------------------------------------------
48 // setters / getters
49 //----------------------------------------------------------------------------
50 auto path() -> auto& { return m_path; }
51 auto path() const -> auto const& { return m_path; }
52 //----------------------------------------------------------------------------
53 auto update(std::chrono::duration<double> const& /*dt*/) -> void override {}
54 //----------------------------------------------------------------------------
55 auto draw_properties() -> bool override {
56 bool changed = false;
57 if (ImGui::Button("open")) {
58 scene().window().open_file_explorer(
59 "open vtk line", std::vector{".vtk"}, *this);
60 }
61 ImGui::SameLine();
62 if (ImGui::Button("reload")) {
63 read();
64 }
65 changed |= ImGui::SliderInt("line width", &m_line_width, 1, 50);
66 changed |= ImGui::ColorEdit4("line color", m_line_color.data());
67 return changed;
68 }
69 //----------------------------------------------------------------------------
70 auto on_path_selected(std::string const& path) -> void override {
71 m_path = path;
72 read();
73 }
74 //----------------------------------------------------------------------------
75 auto read() -> void {
76 m_line3 = m_line3.read_vtk(m_path).front();
77
78
79 bool insert_seg = false;
80 int i = 0;
81 m_gpu_data.clear();
82 for (auto const& y : m_line3.vertices()) {
83 m_gpu_data.vertexbuffer().push_back(vec3f{static_cast<GLfloat>(y(0)),
84 static_cast<GLfloat>(y(1)),
85 static_cast<GLfloat>(y(2))});
86 if (insert_seg) {
87 m_gpu_data.indexbuffer().push_back(i - 1);
88 m_gpu_data.indexbuffer().push_back(i);
89 } else {
90 insert_seg = true;
91 }
92 ++i;
93 }
94 }
95 auto is_transparent() const -> bool override { return m_line_color[3] < 255; }
96};
97//==============================================================================
98} // namespace tatooine::flowexplorer::nodes
99//==============================================================================
102 TATOOINE_REFLECTION_INSERT_METHOD(path, path()))
103#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
Definition: vtk_line_reader.h:15
auto path() const -> auto const &
Definition: vtk_line_reader.h:51
auto read() -> void
Definition: vtk_line_reader.h:75
gl::indexeddata< vec3f > m_gpu_data
Definition: vtk_line_reader.h:19
auto path() -> auto &
Definition: vtk_line_reader.h:50
auto is_transparent() const -> bool override
Definition: vtk_line_reader.h:95
auto draw_properties() -> bool override
Definition: vtk_line_reader.h:55
line< real_type, 3 > m_line3
Definition: vtk_line_reader.h:20
std::string m_path
Definition: vtk_line_reader.h:24
int m_line_width
Definition: vtk_line_reader.h:26
vtk_line_reader(flowexplorer::scene &s)
Definition: vtk_line_reader.h:32
auto render(mat4f const &P, mat4f const &V) -> void override
Definition: vtk_line_reader.h:37
std::array< GLfloat, 4 > m_line_color
Definition: vtk_line_reader.h:25
auto update(std::chrono::duration< double > const &) -> void override
Definition: vtk_line_reader.h:53
auto on_path_selected(std::string const &path) -> void override
Definition: vtk_line_reader.h:70
Definition: renderable.h:42
Definition: scene.h:17
auto scene() const -> auto const &
Definition: node.h:72
Definition: line.h:35
auto vertices() const
Definition: line.h:250
static auto read_vtk(std::string const &filepath)
Definition: line.h:626
Definition: mat.h:14
Definition: vec.h:12