riCOM_cpp
This repository contains the C++ implementation of the riCOM (Real Time Centre Of Mass) algorithm for 4D Scanning electron microscopy.
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 
33 enum 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 
46 template <class T>
48 {
49 public:
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 
60 private:
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  int data_cmap;
81  float zoom;
82  float power;
83  bool auto_render;
84 
85  // Data Properties
86  int nx;
87  int ny;
88  int nxy;
89  int last_y;
90  int last_idr;
91  int last_img;
92  int render_update_offset; // Accounts for ricom Kernel size
93  float data_min;
94  float data_max;
95  float data_range;
96  std::vector<T> *data;
97  bool b_data_set;
98 
99  // FFT data
100  std::vector<std::complex<float>> data_fft;
101  std::vector<float> data_fft_f;
102  std::vector<std::complex<float>> data_val;
103 
104  // Surface and Texture
105  SDL_Surface *sdl_srf;
106  GLuint *tex_id;
107 
108  // Methods
109  inline void render_image(int ye);
110  inline void render_image();
111  inline void set_min_max();
112  inline void set_min_max(int last_y);
113  inline void reset_limits();
114  inline void set_pixel(int idx, int idy);
115  inline void compute_fft();
116  inline bool has(GIM_Flags flag);
117  inline bool detect_frame_switch(int &fr_count);
118  inline float get_val(int idx);
119  inline void value_tooltip(const int x, const int y, const float zoom);
120 };
GIM_Flags
@ ColormapSelector
GIM_Flags operator|(GIM_Flags lhs, GIM_Flags rhs)
GIM_Flags operator&(GIM_Flags lhs, GIM_Flags rhs)
ImGuiImageWindow(const std::string &title, GLuint *tex_id, bool auto_render, int data_cmap, GIM_Flags flags=GIM_Flags::None, bool *visible=nullptr)
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)