riCOM_cpp
This repository contains the C++ implementation of the riCOM (Real Time Centre Of Mass) algorithm for 4D Scanning electron microscopy.
Classes | Namespaces | Functions
GuiUtils.h File Reference
#include <string>
#include <vector>
#include <complex>
#include <filesystem>
#include <SDL_image.h>
#include "imgui.h"
#include "imgui_internal.h"
#include "libnpy.hpp"
#include "tinycolormap.hpp"
Include dependency graph for GuiUtils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Main_Dock
 

Namespaces

 SDL_Utils
 

Functions

template<typename T >
void save_numpy (std::string *path, int nx, int ny, std::vector< T > *data)
 
void save_image (std::string *path, SDL_Surface *sdl_srf)
 
void v_splitter (float thickness, float &size0, const float &min_h, const float &max_h, const float &offset)
 
void SDL_Utils::draw_pixel (SDL_Surface *surface, int x, int y, float val, int col_map)
 
void SDL_Utils::draw_pixel (SDL_Surface *surface, int x, int y, float ang, float mag, int col_map)
 

Function Documentation

◆ save_image()

void save_image ( std::string *  path,
SDL_Surface *  sdl_srf 
)

Definition at line 30 of file GuiUtils.cpp.

31 {
32  std::string ext = std::filesystem::path(*path).extension().string();
33  if ((ext != ".png") && (ext != ".PNG"))
34  {
35  *path += ".png";
36  }
37  IMG_SavePNG(sdl_srf, path->c_str());
38 }

◆ save_numpy()

template<typename T >
void save_numpy ( std::string *  path,
int  nx,
int  ny,
std::vector< T > *  data 
)

Definition at line 17 of file GuiUtils.cpp.

18 {
19  std::string ext = std::filesystem::path(*path).extension().string();
20  if (ext != ".npy")
21  {
22  *path += ".npy";
23  }
24  const std::vector<long unsigned> shape{static_cast<long unsigned>(ny), static_cast<long unsigned>(nx)};
25  npy::SaveArrayAsNumpy(path->c_str(), false, shape.size(), shape.data(), *data);
26 }

◆ v_splitter()

void v_splitter ( float  thickness,
float &  size0,
const float &  min_h,
const float &  max_h,
const float &  offset 
)

Definition at line 41 of file GuiUtils.cpp.

42 {
43 
44  ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyle().Colors[ImGuiCol_ScrollbarGrab]);
45  ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetStyle().Colors[ImGuiCol_ScrollbarGrabHovered]);
46  ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetStyle().Colors[ImGuiCol_ScrollbarGrabActive]);
47  ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, ImGui::GetStyle().ScrollbarRounding);
48  ImGui::Button("v", ImVec2(-1, thickness));
49  ImGui::PopStyleColor(3);
50  ImGui::PopStyleVar(1);
51  if (ImGui::IsItemHovered() || ImGui::IsItemActive())
52  {
53  ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS);
54  }
55 
56  if (ImGui::IsItemActive())
57  {
58  float d = ImGui::GetMousePos().y - offset;
59  if (d < min_h)
60  size0 = min_h;
61  else if (d > max_h)
62  size0 = max_h;
63  else
64  size0 = d;
65  }
66 };