Open3D (C++ API)  0.11.0
ImguiFilamentBridge.h
Go to the documentation of this file.
1 // Altered from Filament's ImGuiHelper.cpp
2 // Filament code is from somewhere close to v1.4.3 and is:
3 /*
4  * Copyright (C) 2018 The Android Open Source Project
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 // Open3D alterations are:
19 // ----------------------------------------------------------------------------
20 // - Open3D: www.open3d.org -
21 // ----------------------------------------------------------------------------
22 // The MIT License (MIT)
23 //
24 // Copyright (c) 2018 www.open3d.org
25 //
26 // Permission is hereby granted, free of charge, to any person obtaining a copy
27 // of this software and associated documentation files (the "Software"), to deal
28 // in the Software without restriction, including without limitation the rights
29 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
30 // copies of the Software, and to permit persons to whom the Software is
31 // furnished to do so, subject to the following conditions:
32 //
33 // The above copyright notice and this permission notice shall be included in
34 // all copies or substantial portions of the Software.
35 //
36 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
41 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
42 // IN THE SOFTWARE.
43 // ----------------------------------------------------------------------------
44 
45 #pragma once
46 
47 // 4068: Filament has some clang-specific vectorizing pragma's that MSVC flags
48 // 4146: PixelBufferDescriptor assert unsigned is positive before subtracting
49 // but MSVC can't figure that out.
50 // 4293: Filament's utils/algorithm.h utils::details::clz() does strange
51 // things with MSVC. Somehow sizeof(unsigned int) > 4, but its size is
52 // 32 so that x >> 32 gives a warning. (Or maybe the compiler can't
53 // determine the if statement does not run.)
54 #ifdef _MSC_VER
55 #pragma warning(push)
56 #pragma warning(disable : 4068 4146 4293)
57 #endif // _MSC_VER
58 
59 #include <filament/Engine.h>
60 #include <filament/IndexBuffer.h>
61 #include <filament/Material.h>
62 #include <filament/MaterialInstance.h>
63 #include <filament/Texture.h>
64 #include <filament/VertexBuffer.h>
65 #include <filament/View.h>
66 
67 #ifdef _MSC_VER
68 #pragma warning(pop)
69 #endif // _MSC_VER
70 
71 #include <cstddef> // <filament/Engine> recursive includes needs this, std::size_t especially
72 #include <memory>
73 
74 struct ImDrawData;
75 
76 namespace open3d {
77 
78 namespace visualization {
79 namespace rendering {
80 class FilamentRenderer;
81 }
82 } // namespace visualization
83 
84 namespace visualization {
85 namespace gui {
86 
87 struct Size;
88 class Window;
89 
90 // Translates ImGui's draw commands into Filament primitives, textures, vertex
91 // buffers, etc. Creates a UI-specific Scene object and populates it with a
92 // Renderable. Does not handle event processing; clients can simply call
93 // ImGui::GetIO() directly and set the mouse state.
95 public:
97  const Size& window_size);
99 
100  // Helper method called after resolving fontPath; public so fonts can be
101  // added by caller. Requires the appropriate ImGuiContext to be current
102  void CreateAtlasTextureAlpha8(unsigned char* pixels,
103  int width,
104  int height,
105  int bytes_per_px);
106 
107  // This populates the Filament View. Clients are responsible for
108  // rendering the View. This should be called on every frame, regardless of
109  // whether the Renderer wants to skip or not.
110  void Update(ImDrawData* imguiData);
111 
112  void OnWindowResized(const Window& window);
113 
114 private:
115  void CreateBuffers(size_t num_required_buffers);
116  void PopulateVertexData(size_t buffer_index,
117  size_t vb_size_in_bytes,
118  void* vb_data,
119  size_t ib_size_in_bytes,
120  void* ib_data);
121  void CreateVertexBuffer(size_t buffer_index, size_t capacity);
122  void CreateIndexBuffer(size_t buffer_index, size_t capacity);
123  void SyncThreads();
124 
125 private:
126  struct Impl;
127  std::unique_ptr<Impl> impl_;
128 };
129 
130 } // namespace gui
131 } // namespace visualization
132 } // namespace open3d
Definition: Window.h:50
Definition: ImguiFilamentBridge.cpp:149
Definition: PinholeCameraIntrinsic.cpp:35
int height
Definition: FilePCD.cpp:72
Definition: ImguiFilamentBridge.h:94
int width
Definition: FilePCD.cpp:71