🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
AggRenderer.hpp
1#pragma once
2
3#include "AstGlobal.h"
4
5#if defined(AST_WITH_AGG)
6
7A_SUPPRESS_WARNINGS_BEGIN
8#include "agg/agg_basics.h"
9#include "agg/agg_rendering_buffer.h"
10#include "agg/agg_rasterizer_scanline_aa.h"
11#include "agg/agg_scanline_p.h"
12#include "agg/agg_renderer_scanline.h"
13#include "agg/agg_pixfmt_rgba.h"
14#include "agg/agg_path_storage.h"
15#include "agg/agg_conv_stroke.h"
16#include "agg/agg_conv_transform.h"
17#include "agg/agg_conv_curve.h"
18#include "agg/agg_conv_dash.h"
19#include "agg/agg_trans_affine.h"
20#include "agg/agg_color_rgba.h"
21#include "agg/agg_gsv_text.h"
22A_SUPPRESS_WARNINGS_END
23
24#include "LineStyle.hpp"
25
26
27AST_NAMESPACE_BEGIN
28
30class AggRenderer {
31public:
32 // 像素格式: 普通 RGBA (非预乘)
33 typedef agg::pixfmt_rgba32 pixfmt_type;
34 typedef agg::renderer_base<pixfmt_type> renderer_base_type;
35 typedef agg::renderer_scanline_aa_solid<renderer_base_type> renderer_aa_type;
36 typedef agg::rasterizer_scanline_aa<> rasterizer_type;
37 typedef agg::scanline_p8 scanline_type;
38
39 AggRenderer(unsigned int width, unsigned int height, double dpi = 96.0);
40 AggRenderer(const AggRenderer&) = delete;
41 AggRenderer& operator=(const AggRenderer&) = delete;
42 ~AggRenderer();
43
44 unsigned int width() const { return width_; }
45 unsigned int height() const { return height_; }
46 double dpi() const { return dpi_; }
47
49 void clear(const agg::rgba& bg = agg::rgba(1.0, 1.0, 1.0, 1.0));
50
52 void draw_line(const double* x, const double* y, size_t n,
53 const LineStyle& style, const agg::trans_affine& trans);
54
56 void draw_path(agg::path_storage& path, const LineStyle& style,
57 const agg::trans_affine& trans, bool hasFace = false);
58
60 void draw_filled_rect(double x1, double y1, double x2, double y2,
61 const agg::rgba& fill_color,
62 const agg::trans_affine& trans);
63
69 void draw_text(const char* text, double x, double y, double size_pt,
70 const agg::rgba& color, double angle_deg = 0.0);
71
78 void draw_marker(int shape, double cx, double cy, double size_pt,
79 const agg::rgba& edge_color, const agg::rgba& fill_color,
80 double linewidth);
81
83 const unsigned char* buffer() const { return pixBuffer_; }
84
86 void save_bmp(const char* filename) const;
87
88private:
89
90 void draw_stroke_impl(/* 处理后的 path pipeline */);
91
92 unsigned int width_, height_;
93 double dpi_;
94
95 agg::int8u* pixBuffer_{};
96 agg::rendering_buffer rbuf_{};
97 pixfmt_type pixFmt_{};
98 renderer_base_type renBase_{};
99 renderer_aa_type renAA_{};
100 rasterizer_type ras_{};
101 scanline_type sl_{};
102};
103
104
105AST_NAMESPACE_END
106
107#endif // AST_WITH_AGG && AST_WITH_MATPLOT