Skip to content

Commit 98d430b

Browse files
committed
Improve irregular wave visualization performance
- Pre-compute wave elevation for unique grid vertices before copying to triangle soup - Cache amplitude and angular frequency arrays in IrregularWaves
1 parent 38377d6 commit 98d430b

4 files changed

Lines changed: 162 additions & 353 deletions

File tree

demos/sphere/sphere_irreg_waves.cpp

Lines changed: 0 additions & 306 deletions
This file was deleted.

include/hydroc/waves/irregular_wave.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,26 @@ class IrregularWaves : public WaveBase {
7171
Eigen::VectorXd wavenumbers_;
7272
Eigen::VectorXd wave_phases_;
7373

74+
// -------------------------------------------------------------------------
75+
// Pre-computed arrays for fast elevation calculation.
76+
// These are computed once from the spectrum and reused for every GetElevation() call.
77+
// This optimization is critical for real-time visualization where GetElevation()
78+
// may be called thousands of times per frame (once per water surface grid point).
79+
// -------------------------------------------------------------------------
80+
81+
/// Wave amplitude for each frequency component [m].
82+
/// Computed as: A_i = sqrt(2 * S(f_i) * df_i), where S is the spectral density.
83+
Eigen::VectorXd amplitudes_;
84+
85+
/// Angular frequency for each component [rad/s].
86+
/// Computed as: omega_i = 2 * pi * f_i
87+
Eigen::VectorXd angular_freqs_;
88+
7489
void InitializeIRFVectors();
90+
91+
/// Pre-compute amplitudes_ and angular_freqs_ arrays from the spectrum.
92+
/// Called automatically after CreateSpectrum(). Must be called before GetElevation().
93+
void PrecomputeAmplitudes();
7594
void ReadEtaFromFile();
7695
void CreateFreeSurfaceElevation();
7796

0 commit comments

Comments
 (0)