Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.14.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
38 namespace open3d {
39 
40 namespace geometry {
41 class Image;
42 }
43 
44 namespace visualization {
45 
46 namespace rendering {
47 class Renderer;
48 class View;
49 class Scene;
50 } // namespace rendering
51 
52 namespace gui {
53 
54 struct Theme;
55 class Window;
56 class WindowSystem;
57 
58 class Application {
59 public:
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;
79  FontId AddFont(const FontDescription &fd);
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 
124  WindowSystem &GetWindowSystem() const;
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 
148  class EnvUnlocker {
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 
203 private:
204  Application();
205 
206  enum class RunStatus { CONTINUE, DONE };
207  RunStatus ProcessQueuedEvents(EnvUnlocker &unlocker);
208 
209 private:
210  struct Impl;
211  std::unique_ptr<Impl> impl_;
212 };
213 
214 } // namespace gui
215 } // namespace visualization
216 } // namespace open3d
Definition: Theme.h:39
Definition: Application.h:58
int height
Definition: FilePCD.cpp:72
Definition: Window.h:49
virtual void unlock()
Definition: Application.h:152
Definition: Application.cpp:120
int ItemId
Definition: MenuBase.h:47
unsigned int FontId
Definition: Gui.h:87
virtual void relock()
Definition: Application.h:153
virtual ~EnvUnlocker()
Definition: Application.h:151
Definition: PinholeCameraIntrinsic.cpp:35
int width
Definition: FilePCD.cpp:71
Definition: WindowSystem.h:46