Open3D (C++ API)  0.16.1
Application.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// The MIT License (MIT)
5//
6// Copyright (c) 2018-2021 www.open3d.org
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24// IN THE SOFTWARE.
25// ----------------------------------------------------------------------------
26
27#pragma once
28
29#include <cstdint>
30#include <functional>
31#include <memory>
32#include <string>
33#include <vector>
34
37
38namespace open3d {
39
40namespace geometry {
41class Image;
42}
43
44namespace visualization {
45
46namespace rendering {
47class Renderer;
48class View;
49class Scene;
50} // namespace rendering
51
52namespace gui {
53
54struct Theme;
55class Window;
56class WindowSystem;
57
59public:
60 static Application &GetInstance();
61
62 virtual ~Application();
63
67 void Initialize();
71 void Initialize(int argc, const char *argv[]);
73 void Initialize(const char *resource_path);
74
76 static constexpr FontId DEFAULT_FONT_ID = 0;
82 void SetFont(FontId id, const FontDescription &fd);
83
85 void Run();
87 void Quit();
88
96 void RunInThread(std::function<void()> f);
102 void PostToMainThread(Window *window, std::function<void()> f);
103
104 std::shared_ptr<Menu> GetMenubar() const;
105 void SetMenubar(std::shared_ptr<Menu> menubar);
106
108 void AddWindow(std::shared_ptr<Window> window);
112 void RemoveWindow(Window *window);
113
122 void ShowMessageBox(const char *title, const char *message);
123
125
126 // (std::string not good in interfaces for ABI reasons)
127 const char *GetResourcePath() const;
128
133 const Theme &GetTheme() const;
134
137 double Now() const;
138
140 void OnMenuItemSelected(Menu::ItemId itemId);
141
146 void OnTerminate();
147
149 public:
151 virtual ~EnvUnlocker() {}
152 virtual void unlock() {}
153 virtual void relock() {}
154 };
165 bool RunOneTick(EnvUnlocker &unlocker, bool cleanup_if_no_windows = true);
166
170 void SetWindowSystem(std::shared_ptr<WindowSystem> ws);
171
176 bool UsingNativeWindows() const;
177
180 void VerifyIsInitialized();
181
182 const std::vector<FontDescription> &GetFontDescriptions() const;
183
187 std::shared_ptr<geometry::Image> RenderToImage(
188 rendering::Renderer &renderer,
189 rendering::View *view,
190 rendering::Scene *scene,
191 int width,
192 int height);
193
194 // Same as RenderToImage(), but returns the depth values in a float image.
195 std::shared_ptr<geometry::Image> RenderToDepthImage(
196 rendering::Renderer &renderer,
197 rendering::View *view,
198 rendering::Scene *scene,
199 int width,
200 int height,
201 bool z_in_view_space = false);
202
203private:
204 Application();
205
206 enum class RunStatus { CONTINUE, DONE };
207 RunStatus ProcessQueuedEvents(EnvUnlocker &unlocker);
208
209private:
210 struct Impl;
211 std::unique_ptr<Impl> impl_;
212};
213
214} // namespace gui
215} // namespace visualization
216} // namespace open3d
virtual void unlock()
Definition: Application.h:152
virtual ~EnvUnlocker()
Definition: Application.h:151
virtual void relock()
Definition: Application.h:153
Definition: Application.h:58
void VerifyIsInitialized()
Definition: Application.cpp:287
FontId AddFont(const FontDescription &fd)
Definition: Application.cpp:322
std::shared_ptr< Menu > GetMenubar() const
Definition: Application.cpp:399
bool UsingNativeWindows() const
Definition: Application.cpp:304
double Now() const
Definition: Application.cpp:392
void SetWindowSystem(std::shared_ptr< WindowSystem > ws)
Definition: Application.cpp:314
void PostToMainThread(Window *window, std::function< void()> f)
Definition: Application.cpp:633
const Theme & GetTheme() const
Definition: Application.cpp:642
void OnTerminate()
Definition: Application.cpp:449
WindowSystem & GetWindowSystem() const
Definition: Application.cpp:310
virtual ~Application()
Definition: Application.cpp:230
void ShowMessageBox(const char *title, const char *message)
Definition: Application.cpp:149
void RunInThread(std::function< void()> f)
Definition: Application.cpp:627
void Run()
Does not return until the UI is completely finished.
Definition: Application.cpp:492
void SetMenubar(std::shared_ptr< Menu > menubar)
Definition: Application.cpp:403
bool RunOneTick(EnvUnlocker &unlocker, bool cleanup_if_no_windows=true)
Definition: Application.cpp:498
void AddWindow(std::shared_ptr< Window > window)
Must be called on the same thread that calls Run()
Definition: Application.cpp:422
std::shared_ptr< geometry::Image > RenderToDepthImage(rendering::Renderer &renderer, rendering::View *view, rendering::Scene *scene, int width, int height, bool z_in_view_space=false)
Definition: Application.cpp:668
std::shared_ptr< geometry::Image > RenderToImage(rendering::Renderer &renderer, rendering::View *view, rendering::Scene *scene, int width, int height)
Definition: Application.cpp:644
void SetFont(FontId id, const FontDescription &fd)
Definition: Application.cpp:329
void RemoveWindow(Window *window)
Definition: Application.cpp:428
static constexpr FontId DEFAULT_FONT_ID
Identifier for font used by default for all UI elements.
Definition: Application.h:76
void OnMenuItemSelected(Menu::ItemId itemId)
Delivers the itemId to the active window. Used internally.
Definition: Application.cpp:475
const char * GetResourcePath() const
Definition: Application.cpp:638
void Initialize()
Definition: Application.cpp:232
static Application & GetInstance()
Definition: Application.cpp:144
const std::vector< FontDescription > & GetFontDescriptions() const
Definition: Application.cpp:388
void Quit()
Closes all the windows, which exits as a result.
Definition: Application.cpp:443
int ItemId
Definition: MenuBase.h:47
Definition: Window.h:49
Definition: WindowSystem.h:46
int width
Definition: FilePCD.cpp:71
int height
Definition: FilePCD.cpp:72
unsigned int FontId
Definition: Gui.h:87
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Theme.h:39