Developer Documentation

Python.cc
1
2 /*===========================================================================*\
3 * *
4 * OpenFlipper *
5 * Copyright (c) 2001-2015, RWTH-Aachen University *
6 * Department of Computer Graphics and Multimedia *
7 * All rights reserved. *
8 * www.openflipper.org *
9 * *
10 *---------------------------------------------------------------------------*
11 * This file is part of OpenFlipper. *
12 *---------------------------------------------------------------------------*
13 * *
14 * Redistribution and use in source and binary forms, with or without *
15 * modification, are permitted provided that the following conditions *
16 * are met: *
17 * *
18 * 1. Redistributions of source code must retain the above copyright notice, *
19 * this list of conditions and the following disclaimer. *
20 * *
21 * 2. Redistributions in binary form must reproduce the above copyright *
22 * notice, this list of conditions and the following disclaimer in the *
23 * documentation and/or other materials provided with the distribution. *
24 * *
25 * 3. Neither the name of the copyright holder nor the names of its *
26 * contributors may be used to endorse or promote products derived from *
27 * this software without specific prior written permission. *
28 * *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
32 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
40 * *
41 \*===========================================================================*/
42
43 #include <pybind11/include/pybind11/pybind11.h>
44 #include <pybind11/include/pybind11/embed.h>
45
46
47 #include <DecimaterPlugin.hh>
48
49 #include <OpenFlipper/BasePlugin/PythonFunctions.hh>
50 #include <OpenFlipper/PythonInterpreter/PythonTypeConversions.hh>
51
52 namespace py = pybind11;
53
54
55
56 PYBIND11_EMBEDDED_MODULE(Decimater, m) {
57
58 QObject* pluginPointer = getPluginPointer("Decimater");
59
60 if (!pluginPointer) {
61 std::cerr << "Error Getting plugin pointer for Plugin-Decimater" << std::endl;
62 return;
63 }
64
65 DecimaterPlugin* plugin = qobject_cast<DecimaterPlugin*>(pluginPointer);
66
67 if (!plugin) {
68 std::cerr << "Error converting plugin pointer for Plugin-Decimater" << std::endl;
69 return;
70 }
71
72 // Export our core. Make sure that the c++ worlds core object is not deleted if
73 // the python side gets deleted!!
74 py::class_< DecimaterPlugin,std::unique_ptr<DecimaterPlugin, py::nodelete> > decimater(m, "Decimater");
75
76 // On the c++ side we will just return the existing core instance
77 // and prevent the system to recreate a new core as we need
78 // to work on the existing one.
79 decimater.def(py::init([plugin]() { return plugin; }));
80
81
82 decimater.def("decimate", static_cast<void (DecimaterPlugin::*) (int,QString)>(&DecimaterPlugin::decimate),
83 QCoreApplication::translate("PythonDocDecimater","Decimate a mesh. You can use the following parameters:\n\n\
84 decimater_type [0 (Incremental), 1 (MC), 2 (Mixed)] \n\
85 random_samples [For MC/Mixed] \n\
86 incremental_percentage [For Mixed] \n\
87 decimation_order [0 (by distance), 1 (by normal deviation), 2 (by edge length)] \n\
88 distance \n\
89 edge_length \n\
90 normal_deviation \n\
91 roundness \n\
92 aspect_ratio,independent_sets \n\
93 vertices \n\
94 triangles \n\
95 \n\
96 \n\
97 Example call: \n\
98 decimater.decimate(5,\"random_samples=2;decimater_type=2;distance=0.0000001;decimation_order=0\") " ).toLatin1().data(),
99 py::arg(QCoreApplication::translate("PythonDocDecimater","ID of the object").toLatin1().data()),
100 py::arg(QCoreApplication::translate("PythonDocDecimater","List of Decimation parameters as a list separated by ';'").toLatin1().data()) );
101 }
102
DecimaterPlugin
Definition: DecimaterPlugin.hh:92
pybind11
Definition: PythonTypeConversions.hh:49
DecimaterPlugin::decimate
void decimate(int _objID, QVariantMap _constraints)
decimate an object
Definition: DecimaterPlugin.cc:559