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 <MeshRepairPlugin.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(MeshRepair, m) {
59 
60  QObject* pluginPointer = getPluginPointer("MeshRepair");
61 
62  if (!pluginPointer) {
63  std::cerr << "Error Getting plugin pointer for Plugin-MeshRepair" << std::endl;
64  return;
65  }
66 
67  MeshRepairPlugin* plugin = qobject_cast<MeshRepairPlugin*>(pluginPointer);
68 
69  if (!plugin) {
70  std::cerr << "Error converting plugin pointer for Plugin-MeshRepair" << 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_< MeshRepairPlugin,std::unique_ptr<MeshRepairPlugin, py::nodelete> > repair(m, "MeshRepair");
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  repair.def(py::init([plugin]() { return plugin; }));
82 
83  repair.def("detectFlatValence3Vertices", &MeshRepairPlugin::detectFlatValence3Vertices,
84  QCoreApplication::translate("PythonDocMeshRepair","Selects all vertices that have valence 3 and the normals of their neighboring faces have an angle less then the given angle").toLatin1().data(),
85  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()),
86  py::arg(QCoreApplication::translate("PythonDocMeshRepair","Maximal angle between the adjacent faces").toLatin1().data()) );
87 
88  repair.def("removeSelectedVal3Vertices", &MeshRepairPlugin::removeSelectedVal3Vertices,
89  QCoreApplication::translate("PythonDocMeshRepair","Remove all selected valence 3 vertices").toLatin1().data(),
90  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()) );
91 
92 
93  repair.def("selectEdgesShorterThan", &MeshRepairPlugin::selectEdgesShorterThan,
94  QCoreApplication::translate("PythonDocMeshRepair","Selects all edges of an object which are shorter than the given length").toLatin1().data(),
95  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()),
96  py::arg(QCoreApplication::translate("PythonDocMeshRepair","All edges shorter than this length will be selected").toLatin1().data()) );
97 
98  repair.def("selectEdgesLongerThan", &MeshRepairPlugin::selectEdgesLongerThan,
99  QCoreApplication::translate("PythonDocMeshRepair","Selects all edges of an object which are longer than the given length").toLatin1().data(),
100  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()),
101  py::arg(QCoreApplication::translate("PythonDocMeshRepair","All edges longer than this length will be selected").toLatin1().data()) );
102 
103  repair.def("removeSelectedEdges", &MeshRepairPlugin::removeSelectedEdges,
104  QCoreApplication::translate("PythonDocMeshRepair","Remove the selected edges").toLatin1().data(),
105  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()) );
106 
107  repair.def("detectSkinnyTriangleByAngle", &MeshRepairPlugin::detectSkinnyTriangleByAngle,
108  QCoreApplication::translate("PythonDocMeshRepair","Select or remove skinny triangles (determined by a minimum angle threshold).").toLatin1().data(),
109  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()),
110  py::arg(QCoreApplication::translate("PythonDocMeshRepair","Minimum angle threshold").toLatin1().data()),
111  py::arg(QCoreApplication::translate("PythonDocMeshRepair","Remove? (Otherwise they will be selected)").toLatin1().data()));
112 
113  repair.def("detectFoldover", &MeshRepairPlugin::detectFoldover,
114  QCoreApplication::translate("PythonDocMeshRepair","Selects edges that are incident to folded over faces.").toLatin1().data(),
115  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()),
116  py::arg(QCoreApplication::translate("PythonDocMeshRepair","Minimum threshold angle for fold-overs").toLatin1().data()) );
117 
118 
119  repair.def("detectTriangleAspect", &MeshRepairPlugin::detectTriangleAspect,
120  QCoreApplication::translate("PythonDocMeshRepair","Selects all faces that have a larger aspect ratio than the given one.").toLatin1().data(),
121  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()),
122  py::arg(QCoreApplication::translate("PythonDocMeshRepair","The minimal aspect ratio to select").toLatin1().data()) );
123 
124  repair.def("flipOrientation", static_cast<void (MeshRepairPlugin::*) (int)>(&MeshRepairPlugin::flipOrientation),
125  QCoreApplication::translate("PythonDocMeshRepair","Flips the normals of all faces by changing the vertex order in each face").toLatin1().data(),
126  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()) );
127 
128 
129  repair.def("updateFaceNormals", &MeshRepairPlugin::updateFaceNormals,
130  QCoreApplication::translate("PythonDocMeshRepair","Recompute Face normals").toLatin1().data(),
131  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()) );
132 
133  repair.def("updateHalfedgeNormals", &MeshRepairPlugin::updateHalfedgeNormals,
134  QCoreApplication::translate("PythonDocMeshRepair","Recompute Halfedge normals").toLatin1().data(),
135  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()) );
136 
137  repair.def("updateVertexNormals", &MeshRepairPlugin::updateVertexNormals,
138  QCoreApplication::translate("PythonDocMeshRepair","Recompute Vertex normals").toLatin1().data(),
139  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()) );
140 
141  repair.def("updateNormals", &MeshRepairPlugin::updateNormals,
142  QCoreApplication::translate("PythonDocMeshRepair","Recompute Face and Vertex normals").toLatin1().data(),
143  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()) );
144 
145  repair.def("snapBoundary", &MeshRepairPlugin::snapBoundary,
146  QCoreApplication::translate("PythonDocMeshRepair","Snaps selected boundary vertices together if they are closer than the given distance. No new vertices will be introduced on either edge, so they are just snapped to existing ones.").toLatin1().data(),
147  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()),
148  py::arg(QCoreApplication::translate("PythonDocMeshRepair","Max snapping distance").toLatin1().data()) );
149 
150  repair.def("fixNonManifoldVertices", &MeshRepairPlugin::fixNonManifoldVertices,
151  QCoreApplication::translate("PythonDocMeshRepair","Remove non-manifold vertices by duplicating them").toLatin1().data(),
152  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()) );
153 
154  repair.def("fixMesh", &MeshRepairPlugin::fixMesh,
155  QCoreApplication::translate("PythonDocMeshRepair","Fix Mesh: Degenerated faces will be removed and all vertices which are closer than the given distance will be collapsed. Non-manifold configurations at vertices will be removed and all faces of each component will be updated to have the same orientation.").toLatin1().data(),
156  py::arg(QCoreApplication::translate("PythonDocMeshRepair","ID of the object").toLatin1().data()),
157  py::arg(QCoreApplication::translate("PythonDocMeshRepair","Max snapping distance").toLatin1().data()) );
158 
159 }
160 
void detectSkinnyTriangleByAngle(int _objectId, double _angle, bool _remove)
Detect/Remove edges where neighboring faces form angle > _angle degrees.
void updateNormals(int _objectId)
Recomputes the face and vertex normals of an object.
void fixMesh(int _objectId, double _epsilon)
Fix a mesh.
void selectEdgesLongerThan(int _objectId, double _length)
Selects all edges of an object which are larger than the given length.
void updateVertexNormals(int _objectId)
Recomputes the vertex normals of an object.
void selectEdgesShorterThan(int _objectId, double _length)
Selects all edges of an object which are shorter than the given length.
void removeSelectedEdges(int _objectId)
Removes all selected edges.
void flipOrientation(int _objectId)
Flips the normals of all selected faces by changing the vertex order.
void fixNonManifoldVertices(int _objectId)
remove non-manifold vertices by duplicating them
void updateHalfedgeNormals(int _objectId)
Recomputes the halfedge normals of an object.
Definition: NormalFixing.cc:82
void snapBoundary(int _objectId, double _eps)
Snaps selected vertices at boundaries.
void detectFlatValence3Vertices(int _objectId, double _angle)
Detect valence 3 vertices with faces that lie in the plane of their adjacent triangles.
void detectFoldover(int _objectId, float _angle)
Detect folded-over configurations by the dihedral angle.
void detectTriangleAspect(int _objectId, float _aspect)
Detect triangles with aspect ratio greater than _aspect and select them.
void removeSelectedVal3Vertices(int _objectId)
Remove all selected valence 3 vertices.
void updateFaceNormals(int _objectId)
Recomputes the face normals of an object.
Definition: NormalFixing.cc:53