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 <MeshObjectInfoPlugin.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(InfoMeshObject, m) {
59 
60  QObject* pluginPointer = getPluginPointer("InfoMeshObject");
61 
62  if (!pluginPointer) {
63  std::cerr << "Error Getting plugin pointer for Plugin-InfoMeshObject" << std::endl;
64  return;
65  }
66 
67  InfoMeshObjectPlugin* plugin = qobject_cast<InfoMeshObjectPlugin*>(pluginPointer);
68 
69  if (!plugin) {
70  std::cerr << "Error converting plugin pointer for Plugin-InfoMeshObject" << 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_< InfoMeshObjectPlugin,std::unique_ptr<InfoMeshObjectPlugin, py::nodelete> > info(m, "InfoMeshObject");
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  info.def(py::init([plugin]() { return plugin; }));
82 
83 
84  info.def("vertexCount", &InfoMeshObjectPlugin::vertexCount,
85  QCoreApplication::translate("PythonDocInfoMeshObject","get total number of verticies of a given object").toLatin1().data(),
86  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
87 
88  info.def("edgeCount", &InfoMeshObjectPlugin::edgeCount,
89  QCoreApplication::translate("PythonDocInfoMeshObject","get total number of edges of a given object").toLatin1().data(),
90  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
91 
92  info.def("faceCount", &InfoMeshObjectPlugin::faceCount,
93  QCoreApplication::translate("PythonDocInfoMeshObject","get total number of faces of a given object").toLatin1().data(),
94  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
95 
96  info.def("boundaryCount", &InfoMeshObjectPlugin::boundaryCount,
97  QCoreApplication::translate("PythonDocInfoMeshObject","get total number of boundaries of a given object").toLatin1().data(),
98  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
99 
100  info.def("componentCount", &InfoMeshObjectPlugin::componentCount,
101  QCoreApplication::translate("PythonDocInfoMeshObject","get total number of components of a given object").toLatin1().data(),
102  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
103 
104  info.def("genus", &InfoMeshObjectPlugin::genus,
105  QCoreApplication::translate("PythonDocInfoMeshObject","get the genus of a given object").toLatin1().data(),
106  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
107 
108  info.def("cog", &InfoMeshObjectPlugin::cog,
109  QCoreApplication::translate("PythonDocInfoMeshObject","get the center of gravity of a given object").toLatin1().data(),
110  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
111 
112  info.def("boundingBoxMin", &InfoMeshObjectPlugin::boundingBoxMin,
113  QCoreApplication::translate("PythonDocInfoMeshObject","get minimum point of the axis-aligned bounding box").toLatin1().data(),
114  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
115 
116  info.def("boundingBoxMax", &InfoMeshObjectPlugin::boundingBoxMax,
117  QCoreApplication::translate("PythonDocInfoMeshObject","get maximum point of the axis-aligned bounding box").toLatin1().data(),
118  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
119 
120  info.def("boundingBoxSize", &InfoMeshObjectPlugin::boundingBoxSize,
121  QCoreApplication::translate("PythonDocInfoMeshObject","get the size of the axis-aligned bounding box").toLatin1().data(),
122  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
123 
124 
125  info.def("edgeLength", &InfoMeshObjectPlugin::edgeLength,
126  QCoreApplication::translate("PythonDocInfoMeshObject","Get the length of an edge").toLatin1().data(),
127  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()),
128  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the edge").toLatin1().data()));
129 
130  info.def("faceArea", &InfoMeshObjectPlugin::faceArea,
131  QCoreApplication::translate("PythonDocInfoMeshObject","Get the area of a face").toLatin1().data(),
132  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()),
133  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the face").toLatin1().data()));
134 
135  info.def("aspectRatio", &InfoMeshObjectPlugin::aspectRatio,
136  QCoreApplication::translate("PythonDocInfoMeshObject","Get the aspect ratio of a face").toLatin1().data(),
137  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()),
138  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the face").toLatin1().data()));
139 
140  info.def("vertexValence", &InfoMeshObjectPlugin::vertexValence,
141  QCoreApplication::translate("PythonDocInfoMeshObject","Get the valence of a vertex").toLatin1().data(),
142  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()),
143  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the vertex").toLatin1().data()));
144 
145  info.def("minEdgeLength", &InfoMeshObjectPlugin::minEdgeLength,
146  QCoreApplication::translate("PythonDocInfoMeshObject","Get the minimal edge length of an object").toLatin1().data(),
147  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
148 
149  info.def("maxEdgeLength", &InfoMeshObjectPlugin::maxEdgeLength,
150  QCoreApplication::translate("PythonDocInfoMeshObject","Get the maximal edge length of an object").toLatin1().data(),
151  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
152 
153  info.def("meanEdgeLength", &InfoMeshObjectPlugin::meanEdgeLength,
154  QCoreApplication::translate("PythonDocInfoMeshObject","Get the mean edge length of an object").toLatin1().data(),
155  py::arg(QCoreApplication::translate("PythonDocInfoMeshObject","ID of the object").toLatin1().data()));
156 }
157 
Plugin to visualize information about objects in the scene.
double meanEdgeLength(int _id)
get the mean edge length
int vertexCount(int _id)
get total number of vertices for a given object
Vector cog(int _id)
get the center of gravity
double aspectRatio(int _id, int _faceHandle)
get the aspect ratio of a face
double maxEdgeLength(int _id)
get the maximal edge length
int vertexValence(int _id, int _vertexHandle)
get vertex valence
double edgeLength(int _id, int _edgeHandle)
get the length of an edge
int boundaryCount(int _id)
get the number of boundaries for a given object
double faceArea(int _id, int _faceHandle)
get the area of a face
int edgeCount(int _id)
get total number of edges for a given object
Vector boundingBoxMax(int _id)
get maximum bounding box point
int faceCount(int _id)
get total number of faces for a given object
Vector boundingBoxSize(int _id)
get the size of the bounding box
Vector boundingBoxMin(int _id)
get minumum bounding box point
int componentCount(int _id)
get the number of components for a given object
double minEdgeLength(int _id)
get the minimal edge length
int genus(int _id)
get the genus of the given object