Open3D (C++ API)  0.11.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 <functional>
30 #include <memory>
31 
33 
34 namespace open3d {
35 
36 namespace geometry {
37 class Image;
38 }
39 
40 namespace visualization {
41 
42 namespace rendering {
43 class View;
44 class Scene;
45 } // namespace rendering
46 
47 namespace gui {
48 
49 struct Theme;
50 class Window;
51 
52 class Application {
53 public:
54  static Application &GetInstance();
55 
56  virtual ~Application();
57 
61  void Initialize();
65  void Initialize(int argc, const char *argv[]);
67  void Initialize(const char *resource_path);
68 
70  void Run();
72  void Quit();
73 
81  void RunInThread(std::function<void()> f);
87  void PostToMainThread(Window *window, std::function<void()> f);
88 
89  std::shared_ptr<Menu> GetMenubar() const;
90  void SetMenubar(std::shared_ptr<Menu> menubar);
91 
93  void AddWindow(std::shared_ptr<Window> window);
95  void RemoveWindow(Window *window);
96 
105  void ShowMessageBox(const char *title, const char *message);
106 
107  // (std::string not good in interfaces for ABI reasons)
108  const char *GetResourcePath() const;
109 
114  const Theme &GetTheme() const;
115 
118  double Now() const;
119 
121  void OnMenuItemSelected(Menu::ItemId itemId);
122 
127  void OnTerminate();
128 
129  class EnvUnlocker {
130  public:
132  virtual ~EnvUnlocker() {}
133  virtual void unlock() {}
134  virtual void relock() {}
135  };
139  bool RunOneTick(EnvUnlocker &unlocker, bool cleanup_if_no_windows = true);
140 
144  std::shared_ptr<geometry::Image> RenderToImage(EnvUnlocker &unlocker,
145  rendering::View *view,
146  rendering::Scene *scene,
147  int width,
148  int height);
149 
150 private:
151  Application();
152 
153  enum class RunStatus { CONTINUE, DONE };
154  RunStatus ProcessQueuedEvents(EnvUnlocker &unlocker);
155 
156 private:
157  struct Impl;
158  std::unique_ptr<Impl> impl_;
159 };
160 
161 } // namespace gui
162 } // namespace visualization
163 } // namespace open3d
Definition: Theme.h:39
Definition: Application.h:52
Definition: Window.h:50
virtual void unlock()
Definition: Application.h:133
Definition: Application.cpp:116
virtual void relock()
Definition: Application.h:134
virtual ~EnvUnlocker()
Definition: Application.h:132
int ItemId
Definition: Menu.h:51
Definition: PinholeCameraIntrinsic.cpp:35
int height
Definition: FilePCD.cpp:72
int width
Definition: FilePCD.cpp:71