10 #include <QMainWindow>
11 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
12 #include <QtOpenGLWidgets/QOpenGLWidget>
14 #include <QOpenGLWidget>
16 #include <QProgressDialog>
22 #include <pybind11/numpy.h>
23 #include <pybind11/stl_bind.h>
25 #ifdef PYCC_STAND_ALONE
28 #include <QApplication>
29 #include <QCoreApplication>
33 using namespace pybind11::literals;
39 template <
class T>
using observer_ptr = std::unique_ptr<T, py::nodelete>;
42 typename std::enable_if<std::is_same<T, double>::value,
void>
::type
45 m.attr(
"ScalarType") = py::dtype(
"float64");
51 m.attr(
"ScalarType") = py::dtype(
"float32");
66 #ifdef PYCC_STAND_ALONE
68 const py::module_ os = py::module_::import(
"os");
69 const py::module_ sysconfig = py::module_::import(
"sysconfig");
70 const QString site_packages = sysconfig.attr(
"get_path")(
"purelib").cast<QString>();
71 const QString platform_path = QString(
"%1\\pycc\\platforms").arg(site_packages);
72 const std::string std_platform_path = platform_path.toStdString();
73 os.attr(
"environ")[
"QT_QPA_PLATFORM_PLUGIN_PATH"] = std_platform_path;
76 static char fakeArg0[] =
"pycc";
77 static char *fakeArgv[] = {&fakeArg0[0],
NULL};
79 if (QCoreApplication::instance() ==
nullptr)
81 new QApplication(argc, &fakeArgv[0]);
90 #if PYBIND11_VERSION_MINOR >= 5
91 const py::module_ pycc_runtime = py::module_::import(
"pycc_runtime");
93 const py::module pycc_runtime = py::module::import(
"pycc_runtime");
95 const auto runtime_module_content = pycc_runtime.attr(
"__dict__").cast<py::dict>();
96 const auto pycc_module_content = m.attr(
"__dict__").cast<py::dict>();
98 for (
const auto &entry : runtime_module_content)
100 pycc_module_content[entry.first] = entry.second;
106 py::class_<QWidget>(m,
"QWidget");
107 py::class_<QOpenGLWidget>(m,
"QOpenGLWidget");
108 py::class_<QProgressDialog, QWidget>(m,
"QProgressDialog");
109 py::class_<QMainWindow, QWidget>(m,
"QMainWindow");
110 py::class_<QFont>(m,
"QFont")
112 [](
const QFont &
self)
113 {
return std::string(
"<QFont(") +
self.toString().toStdString() +
")>"; });
114 py::class_<QSize>(m,
"QSize")
116 .def(py::init<int, int>(),
"width"_a,
"height"_a)
119 .def(
"isEmpty", &QSize::isEmpty)
120 .def(
"isValid", &QSize::isValid)
122 [](
const QSize &
self)
128 py::class_<QPointF>(m,
"QPointF");
130 py::enum_<Qt::CursorShape>(m,
"QtCursorShape");
136 Python module exposing some ACloudViewer functions
141 py::module::import("cccorelib");
143 #ifdef PYCC_STAND_ALONE
148 FileIOFilter::InitInternalFilters();
153 m.attr(
"PointCoordinateType") = py::dtype(
"float32");
154 define_scalar_type<ScalarType>(m);
165 catch (std::exception &e)
170 #ifdef DEFINE_PYCC_RUNTIME
175 catch (std::exception &e)
177 CVLog::Warning(
"Failed to import pycc_runtime content: ", e.what());
182 #ifdef USE_EMBEDDED_MODULES
183 #include <pybind11/embed.h>
PYBIND11_EMBEDDED_MODULE(ccinternals, m)
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static void RegisterInstance(CVLog *logInstance)
Registers a unique instance.
std::string to_string(const T &n)
void import_pyccRuntime(py::module &m)
void load_pluginWrappers(py::module &)
std::enable_if< std::is_same< T, double >::value, void >::type define_scalar_type(py::module &m)
void define_someQtThings(py::module &m)
void define_pycc(py::module &m)
void define_qcc_db(py::module &)
void define_qcc_io(py::module &)
std::unique_ptr< T, py::nodelete > observer_ptr
A unique_ptr that never free its ptr.