boat
C++23 geospatial library
Loading...
Searching...
No Matches
wx.hpp
Go to the documentation of this file.
1// Andrew Naplavkov
2
3#ifndef BOAT_GUI_WX_HPP
4#define BOAT_GUI_WX_HPP
5
6#include <wx/graphics.h>
7#include <boat/gui/detail/geometry.hpp>
8#include <boat/gui/detail/raster.hpp>
9
10namespace boat::gui {
11namespace detail {
12
13wxGraphicsPath& add(geometry::curve auto&& in, wxGraphicsPath& out)
14{
15 out.MoveToPoint(in.at(0).x(), in.at(0).y());
16 for (size_t i = 1; i < in.size(); ++i)
17 out.AddLineToPoint(in[i].x(), in[i].y());
18 return out;
19}
20
21} // namespace detail
22
23inline auto draw_geometry(wxGraphicsContext& out)
24{
25 return geometry::visitor(
26 [&](geometry::point auto&& v) { out.DrawEllipse(v.x(), v.y(), 1, 1); },
27 [&](geometry::linestring auto&& v) {
28 auto path = out.CreatePath();
29 out.StrokePath(detail::add(v, path));
30 },
31 [&](geometry::polygon auto&& v) {
32 auto path = out.CreatePath();
33 detail::add(v.outer(), path).CloseSubpath();
34 for (auto& item : v.inners())
35 detail::add(item, path).CloseSubpath();
36 out.DrawPath(path);
37 });
38}
39
42 execution_policy auto policy,
43 rgba8_view auto in,
44 geometry::matrix const& in_affine,
45 geometry::srs_spec auto&& in_crs,
46 wxGraphicsContext& out,
47 geometry::matrix const& out_affine,
48 geometry::srs_spec auto&& out_crs)
49 requires(sizeof(wxImage::RGBValue) == 3)
50{
51 auto img = wxImage{};
52 wxDouble w, h;
53 out.GetSize(&w, &h);
54 auto rect = draw_image(
55 policy,
56 in,
57 in_affine,
58 in_crs,
59 out_affine,
60 out_crs,
61 {{0, 0}, {int(std::ceil(w)), int(std::ceil(h))}},
62 [&](int w, int h) {
63 img = wxImage{w, h};
64 img.InitAlpha();
65 return [rgb = reinterpret_cast<wxImage::RGBValue*>(img.GetData()),
66 alpha = img.GetAlpha()](auto i, auto px) {
67 rgb[i] = {px[0], px[1], px[2]};
68 alpha[i] = px[3];
69 };
70 });
71 if (rect) {
72 auto [x, y, w, h] = geometry::xywh(*rect);
73 out.DrawBitmap(out.CreateBitmapFromImage(img), x, y, w, h);
74 }
75}
76
77} // namespace boat::gui
78
79#endif // BOAT_GUI_WX_HPP
Definition vocabulary.hpp:37
Definition vocabulary.hpp:46
Definition vocabulary.hpp:49
Definition transform.hpp:29
Definition variant.hpp:17
constexpr auto xywh
Definition vocabulary.hpp:120
auto visitor(auto... fn)
Definition algorithm.hpp:64
boost::qvm::mat< double, 3, 3 > matrix
Definition vocabulary.hpp:104
Definition cache.hpp:9
auto draw_geometry(QPainter &out)
Definition qt.hpp:30
void draw_image(execution_policy auto policy, rgba8_view auto in, geometry::matrix const &in_affine, geometry::srs_spec auto &&in_crs, QPainter &out, geometry::matrix const &out_affine, geometry::srs_spec auto &&out_crs)
Affine matrices map pixels to spatial coordinates.
Definition qt.hpp:39