File: visualization.h

package info (click to toggle)
open3d 0.19.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,496 kB
  • sloc: cpp: 206,543; python: 27,254; ansic: 8,356; javascript: 1,883; sh: 1,527; makefile: 259; xml: 69
file content (71 lines) | stat: -rw-r--r-- 2,737 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// ----------------------------------------------------------------------------
// -                        Open3D: www.open3d.org                            -
// ----------------------------------------------------------------------------
// Copyright (c) 2018-2024 www.open3d.org
// SPDX-License-Identifier: MIT
// ----------------------------------------------------------------------------

#pragma once

#include "pybind/open3d_pybind.h"
#include "pybind11/functional.h"

// We cannot give out a shared_ptr to objects like Window which reference
// Filament objects, because we cannot guarantee that the Python script is
// not holding on to a reference when we cleanup Filament. The Open3D library
// will clear its shared_ptrs expecting the dependent object(s) to clean up,
// but they won't because Python still has a shared_ptr, leading to a crash
// when the variable goes of scope on the Python side.
// The following would crash gui.Window's holder is std::shared_ptr:
//   import open3d.visualization.gui as gui
//   def main():
//       gui.Application.instance.initialize()
//       w = gui.Application.instance.create_window("Crash", 640, 480)
//       gui.Application.instance.run()
//   if __name__ == "__main__":
//       main()
// However, if remove the 'w = ' part, it would not crash.
template <typename T>
class UnownedPointer {
public:
    UnownedPointer() : ptr_(nullptr) {}
    explicit UnownedPointer(T *p) : ptr_(p) {}
    ~UnownedPointer() {}  // don't delete!

    T *get() { return ptr_; }
    T &operator*() { return *ptr_; }
    T *operator->() { return ptr_; }
    void reset() { ptr_ = nullptr; }  // don't delete!

private:
    T *ptr_;
};
PYBIND11_DECLARE_HOLDER_TYPE(T, UnownedPointer<T>);

namespace open3d {
namespace visualization {

template <typename T>
std::shared_ptr<T> TakeOwnership(UnownedPointer<T> x) {
    return std::shared_ptr<T>(x.get());
}

// Please update docs/python_api_in/open3d.visualization.rst when adding /
// reorganizing submodules to open3d.visualization.

void pybind_visualization_declarations(py::module &m);
void pybind_renderoption_declarations(py::module &m);
void pybind_viewcontrol_declarations(py::module &m);
void pybind_visualizer_declarations(py::module &m);
void pybind_visualization_utility_declarations(py::module &m);
void pybind_o3dvisualizer_declarations(py::module &m);

void pybind_visualization_definitions(py::module &m);
void pybind_renderoption_definitions(py::module &m);
void pybind_viewcontrol_definitions(py::module &m);
void pybind_visualizer_definitions(py::module &m);
void pybind_visualization_utility_definitions(py::module &m);
void pybind_o3dvisualizer_definitions(py::module &m);

}  // namespace visualization
}  // namespace open3d