Open3D (C++ API)  0.12.0
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 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 
36 
37 namespace open3d {
38 
39 namespace geometry {
40 class Image;
41 }
42 
43 namespace visualization {
44 
45 namespace rendering {
46 class View;
47 class Scene;
48 } // namespace rendering
49 
50 namespace gui {
51 
52 struct Theme;
53 class Window;
54 
55 class Application {
56 public:
57  static Application &GetInstance();
58 
59  virtual ~Application();
60 
64  void Initialize();
68  void Initialize(int argc, const char *argv[]);
70  void Initialize(const char *resource_path);
71 
84  // All other languages will be assumed to be Cyrillic.
85  void SetFontForLanguage(const char *font, const char *lang_code);
86 
92  void SetFontForCodePoints(const char *font,
93  const std::vector<uint32_t> &code_points);
94 
96  void Run();
98  void Quit();
99 
107  void RunInThread(std::function<void()> f);
113  void PostToMainThread(Window *window, std::function<void()> f);
114 
115  std::shared_ptr<Menu> GetMenubar() const;
116  void SetMenubar(std::shared_ptr<Menu> menubar);
117 
119  void AddWindow(std::shared_ptr<Window> window);
121  void RemoveWindow(Window *window);
122 
131  void ShowMessageBox(const char *title, const char *message);
132 
133  // (std::string not good in interfaces for ABI reasons)
134  const char *GetResourcePath() const;
135 
140  const Theme &GetTheme() const;
141 
144  double Now() const;
145 
147  void OnMenuItemSelected(Menu::ItemId itemId);
148 
153  void OnTerminate();
154 
155  class EnvUnlocker {
156  public:
158  virtual ~EnvUnlocker() {}
159  virtual void unlock() {}
160  virtual void relock() {}
161  };
172  bool RunOneTick(EnvUnlocker &unlocker, bool cleanup_if_no_windows = true);
173 
177  std::shared_ptr<geometry::Image> RenderToImage(EnvUnlocker &unlocker,
178  rendering::View *view,
179  rendering::Scene *scene,
180  int width,
181  int height);
182 
183  struct UserFontInfo {
184  std::string path;
185  std::string lang;
186  std::vector<uint32_t> code_points;
187  };
188  const std::vector<UserFontInfo> &GetUserFontInfo() const;
189 
190 private:
191  Application();
192 
193  enum class RunStatus { CONTINUE, DONE };
194  RunStatus ProcessQueuedEvents(EnvUnlocker &unlocker);
195 
196 private:
197  struct Impl;
198  std::unique_ptr<Impl> impl_;
199 };
200 
201 } // namespace gui
202 } // namespace visualization
203 } // namespace open3d
Definition: Theme.h:39
Definition: Application.h:55
std::vector< uint32_t > code_points
Definition: Application.h:186
Definition: Window.h:50
virtual void unlock()
Definition: Application.h:159
Definition: Application.cpp:201
virtual void relock()
Definition: Application.h:160
virtual ~EnvUnlocker()
Definition: Application.h:158
int ItemId
Definition: Menu.h:51
Definition: PinholeCameraIntrinsic.cpp:35
int height
Definition: FilePCD.cpp:72
std::string path
Definition: Application.h:184
std::string lang
Definition: Application.h:185
int width
Definition: FilePCD.cpp:71