Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.16.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ImguiFilamentBridge.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 // Altered from Filament's ImGuiHelper.cpp
27 // Filament code is from somewhere close to v1.4.3 and is:
28 /*
29  * Copyright (C) 2018 The Android Open Source Project
30  *
31  * Licensed under the Apache License, Version 2.0 (the "License");
32  * you may not use this file except in compliance with the License.
33  * You may obtain a copy of the License at
34  *
35  * http://www.apache.org/licenses/LICENSE-2.0
36  *
37  * Unless required by applicable law or agreed to in writing, software
38  * distributed under the License is distributed on an "AS IS" BASIS,
39  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40  * See the License for the specific language governing permissions and
41  * limitations under the License.
42  */
43 
44 #pragma once
45 
46 // 4068: Filament has some clang-specific vectorizing pragma's that MSVC flags
47 // 4146: PixelBufferDescriptor assert unsigned is positive before subtracting
48 // but MSVC can't figure that out.
49 // 4293: Filament's utils/algorithm.h utils::details::clz() does strange
50 // things with MSVC. Somehow sizeof(unsigned int) > 4, but its size is
51 // 32 so that x >> 32 gives a warning. (Or maybe the compiler can't
52 // determine the if statement does not run.)
53 #ifdef _MSC_VER
54 #pragma warning(push)
55 #pragma warning(disable : 4068 4146 4293)
56 #endif // _MSC_VER
57 
58 #include <filament/Engine.h>
59 #include <filament/IndexBuffer.h>
60 #include <filament/Material.h>
61 #include <filament/MaterialInstance.h>
62 #include <filament/Texture.h>
63 #include <filament/VertexBuffer.h>
64 #include <filament/View.h>
65 
66 #ifdef _MSC_VER
67 #pragma warning(pop)
68 #endif // _MSC_VER
69 
70 #include <cstddef> // <filament/Engine> recursive includes needs this, std::size_t especially
71 #include <memory>
72 
73 struct ImDrawData;
74 
75 namespace open3d {
76 
77 namespace visualization {
78 namespace rendering {
79 class FilamentRenderer;
80 }
81 } // namespace visualization
82 
83 namespace visualization {
84 namespace gui {
85 
86 struct Size;
87 class Window;
88 
89 // Translates ImGui's draw commands into Filament primitives, textures, vertex
90 // buffers, etc. Creates a UI-specific Scene object and populates it with a
91 // Renderable. Does not handle event processing; clients can simply call
92 // ImGui::GetIO() directly and set the mouse state.
94 public:
96  const Size& window_size);
98 
99  // Helper method called after resolving fontPath; public so fonts can be
100  // added by caller. Requires the appropriate ImGuiContext to be current
101  void CreateAtlasTextureAlpha8(unsigned char* pixels,
102  int width,
103  int height,
104  int bytes_per_px);
105 
106  // This populates the Filament View. Clients are responsible for
107  // rendering the View. This should be called on every frame, regardless of
108  // whether the Renderer wants to skip or not.
109  void Update(ImDrawData* imguiData);
110 
111  void OnWindowResized(const Window& window);
112 
113 private:
114  void CreateBuffers(size_t num_required_buffers);
115  void PopulateVertexData(size_t buffer_index,
116  size_t vb_size_in_bytes,
117  void* vb_data,
118  size_t ib_size_in_bytes,
119  void* ib_data);
120  void CreateVertexBuffer(size_t buffer_index, size_t capacity);
121  void CreateIndexBuffer(size_t buffer_index, size_t capacity);
122  void SyncThreads();
123 
124 private:
125  struct Impl;
126  std::unique_ptr<Impl> impl_;
127 };
128 
129 } // namespace gui
130 } // namespace visualization
131 } // namespace open3d
int height
Definition: FilePCD.cpp:72
Definition: Window.h:49
Definition: ImguiFilamentBridge.cpp:148
Definition: PinholeCameraIntrinsic.cpp:35
int width
Definition: FilePCD.cpp:71
Definition: ImguiFilamentBridge.h:93