siderust-cpp 0.8.0
Header-only C++ wrapper for siderust
Loading...
Searching...
No Matches
sky_grid.hpp
Go to the documentation of this file.
1#pragma once
2
15#include "ffi_core.hpp"
16#include <qtty/qtty.hpp>
17#include <vector>
18
19namespace siderust {
20
21namespace detail {
22
24 SiderustSkyGridCell *ptr = nullptr;
25 uintptr_t count = 0;
26
27 ~SkyGridCellsGuard() { siderust_sky_grid_cells_free(ptr, count); }
28
29 SkyGridCellsGuard() = default;
34};
35
36} // namespace detail
37
45 qtty::Steradian solid_angle;
46
47 static SkyGridCell from_c(const SiderustSkyGridCell &c) {
48 return SkyGridCell{spherical::Direction<frames::Horizontal>(qtty::Degree(c.azimuth_deg),
49 qtty::Degree(c.altitude_deg)),
50 qtty::Steradian(c.solid_angle_sr)};
51 }
52};
53
60class SkyGrid {
61 double alt_min_;
62 double alt_max_;
63 double alt_step_;
64 double az_step_;
65 bool equal_area_;
66
67 SkyGrid(double alt_min, double alt_max, double alt_step, double az_step, bool equal_area)
68 : alt_min_(alt_min), alt_max_(alt_max), alt_step_(alt_step), az_step_(az_step),
69 equal_area_(equal_area) {}
70
71public:
73 static SkyGrid uniform(qtty::Degree step) {
74 return SkyGrid(0.0, 90.0, step.value(), step.value(), false);
75 }
76
78 static SkyGrid with_steps(qtty::Degree alt_step, qtty::Degree az_step) {
79 return SkyGrid(0.0, 90.0, alt_step.value(), az_step.value(), false);
80 }
81
83 static SkyGrid equal_area(qtty::Degree alt_step, qtty::Degree az_step_at_horizon) {
84 return SkyGrid(0.0, 90.0, alt_step.value(), az_step_at_horizon.value(), true);
85 }
86
88 SkyGrid &with_alt_range(qtty::Degree lo, qtty::Degree hi) {
89 alt_min_ = lo.value();
90 alt_max_ = hi.value();
91 return *this;
92 }
93
95 std::vector<SkyGridCell> cells() const {
96 SiderustSkyGridCell *ptr = nullptr;
97 uintptr_t count = 0;
99 siderust_sky_grid_cells(alt_min_, alt_max_, alt_step_, az_step_, equal_area_, &ptr, &count),
100 "SkyGrid::cells");
101
103 guard.ptr = ptr;
104 guard.count = count;
105
106 std::vector<SkyGridCell> result;
107 result.reserve(count);
108 for (uintptr_t i = 0; i < count; ++i) {
109 result.push_back(SkyGridCell::from_c(ptr[i]));
110 }
111 return result;
112 }
113
115 std::size_t size() const { return cells().size(); }
116};
117
118} // namespace siderust
Typed hemispherical alt/az grid sampler.
Definition sky_grid.hpp:60
static SkyGrid with_steps(qtty::Degree alt_step, qtty::Degree az_step)
Uniform grid with independent altitude and azimuth steps over [0°, 90°).
Definition sky_grid.hpp:78
SkyGrid & with_alt_range(qtty::Degree lo, qtty::Degree hi)
Restrict the altitude range (builder, e.g. a 10°..90° horizon mask).
Definition sky_grid.hpp:88
std::size_t size() const
Number of cells the grid materialises.
Definition sky_grid.hpp:115
static SkyGrid equal_area(qtty::Degree alt_step, qtty::Degree az_step_at_horizon)
Equal-area grid: azimuth count per altitude ring scales with cos(alt).
Definition sky_grid.hpp:83
std::vector< SkyGridCell > cells() const
Materialise every cell of the grid.
Definition sky_grid.hpp:95
static SkyGrid uniform(qtty::Degree step)
Uniform grid with equal altitude and azimuth steps over [0°, 90°).
Definition sky_grid.hpp:73
Error handling and utility base for the siderust C++ wrapper.
void check_status(siderust_status_t status, const char *operation)
Definition ffi_core.hpp:111
Typed spherical coordinate templates.
A single sky-grid cell: a Horizontal direction and its solid angle.
Definition sky_grid.hpp:43
static SkyGridCell from_c(const SiderustSkyGridCell &c)
Definition sky_grid.hpp:47
spherical::Direction< frames::Horizontal > direction
Alt/az sky direction.
Definition sky_grid.hpp:44
qtty::Steradian solid_angle
Approximate solid angle of the cell.
Definition sky_grid.hpp:45
SkyGridCellsGuard(SkyGridCellsGuard &&)=delete
SkyGridCellsGuard & operator=(const SkyGridCellsGuard &)=delete
SkyGridCellsGuard(const SkyGridCellsGuard &)=delete
SkyGridCellsGuard & operator=(SkyGridCellsGuard &&)=delete
A direction on the celestial sphere, compile-time tagged by frame.
Definition spherical.hpp:50