90 lines
3.2 KiB
C++
90 lines
3.2 KiB
C++
#pragma once
|
|
#include <cstddef>
|
|
#include <memory_resource>
|
|
#include <span>
|
|
#include <utility>
|
|
#include <vector>
|
|
#include "../base/Color.h"
|
|
#include "../base/Memory.h"
|
|
#include "../base/Style.h"
|
|
#include "Interpolation.h"
|
|
#include "global.h"
|
|
namespace renderive {
|
|
struct Sweep_Spectrum_Private;
|
|
/// @brief 扫频频谱图元,按块组织输入频率数据。
|
|
class LIB_DECL Sweep_Spectrum : public Renderable {
|
|
public:
|
|
/// @brief 创建扫频频谱图元。
|
|
Sweep_Spectrum();
|
|
/// @brief 写入一块扫频数据。
|
|
void append_block(std::span<const double> data);
|
|
/// @brief 移动写入一块扫频数据。
|
|
void append_block(std::pmr::vector<double>&& data);
|
|
/// @brief 用 writer 填充并写入一块扫频数据。
|
|
template <typename Writer>
|
|
void write_block(std::size_t count, Writer&& writer) {
|
|
std::pmr::vector<double> values(memory_resource(Memory_Domain::Other));
|
|
values.resize(count);
|
|
std::forward<Writer>(writer)(std::span<double>(values.data(), values.size()));
|
|
append_block(std::move(values));
|
|
}
|
|
/// @brief 绑定频率轴。
|
|
PROP(std::shared_ptr<Axis>, frequency_axis)
|
|
/// @brief 绑定功率轴。
|
|
PROP(std::shared_ptr<Axis>, power_axis)
|
|
/// @brief 扫频频率范围。
|
|
PROP(Range, frequency_range)
|
|
/// @brief 每块频率采样点数。
|
|
PROP(int, bins_per_block)
|
|
/// @brief 扫频块数量。
|
|
PROP(int, block_count)
|
|
/// @brief 频谱线画笔。
|
|
PROP(Pen, pen)
|
|
/// @brief 当前扫频位置画笔。
|
|
PROP(Pen, cur_frequency_pen)
|
|
/// @brief 是否只生成当前可见频率范围。
|
|
PROP(bool, visible_range_only)
|
|
/// @brief 折线插值模式。
|
|
PROP(Line_Interpolation_Mode, interpolation_mode)
|
|
struct Builder;
|
|
private:
|
|
Sweep_Spectrum_Private* d();
|
|
Render_Object_Owner create_render_data() override;
|
|
Render_Object_Owner create_render_state() override;
|
|
Render_Object_Owner create_input_data() override;
|
|
};
|
|
struct Sweep_Spectrum_Prop {
|
|
std::weak_ptr<Axis> frequency_axis{};
|
|
std::weak_ptr<Axis> power_axis{};
|
|
Range frequency_range{};
|
|
int bins_per_block{};
|
|
int block_num{};
|
|
Pen pen;
|
|
Pen current_frequency_pen;
|
|
bool visible_range_only = true;
|
|
Line_Interpolation_Mode interpolation_mode = Line_Interpolation_Mode::Linear_Value;
|
|
Sweep_Spectrum_Prop() {
|
|
pen = Pen{Color::yellow()};
|
|
current_frequency_pen = Pen{Color::red(), 2.0};
|
|
}
|
|
};
|
|
/// @brief 扫频频谱构造器。
|
|
struct LIB_DECL Sweep_Spectrum::Builder : Sweep_Spectrum_Prop {
|
|
PROP_B(std::shared_ptr<Renderable>, parent)
|
|
PROP_B(std::shared_ptr<Axis>, frequency_axis)
|
|
PROP_B(std::shared_ptr<Axis>, power_axis)
|
|
PROP_B(Range, frequency_range)
|
|
PROP_B(int, bins_per_block)
|
|
PROP_B(int, block_num)
|
|
PROP_B(Pen, pen)
|
|
PROP_B(Pen, current_frequency_pen)
|
|
PROP_B(bool, visible_range_only)
|
|
PROP_B(Line_Interpolation_Mode, interpolation_mode)
|
|
/// 创建扫频构造器。
|
|
Builder(std::shared_ptr<Renderable> parent, std::shared_ptr<Axis> frequency_axis, std::shared_ptr<Axis> power_axis);
|
|
/// 构建并返回扫频对象。
|
|
std::shared_ptr<Sweep_Spectrum> build();
|
|
std::shared_ptr<Renderable> parent{};
|
|
};
|
|
} // namespace renderive
|