riCOM_cpp
This repository contains the C++ implementation of the riCOM (Real Time Centre Of Mass) algorithm for 4D Scanning electron microscopy.
Loading...
Searching...
No Matches
ImGuiImageWindow.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Thomas Friedrich, Chu-Ping Yu,
2 * University of Antwerp - All Rights Reserved.
3 * You may use, distribute and modify
4 * this code under the terms of the GPL3 license.
5 * You should have received a copy of the GPL3 license with
6 * this file. If not, please visit:
7 * https://www.gnu.org/licenses/gpl-3.0.en.html
8 *
9 * Authors:
10 * Thomas Friedrich <thomas.friedrich@uantwerpen.be>
11 * Chu-Ping Yu <chu-ping.yu@uantwerpen.be>
12 */
13
14#include <vector>
15#include <string>
16#include <stdio.h>
17#include <algorithm>
18#include <SDL.h>
19#include <SDL_opengl.h>
20
21#include "tinycolormap.hpp"
22#include "fft2d.hpp"
23
24#include "imgui.h"
25#include "imgui_impl_sdl.h"
26#include "imgui_impl_opengl3.h"
27#include "imgui_stdlib.h"
28#include "imgui_internal.h"
29#include "imfilebrowser.h"
30
31#include "GuiUtils.h"
32
33enum class GIM_Flags : unsigned char
34{
35 None = 0,
36 SaveImButton = 1 << 1,
37 SaveDataButton = 1 << 2,
38 ColormapSelector = 1 << 3,
39 FftButton = 1 << 4,
40 PowerSlider = 1 << 5,
41};
42
45
46template <class T>
48{
49public:
50 ImGuiImageWindow(const std::string &title, GLuint *tex_id, bool auto_render, int data_cmap, GIM_Flags flags = GIM_Flags::None, bool *visible = nullptr);
51 void set_data(int width, int height, std::vector<T> *data);
52 void render_window(bool b_redraw, int last_y, int render_update_offset, bool b_trigger_update);
53 void render_window(bool b_redraw, int last_y, bool b_trigger_update);
54 void reset_min_max();
55 void set_nx_ny(int width, int height);
56 bool *pb_open;
59
60private:
61 // Window properties
62 std::string title;
63 GIM_Flags flags;
64 // ImVec2 pos;
65 ImVec2 size;
66 ImVec2 uv_min;
67 ImVec2 uv_max;
68 ImVec4 tint_col;
69 ImVec4 border_col;
70
71 // Interfaces
72 ImGuiIO &io = ImGui::GetIO();
73 ImGui::FileBrowser saveFileDialog;
74 ImGui::FileBrowser saveDataDialog;
75
76 // Image properties
77 float start_x, start_y; // Scrolling/Panning positions
78 float start_xs, start_ys; // Scrolling/Panning positions
79 const char *cmaps[13] = {"Parula", "Heat", "Jet", "Turbo", "Hot", "Gray", "Magma", "Inferno", "Plasma", "Viridis", "Cividis", "Github", "HSV"};
80 const char *bin_options[4] = {"1x1", "2x2", "4x4", "8x8"};
81 int data_cmap;
82 float zoom;
83 float power;
84 bool auto_render;
85 int bin_factor;
86 int bin_factor_idx;
87
88 // Data Properties
89 int nx;
90 int ny;
91 int nxy;
92 int last_y;
93 int last_idr;
94 int last_img;
95 int render_update_offset; // Accounts for ricom Kernel size
96 float data_min;
97 float data_max;
98 float data_range;
99 std::vector<T> *data;
100 bool b_data_set;
101
102 // FFT data
103 std::vector<std::complex<float>> data_fft;
104 std::vector<float> data_fft_f;
105 std::vector<std::complex<float>> data_val;
106
107 // Surface and Texture
108 SDL_Surface *sdl_srf;
109 GLuint *tex_id;
110
111 // Methods
112 inline void render_image(int ye);
113 inline void render_image();
114 inline void set_min_max();
115 inline void set_min_max(int last_y);
116 inline void reset_limits();
117 inline void set_pixel(int idx, int idy);
118 inline void set_pixel_binned(int bx, int by);
119 inline void recreate_surface();
120 inline void compute_fft();
121 inline bool has(GIM_Flags flag);
122 inline bool detect_frame_switch(int &fr_count);
123 inline float get_val(int idx);
124 inline void value_tooltip(const int x, const int y, const float zoom);
125};
GIM_Flags
@ ColormapSelector
GIM_Flags operator|(GIM_Flags lhs, GIM_Flags rhs)
GIM_Flags operator&(GIM_Flags lhs, GIM_Flags rhs)
void set_nx_ny(int width, int height)
void set_data(int width, int height, std::vector< T > *data)
ImGuiImageWindow< float > * fft_window
void render_window(bool b_redraw, int last_y, int render_update_offset, bool b_trigger_update)