From 8b544a6af98d905a7869241a61822598daf97334 2019-06-06 19:43:02 From: Alexis Jeandet Date: 2019-06-06 19:43:02 Subject: [PATCH] Some refac on Spectrograms Signed-off-by: Alexis Jeandet --- diff --git a/core b/core index 70d6748..c6cf2db 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 70d6748a06620f865b683c86c89cc27e1cb0d4b9 +Subproject commit c6cf2dba079da680390ae2de0522a39964c5e629 diff --git a/gui/src/Visualization/VisualizationGraphHelper.cpp b/gui/src/Visualization/VisualizationGraphHelper.cpp index e3aa60e..55dd14a 100644 --- a/gui/src/Visualization/VisualizationGraphHelper.cpp +++ b/gui/src/Visualization/VisualizationGraphHelper.cpp @@ -337,21 +337,112 @@ inline ColomapProperties CMAxisAnalysis(const TimeSeriesUtils::axis_properties& colormap_v_resolution }; } + +template +std::enable_if_t constexpr conditional_v(T first, U second) +{ + return first; +} + +template +std::enable_if_t constexpr conditional_v(T first, U second) +{ + return second; +} + +template inline std::vector> build_access_pattern(const std::vector& axis, const TimeSeriesUtils::axis_properties& axisProperties, const ColomapProperties& colormap_properties) { std::vector> access_pattern; - for (int index = 0, cel_index = axis.size() - 1; index < colormap_properties.v_size_px; index++) + for (int index = 0, axis_index = conditional_v(axis.size() - 1, 0), + data_index = conditional_v(axis.size() - 1, 0); + index < colormap_properties.v_size_px; index++) { - double current_y = pow(10., (axisProperties.max_resolution * index) + axisProperties.min); - if (current_y > axis[cel_index]) - cel_index--; - access_pattern.push_back({ index, cel_index }); + double current_y = (axisProperties.max_resolution * index) + axisProperties.min; + if (current_y > axis[axis_index]) + { + conditional_v( + [&axis_index]() { axis_index--; }, [&axis_index]() { axis_index++; })(); + conditional_v( + [&data_index]() { data_index--; }, [&data_index]() { data_index++; })(); + } + access_pattern.push_back({ index, data_index }); } return access_pattern; } +inline bool is_log(const std::vector& axis) +{ + if (axis.size() > 2) + { + auto first = axis.front(), midle = axis[axis.size() / 2], last = axis.back(); + auto error_linear = (midle - (last + first) / 2) / midle; + first = log10(first); + midle = log10(midle); + last = log10(last); + auto error_log = (midle - (last + first) / 2) / midle; + return error_log < error_linear; + } + return false; +} + +template +inline void fill_data(SpectrogramTimeSerie* serie, colomapT* colormap, + const accessPattern_t& y_access_pattern, const axProp_t& xAxisProperties, + const cmProp_t& colormap_properties) +{ + auto line = serie->begin(); + auto next_line = line + 1; + double current_time = xAxisProperties.min; + int x_index = 0; + auto x_min_resolution + = std::fmin(2. * serie->max_sampling, xAxisProperties.max_resolution * 100.); + std::vector line_values(serie->size(1)); + double avg_coef = 0.; + while (x_index < colormap_properties.h_size_px) + { + if (next_line != std::end(*serie) and current_time >= next_line->t()) + { + line = next_line; + next_line++; + } + if ((current_time - xAxisProperties.min) + > (static_cast(x_index + 1) * colormap_properties.h_resolutuon)) + { + std::for_each(std::cbegin(y_access_pattern), std::cend(y_access_pattern), + [&colormap, &line_values, x_index, avg_coef](const auto& acc) { + colormap->data()->setCell( + x_index, acc.first, line_values[acc.second] / avg_coef); + }); + std::fill(std::begin(line_values), std::end(line_values), 0.); + x_index++; + avg_coef = 0.; + } + if (line->t() + x_min_resolution > current_time) + { + { + std::transform(std::begin(*line), std::end(*line), std::cbegin(line_values), + std::begin(line_values), + [](const auto& input, auto output) { return input.v() + output; }); + } + avg_coef += 1.; + } + else + { + for (int y_index = 0; y_index < colormap_properties.v_size_px; y_index++) + { + if (avg_coef > 0.) + { + std::fill(std::begin(line_values), std::end(line_values), 0); + } + } + } + current_time += xAxisProperties.max_resolution * 0.9; + } +} + /*=============================================================*/ /** @@ -365,7 +456,6 @@ struct PlottablesUpdater