Harmony
HARMONic stabilitY assessment of PE-penetrated power systems
Loading...
Searching...
No Matches
Visualization.cpp File Reference

Implementation of Interactive ImGui/ImPlot visualization for solver results. More...

#include "Constants.h"
#include "Visualization.h"
#include "ui/harmony_banner_gui.h"
#include "stb_image_write.h"
Include dependency graph for Visualization.cpp:

Macros

#define STB_IMAGE_WRITE_IMPLEMENTATION
 

Functions

static void glfw_error_callback (int error, const char *desc)
 
static void init_gui ()
 
static void draw_plot_tabs (const char *tabBarId)
 
static void gui_loop ()
 
static void ensure_running ()
 
static void add_tab (const std::string &title, std::function< void()> fn)
 
void visualization_set_embedded_mode (const bool enabled)
 Use the host ImGui/GLFW context (HarmonyUI) instead of a background window.
 
void visualization_stop ()
 Closes the visualization window and stops the GUI thread.
 
bool visualization_is_running ()
 Returns whether the visualization window is currently open.
 
bool visualization_has_tabs ()
 Returns whether plot tabs are registered.
 
void visualization_clear_tabs ()
 Remove all registered plot tabs (e.g.
 
void visualization_draw_embedded (const char *tabBarId)
 Draw plot tabs inside the current ImGui window (embedded / HarmonyUI mode).
 
void visualization_process_pending_save (GLFWwindow *window)
 Capture a pending PNG save after ImGui::Render() on window.
 
void visualization_wait ()
 Block until the window is closed by the user.
 
void visualization_save_tab (const std::string &tab_title, const std::filesystem::path &output_dir)
 Schedule a PNG capture of the named tab on the next rendered frame.
 
std::vector< std::string > visualization_tab_titles ()
 Titles of tabs currently registered in the visualization window.
 
void add_plot_tab (const std::string &title, std::function< void()> fn)
 Public interface used by external modules (e.g. viz_opf).
 
void bode_plot_implot (const std::vector< double > &freq, const std::vector< std::vector< double > > &mag_dB, const std::vector< std::vector< double > > &phase_deg, const std::vector< std::string > &labels, const std::string &title)
 Opens a Bode magnitude/phase plot in the visualization window.
 
void nyquist_plot_implot (const std::vector< std::vector< std::complex< double > > > &H_data, const std::vector< std::string > &labels, const std::string &title)
 Opens a Nyquist plot in the visualization window.
 
void plot_eigenvalues_implot (const std::vector< std::complex< double > > &eigvals, const std::string &title)
 Plots eigenvalues in the complex plane.
 
void plot_participation_factors_implot (const std::vector< std::vector< double > > &P, const std::vector< std::string > &state_labels, const std::vector< std::string > &mode_labels, const std::string &title)
 Plots participation factor heatmap (states vs modes).
 
void plot_abc_waveforms_implot (const std::vector< double > &t, const Eigen::MatrixXd &Xabc, const std::string &title)
 Plots three-phase abc waveforms over time.
 
void plot_abc_groups_implot (const std::vector< double > &t, const std::vector< Eigen::MatrixXd > &Xabc_groups, const std::string &title)
 Plots multiple abc waveform groups on shared axes.
 
void viz_opf (const OPFVisualData &d)
 Registers an "AC/DC OPF" network diagram tab in the visualization window.
 

Detailed Description

Implementation of Interactive ImGui/ImPlot visualization for solver results.

Macro Definition Documentation

◆ STB_IMAGE_WRITE_IMPLEMENTATION

#define STB_IMAGE_WRITE_IMPLEMENTATION

Function Documentation

◆ add_plot_tab()

void add_plot_tab ( const std::string &  title,
std::function< void()>  fn 
)

Public interface used by external modules (e.g. viz_opf).

Registers a custom ImGui/ImPlot draw callback as a new tab.

References add_tab().

◆ add_tab()

static void add_tab ( const std::string &  title,
std::function< void()>  fn 
)
static

◆ bode_plot_implot()

void bode_plot_implot ( const std::vector< double > &  freq,
const std::vector< std::vector< double > > &  mag_dB,
const std::vector< std::vector< double > > &  phase_deg,
const std::vector< std::string > &  labels,
const std::string &  title 
)

Opens a Bode magnitude/phase plot in the visualization window.

Parameters
freqFrequency axis (Hz).
mag_dBMagnitude in dB, one vector per trace.
phase_degPhase in degrees, one vector per trace.
labelsTrace legend labels.
titlePlot window title.

References add_tab(), j, and kHarmonyPlotPanelHeightPx.

Referenced by StabilityEstimate::bodeplotTF(), and Element::plotYParameters().

◆ draw_plot_tabs()

static void draw_plot_tabs ( const char *  tabBarId)
static

◆ ensure_running()

static void ensure_running ( )
static

References gui_loop().

Referenced by add_tab().

◆ glfw_error_callback()

static void glfw_error_callback ( int  error,
const char *  desc 
)
static

Referenced by init_gui().

◆ gui_loop()

static void gui_loop ( )
static

References draw_plot_tabs(), and init_gui().

Referenced by ensure_running().

◆ init_gui()

static void init_gui ( )
static

◆ nyquist_plot_implot()

void nyquist_plot_implot ( const std::vector< std::vector< std::complex< double > > > &  H_data,
const std::vector< std::string > &  labels,
const std::string &  title 
)

Opens a Nyquist plot in the visualization window.

Parameters
H_dataComplex frequency response, one vector per trace.
labelsTrace legend labels.
titlePlot window title.

References add_tab(), and j.

Referenced by StabilityEstimate::nyquistplotTF().

◆ plot_abc_groups_implot()

void plot_abc_groups_implot ( const std::vector< double > &  t,
const std::vector< Eigen::MatrixXd > &  Xabc_groups,
const std::string &  title 
)

Plots multiple abc waveform groups on shared axes.

Parameters
tTime axis (s).
Xabc_groupsOne 3N matrix per signal group.
titlePlot window title.

References add_tab(), and kHarmonyPlotWaveformHeightPx.

Referenced by example_DQsym_DSSS2(), example_DQsym_RLC(), and DQsym::plot().

◆ plot_abc_waveforms_implot()

void plot_abc_waveforms_implot ( const std::vector< double > &  t,
const Eigen::MatrixXd &  Xabc,
const std::string &  title 
)

Plots three-phase abc waveforms over time.

Parameters
tTime axis (s).
XabcWaveform matrix (3 rows N samples).
titlePlot window title.

References add_tab().

Referenced by example_DQsym_math_operations().

◆ plot_eigenvalues_implot()

void plot_eigenvalues_implot ( const std::vector< std::complex< double > > &  eigvals,
const std::string &  title 
)

Plots eigenvalues in the complex plane.

Parameters
eigvalsList of eigenvalues.
titlePlot window title.

References add_tab(), and kHarmonyPlotEigenHeightPx.

Referenced by Converter::plotEigenvalues().

◆ plot_participation_factors_implot()

void plot_participation_factors_implot ( const std::vector< std::vector< double > > &  P,
const std::vector< std::string > &  state_labels,
const std::vector< std::string > &  mode_labels,
const std::string &  title 
)

Plots participation factor heatmap (states vs modes).

Parameters
PParticipation factor matrix [state][mode].
state_labelsRow labels (state names).
mode_labelsColumn labels (mode indices/names).
titlePlot window title.

References add_tab(), and j.

Referenced by Converter::plotParticipationFactors().

◆ visualization_clear_tabs()

void visualization_clear_tabs ( )

Remove all registered plot tabs (e.g.

before a new run).

◆ visualization_draw_embedded()

void visualization_draw_embedded ( const char *  tabBarId)

Draw plot tabs inside the current ImGui window (embedded / HarmonyUI mode).

References draw_plot_tabs().

◆ visualization_has_tabs()

bool visualization_has_tabs ( )

Returns whether plot tabs are registered.

◆ visualization_is_running()

bool visualization_is_running ( )

Returns whether the visualization window is currently open.

Returns
True if the GUI is running.

Referenced by runJsonSimulation().

◆ visualization_process_pending_save()

void visualization_process_pending_save ( GLFWwindow *  window)

Capture a pending PNG save after ImGui::Render() on window.

Referenced by runHarmonyLauncher().

◆ visualization_save_tab()

void visualization_save_tab ( const std::string &  tab_title,
const std::filesystem::path &  output_dir 
)

Schedule a PNG capture of the named tab on the next rendered frame.

Schedules a PNG capture of the named tab on the next rendered frame.

The file is written as "<tab_title>.png" in the working directory. Thread-safe: can be called from any thread.

◆ visualization_set_embedded_mode()

void visualization_set_embedded_mode ( bool  enabled)

Use the host ImGui/GLFW context (HarmonyUI) instead of a background window.

Call before any simulation runs. Prevents a second GLFW/ImGui context that can crash with ImGui focus-scope errors.

Referenced by runHarmonyLauncher().

◆ visualization_stop()

void visualization_stop ( )

Closes the visualization window and stops the GUI thread.

Referenced by runHarmonyLauncher().

◆ visualization_tab_titles()

std::vector< std::string > visualization_tab_titles ( )

Titles of tabs currently registered in the visualization window.

◆ visualization_wait()

void visualization_wait ( )

Block until the window is closed by the user.

Blocks until the user closes the visualization window.

Referenced by runJsonSimulation().

◆ viz_opf()