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 <MeshComparePlugin.hh>
48 #include <QString>
49 #include <QChar>
50 
51 #include <OpenFlipper/BasePlugin/PythonFunctions.hh>
52 #include <OpenFlipper/PythonInterpreter/PythonTypeConversions.hh>
53 
54 namespace py = pybind11;
55 
56 
57 
58 PYBIND11_EMBEDDED_MODULE(MeshCompare, m) {
59 
60  QObject* pluginPointer = getPluginPointer("MeshCompare");
61 
62  if (!pluginPointer) {
63  std::cerr << "Error Getting plugin pointer for Plugin-MeshCompare" << std::endl;
64  return;
65  }
66 
67  MeshComparePlugin* plugin = qobject_cast<MeshComparePlugin*>(pluginPointer);
68 
69  if (!plugin) {
70  std::cerr << "Error converting plugin pointer for Plugin-MeshCompare" << std::endl;
71  return;
72  }
73 
74  // Export our core. Make sure that the c++ worlds core object is not deleted if
75  // the python side gets deleted!!
76  py::class_< MeshComparePlugin,std::unique_ptr<MeshComparePlugin, py::nodelete> > compare(m, "MeshCompare");
77 
78  // On the c++ side we will just return the existing core instance
79  // and prevent the system to recreate a new core as we need
80  // to work on the existing one.
81  compare.def(py::init([plugin]() { return plugin; }));
82 
83  compare.def("compare", &MeshComparePlugin::compare,
84  QCoreApplication::translate("PythonDocMeshCompare","Compares two meshes. Use the getter functions to retrieve the maximal deviations").toLatin1().data(),
85  py::arg(QCoreApplication::translate("PythonDocMeshCompare","ID of the first object").toLatin1().data()),
86  py::arg(QCoreApplication::translate("PythonDocMeshCompare","ID of the second object").toLatin1().data()),
87  py::arg(QCoreApplication::translate("PythonDocMeshCompare","Compute distance between meshes").toLatin1().data()) = true,
88  py::arg(QCoreApplication::translate("PythonDocMeshCompare","Compute normal deviation between meshes").toLatin1().data()) = true,
89  py::arg(QCoreApplication::translate("PythonDocMeshCompare","Compute Gauss curvature deviation between meshes").toLatin1().data()) = true,
90  py::arg(QCoreApplication::translate("PythonDocMeshCompare","Compute mean curvature deviation between meshes").toLatin1().data()) = true );
91 
92  compare.def("lastMaximalDistance", &MeshComparePlugin::lastMaximalDistance,
93  QCoreApplication::translate("PythonDocMeshCompare","Get the maximal distance of the last comparison (-1, if no comparison performed so far)").toLatin1().data() );
94 
95  compare.def("lastMaximalNormalDeviation", &MeshComparePlugin::lastMaximalNormalDeviation,
96  QCoreApplication::translate("PythonDocMeshCompare","Get the maximal normal deviation of the last comparison in degree (-1, if no comparison performed so far)").toLatin1().data() );
97 
98  compare.def("lastMaximalMeanCurvatureDeviation", &MeshComparePlugin::lastMaximalMeanCurvatureDeviation,
99  QCoreApplication::translate("PythonDocMeshCompare","Get the maximal mean curvature deviation of the last comparison (-1, if no comparison performed so far)").toLatin1().data() );
100 
101  compare.def("lastMaximalGaussCurvatureDeviation", &MeshComparePlugin::lastMaximalGaussCurvatureDeviation,
102  QCoreApplication::translate("PythonDocMeshCompare","Get the maximal Gauss curvature deviation of the last comparison (-1, if no comparison performed so far)").toLatin1().data() );
103 
104 }
double lastMaximalMeanCurvatureDeviation()
Get the maximal mean curvature deviation of the last comparison (-1, if no comparison performed so fa...
double lastMaximalNormalDeviation()
Get the maximal normal deviation of the last comparison in degree (-1, if no comparison performed so ...
double lastMaximalGaussCurvatureDeviation()
Get the maximal gauss curvature deviation of the last comparison (-1, if no comparison performed so f...
double lastMaximalDistance()
Get the maximal distance of the last comparison (-1, if no comparison performed so far) ...
void compare(int _sourceId, int _targetId, bool _computeDist=true, bool _computeNormal=true, bool _computeGauss=true, bool _computeMean=true)