UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
viz.hpp
1
42#ifndef UFO_VIZ_VIZ_HPP
43#define UFO_VIZ_VIZ_HPP
44
45// UFO
46#include <ufo/compute/compute.hpp>
47#include <ufo/vision/camera.hpp>
48#include <ufo/vision/color.hpp>
49#include <ufo/viz/renderable.hpp>
50// #include <ufo/viz/renderable/map.hpp>
51
52// STL
53#include <array>
54#include <cstddef>
55#include <filesystem>
56#include <memory>
57#include <mutex>
58#include <string>
59#include <thread>
60#include <vector>
61
62// Forward declare
63struct GLFWwindow;
64
65namespace ufo
66{
67class Viz
68{
69 public:
70 Viz();
71
72 ~Viz();
73
74 [[nodiscard]] bool running() const;
75
76 bool open(int width = 1280, int height = 800, bool resizable = true,
77 std::string const& window_name = "UFOViz",
78 WGPUPowerPreference power_preference = WGPUPowerPreference_Undefined,
79 WGPUBackendType backend_type = WGPUBackendType_Undefined);
80
81 void close();
82
83 void run();
84
85 void runAsync();
86
87 void update();
88
89 [[nodiscard]] WGPUDevice device() const;
90
91 void addRenderable(std::shared_ptr<Renderable> const& renderable);
92
93 // template <std::size_t Dim, class... Maps>
94 // void addRenderable(Map<Dim, Maps...> const& map)
95 // {
96 // renderables_.push_back(std::make_shared<RenderableMap<Map<Dim, Maps...>>>(map));
97 // }
98
99 // TODO: Implement other
100
101 void eraseRenderable(std::shared_ptr<Renderable> const& renderable);
102
103 // template <std::size_t Dim, class... Maps>
104 // bool eraseRenderable(Map<Dim, Maps...> const& map)
105 // {
106 // auto it = std::find_if(
107 // renderables_.begin(), renderables_.end(),
108 // [&map](std::shared_ptr<Renderable> const& renderable) {
109 // auto renderable_map =
110 // std::dynamic_pointer_cast<RenderableMap<Map<Dim, Maps...>>>(renderable);
111 // if (nullptr == renderable_map) {
112 // return false;
113 // }
114 // return renderable_map->map() == map;
115 // });
116
117 // if (it != renderables_.end()) {
118 // renderables_.erase(it);
119 // return true;
120 // }
121
122 // return false;
123 // }
124
125 // TODO: Implement other
126
127 void clearRenderables();
128
129 [[nodiscard]] std::size_t numRenderables() const;
130
131 void loadConfig(std::filesystem::path const& config);
132
133 void saveConfig(std::filesystem::path const& file) const;
134
135 private:
136 [[nodiscard]] WGPULimits requiredLimits(WGPUAdapter adapter) const;
137
138 [[nodiscard]] WGPUTextureFormat surfaceFormat(
139 WGPUSurfaceCapabilities capabilities) const;
140
141 void resizeSurface(int width, int height);
142
143 void updateCamera(float dt);
144
145 bool initWindow(int width, int height, bool resizable, std::string const& title);
146
147 bool initWGPU(WGPUPowerPreference power_preference, WGPUBackendType backend_type);
148
149 bool initGUI();
150
151 bool initCamera();
152
153 void updateGui();
154
155 // Party events
156 void onMouseMove(double x_pos, double y_pos);
157
158 void onMouseButton(int button, int action, int modifiers);
159
160 void onScroll(double x_offset, double y_offset);
161
162 void onKey(int key, int scancode, int action, int mods);
163
164 void updateViewMatrix();
165
166 private:
167 GLFWwindow* window_ = nullptr;
168
169 WGPUInstance instance_ = nullptr;
170 WGPUSurface surface_ = nullptr;
171 WGPUAdapter adapter_ = nullptr;
172 WGPUDevice device_ = nullptr;
173 WGPUQueue queue_ = nullptr;
174 WGPUSurfaceConfiguration surface_config_ = WGPU_SURFACE_CONFIGURATION_INIT;
175
176 WGPUTextureFormat surface_preferred_format_ = WGPUTextureFormat_Undefined;
177 int surface_width_ = 0;
178 int surface_height_ = 0;
179
180 WGPUTextureFormat depth_texture_format_ = WGPUTextureFormat_Depth24Plus;
181 WGPUTexture depth_texture_ = nullptr;
182 WGPUTextureView depth_view_ = nullptr;
183
184 FineRGBA clear_color_ = FineRGBA(0.45f, 0.55f, 0.60f, 1.00f);
185
186 bool show_left_panel_ = true;
187 bool show_right_panel_ = true;
188 bool show_bottom_panel_ = true;
189 int control_type_ = 0;
190 int projection_type_ = 0;
191
192 std::thread render_thread_;
193
194 float prev_time_{};
195
196 float scale_ = 1.0f;
197
198 std::vector<std::shared_ptr<Renderable>> renderables_;
199
200 Camera camera_;
201 float translation_speed_ = 2.5f;
202 float rotation_speed_ = 90.0f; // Degrees per second
203 ufo::Vec2f angles_{0.0f, 0.0f};
204 ufo::Vec3f center_{4.4f, 0.0f, 1.7f};
205 float zoom_ = 0.0f;
206
207 bool mouse_drag_ = false;
208 ufo::Vec2f start_mouse_pos_ = {0.0f, 0.0f};
209 Camera start_camera_state_ = {};
210 float mouse_sense_ = 1.0f;
211 float scroll_sensitivity_ = 0.1f;
212
213 std::vector<float> frame_times_;
214};
215} // namespace ufo
216
217#endif // UFO_VIZ_VIZ_HPP
All vision-related classes and functions.
Definition cloud.hpp:49