-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgui.cpp
More file actions
184 lines (143 loc) · 5.58 KB
/
gui.cpp
File metadata and controls
184 lines (143 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "gui.h"
#include <iostream>
float ui_scale = 1.5f; // scale value for the UI and UI text
//float a_slider_value; // UI variable used to store the value of a floating point slider widget
bool reset = false;
bool num_file = false;
bool rgb_file = false;
extern float gui_VolumeSize[];
extern float gui_VolumeSlice[];
extern float coords[];
extern bool window_focused;
bool button_click = false;
void LoadVolume(std::string filepath);
void glfw_error_callback(int error, const char* description)
{
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
}
GLFWwindow* InitGLFW() {
GLFWwindow* window;
// Setup window
glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit())
return NULL;
// GL 3.0 + GLSL 130
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
// Create window with graphics context
window = glfwCreateWindow(1600, 1200, "ImGui GLFW+OpenGL3 Hello World Program", NULL, NULL);
if (window == NULL)
return NULL;
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
return window;
}
/// <summary>
/// Initialize the GUI
/// </summary>
/// <param name="window">Pointer to the GLFW window that will be used for rendering</param>
/// <param name="glsl_version">Version of GLSL that will be used</param>
void InitUI(GLFWwindow* window, const char* glsl_version) {
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
ImGui::GetStyle().ScaleAllSizes(ui_scale);
ImGui::GetIO().FontGlobalScale = ui_scale;
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
// Load Fonts
io.Fonts->AddFontFromFileTTF("Roboto-Medium.ttf", ui_scale * 16.0f);
}
/// <summary>
/// Destroys the ImGui rendering interface (usually called when the program closes)
/// </summary>
void DestroyUI() {
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
/// <summary>
/// This function renders the user interface every frame
/// </summary>
void RenderUI() {
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Display a Demo window showing what ImGui is capable of
// See https://pthom.github.io/imgui_manual_online/manual/imgui_manual.html for code details
//ImGui::ShowDemoWindow();
// Hello World GUI Window
{
float old_size = ImGui::GetFont()->Scale;
ImGui::GetFont()->Scale *= 0.7;
ImGui::PushFont(ImGui::GetFont());
static float f = 0.0f;
static int counter = 0;
ImGui::Begin("Volume Slicer");
///HELIA - updates here
window_focused = (ImGui::IsWindowHovered() || ImGui::IsWindowFocused()) ? true : false;
//Opens File Dialog
if (ImGui::Button("Open File Dialog"))
{
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".npy,.bmp,.cpp,.h,.hpp", ".");
}
if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey"))
{
if (ImGuiFileDialog::Instance()->IsOk())
{
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
LoadVolume(filePathName);
}
ImGuiFileDialog::Instance()->Close();
}
// Adjusting the size of the volume along each axis
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(230, 0, 0, 255));
ImGui::Text("\t\tX\t\t");
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 153, 51, 255));
ImGui::Text("\t\tY\t\t");
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 102, 255, 255));
ImGui::Text("\t\tZ");
ImGui::PopStyleColor(3);
ImGui::SliderFloat3("Volume Size", gui_VolumeSize, 0.25f, 2.0f);
ImGui::SliderFloat3("Volume Slice", gui_VolumeSlice, 0.0f, 1.0f);
ImGui::Spacing();
reset = ImGui::Button("Reset", ImVec2(70, 35));
ImGui::Spacing();
if (ImGui::BeginTable("Coordinates", 2, ImGuiTableFlags_Resizable + ImGuiTableFlags_Borders, ImVec2(0.0f, 5.0f), 2.0f))
{
ImGui::TableSetupColumn("Axis");
ImGui::TableSetupColumn("Value");
ImGui::TableHeadersRow();
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("X");
ImGui::TableNextColumn();
ImGui::Text("%f", coords[0]);
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Y");
ImGui::TableNextColumn();
ImGui::Text("%f", coords[1]);
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Z");
ImGui::TableNextColumn();
ImGui::Text("%f", coords[2]);
ImGui::EndTable();
}
ImGui::GetFont()->Scale = old_size;
ImGui::PopFont();
ImGui::End();
}
//ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); // Render a separate window showing the FPS
ImGui::Render(); // Render all windows
}