ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
m3c2.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <pybind11/native_enum.h>
9 #include <pybind11/pybind11.h>
10 
11 #include <qM3C2Dialog.h>
12 #include <qM3C2Process.h>
13 
14 #include <ecvMainAppInterface.h>
15 #include <ecvPointCloud.h>
16 
17 #include <stdexcept>
18 
19 #include "../../src/casters.h"
20 
21 namespace py = pybind11;
22 using namespace pybind11::literals;
23 
24 ccPointCloud *ComputeWrapper(const qM3C2Dialog &dlg, bool allowDialogs)
25 {
26  QString errorMsg;
27  ccPointCloud *outputCloud;
28 
29  // These should be arguments but pybind11 trips on them
30  // in standalone mode, with a TypeError, not sure why
31  QWidget *parentWidget = nullptr;
32  ecvMainAppInterface *app = nullptr;
33  if (app != nullptr)
34  {
35  // It makes CC crash
36  throw py::value_error("non null app pointer is not supported");
37  }
38 
39  bool success =
40  qM3C2Process::Compute(dlg, errorMsg, outputCloud, allowDialogs, parentWidget, app);
41  if (!success)
42  {
43  const std::string msg = errorMsg.toStdString();
44  throw std::runtime_error(msg.c_str());
45  }
46  return outputCloud;
47 }
48 
49 void define_m3c2_plugin(py::module_ &m)
50 {
51  m.attr("plugin_name") = "qM3C2";
52 
53  py::class_<qM3C2Dialog> pyM3C2Dialog(m, "qM3C2Dialog");
54 
55  py::native_enum<qM3C2Dialog::ExportOptions>(
56  pyM3C2Dialog, "ExportOptions", "enum.Enum", "qM3C2Dialog::ExportOptions.")
57  .value("PROJECT_ON_CLOUD1", qM3C2Dialog::ExportOptions::PROJECT_ON_CLOUD1)
58  .value("PROJECT_ON_CLOUD2", qM3C2Dialog::ExportOptions::PROJECT_ON_CLOUD2)
59  .value("PROJECT_ON_CORE_POINTS", qM3C2Dialog::ExportOptions::PROJECT_ON_CORE_POINTS)
60  .export_values()
61  .finalize();
62 
63  pyM3C2Dialog
64  .def(py::init([](ccPointCloud *cloud1, ccPointCloud *cloud2)
65  { return new qM3C2Dialog(cloud1, cloud2, nullptr); }),
66  "cloud1"_a,
67  "cloud2"_a,
68  py::return_value_policy::take_ownership)
69  .def("getCloud1", &qM3C2Dialog::getCloud1, py::return_value_policy::reference)
70  .def("getCloud2", &qM3C2Dialog::getCloud2, py::return_value_policy::reference)
71  .def("getCorePointsCloud",
73  py::return_value_policy::reference)
74  .def("setCorePointsCloud", &qM3C2Dialog::setCorePointsCloud, "cloud"_a)
75  .def("getNormalsOrientationCloud",
77  py::return_value_policy::reference)
78  .def("getExportOption", &qM3C2Dialog::getExportOption)
79  .def("keepOriginalCloud", &qM3C2Dialog::keepOriginalCloud)
80  .def("getMaxThreadCount", &qM3C2Dialog::getMaxThreadCount)
81  .def("loadParamsFromFile",
82  static_cast<bool (qM3C2Dialog::*)(QString)>(&qM3C2Dialog::loadParamsFromFile),
83  "filename"_a)
84  .def("loadParamsFromPersistentSettings", &qM3C2Dialog::loadParamsFromPersistentSettings)
85  .def("saveParamsToPersistentSettings", &qM3C2Dialog::saveParamsToPersistentSettings)
86  .def("exec", &qM3C2Dialog::exec);
87 
88  py::class_<qM3C2Process>(m, "qM3C2Process")
89  .def_static("Compute", &ComputeWrapper, "dialog"_a, "allowsDialog"_a);
90 }
91 
92 PYBIND11_MODULE(pym3c2, m)
93 {
95 }
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Main application interface (for plugins)
M3C2 plugin's main dialog.
Definition: qM3C2Dialog.h:22
void setCorePointsCloud(ccPointCloud *cloud)
Sets the core points cloud.
Definition: qM3C2Dialog.h:44
void loadParamsFromFile()
void loadParamsFromPersistentSettings()
Loads parameters from persistent settings.
ccPointCloud * getNormalsOrientationCloud() const
Returns the cloud to be used for normals orientation (if any)
ExportOptions getExportOption() const
Returns selected export option.
ccPointCloud * getCloud2() const
Returns cloud #2.
Definition: qM3C2Dialog.h:34
ccPointCloud * getCloud1() const
Returns cloud #1.
Definition: qM3C2Dialog.h:32
ccPointCloud * getCorePointsCloud() const
Get core points cloud (if any)
int getMaxThreadCount() const
Returns the max number of threads to use.
bool keepOriginalCloud() const
void saveParamsToPersistentSettings()
Saves parameters to persistent settings.
static bool Compute(const qM3C2Dialog &dlg, QString &errorMessage, ccPointCloud *&outputCloud, bool allowDialogs, QWidget *parentWidget=nullptr, ecvMainAppInterface *app=nullptr)
PYBIND11_MODULE(pym3c2, m)
Definition: m3c2.cpp:92
void define_m3c2_plugin(py::module_ &m)
Definition: m3c2.cpp:49
ccPointCloud * ComputeWrapper(const qM3C2Dialog &dlg, bool allowDialogs)
Definition: m3c2.cpp:24